CHROMA
readcppacs.cc
Go to the documentation of this file.
1 
2 /*! \file
3  * \brief Read a CPPACS gauge configuration
4  */
5 
6 #include "chromabase.h"
7 #include "io/cppacs_io.h"
8 #include "io/readcppacs.h"
9 #include "qdp_util.h" // from QDP
10 
11 namespace Chroma {
12 
13 //! Read a CPPACCPPACS configuration file
14 /*!
15  * \ingroup io
16  *
17  * Based on the C-routine ToSTDConf.c available at
18  * http://www.lqa.rccp.tsukuba.ac.jp/tools.html
19  *
20  * Author: Andreas Juettner
21  *
22  * \param header structure holding config info ( Modify )
23  * \param u gauge configuration ( Modify )
24  * \param cfg_file path ( Read )
25  */
26 
27 void readCPPACS(CPPACSGauge_t& header, multi1d<LatticeColorMatrix>& u, const std::string& cfg_file)
28 {
29  START_CODE();
30 #define NBC 144 /* = 8*2*3*3 = number of bytes to copy */
31 #define NBK 0 /* = 8*2*3*0 = number of bytes to skip */
32 #define NBS 576 /* = 8*2*3*3*4 = number of bytes for each site */
33  int NX,NY,NZ,NT ;
34  char header_ildg[1020] ;
35  int Nsp, Ntm;
36 
37 #ifdef PLAQ
38  double wss,wst ;
39 #endif
40  NT = Layout::lattSize()[3];
41  NZ = Layout::lattSize()[2];
42  NY = Layout::lattSize()[1];
43  NX = Layout::lattSize()[0];
44  BinaryFileReader cfg_in(cfg_file) ;
45  int magic_number ;
46  read(cfg_in, magic_number);
47 
48  bool byterev = false;
49  if( magic_number != 19920410 ) {
50  QDPIO::cout << "readCPPACS: magic number invalid" << std::endl;
51  QDPIO::cout << "Trying byte reversal" << std::endl;
52  QDPUtil::byte_swap((void *)&magic_number, sizeof(int), 1 );
53  byterev = true;
54  }
55  QDPIO::cout << "Magic number: " << magic_number << std::endl;
56 
57 
58  if( magic_number != 19920410){
59  QDP_error_exit("readCPPACS: unexpected magic number");
60  }
61 
62  if(byterev)
63  QDPIO::cout<<"Doing bytereversal on the links...\n" ;
64 
65  // read in the header
66  cfg_in.readArray(header_ildg,1,1020);
67  /* read header and check file name */
68 
69  /* check lattice size */
70  header_ildg[19] = '\0' ; Ntm = atoi(&header_ildg[17]) ;
71  header_ildg[16] = '\0' ; Nsp = atoi(&header_ildg[14]) ;
72  if( Ntm != NT ) {
73  fprintf(stderr,"readCPPACS: NT mismatch %d %d\n",NT,Ntm) ;
74  exit(1) ; }
75  if( Nsp != NZ ) {
76  fprintf(stderr,"readCPPACS: NX mismatch %d %d\n",NX,Nsp) ;
77  exit(1) ; }
78  if( Nsp != NY ) {
79  fprintf(stderr,"readCPPACS: NY mismatch %d %d\n",NY,Nsp) ;
80  exit(1) ; }
81  if( Nsp != NX ) {
82  fprintf(stderr,"readCPPACS: NZ mismatch %d %d\n",NZ,Nsp) ;
83  exit(1) ; }
84 
85 // Read in SU(3) matrices.
86 // the running of the lexicographic index and the su3_matrix layout in CPPACS
87 // gauge configs is the same as in QDP
88 // (the fastest running direction is the 0th direction, corresponding to the
89 // x-direction)
90 
91  u = zero ;
92 
93  LatticeColorMatrixD uu ;
94 
95  ColorMatrixD uuuD ;
96  ColorMatrix uuu ;
97 
98  for(int site=0; site < Layout::vol(); ++site)
99  {
100  multi1d<int> coord = crtesn(site, Layout::lattSize()); // The coordinate
101  // read in a single site
102  for(int mu=0; mu < Nd; ++mu)
103  {
104  read(cfg_in, uuuD );
105  if(byterev){
106  QDPUtil::byte_swap((void *)&uuuD.elem(),sizeof(double),2*Nc*Nc);
107  }
108  uuu = uuuD ;
109  pokeSite(u[mu],uuu,coord);
110  }
111 
112  }
113 
114  cfg_in.close();
115 
116  END_CODE();
117 }
118 
119 
120 
121 //! Read a CPPACS configuration file
122 /*!
123  * \ingroup io
124  *
125  * \param xml xml reader holding config info ( Modify )
126  * \param u gauge configuration ( Modify )
127  * \param cfg_file path ( Read )
128  */
129 
130 void readCPPACS(XMLReader& xml, multi1d<LatticeColorMatrix>& u, const std::string& cfg_file)
131 {
132  START_CODE();
133 
134  CPPACSGauge_t header;
135 
136  // Read the config and its binary header
137  readCPPACS(header, u, cfg_file);
138 
139 #if 0
140  // Now, set up the XML header. Do this by first making a buffer
141  // writer that is then used to make the reader
142  XMLBufferWriter xml_buf;
143 // write(xml_buf, "CPPACS", header);
144 
145  try
146  {
147  xml.open(xml_buf);
148  }
149  catch(const std::string& e)
150  {
151  QDP_error_exit("Error in readCPPACS: %s",e.c_str());
152  }
153 #endif
154 
155  END_CODE();
156 }
157 
158 } // end namespace Chroma
159 
Primary include file for CHROMA library code.
int mu
Definition: cool.cc:24
CPPACS gauge format routines.
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void readCPPACS(CPPACSGauge_t &header, multi1d< LatticeColorMatrix > &u, const std::string &cfg_file)
Read a CPPACCPPACS configuration file.
Definition: readcppacs.cc:27
multi1d< int > coord(Nd)
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
QDP_error_exit("too many BiCG iterations", n_count, rsd_sq, cp, c, re_rvr, im_rvr, re_a, im_a, re_b, im_b)
static multi1d< LatticeColorMatrix > u
START_CODE()
Double zero
Definition: invbicg.cc:106
::std::string string
Definition: gtest.h:1979
Read a CPPACS gauge configuration.
CPPACS gauge field header.
Definition: cppacs_io.h:16