/* Contains C subroutines callable from f77 to handle files. */ #include #include "defs.h" FILE *fp; void open_file__(char *name, int *iwarn) { char filename[80]; int i; for (i=0; i<80; i++){ if (name[i]==32) filename[i]=0; else filename[i]=name[i]; } *iwarn = 0; fp = fopen(filename,"r"); if (fp==0){ *iwarn = 1; } } void open_file_w__(char *name) { char filename[80]; int i; for (i=0; i<80; i++){ if (name[i]==32) filename[i]=0; else filename[i]=name[i]; } fp = fopen(filename,"w"); } void close_file__() { fclose(fp); } void read_header__(long long *ibuf, long long *ibuf1, long long *ibuf2) { int i; i = fread(ibuf, 8,200,fp); i = fread(ibuf1,8,100,fp); i = fread(ibuf2,8,100,fp); } void write_header__(long long *ibuf, long long *ibuf1, long long *ibuf2) { int i; i = fwrite(ibuf, 8,200,fp); i = fwrite(ibuf1,8,100,fp); i = fwrite(ibuf2,8,100,fp); } void byte_swap8__(char *val) { char temp; temp = val[0]; val[0] = val[7]; val[7] = temp; temp = val[1]; val[1] = val[6]; val[6] = temp; temp = val[2]; val[2] = val[5]; val[5] = temp; temp = val[3]; val[3] = val[4]; val[4] = temp; } void byte_swap4__(char *val) { char temp; temp = val[0]; val[0] = val[3]; val[3] = temp; temp = val[1]; val[1] = val[2]; val[2] = temp; } void byte_swap2__(char *val) { char temp; temp = val[0]; val[0] = val[1]; val[1] = temp; } void read_part__(int *nread, float *xx, float *yy, float *zz, float *vx, float *vy, float *vz, float *mass, int *id, int *iread) { struct particle ppart[BLOCKSIZE]; int i; *iread = fread(ppart,sizeof(struct particle),*nread,fp); for (i=0; i<*iread; i++){ xx[i] = ppart[i].pos[0]; yy[i] = ppart[i].pos[1]; zz[i] = ppart[i].pos[2]; vx[i] = ppart[i].vel[0]; vy[i] = ppart[i].vel[1]; vz[i] = ppart[i].vel[2]; mass[i] = ppart[i].mass; id[i] = ppart[i].id; } } void write_part__(int *nread, float *xx, float *yy, float *zz, float *vx, float *vy, float *vz, float *mass, int *id, int *iread) { struct particle ppart[BLOCKSIZE]; int i; if (*iread>BLOCKSIZE){ fprintf(stdout,"%s","Trying to write out too many particles "); abort(); } for (i=0; i<*iread; i++){ ppart[i].pos[0] = xx[i]; ppart[i].pos[1] = yy[i]; ppart[i].pos[2] = zz[i]; ppart[i].vel[0] = vx[i]; ppart[i].vel[1] = vy[i]; ppart[i].vel[2] = vz[i]; ppart[i].mass = mass[i]; ppart[i].id = id[i]; } *nread = fwrite(ppart,sizeof(struct particle),*iread,fp); } void write_pos__(int *nwrite, short int *xx, short int *yy, short int *zz) { struct posit pos_two[BLOCKSIZE]; int i; for (i=0;i<*nwrite;i++){ pos_two[i].pos[0] = xx[i]; pos_two[i].pos[1] = yy[i]; pos_two[i].pos[2] = zz[i]; } i = fwrite(pos_two, sizeof(struct posit),*nwrite,fp); *nwrite = i; } void readstar2__(int *ntry, short int *xx, short int *yy, short int *zz) { struct posit pos_two[BLOCKSIZE]; int i; i = fread(pos_two, sizeof(struct posit),*ntry,fp); *ntry = i; for(i=0;i<*ntry;i++){ xx[i] = pos_two[i].pos[0]; yy[i] = pos_two[i].pos[1]; zz[i] = pos_two[i].pos[2]; } } void write_ids__(int *nwrite, int *ids) { int i; i = fwrite(ids, sizeof(int),*nwrite,fp); *nwrite = i; } void readint4__(int *nwrite, int *ids) { int i; i = fread(ids, sizeof(int),*nwrite,fp); *nwrite = i; } void pos_digit__(char *string, int *pos, int *ifin) { int i; *pos = 0; *ifin = 0; for (i=0; i<12; i++){ if ((string[i]>='0')&&(string[i]<='9')){ *pos = i+1; break; } } for (i=20; i>0; i--){ if ((string[i]>='0')&&(string[i]<='9')){ *ifin = i+1; break; } } }