int main(void) { float *a = createvect(NUM); // assign an int setvect(NUM, a, 1); assignInt(NUM, a); printf("0: a = "); printvect(NUM, a); printf("\n"); // assign then reassign an int setvect(NUM, a, 1); reassignInt(NUM, a); printf("1: a = "); printvect(NUM, a); printf("\n"); // assign a foat setvect(NUM, a, 1); assignFloat(NUM, a); printf("2: a = "); printvect(NUM, a); printf("\n"); // assign then reassign a float setvect(NUM, a, 1); reassignFloat(NUM, a); printf("3: a = "); printvect(NUM, a); printf("\n"); // tricky example setvect(NUM, a, 1); tricky(NUM, a); printf("4: a = "); printvect(NUM, a); printf("\n"); return 0; }
int FofReader::getNextRow() { assert(fileStream.is_open()); // read one line char memchunk[numBytesPerRow]; //cout<<"reader: currRow: "<<currRow<<endl; //read the line (one halo) at once if (!fileStream.read(memchunk,numBytesPerRow)) { return 0; } // now parse the line and assign it to the proper variables using memcpy assignInt( &lkl, &memchunk[0], swap); assignInt( &iadr, &memchunk[sizeof(int)], swap); assignFloat(&rc1, &memchunk[2*sizeof(int)], swap); assignFloat(&rc2, &memchunk[2*sizeof(int)+1*sizeof(float)], swap); assignFloat(&rc3, &memchunk[2*sizeof(int)+2*sizeof(float)], swap); assignFloat(&vc1, &memchunk[2*sizeof(int)+3*sizeof(float)], swap); assignFloat(&vc2, &memchunk[2*sizeof(int)+4*sizeof(float)], swap); assignFloat(&vc3, &memchunk[2*sizeof(int)+5*sizeof(float)], swap); assignFloat(&total_mass, &memchunk[2*sizeof(int)+6*sizeof(float)], swap); assignFloat(&xv1, &memchunk[2*sizeof(int)+7*sizeof(float)], swap); assignFloat(&xv2, &memchunk[2*sizeof(int)+8*sizeof(float)], swap); assignFloat(&xv3, &memchunk[2*sizeof(int)+9*sizeof(float)], swap); assignFloat(&xlambda, &memchunk[2*sizeof(int)+10*sizeof(float)], swap); assignFloat(&disp, &memchunk[2*sizeof(int)+11*sizeof(float)], swap); assignFloat(&vdisp, &memchunk[2*sizeof(int)+12*sizeof(float)], swap); assignFloat(&root1, &memchunk[2*sizeof(int)+13*sizeof(float)], swap); assignFloat(&root2, &memchunk[2*sizeof(int)+14*sizeof(float)], swap); assignFloat(&root3, &memchunk[2*sizeof(int)+15*sizeof(float)], swap); assignFloat(&vol8, &memchunk[2*sizeof(int)+16*sizeof(float)], swap); assignFloat(&delta, &memchunk[2*sizeof(int)+17*sizeof(float)], swap); assignFloat(&e_kin, &memchunk[2*sizeof(int)+18*sizeof(float)], swap); assignFloat(&vect[0], &memchunk[2*sizeof(int)+19*sizeof(float)], swap); assignFloat(&vect[1], &memchunk[2*sizeof(int)+20*sizeof(float)], swap); assignFloat(&vect[2], &memchunk[2*sizeof(int)+21*sizeof(float)], swap); assignFloat(&vect[3], &memchunk[2*sizeof(int)+22*sizeof(float)], swap); assignFloat(&vect[4], &memchunk[2*sizeof(int)+23*sizeof(float)], swap); assignFloat(&vect[5], &memchunk[2*sizeof(int)+24*sizeof(float)], swap); assignFloat(&vect[6], &memchunk[2*sizeof(int)+25*sizeof(float)], swap); assignFloat(&vect[7], &memchunk[2*sizeof(int)+26*sizeof(float)], swap); assignFloat(&vect[8], &memchunk[2*sizeof(int)+27*sizeof(float)], swap); assignInt( &ispecies[0], &memchunk[2*sizeof(int)+28*sizeof(float)], swap); assignInt( &ispecies[1], &memchunk[2*sizeof(int)+28*sizeof(float)+1*sizeof(int)], swap); assignInt( &ispecies[2], &memchunk[2*sizeof(int)+28*sizeof(float)+2*sizeof(int)], swap); assignInt( &ispecies[3], &memchunk[2*sizeof(int)+28*sizeof(float)+3*sizeof(int)], swap); assignInt( &ispecies[4], &memchunk[2*sizeof(int)+28*sizeof(float)+4*sizeof(int)], swap); assignInt( &ispecies[5], &memchunk[2*sizeof(int)+28*sizeof(float)+5*sizeof(int)], swap); currRow++; // stop reading/ingesting, if number of particles (lkl) gets smaller than 20 // Note: This only works like this, if halos are sorted by mass desc! if (lkl < nlimit) { printf("Limiting number of particles in FOF group is reached (%d < %d).\n", lkl, nlimit); return 0; } // stop after reading maxRows, but only if it is not -1 // Note: Could this be accelerated? It's unnecessary most of the time, // but now it is evaluated for each row ... if (maxRows != -1) { if (currRow-startRow > maxRows) { printf("Maximum number of rows to be ingested is reached (%d).\n", maxRows); return 0; } } return 1; }