to.close();
int main(int argc, char *argv[]){  // Put the machine into a known state  QDP_initialize(&argc, &argv);  // Setup the layout  const int foo[] = {2,2,2,2};  multi1d<int> nrow(Nd);  nrow = foo;  // Use only Nd elements  Layout::setLattSize(nrow);  Layout::create();  NmlWriter nml("foo.nml");//  nml.open("foo.nml");  Write(nml,nrow);#if defined(ARCH_PARSCALAR)  write(nml,"logicalSize",Layout::logicalSize());#endif#if 1  cerr << "Open t_foo.input" << endl;  NmlReader nml_in("t_foo.input");  {    int x;    push(nml_in,"stuff");    Read(nml_in,x);      Write(nml,x);  }  nml_in.close();#endif#if 0  {    LatticeFermion a,b;    random(a); random(b);    Double   rfoo;    DComplex foo;    rfoo = norm2(a);    foo = innerProduct(a,b);    Write(nml,rfoo);  }#endif#if 0  {    LatticeColorMatrix a,b,c;    a = b = c = 1;    LatticeComplex e;    e = colorContract(a,b,c);    Write(nml,e);  }#endif  #if 1  {    LatticeColorVector a,b,c;    LatticeReal one = 1;    LatticeComplex comp = cmplx(one,0);    // Setting a,b,c = 1 for all components should cancel after contraction    c = zero;    for(int m=0; m < Nc; ++m)      pokeColor(c,comp,m);    a = b = c;    LatticeComplex f;    f = colorContract(a,b,c);    Write(nml,f);    // Setting a,b,c = 1 for just 1 set of components should not cancel    a = b = c = zero;    pokeColor(a,comp,0);    pokeColor(b,comp,2);    pokeColor(c,comp,1);    LatticeComplex g;    g = colorContract(a,b,c);    Write(nml,g);  }#endif  #if 0  {    Map near;    Nearest bbb;    near.make(bbb);    LatticeReal fred,sue;    random(fred);    sue = near(fred);    Write(nml,fred);    Write(nml,sue);  }#endif#if 0  {    BiDirectionalMap near;    Nearest bbb;    near.make(bbb);    LatticeReal fred,sue,sam;    random(fred);    sue = near(fred,+1);    sam = near(fred,-1);    Write(nml,fred);    Write(nml,sue);    Write(nml,sam);  }#endif#if 0  {    ArrayMap nearneigh;    NearestNeighborMapFunc bbb;    nearneigh.make(bbb);    LatticeReal fred,sue;    random(fred);    Write(nml,fred);    for(int m=0; m < Nd; ++m)    {      sue = nearneigh(fred,m);      Write(nml,m);      Write(nml,sue);    }  }#endif#if 0  {    ArrayBiDirectionalMap nearneigh;    NearestNeighborMapFunc bbb;    nearneigh.make(bbb);//    LatticeReal fred,sue,sam;    LatticeColorMatrix fred;    random(fred);    Write(nml,fred);    for(int m=0; m < Nd; ++m)    {      LatticeColorMatrix sue = nearneigh(fred,+1,m);      LatticeColorMatrix sam;      sam = nearneigh(fred,-1,m);      Write(nml,m);      Write(nml,sue);      Write(nml,sam);    }  }#endif//  exit(0);  cerr << "try a string\n";  nml << "write a string";  Real one = 1.0;  cerr << "try a scalar\n";  nml << "write a scalar";  write(nml,"test this",one);//  exit(0);  cerr << "latticereal\n";  LatticeReal bar = 17.0;  random(bar);//  for(int i=0; i < Layout::subgridVol(); ++i)//    cerr << "bar[" << i << "]=" << bar.elem(i) << endl;  cerr << "write\n";  Write(nml,bar);  cerr << "done write\n";#if 0  // Initialize the random number generator  Seed seed;  seed = 11;  nml << seed;  RNG::setrn(seed);#endif//  typedef QDPType<int> LatticeInteger;//  typedef OLattice<int> LatticeInteger;//  typedef QDPType<OLattice<int> > LatticeInteger;//  LatticeComplexInteger a, b, c;//  LatticeReal a, b, c;  LatticeReal a, b, c, e;  Complex d;//  float ccc = 2.0;//  float x;  #if 0  LatticeComplex  foob(zero);  nml << "Here is foob";  Write(nml,foob);#endif#if 1  b = 3;  c = 4;  d = 5;  b[rb[1]] = zero;  nml << "First set of b";  Write(nml,b);  random(b);  nml << "Second set of b";  Write(nml,b);  b[rb[0]] = -17;  nml << "Third set of b";  Write(nml,b);//  b.elem(1).elem() = -1;//  b.elem().elem(1).elem() = -1;//  b.elem().elem(1) = -1;  nml << "here 0";#endif//  a = -b + c*d;//  a = c*d - b;//  a = b*c;//  a = -b + ccc*c;//  a = -b + 2*c;  a = shift(b*c,FORWARD,0);//  a = b*c;//  a = ccc*c;//  x = ccc*c;  nml << "here b";  Write(nml,b);  nml << "here a";  Write(nml,a);  nml << "here e";  LatticeReal rr;//  random(rr);  rr = 0.2;  e = where(rr < 0.5, a, c);  Write(nml,e);#if 1  nml << "test peekColor";  LatticeColorMatrix barf = 1.0;  LatticeComplex fred = peekColor(barf,0,0);  Write(nml,barf);  Write(nml,fred);  multi1d<int> ccrd(Nd);  ccrd = 1;  nml << "test peeksite";  random(fred);  Complex sitefred = peekSite(fred,ccrd);  Write(nml,fred);  Write(nml,sitefred);  nml << "test pokeColor";  random(barf);  fred = 1.0;  LatticeColorMatrix barfagain = pokeColor(barf,fred,0,0);  Write(nml,barfagain);  nml << "test pokeSite";  random(sitefred);  LatticeComplex fredagain = pokeSite(fred,sitefred,ccrd);  Write(nml,fredagain);#endif#if 0  a = -b + ccc*c;//  a = ccc*c;  nml << "here a";  Write(nml,a);#endif#if 0//  std::ofstream f;//  f.open("foobar",std::ios_base::out|std::ios_base::binary);//  float aa[3] = {0.0,0.0,0.0};//  std::fwrite(&aa,sizeof(LatticeComplex),1,f.rdbuf());//  f.close();  {    NmlWriter to("fred.txt");    write(to,"a",a);  }  {    cerr << "open fred.bin\n";    BinaryWriter to("fred.bin");    write(to,a);  }  {    float x;    cerr << "enter some data" << endl;    TextReader from("input");    from >> x;    cerr << "float: you entered :" << x << ":" << endl;  }  {    Real x;    cerr << "enter some data" << endl;    TextReader from("input");    from >> x;    cerr << "Real: you entered :" << x << ":" << endl;  }    // Zero out a and read it again  a = zero;  {    BinaryReader from("fred.bin");    read(from,a);  }  nml << "Reset and reread a";  Write(nml,a);#endif#if 1 {   cerr << "create metadata xml" << endl;   XMLMetaWriter xml;   push(xml,"fred");   float yy = 42.1;   write(xml,"yy",yy);   Real zzz = 3.1;   Complex zz = cmplx(17.5,zzz);   write(xml,"zz",zz);#if 0   LatticeComplex ee;   random(ee);   write(xml,"ee",ee);   LatticeFermion ff;   random(ff);   write(xml,"ff",ff);#endif   pop(xml);   cout << "Here is the metadata" << endl << xml.str() << endl;   XMLDataWriter file_xml("t_foo.xml_output");   file_xml.writeXML(xml.printRoot()); }#endif#if 1 {   cerr << "read metadata xml" << endl;   XMLReader xml;   xml.open("t_foo.xml_output");   float yy;   read(xml,"/fred/yy",yy);   Write(nml,yy);   cerr << "Found reading metadata xml that  yy = " << yy << endl;//   Complex zz;//   read(xml,"zz",zz);//   Write(nml,zz); }#endif#if 1 {   cerr << "create xml" << endl;   XMLMetaWriter file_xml;   string file_string = "Here is the file xml";//   int file_string = -1;   write(file_xml,"file_string",file_string);   XMLMetaWriter rec_xml;   string rec_string = "Here is the record xml";//   int rec_string = -3;   write(rec_xml,"rec_string",rec_string);   gaussian(a);   gaussian(b);   nml << "Test of QDPSerialWriter - here first is a";   Write(nml,a);   nml << "Test of QDPSerialWriter - here first is a";   Write(nml,b);   cerr << "create serialwriter" << endl;   QDPSerialWriter to(file_xml,"fred.dime");   cerr << "write to" << endl;   to.write(rec_xml,a);   cerr << "end write" << endl;   to.write(rec_xml,b);   cerr << "end write" << endl;   nml << "Test of QDPSerialWriter";   Write(nml,a);   Write(nml,b); }#endif#if 1 {   cerr << "create xml" << endl;   XMLReader file_xml;   XMLReader rec_xml;   a = 0;   b = 0;   cerr << "open serialreader" << endl;   QDPSerialReader from(file_xml,"fred.dime");   cerr << "read from file" << endl;   from.read(rec_xml,a);   cerr << "end read 1" << endl;   from.read(rec_xml,b);   cerr << "end read 2" << endl;   nml << "Read a and b from QDPSerialReader";   Write(nml,a);   Write(nml,b); }#endif#if 0  if (Nd == 4)  {    // Read a nersc file    multi1d<LatticeColorMatrix> u(Nd);    readArchiv(u, "archiv.cfg");    nml << "Here is the nersc archive u field";    Write(nml,u);  }#endif#if 0  if (Nd == 4)  {    // Read a szin gauge file    multi1d<LatticeColorMatrix> u(Nd);    Seed seed_old;    cerr << "Calling szin reader" << endl;    readSzin(u, 0, "szin.cfg", seed_old);    nml << "Here is the SZIN u field";    Write(nml,u);  }#endif#if 0  if (Nd == 4)  {    // Read a szin quark prop file    LatticePropagator qprop;    cerr << "Read a szin qprop" << endl;    readSzinQprop(qprop, "propagator_0");    nml << "Here is the szin quark prop";    Write(nml,qprop);  }#endif#if 0  LatticeInteger d;  nml << "here c";  const Expression<BinaryNode<OpAdd,    Reference<LatticeInteger>, Reference<LatticeInteger> > > &expr1 = b + c;  nml << "here d";  d = expr1;  nml << "here e";  nml << d;  nml << "here f";    int num = forEach(expr1, CountLeaf(), SumCombine());  nml << num << endl;//  const Expression<BinaryNode<OpAdd, Reference<LatticeInteger>, //    BinaryNode<OpMultiply, Scalar<int>,//    Reference<LatticeInteger> > > > &expr2 = b + 3 * c;//  num = forEach(expr2, CountLeaf(), SumCombine());//  nml << num << endl;    const Expression<BinaryNode<OpAdd, Reference<LatticeInteger>,     BinaryNode<OpMultiply, Reference<LatticeInteger>,    Reference<LatticeInteger> > > > &expr3 = b + c * d;  num = forEach(expr3, CountLeaf(), SumCombine());  nml << num << endl;#endif  // Time to bolt  QDP_finalize();  return 0;}