CHROMA
writemilc.cc
Go to the documentation of this file.
1 
2 /*! \file
3  * \brief Writer a MILC gauge configuration in the 1997 format
4  */
5 
6 #include "chromabase.h"
7 #include "io/milc_io.h"
8 #include "io/writemilc.h"
9 #include "qdp_util.h" // from QDP
10 
11 #include <string>
12 using std::string;
13 
14 namespace Chroma {
15 
16 //! Write a MILC configuration file
17 /*!
18  * \ingroup io
19  *
20  * \param header structure holding config info ( Read )
21  * \param u gauge configuration ( Read )
22  * \param cfg_file path ( Read )
23  */
24 
25 void writeMILC(const MILCGauge_t& header, const multi1d<LatticeColorMatrix>& u,
26  const std::string& cfg_file)
27 {
28  START_CODE();
29 
30  BinaryFileWriter cfg_out(cfg_file); // for now, cfg_io_location not used
31 
32  int magic_number = 20103;
33  write(cfg_out, magic_number);
34 
35  write(cfg_out, header.nrow, Nd);
36 
37  // Time stamp - write exactly 64 bytes padded with nulls
38  char date_tmp[65];
39  int len = (header.date.size() < 64) ? header.date.size() : 64;
40  memset(date_tmp, '\0', 65);
41  memcpy(date_tmp, header.date.data(), len);
42  cfg_out.writeArray(date_tmp, 1, 64);
43 
44  // Site order - only support non-sitelist format
45  int order = 0;
46  write(cfg_out, order);
47 
48  // Go ahead and write checksums, but will not use for now
49  unsigned int sum29=0, sum31=0; // WARNING: these are BOGUS
50  write(cfg_out, sum29);
51  write(cfg_out, sum31);
52 
53  /*
54  * Write away...
55  */
56 
57  // MILC format has the directions inside the sites
58  for(int site=0; site < Layout::vol(); ++site)
59  {
60  multi1d<int> coord = crtesn(site, Layout::lattSize()); // The coordinate
61 
62  // Write Nd SU(3) matrices.
63  for(int j = 0; j < Nd; j++)
64  {
65  // NOTE: the su3_matrix layout should be the same as in QDP
66  write(cfg_out, u[j], coord);
67  }
68  }
69 
70  cfg_out.close();
71 
72  END_CODE();
73 }
74 
75 
76 
77 //! Write a MILC configuration file
78 /*!
79  * \ingroup io
80  *
81  * \param xml xml writer holding config info ( Modify )
82  * \param u gauge configuration ( Modify )
83  * \param cfg_file path ( Write )
84  */
85 
86 void writeMILC(XMLBufferWriter& xml, multi1d<LatticeColorMatrix>& u, const std::string& cfg_file)
87 {
88  START_CODE();
89 
90  MILCGauge_t header;
91  XMLReader xml_in(xml); // use the buffer writer to instantiate a reader
92  read(xml_in, "/MILC", header);
93 
94  writeMILC(header, u, cfg_file);
95 
96  END_CODE();
97 }
98 
99 } // end namespace Chroma
Primary include file for CHROMA library code.
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void writeMILC(const MILCGauge_t &header, const multi1d< LatticeColorMatrix > &u, const std::string &cfg_file)
Write a MILC configuration file.
Definition: writemilc.cc:25
unsigned j
Definition: ldumul_w.cc:35
multi1d< int > coord(Nd)
Nd
Definition: meslate.cc:74
MILC gauge format routines.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
START_CODE()
::std::string string
Definition: gtest.h:1979
MILC gauge field header.
Definition: milc_io.h:17
multi1d< int > nrow
Definition: milc_io.h:19
std::string date
Definition: milc_io.h:20
Write a MILC gauge configuration in the 1997 format.