Commit b45140ce authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

placing general parts separately

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.
added description of writing process and some functions to oanystream


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/branches/libdatrwxx.su
SVN Revision: 3481
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent f0ac3985
......@@ -51,11 +51,13 @@ CHECKVARS=$(foreach var,$(1),$(call CHECKVAR,$(var)))
$(call CHECKVARS,LOCINCLUDEDIR LOCLIBDIR LOCBINDIR)
$(call CHECKVARS,TF_BROWSER TF_WWWBASEDIR)
LIBHEADERS=$(wildcard *.h sff/*.h tsoft/*.h tfascii/*.h su/*.h)
LIBHEADERS+=$(wildcard bonjer/*.h pdas/*.h mseed/*.h hpmo/*.h sac/*.h gse/*.h)
SUBDIRS=$(addsuffix /,sff tsoft tfascii su bonjer pdas mseed hpmo sac gse)
LIBHEADERS=$(wildcard *.h)
LIBHEADERS+=$(wildcard $(addsuffix *.h,$(SUBDIRS)))
LIBSRC=$(wildcard *.cc sff/*.cc tsoft/*.cc tfascii/*.cc su/*.cc)
LIBSRC+=$(wildcard bonjer/*.cc pdas/*.cc mseed/*.cc hpmo/*.cc sac/*.cc gse/*.cc)
LIBSRC+=$(wildcard $(addsuffix *.cc,$(SUBDIRS)))
TESTHEADERS=$(wildcard tests/*.h)
TESTSRC=$(wildcard tests/*.cc)
......@@ -89,9 +91,22 @@ CXXFLAGS+=-Wall $(FLAGS)
LDFLAGS+=-L$(LOCLIBDIR)
CPPFLAGS+=-I$(LOCINCLUDEDIR) $(FLAGS)
flist: Makefile $(wildcard *.cfg contrib/*.h) $(LIBHEADERS) $(LIBSRC) \
$(TESTSRC) README
echo $^ | tr ' ' '\n' | sort > $@
EDITFILES=Makefile README $(wildcard *.cfg contrib/*.h)
EDITALL=$(EDITFILES) $(LIBHEADERS) $(LIBSRC) $(TESTSRC) $(EDITFILES)
EDITFORMATHEADERS=$(filter $(patsubst %/,%.h,$(SUBDIRS)),$(LIBHEADERS))
EDITROOT=$(filter-out $(EDITFORMATHEADERS),$(wildcard *.cc *.h))
EDITFIRST=$(filter-out $(LIBHEADERS) $(LIBSRC) $(TESTSRC),$(EDITALL))
EDITSECOND=$(filter-out $(TESTSRC) $(EDITROOT) $(EDITFIRST),$(EDITALL))
flist: $(LIBHEADERS) $(LIBSRC) $(TESTSRC) $(EDITFILES)
echo $(filter $(EDITFIRST),$^) | tr ' ' '\n' | sort > $@
echo "----" >> $@
echo $(filter $(EDITROOT),$^) | tr ' ' '\n' | sort >> $@
echo "----" >> $@
echo $(sort $(filter $(EDITSECOND),$^)) | tr ' ' '\n' >> $@
echo "----" >> $@
echo $(filter-out $(EDITSECOND) $(EDITROOT) $(EDITFIRST),$^) \
| tr ' ' '\n' | sort >> $@
.PHONY: edit
edit: flist; vim $<
......
......@@ -208,7 +208,7 @@ constructor datrw::ianystream::ianystream().
\subsection subsec_howtoworks_fileheader Reading the file header
You create an instance of the input stream class by passing an C++ istream
(isually a std::ifstream opened with the appropriate open mode as indicated by
(usually a std::ifstream opened with the appropriate open mode as indicated by
\ref openmode of the libdatrwxx input stream class, like
datrw::isffstream::openmode)
from which data should be read to the constructor of the stream class.
......@@ -323,8 +323,82 @@ The operators are provided in namespace ::datrw.
/*! \page page_writing_operation Description of writing operation
\todo
An description will be given soon
All output streams are derived from datrw::odatstream.
The interface of datrw::odatstream consequently defines the behaviour of all
output stream classes.
datrw::oanystream implements the same interface and behaviour.
It is a general output stream, more or less, which selects one of the
implemented stream classes based on the second parameter passed to its
constructor datrw::oanystream::oanystream().
\section sec_out_howtoworks_go So, what happens when you are up to write a file?
\subsection subsec_out_howtoworks_fileheader Writing the file header
You create an instance of the output stream class by passing an C++ ostream
(usually a std::ofstream opened with the appropriate open mode as indicated by
\ref openmode of the libdatrwxx output stream class, like
datrw::osffstream::openmode)
to which data should be written to the constructor of the stream class.
Then you can use the \em file \em header \em set \em functions
\li datrw::odatstream::setfree()
\li datrw::odatstream::setsrce()
or the corresponding output operators to write file header data.
The functions
\li datrw::odatstream::handlesfilefree()
\li datrw::odatstream::handlessrce()
tell you whether the specific output stream can handle file FREE block and
SRCE data.
This is not possible for all data formats.
A call to datrw::odatstream::setwid2() will flush the file header.
Any subsequent call to datrw::odatstream::setfree() will pass a trace FREE
block and not a file FREE block.
\subsection subsec_out_howtoworks_tracedata Writing samples to a trace
Prior to writing the actual time series, you have to pass the trace header
data to the output stream.
You can do this through the \em trace \em header \em set \em functions
\li datrw::odatstream::setwid2()
\li datrw::odatstream::setinfo()
\li datrw::odatstream::setfree()
or the corresponding output operators.
A call to datrw::odatstream::setwid2() per trace is mandatory.
The functions
\li datrw::odatstream::handlestracefree()
\li datrw::odatstream::handlesinfo()
tell you whether the specific output stream can handle trace FREE block and
INFO data.
This is not possible for all data formats.
Finally you use the overloaded
\em series \em set \em function
\li datrw::odatstream::writeseries()
or the corresponding output operator to write the actual time series.
This call will flush the trace such that a subsequent call to a trace header
set function will pass data to the next trace.
\note
The output stream classes are intended to take any type of data (floating
point as well as integer).
\b Beware that floating point data will be truncated when being written to an
integer data file format.
You can check this by the \em series \em type \em query \em function
\li datrw::odatstream::seriestype()
\subsection subsec_howtoworks_operators Ever heard of output operators?
Output operators support an easy way to apply the modules in this library.
Almost all data set functions (be it header data or trace samples) can be
accessed through output operators.
This is the case for all classes.
The operators are provided in namespace ::datrw.
\sa \ref page_writing_howto, ::datrw
*/
......
......@@ -47,6 +47,7 @@
#include<aff/series.h>
#include<sffxx.h>
#include<datrwxx/error.h>
#include<datrwxx/formats.h>
namespace datrw {
......@@ -105,6 +106,16 @@ namespace datrw {
void writeseries(const Tiseries& series);
//! flush file header to file
void flushfileheader();
//! true if file FREE block can be handled
bool handlesfilefree() const;
//! true if SRCE data can be handled
bool handlessrce() const;
//! true if trace FREE block can be handled
bool handlestracefree() const;
//! true if INFO data can be handled
bool handlesinfo() const;
//! indicate type of series data
Edatatype seriestype() const;
//! print some info about data conversion.
static void help(std::ostream& os=std::cout,
const char* name="idatsream");
......
/*! \file formats.cc
* \brief common description of formats (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 26/11/2010
*
* common description of formats (implementation)
*
* Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
*
* REVISIONS and CHANGES
* - 26/11/2010 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define DATRW_FORMATS_CC_VERSION \
"DATRW_FORMATS_CC V1.0 "
#define DATRW_FORMATS_CC_CVSID \
"$Id$"
#include <datrwxx/formats.h>
#include <datrwxx/sff.h>
#include <datrwxx/pdas.h>
#include <datrwxx/hpmo.h>
#include <datrwxx/mseed.h>
#include <datrwxx/bonjer.h>
#include <datrwxx/sac.h>
#include <datrwxx/gse.h>
#include <datrwxx/tsoft.h>
#include <datrwxx/tfascii.h>
#include <datrwxx/su.h>
namespace datrw {
Eformat anyID(const std::string& id)
{
Eformat retval;
if (id==pdas::streamID) { retval=Fpdas; }
else if (id==sff::streamID) { retval=Fsff; }
else if (id==hpmo::streamID) { retval=Fhpmo; }
else if (id==mseed::streamID) { retval=Fmseed; }
else if (id==bonjer::streamID) { retval=Fbonjer; }
else if (id==sac::streamID) { retval=Fsac; }
else if (id==gse::streamID) { retval=Fgse; }
else if (id==tsoft::streamID) { retval=Ftsoft; }
else if (id==tfascii::streamID) { retval=Ftfascii; }
else if (id==su::streamID) { retval=Fsu; }
else { DATRW_abort("unknown data type identifier!"); }
return(retval);
} // Eformat anyID(const std::string& identifier)
/*----------------------------------------------------------------------*/
std::string anyID(const Eformat& id)
{
std::string retval="NSP";
switch(id) {
case Fpdas: retval=pdas::streamID; break;
case Fsff: retval=sff::streamID; break;
case Fhpmo: retval=hpmo::streamID; break;
case Fmseed: retval=mseed::streamID; break;
case Fbonjer: retval=bonjer::streamID; break;
case Fsac: retval=sac::streamID; break;
case Fgse: retval=gse::streamID; break;
case Ftsoft: retval=tsoft::streamID; break;
case Ftfascii: retval=tfascii::streamID; break;
case Fsu: retval=su::streamID; break;
default: DATRW_abort("unknown data type ID#!");
}
return(retval);
} // std::string anyID(const Eformat& id)
/*----------------------------------------------------------------------*/
void online_help(std::ostream& os)
{
os << std::endl
<< "Online help obtained from data extraction facilities:"
<< std::endl;
os << "SFF data input: "; isffstream::help(os);
os << std::endl;
os << "SFF data output: "; osffstream::help(os);
os << std::endl;
os << "HPMO data input: "; ihpmostream::help(os);
os << std::endl;
os << "MiniSEED data input: "; imseedstream::help(os);
os << std::endl;
os << "PDAS data input: "; ipdasstream::help(os);
os << std::endl;
os << "Bonjer data input: "; ibonjerstream::help(os);
os << std::endl;
os << "SAC data input: "; isacstream::help(os);
os << std::endl;
os << "GSE data input: "; igsestream::help(os);
os << std::endl;
os << "GSE data output: "; ogsestream::help(os);
os << std::endl;
os << "TSOFT data input: "; itsoftstream::help(os);
os << std::endl;
os << "TFASCII data input: "; itfasciistream::help(os);
os << std::endl;
os << "SU data input: "; isustream::help(os);
} // void online_help(std::ostream& os)
/*----------------------------------------------------------------------*/
void supported_input_data_types(std::ostream& os)
{
os << "data formats supported by ianystream:" << std::endl;
os.width(13); os << sff::streamID
<< ": Stuttgart File Format" << std::endl;
os.width(13); os << hpmo::streamID
<< ": HP-MO data format defined by W. Grossmann (BFO)"
<< std::endl;
os.width(13); os << pdas::streamID
<< ": PDAS100 (i.e. DaDisp)" << std::endl;
os.width(13); os << mseed::streamID
<< ": MiniSEED (SeisComP, EDL, etc.)" << std::endl;
os.width(13); os << bonjer::streamID
<< ": K2 ASCII data format (defined by K. Bonjer?)"
<< std::endl;
os.width(13); os << sac::streamID << ": SAC binary format" << std::endl;
os.width(13); os << gse::streamID << ": raw GSE format" << std::endl;
os.width(13); os << tsoft::streamID << ": TSOFT format" << std::endl;
os.width(13); os << tfascii::streamID
<< ": ASCII format of T. Forbrigers any2ascii" << std::endl;
os.width(13); os << su::streamID << ": Seismic Unix format" << std::endl;
}
/*----------------------------------------------------------------------*/
void supported_output_data_types(std::ostream& os)
{
os << "data formats supported by oanystream:" << std::endl;
os << " sff: Stuttgart File Format" << std::endl;
os << " gse: raw GSE format" << std::endl;
}
/*----------------------------------------------------------------------*/
void supported_data_types(std::ostream& os)
{
os << "data formats supported for reading:" << std::endl;
os << "-----------------------------------" << std::endl;
supported_input_data_types(os);
os << "data formats supported for writing:" << std::endl;
os << "-----------------------------------" << std::endl;
supported_output_data_types(os);
}
} // namespace datrw
/* ----- END OF formats.cc ----- */
/*! \file formats.h
* \brief common description of formats (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 26/11/2010
*
* common description of formats (prototypes)
*
* Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
*
* REVISIONS and CHANGES
* - 26/11/2010 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef DATRW_FORMATS_H_VERSION
#define DATRW_FORMATS_H_VERSION \
"DATRW_FORMATS_H V1.0 "
#define DATRW_FORMATS_H_CVSID \
"$Id$"
#include <iostream>
#include <string>
namespace datrw {
/*! ID flags for supported file formats
*
* These flags are used for input as well as for output streams.
* Not all of them will be supported by input and output streams as well.
*/
enum Eformat {
Fsff, //<! SFF data
Fpdas, //<! PDAS data
Fhpmo, //<! BFO HP-MO data (Grossmann format)
Fmseed, //<! MiniSEED data
Fbonjer, //<! Format specified by K. Bonjer
Fsac, //<! SAC binary data
Fgse, //<! raw GSE data
Ftsoft, //<! TSOFT data
Ftfascii, //<! ASCII format of T. Forbrigers any2ascii
Fsu //<! Seismic Unix format
}; // enum Eformat
/*----------------------------------------------------------------------*/
/*! ID flags to indicate variable type used for storing samples
*/
enum Edatatype {
Fint, //<! File format uses integer data
Ffloat, //<! File format uses float data
Fdouble //<! File format uses double data
}; // enum Edatatype
/*----------------------------------------------------------------------*/
//! true, if underlying file format is binary
bool isbinary(const Eformat& format);
// convert identifier from and to string representation
Eformat anyID(const std::string& identifier);
std::string anyID(const Eformat& id);
// print out information about supported data types
void supported_data_types(std::ostream& os=std::cout);
// print out information about supported data types for input
void supported_input_types(std::ostream& os=std::cout);
// print out information about supported data types for output
void supported_output_types(std::ostream& os=std::cout);
// print out information about data conversion
void online_help(std::ostream& os=std::cout);
} // namespace datrw
#endif // DATRW_FORMATS_H_VERSION (includeguard)
/* ----- END OF formats.h ----- */
......@@ -133,101 +133,6 @@ namespace datrw {
delete Mis;
}
/*======================================================================*/
// functions
Eformat anyID(const std::string& id)
{
Eformat retval;
if (id==pdas::streamID) { retval=Fpdas; }
else if (id==sff::streamID) { retval=Fsff; }
else if (id==hpmo::streamID) { retval=Fhpmo; }
else if (id==mseed::streamID) { retval=Fmseed; }
else if (id==bonjer::streamID) { retval=Fbonjer; }
else if (id==sac::streamID) { retval=Fsac; }
else if (id==gse::streamID) { retval=Fgse; }
else if (id==tsoft::streamID) { retval=Ftsoft; }
else if (id==tfascii::streamID) { retval=Ftfascii; }
else if (id==su::streamID) { retval=Fsu; }
else { DATRW_abort("unknown data type identifier!"); }
return(retval);
} // Eformat anyID(const std::string& identifier)
/*----------------------------------------------------------------------*/
std::string anyID(const Eformat& id)
{
std::string retval="NSP";
switch(id) {
case Fpdas: retval=pdas::streamID; break;
case Fsff: retval=sff::streamID; break;
case Fhpmo: retval=hpmo::streamID; break;
case Fmseed: retval=mseed::streamID; break;
case Fbonjer: retval=bonjer::streamID; break;
case Fsac: retval=sac::streamID; break;
case Fgse: retval=gse::streamID; break;
case Ftsoft: retval=tsoft::streamID; break;
case Ftfascii: retval=tfascii::streamID; break;
case Fsu: retval=su::streamID; break;
default: DATRW_abort("unknown data type ID#!");
}
return(retval);
} // std::string anyID(const Eformat& id)
/*----------------------------------------------------------------------*/
void online_help(std::ostream& os)
{
os << std::endl
<< "Online help obtained from data extraction facilities:"
<< std::endl;
os << "SFF data: "; isffstream::help(os);
os << std::endl;
os << "HPMO data: "; ihpmostream::help(os);
os << std::endl;
os << "MiniSEED data: "; imseedstream::help(os);
os << std::endl;
os << "PDAS data: "; ipdasstream::help(os);
os << std::endl;
os << "Bonjer data: "; ibonjerstream::help(os);
os << std::endl;
os << "SAC data: "; isacstream::help(os);
os << std::endl;
os << "GSE data: "; igsestream::help(os);
os << std::endl;
os << "TSOFT data: "; itsoftstream::help(os);
os << std::endl;
os << "TFASCII data: "; itfasciistream::help(os);
os << std::endl;
os << "SU data: "; isustream::help(os);
} // void online_help(std::ostream& os)
/*----------------------------------------------------------------------*/
void supported_data_types(std::ostream& os)
{
os << "data formats supported by ianystream:" << std::endl;
os.width(13); os << sff::streamID
<< ": Stuttgart File Format" << std::endl;
os.width(13); os << hpmo::streamID
<< ": HP-MO data format defined by W. Grossmann (BFO)"
<< std::endl;
os.width(13); os << pdas::streamID
<< ": PDAS100 (i.e. DaDisp)" << std::endl;
os.width(13); os << mseed::streamID
<< ": MiniSEED (SeisComP, EDL, etc.)" << std::endl;
os.width(13); os << bonjer::streamID
<< ": K2 ASCII data format (defined by K. Bonjer?)"
<< std::endl;
os.width(13); os << sac::streamID << ": SAC binary format" << std::endl;
os.width(13); os << gse::streamID << ": raw GSE format" << std::endl;
os.width(13); os << tsoft::streamID << ": TSOFT format" << std::endl;
os.width(13); os << tfascii::streamID
<< ": ASCII format of T. Forbrigers any2ascii" << std::endl;
os.width(13); os << su::streamID << ": Seismic Unix format" << std::endl;
os << DATRW_READANY_CC_CVSID << std::endl;
}
} // namespace datrw
/*======================================================================*/
......
......@@ -35,6 +35,7 @@
* - 06/10/2010 V1.4 added ASCII format of T. Forbrigers any2ascii
* - 23/11/2010 V1.5 use static members
* - 25/11/2010 V1.6 added Seismic Unix format
* - 26/11/2010 V1.7 moved not input specifc part to formats.h
*
* ============================================================================
*/
......@@ -43,27 +44,15 @@
#ifndef DATRW_READANY_H_VERSION
#define DATRW_READANY_H_VERSION \
"DATRW_READANY_H V1.6"
"DATRW_READANY_H V1.7"
#define DATRW_READANY_H_CVSID \
"$Id$"
#include<datrwxx/datread.h>
#include<datrwxx/formats.h>
namespace datrw {
enum Eformat {
Fsff, //<! SFF data
Fpdas, //<! PDAS data
Fhpmo, //<! BFO HP-MO data (Grossmann format)
Fmseed, //<! MiniSEED data
Fbonjer, //<! Format specified by K. Bonjer
Fsac, //<! SAC binary data
Fgse, //<! raw GSE data
Ftsoft, //<! TSOFT data
Ftfascii, //<! ASCII format of T. Forbrigers any2ascii
Fsu //<! Seismic Unix format
}; // enum Eformat
#define ANYDELEGATE( function ) function() const { return(Mis->function()); }
/*! Class to read any type of data file
......@@ -100,18 +89,6 @@ namespace datrw {
#undef ANYDELEGATE
bool isbinary(const Eformat& format);
// convert identifier from and to string representation
Eformat anyID(const std::string& identifier);
std::string anyID(const Eformat& id);
// print out information about supported data types
void supported_data_types(std::ostream& os=std::cout);
// print out information about data conversion
void online_help(std::ostream& os=std::cout);
template<class C>
ianystream& operator>>(ianystream& is, C& c)
{ is.idatstream() >> c; return(is); }
......
......@@ -51,7 +51,7 @@ namespace datrw {
if (Mformat==Fsff) { Mos=new osffstream(os); }
else if (Mformat==Fgse) { Mos=new ogsestream(os); }
else
{ DATRW_abort("ERROR (ianystream): unknown format!"); }
{ DATRW_abort("ERROR (ianystream): unsupported format!"); }
}
/*----------------------------------------------------------------------*/
......@@ -61,55 +61,6 @@ namespace datrw {
delete Mos;
}