#include #include #include #include #include "gadget_io.h" /*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/ /*---------------------------- Small Example HowToUse -------------------------*/ /*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/ int main(int argc, char **argv) { FILE *fd = 0; char filename[265]; if(argc >= 2) { for(int f = 0; f < argc-1; f++) { strcpy(filename,argv[1+f]); if(!(fd = fopen(filename,"r"))) { printf("Cant open file <%s> !\n",filename); exit(2); } else { /*----------- RED HEADER TO GET GLOBAL PROPERTIES -------------*/ int npart[6]; double masstab[6],redshift,time; int n = read_gadget_head(npart,masstab,&time,&redshift,fd); int ntot=0; for(int i = 0; i < 6; i++) ntot += npart[i]; /*---------- ALLOCATE MEMORY ---------------------------------*/ vec3 *pos; pos=malloc(3*ntot*sizeof(float)); /*---------- READ DATA BLOCKS --------------------------------*/ n = read_gadget_float3((float*)pos,"POS ",fd); for(int i = 0; i < npart[1]; i++) printf("%d %f %f %f\n",i,pos[i].x,pos[i].y,pos[i].z); /*---------- FREE DATA ------------------------*/ free(pos); } /*---------- CLOSE FILE AND FREE DATA ------------------------*/ fclose(fd); printf("\n\n"); // empty line for gnuplot to distinguish blocks } } else { printf("Please give at least one filename ...\n"); exit(4); } exit(0); }