Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

fermiqcd_MILC_IO.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 bool milc_read_as_float_noswitch(FILE *fp,
00015                                  void* data,
00016                                  long psize,
00017                                  long header_size,
00018                                  long position,
00019                                  const mdp_lattice &lattice) {
00020   cout << position << '\n';
00021   double *p=(double*) data;
00022   site x(lattice);
00023   x.set_global(position);
00024 #ifdef USE_DOUBLE_PRECISION
00025   float  *q=(float*) malloc(psize/2);
00026   position=(((x(0)*lattice.size(3)+x(3))*lattice.size(2)+x(2))*lattice.size(1)+x(1));
00027   if(fseek(fp, position*psize/2+header_size, SEEK_SET) ||
00028      fread(q, psize/2,1, fp)!=1) {
00029     return false;
00030   }
00031   for(uint i=0; i<psize/sizeof(double); i++) {
00032     p[i]=q[i];
00033   }
00034   free(q);
00035 #else 
00036   float  *q=(float*) malloc(psize);
00037   position=(((x(0)*lattice.size(3)+x(3))*lattice.size(2)+x(2))*lattice.size(1)+x(1));
00038   if(fseek(fp, position*psize+header_size, SEEK_SET) ||
00039      fread(q, psize,1, fp)!=1) {
00040     return false;
00041   }
00042   for(uint i=0; i<psize/sizeof(float); i++) {
00043     p[i]=q[i];
00044   }
00045   free(q);
00046 #endif
00047   return true;
00048 }
00049 
00050 bool milc_read_as_float_switch(FILE *fp,
00051                                void* data,
00052                                long psize,
00053                                long header_size,
00054                                long position,
00055                                const mdp_lattice &lattice) {
00056   cout << "switch" << position << '\n';
00057   double *p=(double*) data;
00058   site x(lattice);
00059   x.set_global(position);
00060 #ifdef USE_DOUBLE_PRECISION
00061   float  *q=(float*) malloc(psize/2);
00062   position=(((x(0)*lattice.size(3)+x(3))*lattice.size(2)+x(2))*lattice.size(1)+x(1));
00063   if(fseek(fp, position*psize/2+header_size, SEEK_SET) ||
00064      fread(q, psize/2,1, fp)!=1) return false;
00065   for(uint i=0; i<psize/sizeof(double); i++) {
00066     switch_endianess_byte4(q[i]);
00067     p[i]=q[i];
00068   }
00069   free(q);
00070 #else 
00071   float  *q=(float*) malloc(psize);
00072   position=(((x(0)*lattice.size(3)+x(3))*lattice.size(2)+x(2))*lattice.size(1)+x(1));
00073 
00074   if(fseek(fp, position*psize+header_size, SEEK_SET) ||
00075      fread(q, psize,1, fp)!=1) {
00076        return false;
00077   }
00078   for(uint i=0; i<psize/sizeof(float); i++) {
00079     switch_endianess_byte4(q[i]);
00080     p[i]=q[i];
00081   }
00082   free(q);
00083 #endif
00084   return true;
00085 }
00086 
00087 
00088 bool load_milc(gauge_field &U, string filename, 
00089                long max_buffer_size=128, int processIO=0) {
00090 
00091   struct {
00092     long magic_number;               /* Identifies file format */
00093     long dims[4];                    /* Full lattice dimensions */
00094     char   time_stamp[64];           /* Date and time stamp - used to
00095                                         check consistency between the
00096                                         ASCII header file and the
00097                                         lattice file */
00098     long header_bytes;               /* NOT WRITTEN TO THE FILE but
00099                                         helpful for finding the data */
00100     long what_is_this;
00101     long order;                      /* 0 means no coordinate list is
00102                                         attached and the values are in
00103                                         coordinate serial order.
00104                                         Nonzero means that a
00105                                         coordinate list is attached,
00106                                         specifying the order of values */
00107     // long boo;
00108   } milc_header;
00109 
00110   bool ew=false;
00111   int size=sizeof(milc_header);
00112   FILE *fp=fopen(filename.c_str(),"r");
00113   if(fp==0) return false;
00114   if(fread(&milc_header, 1, size, fp)!=size) {
00115     fclose(fp);
00116     return false;
00117   }
00118 
00119   if(milc_header.magic_number==0x874e0000) {
00120     switch_endianess_byte4(milc_header.dims[0]);
00121     switch_endianess_byte4(milc_header.dims[1]);
00122     switch_endianess_byte4(milc_header.dims[2]);
00123     switch_endianess_byte4(milc_header.dims[3]);
00124     ew=true;
00125   }
00126 
00127   if(U.lattice().ndim!=4 ||
00128      milc_header.dims[0]!=U.lattice().size(1) ||
00129      milc_header.dims[1]!=U.lattice().size(2) ||
00130      milc_header.dims[2]!=U.lattice().size(3) ||
00131      milc_header.dims[3]!=U.lattice().size(0)) {
00132     fclose(fp);
00133     return false;
00134   }
00135   fclose(fp);
00136 
00137   if(ew)
00138     return U.load(filename,processIO, max_buffer_size,false,size,
00139                   milc_read_as_float_switch, false);
00140   else
00141     return U.load(filename,processIO, max_buffer_size,false,size,
00142                   milc_read_as_float_noswitch, false);
00143 }
00144 

Generated on Sun Feb 27 15:12:19 2005 by  doxygen 1.4.1