예제 #1
0
int read_complex_scidac_xml(QIO_Reader *infile, complex *dest, int count, 
			    QIO_String *recxml){
  int status;
  int typesize, datacount;
  QIO_RecordInfo recinfo;

  /* Read the lattice field: "count" complex numbers per site */
  status = QIO_read_record_info(infile, &recinfo, recxml);
  status = qio_status(status);
  if(status < 0)return -1;
  if(status > 0)terminate(1);

  datacount = QIO_get_datacount(&recinfo);
  if(datacount != count){
    node0_printf("read_complex_scidac_xml: Got datacount %d but wanted %d\n",
		 datacount, count);
    terminate(1);
  }
  typesize = QIO_get_typesize(&recinfo);

  if(typesize == 2*4)
    status = read_F_C_to_field(infile, recxml, dest, count);
  else
    status = read_D_C_to_field(infile, recxml, dest, count);

  return status;
}
예제 #2
0
int read_ksproprecord_usqcd(QIO_Reader *infile, int *color, su3_vector *dest)
{
  QIO_USQCDKSPropRecordInfo proprecord_info;
  QIO_String *recxml;
  int status, typesize;
  QIO_RecordInfo recinfo;

  recxml = QIO_string_create();

  /* Check the record type (double or single precision) */
  status = QIO_read_record_info(infile, &recinfo, recxml);
  if(status != QIO_SUCCESS)return status;
  typesize = QIO_get_typesize(&recinfo);

  if(typesize == 6*4)
    /* Read as a single precision record */
    status = read_F3_V_to_field(infile, recxml, dest, 1);
  else
    /* Read as a double precision record */
    status = read_D3_V_to_field(infile, recxml, dest, 1);

  if(status != QIO_SUCCESS)return status;

  status = QIO_decode_usqcd_ksproprecord_info(&proprecord_info, recxml);
  if(status != QIO_SUCCESS)terminate(1);
  QIO_string_destroy(recxml);

  *color = QIO_get_usqcd_ksproprecord_color(&proprecord_info);
  return QIO_SUCCESS;
}
예제 #3
0
int read_kspropsource_C_usqcd(QIO_Reader *infile, char *srcinfo, int n,
			      complex *dest)
{
  QIO_USQCDKSPropSourceInfo propsource_info;
  QIO_String *recxml;
  char *info;
  int status, typesize;
  QIO_RecordInfo recinfo;

  recxml = QIO_string_create();

  /* Check the record type (double or single precision) */
  status = QIO_read_record_info(infile, &recinfo, recxml);
  if(status != QIO_SUCCESS)return status;
  typesize = QIO_get_typesize(&recinfo);

  if(typesize == 8)
    status = read_F_C_to_field(infile, recxml, dest, 1);
  else
    status = read_D_C_to_field(infile, recxml, dest, 1);

  if(status != QIO_SUCCESS)return status;

  status = QIO_decode_usqcd_kspropsource_info(&propsource_info, recxml);
  if(status != QIO_SUCCESS)terminate(1);
  QIO_string_destroy(recxml);

  info = QIO_get_usqcd_kspropsource_info(&propsource_info);

  strncpy(srcinfo, info, n);
  return QIO_SUCCESS;
}
예제 #4
0
int read_ks_vector_scidac_xml(QIO_Reader *infile, su3_vector *dest, int count,
			      QIO_String *recxml)
{
  int status, typesize;
  QIO_RecordInfo recinfo;
  char myname[] = "read_ks_vector_scidac_xml";

  /* Check the record type (double or single precision) */
  status = QIO_read_record_info(infile, &recinfo, recxml);
  if(status != QIO_SUCCESS)return status;
  typesize = QIO_get_typesize(&recinfo);

  /* Read the lattice field: "count" color vectors per site */
  if(typesize == 6*4)
    /* Read them as a single precision record */
    return read_F3_V_to_field(infile, recxml, dest, count);
  else if(typesize == 6*8)
    /* Read them as a double precision record */
    return read_D3_V_to_field(infile, recxml, dest, count);
  else {
    node0_printf("%s: Incorrect data type size %d\n", myname, typesize);
    return 1;
  }

}
예제 #5
0
static gauge_file *restore_scidac(char *filename, int serpar){
  QIO_Layout layout;
  QIO_Filesystem fs;
  QIO_Reader *infile;
  QIO_RecordInfo recinfo;
  QIO_String *recxml;
  int status;
  int typesize;
  field_offset dest = F_OFFSET(link[0]);
  gauge_file *gf;

  QIO_verbose(QIO_VERB_OFF);

  /* Build the layout structure */
  build_qio_layout(&layout);

  /* Define the I/O nodes */
  build_qio_filesystem(&fs);

  /* Make a dummy gauge file structure for MILC use */
  gf = setup_input_gauge_file(filename);

  /* Set the filename in the gauge_file structure */
  gf->filename = filename;

  /* Open file for reading */
  infile = open_scidac_input(filename, &layout, &fs, serpar);
  if(infile == NULL)terminate(1);

  /* Check the record type (double or single precision) */
  recxml = QIO_string_create();
  status = QIO_read_record_info(infile, &recinfo, recxml);
  if(status)terminate(1);
  typesize = QIO_get_typesize(&recinfo);

  /* Read the lattice field as single or double precision according to
     the type size (bytes in a single SU(3) matrix) */
  if(typesize == 72)
    status = read_F3_M_to_site(infile, recxml, dest, LATDIM);
  else if (typesize == 144)
    status = read_D3_M_to_site(infile, recxml, dest, LATDIM);
  else
    {
      node0_printf("restore_scidac: Bad typesize %d\n",typesize);
      terminate(1);
    }
  if(status)terminate(1);

  /* Discard for now */
  QIO_string_destroy(recxml);

  /* Close the file */
  QIO_close_read(infile);

  return gf;
}
예제 #6
0
/* Read color matrices in SciDAC format to a field */
void restore_color_matrix_scidac_to_field(char *filename, 
		  su3_matrix *dest, int count, int prec){
  QIO_Layout layout;
  QIO_Filesystem fs;
  QIO_Reader *infile;
  QIO_String *recxml;
  int status, typesize;
  QIO_RecordInfo recinfo;
  char myname[] = "restore_color_matrix_scidac_to_field";

  QIO_verbose(QIO_VERB_OFF);

  /* Build the layout structure */
  build_qio_layout(&layout);

  /* Set the file system parameters */
  build_qio_filesystem(&fs);

  /* Open file for reading */
  infile = open_scidac_input(filename, &layout, &fs, QIO_SERIAL);
  if(infile == NULL)terminate(1);

  /* Check the record type (double or single precision) */
  recxml = QIO_string_create();
  status = QIO_read_record_info(infile, &recinfo, recxml);
  if(status != QIO_SUCCESS)terminate(1);
  typesize = QIO_get_typesize(&recinfo);

  /* Read the lattice field */
  if(typesize == 18*4)
    status = read_F3_M_to_field(infile, recxml, dest, count);
  else if(typesize == 18*8)
    status = read_D3_M_to_field(infile, recxml, dest, count);
  else {
    node0_printf("%s: Incorrect data type size %d prec %d\n", myname, typesize, prec);
    terminate(1);
  }
  if(status)terminate(1);

  /* Discard for now */
  QIO_string_destroy(recxml);

  close_scidac_input(infile);
}
예제 #7
0
int QIO_generic_read_record_data(QIO_Reader *in, 
	     void (*put)(char *buf, size_t index, int count, void *arg),
	     size_t datum_size, int word_size, void *arg,
  	     DML_Checksum *checksum, uint64_t *nbytes)
{
  char myname[] = "QIO_generic_read_record_data";
  int count;
  LRL_RecordReader *lrl_record_in;
  size_t datum_size_info;
  DML_Layout *layout = in->layout;
  int this_node = layout->this_node; 
  int status;
  int recordtype; 
  int latdim;
  QIO_RecordInfo *record_info = &in->record_info;

  /* List of acceptable binary data LIME types */
  int ntypes = 2;
  /* Avoid a compiler bug */
  LIME_type lime_type0 = QIO_LIMETYPE_BINARY_DATA;
  LIME_type lime_type1 = QIO_LIMETYPE_ILDG_BINARY_DATA;
  LIME_type lime_type_list[2] = {lime_type0, lime_type1};
  //  LIME_type lime_type_list[2] = {
  //    QIO_LIMETYPE_BINARY_DATA,
  //    QIO_LIMETYPE_ILDG_BINARY_DATA
  //  };
  LIME_type lime_type;


  /* It is an error to call for the data before reading the info
     in a given record */
  if(in->read_state != QIO_RECORD_DATA_NEXT){
    printf("%s(%d): Bad read state %d\n",myname,this_node,in->read_state);
    return QIO_ERR_INFO_MISSED;
  }

  /* Add record type and subset data to layout structure */
  recordtype = QIO_get_recordtype(record_info);
  layout->recordtype = recordtype;
  status = DML_insert_subset_data(layout, 
				  QIO_get_hyperlower(record_info),
				  QIO_get_hyperupper(record_info),
				  QIO_get_hyper_spacetime(record_info));
  if(status != 0)
    return QIO_ERR_BAD_SUBSET;

  /* Require consistency between the byte count obtained from the
     private record metadata and the datum_size and count parameters
     (per site for field or hypercube data or total for global data) */
  count = QIO_get_datacount(record_info);
  if(datum_size !=  QIO_get_typesize(record_info) * count)
    {
      printf("%s(%d): requested byte count %lu disagrees with the record %d * %d\n",
	     myname,this_node,(unsigned long)datum_size,
	     QIO_get_typesize(record_info), count);
      
      if(this_node == layout->master_io_node)
	QIO_print_record_info(record_info);
      
      return QIO_ERR_BAD_READ_BYTES;
    }
  
  
  /* Verify byte count per site (for field or hypercube) or total (for
     global) */
  datum_size_info = QIO_get_typesize(record_info) * count;

  if(datum_size != datum_size_info){
    printf("%s(%d): byte count mismatch request %lu != actual %lu\n",
	   myname, this_node, (unsigned long)datum_size, 
	   (unsigned long)datum_size_info);

    return QIO_ERR_BAD_READ_BYTES;
  }

  if(QIO_verbosity() >= QIO_VERB_DEBUG){
    printf("%s(%d): Calling QIO_open_read_field\n",myname,this_node);fflush(stdout);
  }

  /* Nodes read the field */

  /* Scan ahead and open the record with one of the listed LIME types */
  lrl_record_in = QIO_open_read_field(in, recordtype, datum_size, 
         lime_type_list, ntypes, &lime_type, &status);
  if(status != QIO_SUCCESS)return status;

  if(QIO_verbosity() >= QIO_VERB_DEBUG){
    printf("%s(%d): Calling QIO_read_field_data\n",
	   myname,this_node);fflush(stdout);
  }

  /* Then read the data and close the record */
  status = QIO_read_field_data(in, lrl_record_in, recordtype, 
			       put, count, datum_size, word_size, 
			       arg, checksum, nbytes);
  if(status != QIO_SUCCESS){
    printf("%s(%d): Error reading field data\n",myname,this_node);
    return status;
  }

  if(QIO_verbosity() >= QIO_VERB_DEBUG){
    printf("%s(%d): done reading field\n",myname,this_node);fflush(stdout);
  }

  /* Copy most recent node checksum into reader */
  memcpy(&(in->last_checksum), checksum, sizeof(DML_Checksum));

  if(this_node == layout->master_io_node){
    if(QIO_verbosity() >= QIO_VERB_REG){
      printf("%s(%d): Read field\n",myname,this_node);
      QIO_print_record_info(record_info);
    }
  }
      
  in->read_state = QIO_RECORD_CHECKSUM_NEXT;
  return QIO_SUCCESS;
}
예제 #8
0
파일: scidac_to_v5.c 프로젝트: andypea/MILC
int main(int argc, char *argv[])
{

  int ndim,dims[4];
  gauge_file *gf;
  gauge_header *gh;
  FILE *fp;
  char *filename_milc,*filename_scidac;
  QIO_Layout layout;
  QIO_Reader *infile;
  QIO_RecordInfo rec_info;
  char *datatype;
  int status;
  int datum_size;
  int input_prec;
  int count = 4;
  int word_size;
  int typesize;
  w_serial_site_writer state;
  
  if(argc < 3)
    {
      fprintf(stderr,"Usage %s <SciDAC file> <MILC file>\n",argv[0]);
      exit(1);
    }
  filename_scidac = argv[1];
  filename_milc   = argv[2];

  if(this_node == 0)printf("Converting file %s to MILC v5 file %s\n",
			   filename_scidac, filename_milc);

  initialize_machine(&argc,&argv);
#ifdef HAVE_QDP
  QDP_initialize(&argc, &argv);
#endif

  this_node = mynode();
  number_of_nodes = numnodes();

  if(number_of_nodes != 1){
    printf("This is single-processor code. Please rebuild as such.\n");
    terminate(1);
  }

  /* Open the SciDAC file and discover the lattice dimensions.  Then
     close. */

  status = read_lat_dim_scidac(filename_scidac, &ndim, dims);
  if(status)terminate(1);
  
  if(ndim != 4){
    printf("Wanted ndims = 4 in %s but got %d\n",filename_scidac,ndim);
    terminate(1);
  }

  nx = dims[0]; ny = dims[1]; nz = dims[2]; nt = dims[3];
  volume = nx*ny*nz*nt;

  /* Finish setting up, now we know the dimensions */
  setup();

  /* Build the QIO layout */
  build_qio_layout(&layout);

  /* Open the SciDAC file for reading */
  infile = open_scidac_input(filename_scidac, &layout, 0, QIO_SERIAL);
  if(infile == NULL)terminate(1);

  /* Open the MILC v5 file for writing */
  fp = fopen(filename_milc, "wb");
  if(fp == NULL)
    {
      printf("Can't open file %s, error %d\n",
	     filename_milc,errno);fflush(stdout);
      terminate(1);
    }
  gf = setup_output_gauge_file();
  gh = gf->header;

  /* Read the SciDAC record header. */
  xml_record_in = QIO_string_create();
  status = QIO_read_record_info(infile, &rec_info, xml_record_in);
  if(status != QIO_SUCCESS)terminate(1);
  node0_printf("Record info \n\"%s\"\n",QIO_string_ptr(xml_record_in));

  /* Make sure this is a lattice field */
  datatype = QIO_get_datatype(&rec_info);
  typesize = QIO_get_typesize(&rec_info);
  if(strcmp(datatype, "QDP_F3_ColorMatrix") == 0 ||
     strcmp(datatype, "USQCD_F3_ColorMatrix") == 0 ||
     typesize == 72){
    datum_size = sizeof(fsu3_matrix);  
    input_prec = 1;
    word_size = sizeof(float);
  }
  else if(strcmp(datatype, "QDP_D3_ColorMatrix") == 0 ||
	  strcmp(datatype, "USQCD_F3_ColorMatrix") == 0 ||
	  typesize == 144){
    datum_size = sizeof(dsu3_matrix);  
    input_prec = 2;
    word_size = sizeof(double);
  }
  else {
    printf("Unrecognized datatype %s\n",datatype);
    terminate(1);
  }

  /* Copy the time stamp from the SciDAC file */
  strncpy(gh->time_stamp, QIO_get_record_date(&rec_info), 
	  MAX_TIME_STAMP);
  gh->time_stamp[MAX_TIME_STAMP-1] = '\0';

  /* Write the MILC v5 header */
  gh->order = NATURAL_ORDER;

  /* Node 0 writes the header */
  
  swrite_gauge_hdr(fp,gh);
  
  /* Assign values to file structure */

  gf->fp = fp; 
  gf->filename = filename_milc;
  gf->byterevflag    = 0;            /* Not used for writing */
  gf->rank2rcv       = NULL;         /* Not used for writing */
  gf->parallel       = 0;

  /* Initialize writing the lattice data */
  w_serial_start_lattice(gf, &state, input_prec);

  /* Read the SciDAC record data.  The factory function writes the
     site links to a file. */

  status = QIO_read_record_data(infile, w_serial_site_links, 
				datum_size*count, word_size, 
				(void *)&state);
  if(status != QIO_SUCCESS)terminate(1);

  node0_printf("SciDAC checksums %x %x\n",
	       QIO_get_reader_last_checksuma(infile),
	       QIO_get_reader_last_checksumb(infile));

  /* Close the SciDAC file */
  QIO_close_read(infile);

  /* Finish the MILC v5 file */
  w_serial_finish_lattice(&state);

  w_serial_f(gf);

  QIO_string_destroy(xml_record_in);

#ifdef HAVE_QDP
  QDP_finalize();
#endif  
  normal_exit(0);

  return 0;
}
예제 #9
0
static gauge_file *file_scan_scidac(char *filename, int serpar){
  QIO_Layout layout;
  QIO_Filesystem fs;
  QIO_Reader *infile;
  QIO_RecordInfo recinfo;
  QIO_String *recxml;
  int status;
  int typesize;
  su3_matrix *dest = NULL;
  gauge_file *gf;
  int ndim;
  int dims[4];

  /* Read header to get lattice dimensions and close the file */
  read_lat_dim_scidac(filename, &ndim, dims);
  nx = dims[0]; ny = dims[1]; nz = dims[2]; nt = dims[3];
  volume = nx*ny*nz*nt;

  /* Finish setting up, now we know the dimensions */

  broadcast_bytes((char *)&nx,sizeof(int));
  broadcast_bytes((char *)&ny,sizeof(int));
  broadcast_bytes((char *)&nz,sizeof(int));
  broadcast_bytes((char *)&nt,sizeof(int));
  
  setup_layout();

  /* Build the layout structure */
  build_qio_layout(&layout);

  /* Define the I/O nodes */
  build_qio_filesystem(&fs);

  /* Make a dummy gauge file structure for MILC use */
  gf = setup_input_gauge_file(filename);

  /* Set the filename in the gauge_file structure */
  gf->filename = filename;

  /* Reopen file for reading */
  QIO_verbose(QIO_VERB_OFF);

  infile = open_scidac_input(filename, &layout, &fs, serpar);
  if(infile == NULL)terminate(1);

  /* Check the record type (double or single precision) */
  recxml = QIO_string_create();
  status = QIO_read_record_info(infile, &recinfo, recxml);
  if(status)terminate(1);
  typesize = QIO_get_typesize(&recinfo);

  /* Read the lattice field as single or double precision according to
     the type size (bytes in a single SU(3) matrix) */
  if(typesize == 72)
    status = read_F3_M_to_null(infile, recxml, dest, LATDIM);
  else if (typesize == 144)
    status = read_D3_M_to_null(infile, recxml, dest, LATDIM);
  else
    {
      node0_printf("file_scan_scidac: Bad typesize %d\n",typesize);
      terminate(1);
    }
  if(status){
    node0_printf("ERROR scanning file\n");
  } else {
    node0_printf("SUCCESS scanning file\n");
  }

  /* Discard for now */
  QIO_string_destroy(recxml);

  /* Close the file */
  QIO_close_read(infile);

  return gf;
}
예제 #10
0
파일: QIO_info_private.c 프로젝트: ssyr/qio
/* Compare only fields that occur in the expected record info */
int QIO_compare_record_info(QIO_RecordInfo *found, QIO_RecordInfo *expect){
  char myname[] = "QIO_compare_record_info";

  if(QIO_defined_recordtype(expect))
    if(!QIO_defined_recordtype(found) &&
       QIO_get_recordtype(found)  != QIO_get_recordtype(expect))
      {
	printf("%s:Recordtype flag mismatch expected %d found %d \n",myname,
	       QIO_get_recordtype(expect),QIO_get_recordtype(found));
	return QIO_ERR_REC_INFO;
      }

  if(QIO_defined_datatype(expect))
    if(!QIO_defined_datatype(found) && 
       strncmp(QIO_get_datatype(found),QIO_get_datatype(expect),
	       QIO_MAXVALUESTRING))
      {
	printf("%s:Datatype mismatch expected %s found %s \n",myname,
	       QIO_get_datatype(expect),QIO_get_datatype(found));
	return QIO_ERR_REC_INFO;
      }

  if(QIO_defined_precision(expect))
    if(!QIO_defined_precision(found) &&
       strncmp(QIO_get_precision(found),QIO_get_precision(expect),
	       QIO_MAXVALUESTRING))
      {
	printf("%s:Precision mismatch expected %s found %s \n",myname,
	       QIO_get_precision(expect),QIO_get_precision(found));
	return QIO_ERR_REC_INFO;
      }

  if(QIO_defined_colors(expect))
    if(!QIO_defined_colors(found) &&
       QIO_get_colors(found) != QIO_get_colors(expect))
      {
	printf("%s:Colors mismatch expected %d found %d \n",myname,
	       QIO_get_colors(expect),QIO_get_colors(found));
	return QIO_ERR_REC_INFO;
      }

  if(QIO_defined_spins(expect))
    if(!QIO_defined_spins(found) &&
       QIO_get_spins(found)  != QIO_get_spins(expect))
      {
	printf("%s:Spins mismatch expected %d found %d \n",myname,
	       QIO_get_spins(expect),QIO_get_spins(found));
	return QIO_ERR_REC_INFO;
      }

  if(QIO_defined_typesize(expect))
    if(!QIO_defined_typesize(found) &&
       QIO_get_typesize(found) != QIO_get_typesize(expect))
      {
	printf("%s:Typesize mismatch expected %d found %d \n",myname,
	       QIO_get_typesize(expect),QIO_get_typesize(found));
	return QIO_ERR_REC_INFO;
      }

  if(QIO_defined_datacount(expect))
    if(!QIO_defined_datacount(found) &&
       QIO_get_datacount(found) != QIO_get_datacount(expect))
      {
	printf("%s:Datacount mismatch expected %d found %d \n",myname,
	       QIO_get_datacount(expect),QIO_get_datacount(found));
	return QIO_ERR_REC_INFO;
      }

  return QIO_SUCCESS;
}