// ----------------------------------------------------------------- int sread_byteorder(int byterevflag, FILE* fp, void *src, size_t size, char *myname, char *descrip) { int status = sread_data(fp,src,size,myname,descrip); if (byterevflag == 1) byterevn((int32type *)src, size / sizeof(int32type)); return status; }
static int read_cmplx_fm_source_hdr(cmplx_source_file *csf, int source_type) { cmplx_source_header *csh = csf->header; int *dims = csh->dims; int32type t_stamp; int32type size_of_element; int32type tmp, elements_per_site; int32type order; int byterevflag = 0; char myname[] = "read_cmplx_fm_source_hdr"; if( sizeof(float) != sizeof(int32type)) { printf("%s: Can't byte reverse\n", csf->filename); printf("requires size of int32type(%d) = size of float(%d)\n", (int)sizeof(int32type),(int)sizeof(float)); terminate(1); } if(sread_data(csf->fp,&csh->magic_number,sizeof(int32type), myname,"magic_no")) terminate(1); tmp = csh->magic_number; if(csh->magic_number == IO_UNI_MAGIC) byterevflag = 0; else { byterevn((int32type *)&csh->magic_number,1); if(csh->magic_number == IO_UNI_MAGIC) { byterevflag = 1; /** printf("Reading with byte reversal\n"); **/ } else { /* Restore magic number as originally read */ csh->magic_number = tmp; /* End of the road. */ printf("%s: Unrecognized magic number in source file header.\n", csf->filename); printf("Expected %x but read %x\n", IO_UNI_MAGIC,tmp); terminate(1); } }; if(sread_byteorder(byterevflag,csf->fp,&t_stamp, sizeof(t_stamp),myname,"t_stamp"))terminate(1); if(sread_byteorder(byterevflag,csf->fp,&size_of_element, sizeof(int32type),myname,"size_of_element"))terminate(1); if(sread_byteorder(byterevflag,csf->fp,&elements_per_site, sizeof(int32type),myname,"elements_per_site"))terminate(1); if(sread_byteorder(byterevflag,csf->fp,dims, 4*sizeof(int32type),myname,"dimensions"))terminate(1); /* Consistency checks */ if ( nx != dims[0] || ny != dims[1] || nz != dims[2] || 1 != dims[3] ){ printf("Source field dimensions %d %d %d %d are incompatible with this lattice %d %d %d %d\n", dims[0], dims[1], dims[2], dims[3], nx, ny, nz, nt); terminate(1); } if( source_type == COMPLEX_FIELD_FM_FILE ){ if( size_of_element != sizeof(float) || elements_per_site != 2 /* complex field */) { printf(" File %s is not a complex field", csf->filename); printf(" got size_of_element %d and elements_per_site %d\n", size_of_element, elements_per_site); terminate(1); } } else { printf("Unknown source type %d\n",source_type); terminate(1); } /* The site order parameter is ignored */ if(sread_byteorder(byterevflag,csf->fp,&order,sizeof(int32type), myname,"order parameter"))terminate(1); return byterevflag; }
// ----------------------------------------------------------------- // Access from node0 only int read_gauge_hdr(gauge_file *gf) { FILE *fp = gf->fp; gauge_header *gh = gf->header; int32type tmp, btmp; int j, stat, byterevflag = 0; char myname[] = "read_gauge_hdr"; // Read header, do byte reversal, if necessary, and check consistency // Read and verify magic number stat = sread_data(fp, &gh->magic_number, sizeof(gh->magic_number), myname, "magic number"); if (stat != 0) terminate(1); tmp = gh->magic_number; btmp = gh->magic_number; byterevn((int32type *)&btmp, 1); /** See if header chunk is BEGI = 1111836489 for big endian or the byte reverse 1229407554 for little endian **/ if (tmp == GAUGE_VERSION_NUMBER) byterevflag = 0; else if (btmp == GAUGE_VERSION_NUMBER) { byterevflag = 1; gh->magic_number = btmp; // printf("Reading with byte reversal\n"); if (sizeof(float) != sizeof(int32type)) { printf("read_gauge_hdr: Can't byte reverse\n"); printf("requires size of int32type(%d) = size of float(%d)\n", (int)sizeof(int32type), (int)sizeof(float)); terminate(1); } } else if (tmp == LIME_MAGIC_NO || btmp == LIME_MAGIC_NO) { // LIME format suggests a SciDAC file // Print error, set flag and return printf("%s: Looks like a SciDAC-formatted file\n", myname); gh->magic_number = LIME_MAGIC_NO; return 0; } else { // End of the road printf("read_gauge_hdr: Unrecognized magic number in gauge header\n"); printf("Expected %x but read %x\n", GAUGE_VERSION_NUMBER, tmp); printf("Expected %s but read %d\n", (char *)GAUGE_VERSION_NUMBER, tmp); terminate(1); return byterevflag; } // Read and process header information // Get lattice dimensions stat = sread_byteorder(byterevflag, fp, gh->dims, sizeof(gh->dims), myname, "dimensions"); if (stat != 0) terminate(1); // Check lattice dimensions for consistency if (gh->dims[0] != nx || gh->dims[1] != ny || gh->dims[2] != nz || gh->dims[3] != nt) { /* So we can use this routine to discover the dimensions, we provide that if nx = ny = nz = nt = -1 initially we don't die */ if (nx != -1 || ny != -1 || nz != -1 || nt != -1) { printf("%s: Incorrect lattice dimensions ",myname); for (j = 0; j < NDIMS; j++) printf("%d ", gh->dims[j]); printf("\n"); fflush(stdout); terminate(1); } else { nx = gh->dims[0]; ny = gh->dims[1]; nz = gh->dims[2]; nt = gh->dims[3]; volume = nx * ny * nz * nt; } } // Read date and time stamp stat = sread_data(fp, gh->time_stamp, sizeof(gh->time_stamp), myname, "time stamp"); if (stat != 0) terminate(1); // Read header byte length gh->header_bytes = sizeof(gh->magic_number) + sizeof(gh->dims) + sizeof(gh->time_stamp) + sizeof(gh->order); // Read data order stat = sread_byteorder(byterevflag, fp, &gh->order, sizeof(gh->order), myname, "order parameter"); if (stat != 0) terminate(1); return byterevflag; }