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

extended data write and FREE block handling functionality

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.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/branches/su1
SVN Revision: 3691
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent f2441a6a
......@@ -13,11 +13,12 @@
*
* REVISIONS and CHANGES
* - 25/12/2010 V1.0 Thomas Forbriger
* - 14/01/2011 V1.1 only try to remove file if file exists
*
* ============================================================================
*/
#define TF_FAPID_SFF_NEW_CC_VERSION \
"TF_FAPID_SFF_NEW_CC V1.0"
"TF_FAPID_SFF_NEW_CC V1.1"
#define TF_FAPID_SFF_NEW_CC_CVSID \
"$Id$"
......@@ -26,6 +27,9 @@
#include <fapidxx/fapidsff.h>
#include <fapidxx/helper.h>
#include <fapidxx/error.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
using namespace fapidxx;
......@@ -57,8 +61,17 @@ c----------------------------------------------------------------------
int sff_new__(integer *lu, char *filename, integer *ierr, ftnlen filename_len)
{
std::string name=stringfromfstring(filename, filename_len);
int status=remove(name.c_str());
if (status==0) { *ierr=0; } else { *ierr=1; }
struct stat buf;
int status=lstat(name.c_str(), &buf);
if (status==0)
{
int status=remove(name.c_str());
if (status==0) { *ierr=0; } else { *ierr=1; }
}
else
{
*ierr=0;
}
int retval=0;
return(retval);
} // int sff_new__
......
/*! \file fapid_sff_wopenfs.cc
* \brief open file for writing with FREE block and SRCE line (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 14/01/2011
*
* open file for writing with FREE block and SRCE line (implementation)
*
* Copyright (c) 2011 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
* - 14/01/2011 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_FAPID_SFF_WOPENFS_CC_VERSION \
"TF_FAPID_SFF_WOPENFS_CC V1.0 "
#define TF_FAPID_SFF_WOPENFS_CC_CVSID \
"$Id$"
#include <fapidxx/fapidsff.h>
#include <fapidxx/fileunit.h>
#include <fapidxx/helper.h>
#include <fapidxx/error.h>
#include <sffxx.h>
using namespace fapidxx;
/*! \brief Open file for writing and pass FREE block and SRCE line
*
* \ingroup implemented_functions
*
* Description from stuff.f:
* \code
c----------------------------------------------------------------------
subroutine sff_WOpenFS(lu, filename,
& lines, nline,
& type, cs, c1, c2, c3, date, time, ierr)
c
c Open file for writing. Write STAT line, FREE block and SRCE line.
c
c input:
c lu logical file unit
c filename name of file
c nline number of lines in FREE block
c lines lines in FREE block
c type type of source (any 20 character string)
c cs coordinate system (S: spherical, C: cartesian)
c c1, c2, c3 coordiantes as defined by SFF
c time, date time and date of source signal
c output:
c ierr error status (ok: ierr=0)
c
integer lu, ierr, nline
character filename*(*), type*(*), cs*1
real c1, c2, c3
character time*(*), date*(*)
character lines(nline)*80
c----------------------------------------------------------------------
* \endcode
*/
int sff_wopenfs__(integer *lu, char *filename, char *lines, integer *nline,
char *type__, char *cs, real *c1, real *c2, real *c3,
char *date, char *time, integer *ierr, ftnlen filename_len,
ftnlen lines_len, ftnlen type_len, ftnlen cs_len,
ftnlen date_len, ftnlen time_len)
{
int retval=0;
*ierr=0;
try {
datrw::oanystream &os=
ostreammanager.open(static_cast<int>(*lu),
stringfromfstring(filename, filename_len));
if (os.handlessrce())
{
sff::SRCE srce;
srce.cs=sff::coosysID(*cs);
srce.cx=static_cast<double>(*c1);
srce.cy=static_cast<double>(*c2);
srce.cz=static_cast<double>(*c3);
srce.type=stringfromfstring(type__, type_len);
srce.date=SRCEdate(date, time, date_len, time_len);
os << srce;
}
if (os.handlesfilefree())
{
sff::FREE filefree=freeblock(nline, lines, lines_len);
os << filefree;
}
}
catch (...) {
*ierr=1;
}
return(retval);
} // int sff_wopenfs__
/* ----- END OF fapid_sff_wopenfs.cc ----- */
......@@ -73,21 +73,7 @@ int sff_wopens__(integer *lu, char *filename, char *type__, char *cs,
srce.cy=static_cast<double>(*c2);
srce.cz=static_cast<double>(*c3);
srce.type=stringfromfstring(type__, type_len);
std::string datestring=stringfromfstring(date, date_len);
std::string timestring=stringfromfstring(time, time_len);
std::string fulldate("");
fulldate+=datestring.substr(0,2);
fulldate+="/";
fulldate+=datestring.substr(2,2);
fulldate+="/";
fulldate+=datestring.substr(4,2);
fulldate+=" ";
fulldate+=timestring.substr(0,2);
fulldate+=":";
fulldate+=timestring.substr(2,2);
fulldate+=":";
fulldate+=timestring.substr(4,6);
srce.date=libtime::TAbsoluteTime(fulldate);
srce.date=SRCEdate(date, time, date_len, time_len);
os << srce;
}
}
......
/*! \file fapid_sff_wtracefi.cc
* \brief write trace with FREE block and INFO line (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 14/01/2011
*
* write trace with FREE block and INFO line (implementation)
*
* Copyright (c) 2011 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
* - 14/01/2011 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_FAPID_SFF_WTRACEFI_CC_VERSION \
"TF_FAPID_SFF_WTRACEFI_CC V1.0 "
#define TF_FAPID_SFF_WTRACEFI_CC_CVSID \
"$Id$"
#include <fapidxx/fapidsff.h>
#include <fapidxx/fileunit.h>
#include <fapidxx/helper.h>
#include <fapidxx/error.h>
using namespace fapidxx;
/*! \brief Write one trace of data with FREE block and INFO line
*
* \ingroup implemented_functions
*
* Description from stuff.f:
* \code
c----------------------------------------------------------------------
subroutine sff_WTraceFI(lu,
& wid2line, nsamp, fdata, idata, last,
& nline, lines,
& cs, c1, c2, c3, nstack, ierr)
c
c Write one data block starting with DAST line.
c Write also FREE block and INFO line.
c The File will be closed after writing the last trace.
c
c input
c lu logical file unit
c wid2line valid WID2 line
c nsamp number of samples
c fdata data array
c last must be true is the trace to be written is the
c last one in this file
c nline number of FREE block lines
c lines FREE block lines
c cs coordinate system
c c1, c2, c3 receiver coordinates
c nstack number of stacks
c
c ouput:
c ierr error status (ok: ierr=0)
c
c workspace:
c idata fdata will be converted to idata using sff_f2i
c (both array may be in same memory space - see
c comments on sff_f2i)
c
integer lu, nsamp, idata(nsamp), nline, nstack
real fdata(nsamp), c1, c2, c3
logical last
character wid2line*132, lines(nline)*80, cs*1
c----------------------------------------------------------------------
* \endcode
*/
int sff_wtracefi__(integer *lu, char *wid2line, integer *nsamp, real *fdata,
integer *idata, logical *last, integer *nline, char *lines,
char *cs, real *c1, real *c2, real *c3, integer *nstack,
integer *ierr, ftnlen wid2line_len,
ftnlen lines_len, ftnlen cs_len)
{
int retval=0;
*ierr=0;
try {
datrw::oanystream &os=ostreammanager(static_cast<int>(*lu));
WID2container wid2c(wid2line, wid2line_len);
unsigned int nsamples=static_cast<unsigned int>(*nsamp);
os << wid2c.wid2;
if (os.handlesinfo())
{
sff::INFO info;
info.cs=sff::coosysID(*cs);
info.cx=static_cast<double>(*c1);
info.cy=static_cast<double>(*c2);
info.cz=static_cast<double>(*c3);
info.nstacks=static_cast<int>(*nstack);
os << info;
}
if (os.handlestracefree())
{
sff::FREE tracefree=freeblock(nline, lines, lines_len);
os << tracefree;
}
aff::LinearShape shape(0, nsamples-1, 0);
datrw::Tfseries series(shape, aff::SharedHeap<real>(fdata, *nsamp));
os << series;
if (*last) ostreammanager.close(static_cast<int>(*lu));
}
catch (...) {
*ierr=1;
}
return(retval);
} // int sff_wtracefi__
/* ----- END OF fapid_sff_wtracefi.cc ----- */
......@@ -120,6 +120,43 @@ namespace fapidxx {
return(float(libtime::time2double(inday)));
} // float maketanf(const libtime::TAbsoluteTime& time)
/*----------------------------------------------------------------------*/
libtime::TAbsoluteTime SRCEdate(char *date, char* time,
ftnlen date_len, ftnlen time_len)
{
std::string datestring=stringfromfstring(date, date_len);
std::string timestring=stringfromfstring(time, time_len);
std::string fulldate("");
fulldate+=datestring.substr(0,2);
fulldate+="/";
fulldate+=datestring.substr(2,2);
fulldate+="/";
fulldate+=datestring.substr(4,2);
fulldate+=" ";
fulldate+=timestring.substr(0,2);
fulldate+=":";
fulldate+=timestring.substr(2,2);
fulldate+=":";
fulldate+=timestring.substr(4,6);
libtime::TAbsoluteTime srcedate(fulldate);
return(srcedate);
} // libtime::TAbsoluteTime SRCEdate
/*----------------------------------------------------------------------*/
sff::FREE freeblock(integer *nline, char *lines, ftnlen lines_len)
{
sff::FREE free;
char* pfree=lines;
for (int ifline=0; ifline<*nline; ++ifline)
{
free.append(stringfromfstring(pfree, lines_len));
pfree += lines_len;
}
return(free);
} // sff::FREE freeblock(integer *nline, char *lines, ftnlen lines_len)
/*======================================================================*/
// WID2container
......
......@@ -66,6 +66,13 @@ namespace fapidxx {
//! create the tanf value
float maketanf(const libtime::TAbsoluteTime& time);
//! create appropriate time string for SRCE line
libtime::TAbsoluteTime SRCEdate(char *date, char* time,
ftnlen date_len, ftnlen time_len);
//! create C++ FREE block from Fortran FREE lines
::sff::FREE freeblock(integer *nline, char *lines, ftnlen lines_len);
/*----------------------------------------------------------------------*/
/*! a struct to handle WID2 data
......
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