Commit 7bce03a7 by Francois Gygi

Use SampleWriter.


git-svn-id: http://qboxcode.org/svn/qb/trunk@485 cba15fb0-1239-40c8-b417-11db7ca47a34
parent 04af7a49
......@@ -3,20 +3,14 @@
// SaveCmd.C:
//
////////////////////////////////////////////////////////////////////////////////
// $Id: SaveCmd.C,v 1.10 2006-05-13 05:40:42 fgygi Exp $
// $Id: SaveCmd.C,v 1.11 2007-01-27 23:49:41 fgygi Exp $
#include "SaveCmd.h"
#include "fstream"
#include "SampleWriter.h"
#include "isodate.h"
#include "release.h"
#include "qbox_xmlns.h"
#ifdef USE_CSTDIO_LFS
#include <cstdio>
#include <cstdlib>
#include <sstream>
#endif
using namespace std;
////////////////////////////////////////////////////////////////////////////////
......@@ -31,7 +25,7 @@ int SaveCmd::action(int argc, char **argv)
}
// set default encoding
string encoding = "base64";
bool base64 = true;
bool atomsonly = false;
char* filename = 0;
......@@ -42,11 +36,7 @@ int SaveCmd::action(int argc, char **argv)
if ( arg=="-text" )
{
encoding = "text";
}
else if ( arg=="-base64" )
{
encoding = "base64";
base64 = false;
}
else if ( arg=="-atomsonly" )
{
......@@ -72,89 +62,10 @@ int SaveCmd::action(int argc, char **argv)
<< endl;
return 1;
}
SampleWriter swriter(s->ctxt_);
string description = string(" Created ") + isodate() +
string(" by qbox-") + release() + string(" ");
swriter.writeSample(*s, filename, description, base64, atomsonly);
#if USE_CSTDIO_LFS
// This section for compilers with broken large file support
// As of 2003-09-30, this includes gcc-3.2, icc-7.0, pgCC-5.0
// IBM xlC has correct large file support
// Remove this ifdef when other compilers catch up...
FILE* outfile;
if ( ui->onpe0() )
{
outfile = fopen(filename,"w");
string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<fpmd:sample xmlns:fpmd=\"");
header += qbox_xmlns();
header += string("\"\n");
header += string(
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
header += string(" xsi:schemaLocation=\"");
header += qbox_xmlns();
header += string(" sample.xsd\">\n");
off_t len = header.size();
fwrite(header.c_str(),sizeof(char),len,outfile);
string desc = string("<description> Created ") +
isodate() +string(" by qbox-") + release() +
string(" </description>\n");
ostringstream ss("");
ss << desc;
ss << s->atoms;
string str = ss.str();
const char* buf = str.c_str();
len = str.length();
fwrite(buf,sizeof(char),len,outfile);
}
if ( !atomsonly )
{
s->wf.write(outfile,encoding,"wavefunction");
if ( s->wfv != 0 )
s->wfv->write(outfile,encoding,"wavefunction_velocity");
}
if ( ui->onpe0() )
{
char *trailer = "</fpmd:sample>\n";
fwrite(trailer,sizeof(char),strlen(trailer),outfile);
fclose(outfile);
}
#else
ofstream os;
if ( ui->onpe0() )
{
os.open(filename);
cout << " <!-- SaveCmd: saving to file " << filename
<< ", encoding=" << encoding << " -->" << endl;
os
<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
<<"<fpmd:sample xmlns:fpmd=\""
<< qbox_xmlns()
<< "\"\n"
<<" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
<<" xsi:schemaLocation=\""
<< qbox_xmlns() << " sample.xsd\">"
<< endl;
os << "<description> Created " << isodate() << " by qbox-" << release()
<< " </description>" << endl;
os << s->atoms;
}
if ( !atomsonly )
{
s->wf.print(os,encoding,"wavefunction");
if ( s->wfv != 0 )
s->wfv->print(os,encoding,"wavefunction_velocity");
}
if ( ui->onpe0() )
os << "</fpmd:sample>" << endl;
os.close();
#endif
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment