Ejemplo n.º 1
0
void read_multiselect_twopt(
  char filename[80],   /* the name of the input correlator file */
  int nfile,           /* Number of output files */
  twopt_oneselect *fp /* Selection parameter sets */
  )
{
  FILE *corrfp ;
  FILE *dumpfp[MAX_NO_FILE];
  complex *corr;
  size_t nobj, ngot ; 
  const int32type magic_number = 44451189 ; 
  const int32type version_number  = 1  ; /** update this flag when the data format changes ***/
  int i ;
  int ifile ;
  int t ;
  int jselect;
  size_t  name_len = 80 ;
  size_t howmany ;
  size_t where,skip,corr_stride,base;
  int check_sum ; 
  int check_sum_in ; 
  int dim ; 
  int byte_rev_flag  =  do_nothing ;
  int nt,no_q_values,no_spectator,no_zonked,no_oper,nocopies;
  int32type *q_momstore;
  int zonked_pt;       /* zonked quark index */
  int spect_pt;        /* spectator quark index */
  int q_pt;            /* momentum index */
  int oper_pt;         /* operator index */
  int copy_pt;         /* copy index */
  Real wt;            /* weight */
  complex *corr_tmp;   /* temporary storage for correlator */
  char *nextfield,*cfgid;   /* Identifying characters for binary
                              correlator file */
  char myname[] = "read_multiselect_twopt";

  /* Memory for some header information ***/
#define HEADER_DIM_WRITE_CORR 11
  size_t  header_size = (size_t) HEADER_DIM_WRITE_CORR ;
  int32type header_data[HEADER_DIM_WRITE_CORR] ;
#undef HEADER_DIM_WRITE_CORR

  /**** open the ASCII output files for APPENDING *****/
  for(ifile = 0; ifile < nfile; ifile++)
    {
      if( (dumpfp[ifile] = fopen(fp[ifile].filename,"a")) == NULL )
	{
	  printf("Could not open the file %s\n",fp[ifile].filename);
	  exit(1);
	}
    }

  /**** open the binary correlator file ******/
  if( (corrfp = fopen(filename ,"rb")) == NULL )
  {
    printf("%s ERROR: Could not open the file %s\n",
	   myname,filename);
    exit(1);
  }

  /** read the header information ***/
  if( fread(header_data,sizeof(int32type),header_size,corrfp) != header_size )
  {
    printf("%s Error %d reading the HEADER from %s\n",
	   myname,errno,filename);
    exit(1);
  }

  /*** unpack and check the header ******/

  /***** check the header ****/
  if( header_data[0] != magic_number )
  {
    byte_rev_flag = do_byte_rev ;
  }


  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array( header_data, header_size); 
  }


  /***** check the header ****/
  if( header_data[0] != magic_number )
  {
    printf("%s ERROR: magic number mismatch between code %x and file %x\n",
	   myname,magic_number, header_data[0]  );
    exit(1); 
  }


  if( header_data[1] != version_number )
  {
    printf("%s ERROR: version number mismatch between code %d and file %d\n",
	    myname,version_number, header_data[1]);
    exit(1); 
  }


  nt = header_data[2]  ;
  check_sum_in = header_data[3] ;
  no_q_values = header_data[4]  ;
  no_spectator = header_data[5]  ;
  no_zonked = header_data[6]  ;
  no_oper = header_data[7]  ;
  dim = header_data[8]  ; 
