From 08e4025273752422ee5e68c01fb881c84328ecc4 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (laptop)" <j.wuttke@fz-juelich.de> Date: Tue, 13 Oct 2009 16:44:37 +0200 Subject: [PATCH] =?UTF-8?q?corr.=20leichte=20=C3=84nderung=20an=20y08:=20#?= =?UTF-8?q?tables=20comment=20now=20inline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pub/src/olm.cpp | 72 +++++++++++++++++++++++-------------------------- pub/src/olm.h | 4 +-- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/pub/src/olm.cpp b/pub/src/olm.cpp index 02ad1a73..fa97590f 100644 --- a/pub/src/olm.cpp +++ b/pub/src/olm.cpp @@ -24,56 +24,59 @@ int err; //***************************************************************************// -void COlo::SaveHeader( FILE *fd, bool isdata ) +void COlo::SaveHeader( FILE *file, bool isdata ) // written for file format y08 { string out; - fprintf( fd, "Meta:\n" + fprintf( file, "Meta:\n" " format: frida/y08 for yaml1\n" " type: %s\n", isdata ? "generic tabular data" : "frida2 curve" ); - fprintf( fd, "History:\n" ); + fprintf( file, "History:\n" ); for ( uint i=0; i<lDoc.size(); i++ ) - fprintf( fd, "- %s\n", yaml(lDoc[i]).c_str() ); + fprintf( file, "- %s\n", yaml(lDoc[i]).c_str() ); out = string( "saved as " ) + name + " on " + mystd::myasctime(mystd::justnow(),0); - fprintf( fd, "- \%s\n", yaml( out ).c_str() ); + fprintf( file, "- \%s\n", yaml( out ).c_str() ); - fprintf( fd, "Coord:\n" ); - fprintf( fd, " x:\n name: %s\n unit: %s\n", + fprintf( file, "Coord:\n" ); + fprintf( file, " x:\n name: %s\n unit: %s\n", yaml(xco.name).c_str(), yaml(xco.unit).c_str() ); - fprintf( fd, " y:\n name: %s\n unit: %s\n", + fprintf( file, " y:\n name: %s\n unit: %s\n", yaml(yco.name).c_str(), yaml(yco.unit).c_str() ); for ( uint i=0; i<ZCo.size(); i++ ) - fprintf( fd, " z%u:\n name: %s\n unit: %s\n", + fprintf( file, " z%u:\n name: %s\n unit: %s\n", i, yaml(ZCo[i].name).c_str(), yaml(ZCo[i].unit).c_str() ); - fprintf( fd, "Param:\n" ); + fprintf( file, "Param:\n" ); for ( uint i=0; i<RPar.size(); i++ ) - fprintf( fd, " -\n name: %s\n unit: %s\n value: %20.15g\n", + fprintf( file, + " -\n name: %s\n unit: %s\n value: %20.15g\n", yaml(RPar[i].Co.name).c_str(), yaml(RPar[i].Co.unit).c_str(), RPar[i].val ); + + fprintf( file, "Tables: # %zu tables follow\n", nScan() ); } //! Write header in format ASCII-01 -void COlo::SaveHeader_a01(FILE *fd) +void COlo::SaveHeader_a01(FILE *file) { - fprintf( fd, "fil %s\n", name.c_str() ); + fprintf( file, "fil %s\n", name.c_str() ); lDoc.push_back("saved as "+name+" on "+ mystd::myasctime(mystd::justnow(),0)); for ( uint i=0; i<lDoc.size(); i++ ) - fprintf( fd, "doc %s\n", lDoc[i].c_str() ); + fprintf( file, "doc %s\n", lDoc[i].c_str() ); - fprintf( fd, "x %s\n", xco.to_a01().c_str() ); - fprintf( fd, "y %s\n", yco.to_a01().c_str() ); + fprintf( file, "x %s\n", xco.to_a01().c_str() ); + fprintf( file, "y %s\n", yco.to_a01().c_str() ); for ( uint i=0; i<ZCo.size(); i++ ) - fprintf( fd, "z%-2u %s\n", i, ZCo[i].to_a01().c_str() ); + fprintf( file, "z%-2u %s\n", i, ZCo[i].to_a01().c_str() ); for ( uint i=0; i<RPar.size(); i++ ) - fprintf( fd, "rpa %20.15g %s\n", + fprintf( file, "rpa %20.15g %s\n", RPar[i].val, RPar[i].Co.to_a01().c_str() ); } @@ -96,11 +99,9 @@ COld::COld( class COlc const* c ) //! Save bulk of online file in one of several formats. -void COld::SaveBody( FILE *file, string fmt ) +void COld::SaveBody( FILE *file, const string& fmt ) const { if( fmt=="y08" ){ - fprintf( file, "# %zu tables\n", VS.size() ); - fprintf( file, "Tables:\n" ); for( size_t j=0; j<VS.size(); j++ ){ fprintf( file, " - # table %zu\n", j ); VS[j].Save( file, fmt ); @@ -169,14 +170,16 @@ uint COld::nPts() const { //***************************************************************************// -void COlc::SaveBody( FILE *file ) +void COlc::SaveBody( FILE *file, const string& fmt ) const // written for file format ASCII-01 { - fprintf(file, "#j %zu\n", VC.size()); - for (size_t j=0; j<VC.size(); j++) { - fprintf(file, "scn %zu\n", j); - VC[j].Save(file); - } + if ( fmt=="y08" ) { + for( size_t j=0; j<nScan(); j++ ){ + fprintf( file, " - # table %zu\n", j ); + VC[j].Save( file, fmt ); + } + } else + throw "curve saving not implemented for format " + fmt; } //***************************************************************************// @@ -193,26 +196,19 @@ void CEle::Save( FILE *file, string fmt ) if (Typ==DATA) { D()->SaveBody( file, fmt ); } else if (Typ==CURVE) { - C()->SaveBody( file ); + C()->SaveBody( file, fmt ); } else throw string( "FATAL: invalid Typ in Save" ); P()->as_on_disk = true; } else if( fmt=="a01"){ fprintf(file, "ASCII-01 JWu\n"); - if (Typ==CURVE) - fprintf(file, "typ C\n"); - else if(Typ==DATA) + if(Typ==DATA) fprintf(file, "typ D\n"); else - throw string( "FATAL: invalid Typ in Save" ); + throw string( "FATAL: ASCII-01 save only for data files" ); P()->SaveHeader_a01(file); - if (Typ==DATA) { - D()->SaveBody( file, fmt ); - } else if (Typ==CURVE) { - C()->SaveBody( file ); - } else - throw string( "FATAL: invalid Typ in Save" ); + D()->SaveBody( file, fmt ); fprintf(file, "eof\n"); P()->as_on_disk = true; diff --git a/pub/src/olm.h b/pub/src/olm.h index c5f8faac..d438f1eb 100644 --- a/pub/src/olm.h +++ b/pub/src/olm.h @@ -48,7 +48,7 @@ class COld : public COlo { // on-line data file uint nPts(uint j) const; uint nPts() const; // 0 unless all spectra j have same nPts(j) - void SaveBody( FILE *fd, string fmt ); + void SaveBody( FILE *file, const string& fmt ) const; }; class COlc : public COlo { // on-line curves @@ -81,7 +81,7 @@ class COlc : public COlo { // on-line curves vector<string> pInfo() const; string pInfoCat() const; - void SaveBody(FILE *fd); + void SaveBody( FILE *file, const string& fmt ) const; }; // the following is needed to pack (pointers to) COld and COlc into ONE vector : -- GitLab