CHROMA
t_io.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <cstdio>
4 
5 #include "chroma.h"
6 
7 using namespace Chroma;
8 
9 const std::string foo_xml="<?xml version='1.0'?><foo><coeffs1>ZOLOTAREV</coeffs1><coeffs2>TANH</coeffs2></foo>";
10 
11 int main(int argc, char **argv)
12 {
13  // Put the machine into a known state
14  Chroma::initialize(&argc, &argv);
15 
16  // Setup the layout
17  const int foo[] = {2,2,2,2};
18  multi1d<int> nrow(Nd);
19  nrow = foo; // Use only Nd elements
20  Layout::setLattSize(nrow);
21  Layout::create();
22 
23  XMLFileWriter xml_out("t_io.xml");
24  push(xml_out, "t_io");
25 
26  {
27  LatticeReal a;
28  Double d = 17;
29  random(a);
30 
31  push(xml_out,"xml_test");
32  write(xml_out,"a", a);
33  write(xml_out,"d", d);
34  pop(xml_out);
35 
36  BinaryFileWriter tobinary("t_io.bin");
37  write(tobinary, a);
38  write(tobinary, d);
39  tobinary.close();
40  }
41 
42  {
43  TextFileWriter totext("t_io.txt");
44  totext << int(17) << "\n";
45  }
46 
47  {
48  float x;
49  QDPIO::cout << "Read some data from t_io.txt\n";
50  TextFileReader from("t_io.txt");
51  from >> x;
52  from.close();
53 
54  QDPIO::cout << "you entered :" << x << ":\n";
55  }
56 
57  {
58  multi1d<LatticeColorMatrix> u(Nd);
59  for(int i=0; i < u.size(); ++i)
60  gaussian(u[i]);
61 
62  XMLBufferWriter file_xml, record_xml;
63  push(file_xml, "The_file_xml");
64  write(file_xml, "mary", int(3));
65  pop(file_xml);
66 
67  push(record_xml, "The_record_xml");
68  write(record_xml, "lamb", int(7));
69  pop(record_xml);
70 
71  push(xml_out, "QIO_write_test");
72  write(xml_out, "file_xml", file_xml);
73  write(xml_out, "record_xml", record_xml);
74  write(xml_out, "u", u);
75  pop(xml_out);
76 
77  writeGauge(file_xml, record_xml, u, "t_io.cfg",
78  QDPIO_SINGLEFILE, QDPIO_SERIAL);
79  }
80 
81  {
82  multi1d<LatticeColorMatrix> u(Nd);
83  XMLReader file_xml, record_xml;
84 
85  readGauge(file_xml, record_xml,
86  u, "t_io.cfg",
87  QDPIO_SERIAL);
88 
89  push(xml_out, "QIO_read_test");
90  write(xml_out, "file_xml", file_xml);
91  write(xml_out, "record_xml", record_xml);
92  write(xml_out, "u", u);
93  pop(xml_out);
94  }
95 
96 
97  CoeffType t1;
98  CoeffType t2;
99  std::istringstream foo_xml_is(foo_xml);
100  XMLReader fooreader(foo_xml_is);
101 
102  try {
103  read(fooreader, "/foo/coeffs1", t1);
104  read(fooreader, "/foo/coeffs2", t2);
105  }
106  catch(const std::string& e) {
107  QDPIO::cerr << "Caught error : " << e << std::endl;
108  QDP_abort(1);
109  }
110 
111  try {
112  write(xml_out, "coeffs1", t1);
113  write(xml_out, "coeffs2", t2);
114  }
115  catch(const std::string& e) {
116  QDPIO::cerr << "Caught error : " << e << std::endl;
117  QDP_abort(1);
118  }
119 
120  pop(xml_out);
121 
122 
123  // Time to bolt
125 
126  exit(0);
127 }
Primary include file for CHROMA in application codes.
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 readGauge(XMLReader &file_xml, XMLReader &record_xml, multi1d< LatticeColorMatrix > &u, const std::string &file, QDP_serialparallel_t serpar)
Read a gauge config in QIO format.
Definition: gauge_io.cc:19
CoeffType
Coeffs type.
void writeGauge(XMLBufferWriter &file_xml, XMLBufferWriter &record_xml, const multi1d< LatticeColorMatrix > &u, const std::string &file, QDP_volfmt_t volfmt, QDP_serialparallel_t serpar)
Write a gauge config in QIO format.
Definition: gauge_io.cc:60
int x
Definition: meslate.cc:34
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
Complex a
Definition: invbicg.cc:95
pop(xml_out)
DComplex d
Definition: invbicg.cc:99
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
int main(int argc, char **argv)
Definition: t_io.cc:11
const std::string foo_xml
Definition: t_io.cc:9