/** hl_flag = header_data[9]  ; **/
  nocopies = header_data[10]  ;

  /*** read the external q--momentum from the file ***/
  howmany = (size_t) 3*(no_q_values) ;
  if( ( q_momstore = (int32type *)calloc( howmany , sizeof(int32type))   )  == NULL) 
  {
    printf("%s Can't malloc q-momentum \n",myname);
    exit(1);
  }


  if( fread(q_momstore,sizeof(int32type),howmany,corrfp) != howmany   )
  {
    printf("%s: error %d reading the Q momentum table from %s\n",
	   myname,errno,filename);
    exit(1);
  }

  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array(q_momstore , (int) howmany );
  }

  /** read the two point functions from disk *****/
  nobj = (size_t) nt ; 
  if( (corr = (complex *)calloc( nobj , sizeof(complex) ) )  == NULL) 
  {
    printf("%s: Can't calloc corr, nobj = %d\n",myname,nobj);
    exit(1);
  }

  if( (corr_tmp = (complex *)calloc( nobj , sizeof(complex) ) )  == NULL) 
  {
    printf("There was an error in allocating corr_tmp, nobj = %d\n",nobj);
    exit(1);
  }

  base = ftell(corrfp);

  /* Iterate over sets of selection parameters, reading data for each
     and accumulating results in the correlation array */

  for(ifile = 0; ifile < nfile; ifile++)
    {
      for(t = 0; t < nt; t++)
	{
	  corr[t].real = corr[t].imag = 0.;
	}

      for(jselect = 0; jselect < fp[ifile].nselect; jselect++)
	{
	  /* Unload selection parameters */

	  zonked_pt       = fp[ifile].select[jselect].other;
	  spect_pt        = fp[ifile].select[jselect].spect;
	  q_pt            = fp[ifile].select[jselect].mom;
	  oper_pt         = fp[ifile].select[jselect].oper;
	  copy_pt         = fp[ifile].select[jselect].copy;
	  wt              = fp[ifile].select[jselect].wt;
	  
	  /** locate the required correlator on disk **/
	  
	  corr_stride = TWOPT_FORM_WHERE(nt,no_zonked-1 ,no_spectator-1,
				     no_q_values-1, no_oper-1) ; ; 
	  where = corr_stride*copy_pt + 
	    TWOPT_FORM_WHERE(0,zonked_pt ,spect_pt,q_pt, oper_pt) ;
	  
	  
	  skip = where*sizeof(complex);
	  
	  if(fseek(corrfp,base+skip,SEEK_SET) != 0)
	    {
	      printf("%s: Error %d seeking the two point function on %s\n",
		     myname,errno,filename);
	      exit(1);
	    }
      
	  /** read the two point function from disk *****/
	  if( (ngot = fread(corr_tmp,sizeof(complex),nobj,corrfp)) != nobj   )
	    {
	      printf("%s: error %d reading %d form factor data items from %s. Got %d.\n",
		     myname,errno,nobj,filename,ngot);
	      printf("Error after seeking %d bytes\n",base+skip);
	      exit(1);
	    }
	  
	  if(  byte_rev_flag == do_byte_rev    )
	    {
	      byte_rev_array((int32type*) corr_tmp, nobj*2 );
	    }

	  /* Accumulate result in correlation array */
	  for(t = 0; t < nt; t ++)
	    {
	      corr[t].real += corr_tmp[t].real*wt;
	      corr[t].imag += corr_tmp[t].imag*wt;
	    }
	  
	} /* jselect */
      
      /* Write the result to the ASCII file */
      /* Use the last field after the last period in the filename to
         identify the data set */
      for(nextfield=filename; nextfield!=(char *)NULL+1; 
	  nextfield=strstr(nextfield,".")+1)cfgid = nextfield;

      for(t = 0; t < nt; t++)
	fprintf(dumpfp[ifile],"%2d %12.6g %12.6g %% %s\n",
		t,corr[t].real,corr[t].imag,cfgid);

    } /* ifile */


  /*** close the file ****/
  if( fclose(corrfp) != 0 )
  {
    printf("There was an error during the closing of %s \n",filename);
    exit(1);
  }

  /**** close the ASCII output files *****/
  for(ifile = 0; ifile < nfile; ifile++)
    {
      if( fclose(dumpfp[ifile]) != 0 )
	{
	  printf("Error closing the file %s\n",fp[ifile].filename);
	  exit(1);
	}
    }

  free(corr_tmp);

}
Ejemplo n.º 2
0
void read_prop_twopt(
  complex **corr,           /* the two point correlators */
  int **corr_oper_list,     /* List of operator numbers read */
  int **corr_copy_list,     /* List of copy numbers read */
  char filename[80],        /* the name of the disk file */
  int32type **q_momstore,      /* list of momenta */
  int *hl_flag,             /* flag identifying type of correlator */
  int *no_k_one ,           /* the number of  kappa values */
  int *no_k_two,            /* the number of  kappa values */
  int *number_of_operators,  /* number of operators */
  int *nt ,                 /* time values */
  int *no_q_values,         /* momentum values */
  int *nocopies             /* rotations */
  )
{
  size_t nobj ; 
  FILE *fp ;
  int32type magic_number = 44451189 ; 
  int32type version_number  = 1  ; /** update this flag when the data format changes ***/
  int i ;
  size_t  name_len = 80 ;
  size_t howmany ;
  int check_sum ; 
  int check_sum_in ; 
  int dim ; 
  int byte_rev_flag  =  do_nothing ;

  /* Memory for some header information ***/
#define HEADER_DIM_WRITE_CORR 11
  size_t  header_size = (size_t) HEADER_DIM_WRITE_CORR ;
  int32type header_data[HEADER_DIM_WRITE_CORR] ;
#undef HEADER_DIM_WRITE_CORR


  /**** open the file ******/
  if( (fp = fopen(filename ,"rb")) == NULL )
  {
    printf("ERROR::read_prop_form::Could not open the file %s\n",filename);
    exit(1);
  }

  /** read the header information ***/
  if( fread(header_data,sizeof(int32type),header_size,fp) != header_size )
  {
    printf("There was an error during the reading of the two point (propagating) HEADER to %s\n",
	   filename);
    exit(1);
  }

  /*** unpack and check the header ******/

  /***** check the header ****/
  if( header_data[0] != magic_number )
  {
    printf("ERROR: magic number mismatch between code %d and file %d\n",magic_number, header_data[0]  );

    printf("I will try byte reversing the data\n"); 
    byte_rev_flag = do_byte_rev ;

  }


  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array( header_data, header_size); 
  }


  /***** check the header ****/
  if( header_data[0] != magic_number )
  {
    printf("ERROR: magic number mismatch between code %d and file %d\n",magic_number, header_data[0]  );
    exit(1); 
  }


  if( header_data[1] != version_number )
  {
    printf("ERROR: version number mismatch between code %d and file %d\n",version_number, header_data[1]);
    exit(1); 
  }





  *nt  = header_data[2] ;
  check_sum_in  = header_data[3]  ;
  *no_q_values = header_data[4]  ;
  *no_k_one = header_data[5]  ;
  *no_k_two = header_data[6]  ;
  *number_of_operators = header_data[7]  ;
  dim = header_data[8]  ; 
  *hl_flag = header_data[9]  ;
  *nocopies = header_data[10]  ;

  /*** read the external q--momentum from the file ***/
  howmany = (size_t) 3*(*no_q_values) ;
  if( ( (*q_momstore) = (int32type *)calloc( howmany , sizeof(int32type))   )  == NULL) 
  {
    printf("There was an error in allocating q-momentum \n");
    exit(1);
  }


  if( fread((*q_momstore),sizeof(int32type),howmany,fp) != howmany   )
  {
    printf("There was an error during the reading of the Q momentum table to %s\n",
	   filename);
    exit(1);
  }

  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array((*q_momstore) , (int) howmany );
  }


  /** read the two point functions from disk *****/
  nobj = (size_t) dim ; 
  if( ((*corr) = (complex *)calloc( nobj , sizeof(complex) ) )  == NULL) 
  {
    printf("There was an error in allocating the two point function, nobj = %d\n",nobj);
    exit(1);
  }


  if( fread((*corr),sizeof(complex),nobj,fp) != nobj   )
  {
    printf("There was an error during the reading of he two point finctions from %s\n",
	   filename);
    exit(1);
  }


  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array((int32type*) (*corr), dim*2 );
  }



  /*** close the file ****/
  if( fclose(fp) != 0 )
  {
    printf("There was an error during the closing of %s \n",filename);
    exit(1);
  }

 


  /*** calculate the checksum of the form factors ****/
  check_sum =  bsd_sum((char*)(*corr), sizeof(complex)*dim)  ;

  if( check_sum !=  check_sum_in )
  {
    printf("ERROR: checksum mismatch bewteen the file %d and the code %d \n",check_sum,check_sum_in) ; 
    printf("ERROR: checksum mismatch bewteen the file %d and the code %d \n",check_sum,check_sum_in) ; 
    printf("ERROR: checksum mismatch bewteen the file %d and the code %d \n",check_sum,check_sum_in) ; 

/**    exit(1) ;  ****/
  }

  /* Create operator list */
  if( ((*corr_oper_list) = (int *)calloc( *number_of_operators, sizeof(int) ) )  == NULL) 
    {
      printf("There was an error in allocating the operator list\n");
      exit(1);
    }

  for(i = 0; i < *number_of_operators; i++)
    (*corr_oper_list)[i] = i;

  /* Create copies list */
  if( ((*corr_copy_list) = (int *)calloc( *nocopies, sizeof(int) ) )  == NULL) 
    {
      printf("There was an error in allocating the copies list\n");
      exit(1);
    }

  for(i = 0; i < *nocopies; i++)
    (*corr_copy_list)[i] = i;

  printf("I have read the two point functions from the file %s\n",filename);

}
Ejemplo n.º 3
0
void read_propagating_form_corr(
  complex **corr,           /* the two point correlators */
  int **corr_oper_list,     /* List of operator numbers read */
  int **corr_copy_list,     /* List of copy numbers read */
  int32type **p_momstore,      /* list of B meson momenta */
  int32type **q_momstore,      /* list of momentum transfers */
  int *nt,                  /* time values */
  int *no_p_values,         /* momentum values */
  int *no_q_values,         /* momentum values */
  int *no_oper,             /* number of operators */
  int *no_spectator,        /* the number of  kappa values */
  int *no_sequential,       /* the number of  kappa values */
  int *no_zonked ,          /* the number of  kappa values */
  int *hl_flag,             /* flag identifying type of correlator */
  char filename[80],        /* the name of the disk file */
  int *nocopies             /* rotations */
)
{
  char myname[] = "read_propagating_form_corr";
  FILE *fp ;
  size_t nobj ; 
  const int32type magic_number = 14567332 ; 
  const int32type version_number  = 1  ; /** update this flag when the data format changes ***/
  int i ;
  size_t  name_len = 80 ;
  size_t howmany ;
  int check_sum ; 
  int check_sum_in ; 
  int dim ; 
  int byte_rev_flag  =  do_nothing ;
  
  /* Memory for some header information ***/
#define HEADER_DIM_WRITE_CORR 13
  size_t  header_size = (size_t) HEADER_DIM_WRITE_CORR ;
  int32type header_data[HEADER_DIM_WRITE_CORR] ;


  /**** open the file ******/
  if( (fp = fopen(filename ,"rb")) == NULL )
  {
    printf("Could not open the file %s\n",filename);
    exit(1);
  }

  /** read the header information ***/
  if( fread(header_data,sizeof(int32type),header_size,fp) != header_size )
  {
    printf("%s: error %d reading the form factor HEADER from %s\n",
	   myname,errno,filename);
    exit(1);
  }




  /***** check the header ****/
  if( header_data[0] != magic_number )
  {
    printf("%s: ERROR: magic number mismatch between code %d and file %d\n",
	   myname,magic_number, header_data[0]  );
    printf("I will try byte reversing the data\n"); 
    byte_rev_flag = do_byte_rev ;
  }

  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array( header_data, header_size); 
  }



  if( header_data[0] != magic_number )
  {
    printf("%s: ERROR: magic number mismatch between code %d and file %d\n",
	   myname,magic_number, header_data[0]  );
    exit(1); 
  }

  if( header_data[1] != version_number )
  {
    printf("%s: ERROR: version number mismatch between code %d and file %d\n",
	   myname,version_number, header_data[1]);
    exit(1); 
  }


  *nt = header_data[2]  ;
  check_sum_in = header_data[3] ;
  *no_p_values = header_data[4] ;
  *no_q_values = header_data[5] ;
  *no_oper = header_data[6] ;
  *no_spectator = header_data[7]   ;
  *no_zonked = header_data[8]  ;
  dim = header_data[9]  ;
  *hl_flag  = header_data[10]  ;
  *no_sequential = header_data[11]  ;
  *nocopies = header_data[12]  ;

  /*******  read some more data from the file **********/

  /*** read the external momentum from the  file ***/
  howmany = (size_t) 3*(*no_q_values) ;
  if( ( (*q_momstore) = (int32type *)calloc( howmany , sizeof(int32type))   )  == NULL) 
  {
    printf("%s: There was an error in allocating q-momentum \n",myname);
    exit(1);
  }

  if( fread((*q_momstore)  ,sizeof(int32type),howmany,fp) != howmany   )
  {
    printf("%s: error %d reading the q-momentum table from %s\n",
	   myname,errno,filename);
    exit(1);
  }

  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array((*q_momstore) , (int) howmany );
  }




  /*** read the external momentum from the  file ***/
  howmany = (size_t) 3*(*no_p_values) ;
  if( ( (*p_momstore) = (int32type *)calloc( howmany , sizeof(int32type))   )  == NULL) 
  {
    printf("%s: There was an error in allocating p--momentum \n",myname);
    exit(1);
  }

  if( fread((*p_momstore)  ,sizeof(int32type),howmany,fp) != howmany   )
  {
    printf("%s: error %d reading the p-momentum table from %s\n",
	   myname,errno,filename);
    exit(1);
  }

  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array((*p_momstore) , (int) howmany );
  }




  /*** reserve memory for the three point function ****/
  nobj = (size_t) dim ; 
  if( ((*corr) = (complex *)calloc( nobj , sizeof(complex) ) )  == NULL) 
  {
    printf("%s: There was an error in allocating the three point function, nobj = %d\n",
	   myname,nobj);
    exit(1);
  }

  /** read the three point function to disk *****/
  if( fread((*corr),sizeof(complex),nobj,fp) != nobj   )
  {
    printf("%s: error %d reading the form factor data from %s\n",
	   myname,errno,filename);
    exit(1);
  }

  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array((int32type*) (*corr), dim*2 );
  }


  /*** calculate the checksum of the form factors ****/
  check_sum =  bsd_sum((char*)(*corr), sizeof(complex)*dim)  ;

  if( check_sum !=  check_sum_in )
  {
    printf("%s: ERROR: checksum mismatch bewteen the file %d and the code %d \n",
	   myname,check_sum,check_sum_in) ; 
    printf("%s: ERROR: checksum mismatch bewteen the file %d and the code %d \n",
	   myname,check_sum,check_sum_in) ; 
    printf("%s: ERROR: checksum mismatch bewteen the file %d and the code %d \n",
	   myname,check_sum,check_sum_in) ; 

/**    exit(1) ;  ****/
  }


  /*** close the file ****/
  if( fclose(fp) != 0 )
  {
    printf("%s: error %d closing %s \n",myname,errno,filename);
    exit(1);
  }

  /* Create operator list */
  if( ((*corr_oper_list) = (int *)calloc( *no_oper, sizeof(int) ) )  == NULL) 
    {
      printf("%s: There was an error in allocating the operator list\n",
	     myname);
      exit(1);
    }

  for(i = 0; i < *no_oper; i++)
    (*corr_oper_list)[i] = i;

  /* Create copy list */
  if( ((*corr_copy_list) = (int *)calloc( *nocopies, sizeof(int) ) )  == NULL) 
    {
      printf("%s: There was an error in allocating the copy list\n",
	     myname);
      exit(1);
    }

  for(i = 0; i < *nocopies; i++)
    (*corr_copy_list)[i] = i;

  printf("I have read propagating three point functions from the file %s\n",filename);

}
Ejemplo n.º 4
0
/* Same as above, but reads data for only one B meson momentum AND
   only one spectator kappa */
void read_3pt_onemom_onespect(
  complex **corr,           /* the two point correlators */
  int **corr_oper_list,     /* List of operator numbers read */
  int **corr_copy_list,     /* List of copy numbers read */
  int32type **p_momstore,      /* list of B meson momenta */
  int32type **q_momstore,      /* list of momentum transfers */
  int *nt,                  /* time values */
  int *no_p_values,         /* momentum values */
  int *no_q_values,         /* momentum values */
  int *no_oper,             /* number of operators */
  int *no_spectator,        /* the number of  kappa values */
  int *no_sequential,       /* the number of  kappa values */
  int *no_zonked ,          /* the number of  kappa values */
  int *hl_flag,             /* flag identifying type of correlator */
  char filename[80],        /* the name of the disk file */
  int *nocopies,            /* rotations */
  int p_mom_select,         /* Momentum index selected */
  int spect_select          /* Spectator kappa index selected */
)
{
  FILE *fp ;
  size_t nobj ; 
  const int32type magic_number = 14567332 ; 
  const int32type version_number  = 1  ; /** update this flag when the data format changes ***/
  int i ;
  size_t  name_len = 80 ;
  size_t howmany ;
  int check_sum ; 
  int check_sum_in ; 
  int dim ; 
  int byte_rev_flag  =  do_nothing ;
  size_t base,skip;
  int corr_stride_copy, corr_stride_mom_op, corr_stride_spect_op;
  int copy_pt,oper_pt,q_pt;
  int where,where_ram;
  char myname[] = "read_3pt_onemom";
  
  /* Memory for some header information ***/
#define HEADER_DIM_WRITE_CORR 13
  size_t  header_size = (size_t) HEADER_DIM_WRITE_CORR ;
  int32type header_data[HEADER_DIM_WRITE_CORR] ;


  /**** open the file ******/
  if( (fp = fopen(filename ,"rb")) == NULL )
  {
    printf("Could not open the file %s\n",filename);
    exit(1);
  }

  /** read the header information ***/
  if( fread(header_data,sizeof(int32type),header_size,fp) != header_size )
  {
    printf("%s: error %s reading the form factor HEADER from %s\n",
	   myname,errno,filename);
    exit(1);
  }




  /***** check the header ****/
  if( header_data[0] != magic_number )
  {
    printf("%s: ERROR: magic number mismatch between code %d and file %d\n",
	   myname,magic_number, header_data[0]  );
    printf("I will try byte reversing the data\n"); 
    byte_rev_flag = do_byte_rev ;
  }

  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array( header_data, header_size); 
  }



  if( header_data[0] != magic_number )
  {
    printf("%s: ERROR: magic number mismatch between code %d and file %d\n",
	   myname,magic_number, header_data[0]  );
    exit(1); 
  }

  if( header_data[1] != version_number )
  {
    printf("%s: ERROR: version number mismatch between code %d and file %d\n",
	   myname,version_number, header_data[1]);
    exit(1); 
  }


  *nt = header_data[2]  ;
  check_sum_in = header_data[3] ;
  *no_p_values = header_data[4] ;
  *no_q_values = header_data[5] ;
  *no_oper = header_data[6] ;
  *no_spectator = header_data[7]   ;
  *no_zonked = header_data[8]  ;
  dim = header_data[9]  ;
  *hl_flag  = header_data[10]  ;
  *no_sequential = header_data[11]  ;
  *nocopies = header_data[12]  ;

  /*******  read some more data from the file **********/

  /*** read the external momentum from the  file ***/
  howmany = (size_t) 3*(*no_q_values) ;
  if( ( (*q_momstore) = (int32type *)calloc( howmany , sizeof(int32type))   )  == NULL) 
  {
    printf("%s: There was an error in allocating q-momentum \n",myname);
    exit(1);
  }

  if( fread((*q_momstore)  ,sizeof(int32type),howmany,fp) != howmany   )
  {
    printf("%s: error %d during reading the q-momentum table from %s\n",
	   myname,errno,filename);
    exit(1);
  }

  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array((*q_momstore) , (int) howmany );
  }




  /*** read the external momentum from the  file ***/
  howmany = (size_t) 3*(*no_p_values) ;
  if( ( (*p_momstore) = (int32type *)calloc( howmany , sizeof(int32type))   )  == NULL) 
  {
    printf("%s: There was an error in allocating p--momentum \n",myname);
    exit(1);
  }

  if( fread((*p_momstore)  ,sizeof(int32type),howmany,fp) != howmany   )
  {
    printf("%s: error %d reading the p-momentum table from %s\n",
	   myname,errno,filename);
    exit(1);
  }

  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array((*p_momstore) , (int) howmany );
  }

  /*** reserve memory for the three point function ****/
  /* REDUCE THE STATED DIMENSION BY THE NUMBER OF P-VALUES AND
     THE NUMBER OF SPECTATOR VALUES BECAUSE
     WE ARE SELECTING ONLY ONE */
  dim /= *no_p_values;
  dim /= *no_spectator;
  nobj = (size_t) dim ; 
  if( ((*corr) = (complex *)calloc( nobj , sizeof(complex) ) )  == NULL) 
  {
    printf("%s: There was an error in allocating the three point function, nobj = %d\n",
	   myname,nobj);
    exit(1);
  }

  /* The indexing is as follows:
     linear(t,zonk_pt,seq_pt,spect_pt,q_pt,p_pt,oper_pt,copy) =
     t + nt*(zonk_pt + no_zonked*(seq_pt + no_sequential*(spect_pt +
         no_spectator*(q_pt + no_q_values*(p_pt + 
         no_p_values*(oper_pt + no_oper*copy_pt))))))
  */

  /* Stride between spectator quark values */
  /* linear(0,0,0,spect_pt+1,0,0,0,0) - linear(0,0,0,spect_pt,0,0,0,0) */
  corr_stride_spect_op = 
    (*nt)*(*no_zonked)*(*no_sequential);

  /* Get current file pointer location (at beginning of data) */
  base = ftell(fp);

  /* The spect_pt index is 4th in the corr array, and the momentum
     index is 6th so we block on the 1st 3 indices, select the 4th,
     iterate explicitly over the 5th, select the 6th and iterate over
     the 7th and 8th. */

  for(copy_pt = 0; copy_pt < *nocopies; copy_pt++)
    for(oper_pt = 0; oper_pt < *no_oper; oper_pt++)
      for(q_pt = 0; q_pt < *no_q_values; q_pt++){

	/** locate the required correlator in the file corr array **/

	where = corr_stride_spect_op*(spect_select +
          (*no_spectator)*(q_pt + (*no_q_values)*(p_mom_select + 
	   (*no_p_values)*(oper_pt + (*no_oper)*copy_pt))));

	/** locate the required correlator in the RAM corr array **/
	/* Because no_spectator = no_p_values = 1 the indexing
	   is as follows:

	   linear(t,zonk_pt,seq_pt,spect_pt,q_pt,p_pt,oper_pt,copy) =
	   t + nt*(zonk_pt + no_zonked*(seq_pt + 
           no_sequential*(q_pt + no_q_values*(oper_pt + no_oper*copy_pt))))
	*/

	where_ram = corr_stride_spect_op*(q_pt + 
   	     (*no_q_values)*(oper_pt + (*no_oper)*copy_pt));

	/** read a portion of the the three point functions from disk *****/
	nobj = (size_t) corr_stride_spect_op ; 
	
	/* Position the file for reading */
	skip = where*sizeof(complex);
	fseek(fp,base+skip,SEEK_SET);
	
	/** read the three point function to disk *****/
	if( fread(&((*corr)[where_ram]),sizeof(complex),nobj,fp) != nobj   )
	  {
	    printf("%s: error %d reading the form factor data from %s\n",
		   myname,errno,filename);
	    exit(1);
	  }
	
	if(  byte_rev_flag == do_byte_rev    )
	  {
	    byte_rev_array((int32type*)(&((*corr)[where_ram])), nobj*2 );
	  }
      }
  
  /*** calculate the checksum of the form factors ****/
  /**  check_sum =  bsd_sum((char*)(*corr), sizeof(complex)*dim)  ;
       
  if( check_sum !=  check_sum_in )
  {
    printf("%s: ERROR: checksum mismatch bewteen the file %d and the code %d \n",
    myname,check_sum,check_sum_in) ; 
    printf("%s: ERROR: checksum mismatch bewteen the file %d and the code %d \n",
    myname,check_sum,check_sum_in) ; 
    printf("%s: ERROR: checksum mismatch bewteen the file %d and the code %d \n",
    myname,check_sum,check_sum_in) ; 

  } **/


  /*** close the file ****/
  if( fclose(fp) != 0 )
    {
      printf("%s: error %d closing %s \n",myname,errno,filename);
      exit(1);
    }
  
  /* Create operator list */
  if( ((*corr_oper_list) = (int *)calloc( *no_oper, sizeof(int) ) )  == NULL) 
    {
      printf("%s: There was an error in allocating the operator list\n",
	     myname);
      exit(1);
    }
  
  for(i = 0; i < *no_oper; i++)
    (*corr_oper_list)[i] = i;
  
  /* Create copy list */
  if( ((*corr_copy_list) = (int *)calloc( *nocopies, sizeof(int) ) )  == NULL) 
    {
      printf("%s: There was an error in allocating the copy list\n",myname);
      exit(1);
    }
  
  for(i = 0; i < *nocopies; i++)
    (*corr_copy_list)[i] = i;

  /* Now pretend that only one momentum was read from this file */
  (*p_momstore)[0] = (*p_momstore)[3*p_mom_select];
  (*p_momstore)[1] = (*p_momstore)[3*p_mom_select+1];
  (*p_momstore)[2] = (*p_momstore)[3*p_mom_select+2];

  printf("I have read three point functions for B momentum %d %d %d and spectator index %d from %s\n",
	 (*p_momstore)[0],(*p_momstore)[1],
	 (*p_momstore)[2],spect_select,filename);
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
  FILE *fp ;
  int nt,nosmear ;
  size_t nobj   ;
  Real *vary_matrix ;
  Real *coeff ;
  char vary_out[80] ;
  int i ;
  const int local_src = 0 ;
  char src_name[NAME_LEN] ;
  size_t  name_len = NAME_LEN ;
  char coeff_file[NAME_LEN] ;
  int which_source ; 
  int arg_pt ;
  enum which_corr { NOT_SET = -10 , SINGLE_SRC , VARY_SRC} ;
  int what_src = NOT_SET ;

  int what_fold = NO_TIME_AVERAGE ; /** default is not to average over time ***/
   int byte_rev_flag ; 

  /*********..........**********........*****************/

  printf("=============================================================\n");
  printf(" Extraction of LS and SS correlators from variational matrix \n");
  printf("=============================================================\n");

  if( argc < 3  )
  {
    dump_usage(argv[0]) ;
  }
  strcpy(vary_out,argv[1]);
  which_source = atoi(argv[2]);

  /** parse the input arguments *******/
  arg_pt = 2 ;
  while( arg_pt < argc )
  {

    if( strcmp(argv[arg_pt],"-s" ) == 0 )
    {
      if( what_src != NOT_SET ) dump_usage(argv[0]) ;
      which_source = atoi(argv[arg_pt + 1]);
      arg_pt += 2 ;
      what_src = SINGLE_SRC  ;
    }
    else if( strcmp(argv[arg_pt],"-c" ) == 0 )
    {
      if( what_src != NOT_SET ) dump_usage(argv[0]) ;
      strcpy(coeff_file ,argv[arg_pt+1]);
      arg_pt += 2 ;
      what_src = VARY_SRC  ;
    }
    else if( strcmp(argv[arg_pt],"-fold" ) == 0 )
    {
      what_fold = AVERAGE_TIME  ;
      arg_pt += 1 ;
    }
    else
    {
      dump_usage(argv[0]);
    }


  }


  /**** open the file and read the header  ******/
  fp = read_vary_header(vary_out, local_src,which_source,
			src_name,&nosmear, &nt,&byte_rev_flag ) ;


  printf("The number of timeslices = %d\n",nt);
  printf("The number of smearing functions = %d\n",nosmear);

  /* reserve memory for the variational matrix *****/
  nobj        =  (size_t) nt*nosmear*nosmear  ;
  vary_matrix =  (Real *)  calloc( nobj , sizeof(Real) );

  /** read the variational matrix from disk *****/
  if( fread(vary_matrix,sizeof(Real),nobj,fp) != nobj   )
  {
    printf("There was an error during the reading of the variational matrix \n");
    exit(1);
  }

  /*** close the file ****/
  if( fclose(fp) != 0 )
  {
    printf("There was an error during the closing of %s \n",vary_out);
    exit(1);
  }

  /***  byte_reverse if required ***/

  if(  byte_rev_flag == do_byte_rev    )
  {
    byte_rev_array((int*) vary_matrix, (int) nobj); 
  }




  printf("I have read the variational matrix from the file %s\n",vary_out);

  /* write the correlatorsto file *****/ 
  if( what_src == SINGLE_SRC  )
  {
    if( which_source < 0 || which_source >= nosmear)
    {
      printf("ERROR which_source = %d is out of range 0 to %d\n",which_source,nosmear);
      exit(2);
    }
    printf("smearing_function_file  = %s\n",src_name);

    dump_LSandSS_corr(vary_matrix,which_source, vary_out, local_src,what_fold,nt, nosmear);
  }
  else if( what_src == VARY_SRC  )
  {
    coeff = (Real *) calloc( (size_t) nosmear, sizeof(Real) );
    read_coeff_file(coeff_file ,coeff, nosmear);
    dump_vary_LSandSS_corr(vary_matrix,coeff, vary_out, local_src,what_fold,nt, nosmear);
    free(coeff);
  }
  else
  {
    printf("Bad option chosen \n");
    dump_usage(argv[0]);
  }
  
  if(what_fold == AVERAGE_TIME   )
  {
    printf("\nThe correlators will be averaged over positive and negative times\n");
  }


  /* Free up the memory used in the calculation ***/
  free(vary_matrix);

  return 0 ;

}