/*! \file nchiladaio.cxx * \brief this file contains routines for nchilada snapshot file io */ #include "stf.h" #include "nchiladaitems.h" #ifdef USEXDR ///\name XDR read routines, assist in reading nchilada data //@{ int xdr_header(XDR *pxdrs,struct tipsy_dump *ph) { int pad = 0; if (!xdr_double(pxdrs,&ph->time)) return 0; if (!xdr_int(pxdrs,&ph->nbodies)) return 0; if (!xdr_int(pxdrs,&ph->ndim)) return 0; if (!xdr_int(pxdrs,&ph->nsph)) return 0; if (!xdr_int(pxdrs,&ph->ndark)) return 0; if (!xdr_int(pxdrs,&ph->nstar)) return 0; if (!xdr_int(pxdrs,&pad)) return 0; return 1; } int xdr_gas(XDR *pxdrs,struct tipsy_gas_particle *ph) { int i; if (!xdr_float(pxdrs,&ph->mass)) return 0; for(i=0; ipos[i])) return 0; for(i=0; ivel[i])) return 0; if (!xdr_float(pxdrs,&ph->rho)) return 0; if (!xdr_float(pxdrs,&ph->temp)) return 0; if (!xdr_float(pxdrs,&ph->hsmooth)) return 0; if (!xdr_float(pxdrs,&ph->metals)) return 0; if (!xdr_float(pxdrs,&ph->phi)) return 0; return 1; } int xdr_dark(XDR *pxdrs,struct tipsy_dark_particle *ph) { int i; if (!xdr_float(pxdrs,&ph->mass)) return 0; for(i=0; ipos[i])) return 0; for(i=0; ivel[i])) return 0; if (!xdr_float(pxdrs,&ph->eps)) return 0; if (!xdr_float(pxdrs,&ph->phi)) return 0; return 1; } int xdr_star(XDR *pxdrs,struct tipsy_star_particle *ph) { int i; if (!xdr_float(pxdrs,&ph->mass)) return 0; for(i=0; ipos[i])) return 0; for(i=0; ivel[i])) return 0; if (!xdr_float(pxdrs,&ph->metals)) return 0; if (!xdr_float(pxdrs,&ph->tform)) return 0; if (!xdr_float(pxdrs,&ph->eps)) return 0; if (!xdr_float(pxdrs,&ph->phi)) return 0; return 1; } int xdr_NCHeader(XDR *pxdrs,struct nchilada_dump *ph) { if (!xdr_int(pxdrs,&ph->magic)) return 0; if (!xdr_double(pxdrs,&ph->time)) return 0; if (!xdr_int(pxdrs,&ph->iHighWord)) return 0; if (!xdr_int(pxdrs,&ph->nbodies)) return 0; if (!xdr_int(pxdrs,&ph->ndim)) return 0; if (!xdr_int(pxdrs,&ph->code)) return 0; return 1; } void xdr_NC_Open(XDR *xdrs, enum xdr_op op, FILE **fp, char *achInFile, long lstart) { if(op == XDR_DECODE) *fp = fopen(achInFile,"r"); else if(op == XDR_ENCODE && lstart) *fp = fopen(achInFile,"a"); else if(op == XDR_ENCODE && lstart == 0) *fp = fopen(achInFile,"w"); assert(*fp); fseek(*fp,lstart,0); xdrstdio_create(xdrs,*fp,op); } /* int xdr_type(XDR *pxdrs, void *data, int type, int num) { char *pachTmp; short *psTmp; int *piTmp; int iTmp; float *pfTmp; float fTmp; long *plTmp; long lTmp; double *pdTmp; double dTmp; int j; switch (type) { case int8: pachTmp = ((char *)data); for(j=0; j &Part, const Int_t nbodies,Particle *&Pbaryons, Int_t nbaryons) { Int_t i,j,k,n,nchunk; u_int64_t numParticles=nbodies,startParticle=0; //counters Int_t count,countsph,countstar,countbh,count2,bcount,bcount2,pc,pc_new, Ntot,indark,ingas,instar,inbh,Ntotfile; Int_t ntot_withmasses; char buf[2000]; char DATA[5]; string message; //store cosmology double z,aadjust,Hubble,Hubbleflow; Double_t mscale,lscale,lvscale; Double_t MP_DM=MAXVALUE,LN,N_DM,MP_B=0; int ifirstfile=0,ireaderror=0; std::vector ireadfile; int *ireadtask,*readtaskID; int nusetypes,nbusetypes; int usetypes[NNCHILADATYPE]; Nchilada_Part_Names nchilada_part_name; //common attributes /* fstream fpos[NNCHILADATYPE],fvel[NNCHILADATYPE],fmass[NNCHILADATYPE]; fstream fgasu,fgasz,fgassfr; fstream fstartage,fstarz; */ FILE *fpos[NNCHILADATYPE],*fvel[NNCHILADATYPE],*fmass[NNCHILADATYPE],*fid[NNCHILADATYPE]; FILE *fgasu,*fgasz,*fgassfr; FILE *fstartage,*fstarz; nchilada_dump fhpos,fhvel,fhmass,fhid,fhgasu,fhgasz,fhgassfr,fhstartage,fhstarz; void *posdata,*veldata,*massdata,*iddata,*gasudata,*gaszdata,*gassfrdata,*startagedata,*starzdata; Double_t tageval; int *intbuff; long long *longbuff; unsigned int *uintbuff; unsigned long long *ulongbuff; float *posfloatbuff,*velfloatbuff,*massfloatbuff; float *gasufloatbuff,*gassfrfloatbuff,*gaszfloatbuff; float *starzfloatbuff,*startagefloatbuff; double *posdoublebuff,*veldoublebuff,*massdoublebuff; double *gasudoublebuff,*gassfrdoublebuff,*gaszdoublebuff; double *starzdoublebuff,*startagedoublebuff; if (opt.partsearchtype==PSTALL) { //lets assume there are dm/stars/gas. nusetypes=3; usetypes[0]=NCHILADAGASTYPE;usetypes[1]=NCHILADADMTYPE;usetypes[2]=NCHILADASTARTYPE; } else if (opt.partsearchtype==PSTDARK) { nusetypes=1;usetypes[0]=NCHILADADMTYPE; if (opt.iBaryonSearch) { nbusetypes=2;usetypes[1]=NCHILADAGASTYPE;usetypes[2]=NCHILADASTARTYPE; } } else if (opt.partsearchtype==PSTGAS) {nusetypes=1;usetypes[0]=NCHILADAGASTYPE;} else if (opt.partsearchtype==PSTSTAR) {nusetypes=1;usetypes[0]=NCHILADASTARTYPE;} #ifndef USEMPI Int_t Ntotal; int ThisTask=0,NProcs=1; ireadfile = std::vector(opt.num_files, 1); #endif //if verbose spit out the types of particles that are going to be searched for if (ThisTask==0 && opt.iverbose>1) { cout<<" --------------- "<=0) { //to temporarily store data from gadget file Pbuf=new Particle[BufSize*NProcs]; Nreadbuf=new Int_t[opt.num_files]; for (int j=0;j(opt.num_files); ifirstfile=MPISetFilesRead(opt,ireadfile,ireadtask); } else { Nlocalthreadbuf=new Int_t[opt.nsnapread]; irecv=new int[opt.nsnapread]; mpi_irecvflag=new int[opt.nsnapread]; for (i=0;i=0) { #endif //now for each file lets open up the fstream file pointers /* for (j=0;j=1) || opt.partsearchtype==PSTGAS) { fgasu.open((string(opt.fname)+ nchilada_part_name.part_names[NCHILADAGASTYPE]+string("U")).c_str()); fgassfr.open((string(opt.fname)+ nchilada_part_name.part_names[NCHILADAGASTYPE]+string("SFR")).c_str()); fgasz.open((string(opt.fname)+ nchilada_part_name.part_names[NCHILADAGASTYPE]+string("Z")).c_str()); } if (opt.partsearchtype==PSTALL || (opt.partsearchtype==PSTDARK && opt.iBaryonSearch>=1) || opt.partsearchtype==PSTGAS) { fstartage.open((string(opt.fname)+ nchilada_part_name.part_names[NCHILADASTARTYPE]+string("U")).c_str()); fstarz.open((string(opt.fname)+ nchilada_part_name.part_names[NCHILADASTARTYPE]+string("Z")).c_str()); } */ for (j=0;j=1) || opt.partsearchtype==PSTGAS) { fgasu=fopen((string(opt.fname)+ nchilada_part_name.part_names[NCHILADAGASTYPE]+string("U")).c_str(), "rb"); #ifdef STARON fgassfr=fopen((string(opt.fname)+ nchilada_part_name.part_names[NCHILADAGASTYPE]+string("SFR")).c_str(), "rb"); fgasz=fopen((string(opt.fname)+ nchilada_part_name.part_names[NCHILADAGASTYPE]+string("Z")).c_str(), "rb"); #endif } #endif #if defined(STARON) || defined(BHON) if (opt.partsearchtype==PSTALL || (opt.partsearchtype==PSTDARK && opt.iBaryonSearch>=1) || opt.partsearchtype==PSTGAS) { fstartage=fopen((string(opt.fname)+ nchilada_part_name.part_names[NCHILADASTARTYPE]+string("U")).c_str(), "rb"); fstarz=fopen((string(opt.fname)+ nchilada_part_name.part_names[NCHILADASTARTYPE]+string("Z")).c_str(), "rb"); } #endif //will need to think how best to read stuff in chunks for (j=0;j0) Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetType(STARTYPE); else Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetType(BHTYPE); #else Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetType(STARTYPE); #endif } #ifdef GASON if (k==NCHILADAGASTYPE) { if (fhgasu.code==float32) Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetU(gasufloatbuff[i]); else Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetU(gasudoublebuff[i]); #ifdef STARON if (fhgassfr.code==float32) Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetSFR(gassfrfloatbuff[i]); else Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetSFR(gassfrdoublebuff[i]); if (fhgasz.code==float32) Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetZmet(gaszfloatbuff[i]); else Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetZmet(gaszdoublebuff[i]); #endif } #endif #ifdef STARON if (k==NCHILADASTARTYPE) { if (fhstartage.code==float32) tageval=startagefloatbuff[i]; else tageval=startagedoublebuff[i]; #ifdef BHON if (tageval<0) tageval*=-1; #endif if (fhstarz.code==float32) Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetZmet(starzfloatbuff[i]); else Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetZmet(starzdoublebuff[i]); Pbuf[ibuf*BufSize+Nbuf[ibuf]].SetTage(tageval); } #endif if(ireadtask[ibuf]>=0&&ibuf!=ThisTask) Nreadbuf[ireadtask[ibuf]]++; Nbuf[ibuf]++; if (ibuf==ThisTask) { Nbuf[ibuf]--; Part[Nlocal++]=Pbuf[ibuf*BufSize+Nbuf[ibuf]]; } else { //before a simple send was done because only Task zero was reading the data //but now if ibuf=0) { Nbuf[ibuf]=0; } } //start of non mpi section #else if (fhpos.code==float32) { Part[i].SetPosition(posfloatbuff[i],posfloatbuff[i+nbodies],posfloatbuff[i+nbodies*2]); Part[i].SetVelocity(velfloatbuff[i],velfloatbuff[i+nbodies],velfloatbuff[i+nbodies*2]); Part[i].SetMass(massfloatbuff[i]); } else { Part[i].SetPosition(posdoublebuff[i],posdoublebuff[i+nbodies],posdoublebuff[i+nbodies*2]); Part[i].SetVelocity(veldoublebuff[i],veldoublebuff[i+nbodies],veldoublebuff[i+nbodies*2]); Part[i].SetMass(massdoublebuff[i]); } if (fhid.code==uint32) Part[i].SetPID(intbuff[i]); else Part[i].SetPID(longbuff[i]); Part[i].SetID(i); if (k==NCHILADAGASTYPE) Part[i].SetType(GASTYPE); else if (k==NCHILADADMTYPE) Part[i].SetType(DARKTYPE); else if (k==NCHILADASTARTYPE) { #ifdef BHON if (fhstartage.code==float32) tageval=startagefloatbuff[i]; else tageval=startagedoublebuff[i]; if (tageval>0) Part[i].SetType(STARTYPE); else Part[i].SetType(BHTYPE); #else Part[i].SetType(STARTYPE); #endif } #ifdef GASON if (k==NCHILADAGASTYPE) { if (fhgasu.code==float32) Part[i].SetU(gasufloatbuff[i]); else Part[i].SetU(gasudoublebuff[i]); #ifdef STARON if (fhgassfr.code==float32) Part[i].SetSFR(gassfrfloatbuff[i]); else Part[i].SetSFR(gassfrdoublebuff[i]); if (fhgasz.code==float32) Part[i].SetZmet(gaszfloatbuff[i]); else Part[i].SetZmet(gaszdoublebuff[i]); #endif } #endif #ifdef STARON if (k==NCHILADASTARTYPE) { if (fhstartage.code==float32) tageval=startagefloatbuff[i]; else tageval=startagedoublebuff[i]; #ifdef BHON if (tageval<0) tageval*=-1; #endif if (fhstarz.code==float32) Part[i].SetZmet(starzfloatbuff[i]); else Part[i].SetZmet(starzdoublebuff[i]); Part[i].SetTage(tageval); } #endif #endif //end of mpi ifdef }//end of loop over particles }//end of loop over particle types //close files for (j=0;j=1) || opt.partsearchtype==PSTGAS) { fclose(fgasu); #ifdef STARON fclose(fgassfr); fclose(fgasz); #endif } #endif #if defined(STARON) || defined(BHON) if (opt.partsearchtype==PSTALL || (opt.partsearchtype==PSTDARK && opt.iBaryonSearch>=1) || opt.partsearchtype==PSTGAS) { fclose(fstartage); fclose(fstarz); } #endif #ifdef USEMPI }//end of read task section else { MPIReceiveParticlesFromReadThreads(opt,Pbuf,Part.data(),readtaskID, irecv, mpi_irecvflag, Nlocalthreadbuf, mpi_request,Pbaryons); } for (i=0;i=0 && opt.nsnapread>1) { delete[] Pbuf; Nlocalbuf=0; for (i=0;i0) { Pbuf=new Particle[Nlocalbuf]; //determine offsets nreadoffset[0]=0;for (i=1;i 0) { Nbuf[ibuf]=0; for (i=0;i=0) { delete[] Pbuf; if (opt.iBaryonSearch && opt.partsearchtype!=PSTALL) delete[] mpi_nsend_baryon; //set IDS for (i=0;i