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

WID2 data no is passed in binary format from prepwid2 internally

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/trunk
SVN Revision: 3840
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 65836541
......@@ -24,23 +24,22 @@ c
c commandline
integer maxopt, lastarg, iargc
character*80 argument
parameter(maxopt=6)
parameter(maxopt=7)
character*2 optid(maxopt)
character*40 optarg(maxopt)
logical optset(maxopt), opthasarg(maxopt)
c debugging
logical debug, verbose
double precision dt
c here are the keys to our commandline options
data optid/2h-d, 2h-v, 2h-x, 2h-t, '-w', '-r'/
data opthasarg/3*.FALSE.,3*.TRUE./
data optarg/3*1h-,'sff','testfile.sff','junk.sff'/
data optid/'-D', '-v', '-x', '-t', '-w', '-r', '-d'/
data opthasarg/3*.FALSE.,4*.TRUE./
data optarg/3*'-','sff','testfile.sff','junk.sff','1.e-3'/
c
character*20 formatid
character*40 infile, outfile
logical doread, dowrite
c
c
c
c------------------------------------------------------------------------------
c basic information
......@@ -51,6 +50,7 @@ c
if ((argument(1:5).eq.'-help').or.(iargc().lt.1)) then
print *,version
print *,'Usage: fapidtest [-r file] [-w file] [-t type]'
print *,' [-d t]'
print *,' or: fapidtest -help'
print *,' or: fapidtest -x'
if (argument(1:5).ne.'-help')
......@@ -62,6 +62,7 @@ c
print *,'-r file test reading from file'
print *,'-w file test writing to file'
print *,'-t type select file type for input/output'
print *,'-d t set sampling interval to ''t'' seconds'
print *,' '
call sff_help_formats
stop
......@@ -85,6 +86,7 @@ c
outfile=optarg(5)
doread=optset(6)
infile=optarg(6)
read(optarg(7), *, err=99) dt
c
c------------------------------------------------------------------------------
c go
......@@ -94,18 +96,30 @@ c
if (ierr.ne.0) then
stop 'ERROR: selecting format'
endif
if (doread) call readtest(infile)
if (dowrite) call writetest(outfile)
if (dowrite) then
if (verbose) then
print *,'write data with sampling interval ',dt,' s'
endif
call writetest(outfile, dt)
endif
if (doread) then
if (verbose) then
print *,'read data'
endif
call readtest(infile)
endif
stop
99 stop 'ERROR: reading command line arument'
end
c======================================================================
c functions
c ---------
subroutine writetest(filename)
subroutine writetest(filename, indt)
c
character*(*) filename
double precision indt
c
integer m
parameter(m=1024)
......@@ -113,7 +127,7 @@ c
integer id(m)
equivalence(d,id)
integer n,i,j,s,k
real p,dx,dt
real p,dx,dt,rate
c
integer lu, ierr
parameter(lu=10)
......@@ -123,14 +137,15 @@ c
print *,'write test'
print *,'----------'
print *,'open ',filename(1:index(filename,' '))
dt=indt
rate=1./dt
dx=1.
dt=1.e-3
n=40
p=(dt*m)/(dx*n)
stype='synthetic'
date='110401'
time='123209.012345'
call sff_PrepWid2(m, 1./dt, 'sta ',
call sff_PrepWid2(m, rate, 'sta ',
& 2011, 04, 01, 12, 32, 'chan ', 'aux ', 'ins ',
& 10.023456, -1., -1., -1., -1., wid2line, ierr)
if (ierr.ne.0) stop 'ERROR: preparing wid2line'
......@@ -139,6 +154,7 @@ c
s=int((dx*p)/dt)
k=s
do i=1,n
print *,'write trace #',i
do j=1,m
d(j)=0.
enddo
......@@ -154,7 +170,7 @@ c
if (ierr.ne.0) stop 'ERROR: writing trace'
enddo
c
stop
return
end
c
c----------------------------------------------------------------------
......@@ -181,9 +197,6 @@ c sff trace
character rcs*1, wid2line*132
real rc1, rc2, rc3, tanf, dt
integer nstack
c functions
real sffu_offset, sffu_tfirst, ts_max, ts_min, ts_average
real offshift
c
print *,'read test'
print *,'---------'
......@@ -219,7 +232,7 @@ c
stop 'ERROR: reading trace'
endif
enddo
stop
return
end
c
c ----- END OF fapidtest.f -----
......@@ -31,17 +31,20 @@
* REVISIONS and CHANGES
* - 18/11/2010 V1.0 Thomas Forbriger
* - 25/11/2010 V1.1 implemented more efficient string trimming
* - 02/04/2011 V1.2 implement WID2container::WID2struct
*
* ============================================================================
*/
#define FAPIDXX_HELPER_CC_VERSION \
"FAPIDXX_HELPER_CC V1.1"
"FAPIDXX_HELPER_CC V1.2"
#define FAPIDXX_HELPER_CC_CVSID \
"$Id$"
#include<algorithm>
#include<sstream>
#include<cstring>
#include <fapidxx/helper.h>
#include <fapidxx/error.h>
namespace fapidxx {
......@@ -188,6 +191,9 @@ namespace fapidxx {
* This function sets the data in WID2container::wid2 from an input
* character string.
*
* \note
* This function does NOT decode the special WID2 string format.
*
* \param line WID2 line character sequence (input value)
*/
void WID2container::setwid2(const std::string& line)
......@@ -212,7 +218,28 @@ namespace fapidxx {
*/
void WID2container::setwid2(char *fstring, ftnlen slen)
{
this->setwid2(stringfromfstring(fstring, slen));
// check for special ID
if (std::strncmp(fstring, WID2container::WID2struct::encodeID,
WID2container::WID2struct::idlen)!=0)
{
this->setwid2(stringfromfstring(fstring, slen));
}
else
{
/*
* The byte sequence fstring points to is the content of a
* WID2container::WID2struct struct. Create a WID2container::WID2struct
* in memory, copy the memory contents fstring points to into
* this struct and read the WID2 data from it.
*/
int w2size=sizeof(WID2container::WID2struct);
FAPIDXX_assert(w2size<=slen,
"WID2container::setwid2: string is too short");
WID2container::WID2struct* ws=new WID2container::WID2struct;
std::memcpy(ws, fstring, w2size);
this->wid2=ws->get();
delete ws;
}
} // void WID2container::setwid2(char *fstring, ftnlen slen)
/*----------------------------------------------------------------------*/
......@@ -230,14 +257,71 @@ namespace fapidxx {
*/
void WID2container::encode(char *fstring, ftnlen slen) const
{
fillfstring(wid2.line(), fstring, slen);
WID2container::WID2struct ws;
ws.set(this->wid2);
int w2size=sizeof(WID2container::WID2struct);
FAPIDXX_assert(w2size<=slen,
"WID2container::encode: struct is too large");
std::memcpy(fstring, &ws, w2size);
} // void WID2container::encode(char *fstring, ftnlen slen)
/*----------------------------------------------------------------------*/
/*======================================================================*/
// WID2contsiner::WID2struct
/*! \brief ID indicating the WID2 is encoded in binary form in the WID2 line
*/
const char* WID2container::encodeID="WIDY";
const char* WID2container::WID2struct::encodeID="WIDY";
/*----------------------------------------------------------------------*/
void WID2container::WID2struct::set(const ::sff::WID2& wid2)
{
strncpy(this->ID, WID2container::WID2struct::encodeID, idlen);
strncpy(this->station, wid2.station.c_str(), slen);
strncpy(this->channel, wid2.channel.c_str(), clen);
strncpy(this->auxid, wid2.auxid.c_str(), alen);
strncpy(this->instype, wid2.instype.c_str(), ilen);
this->station[slen]='\0';
this->channel[clen]='\0';
this->auxid[alen]='\0';
this->instype[ilen]='\0';
this->hour=wid2.date.hour();
this->minute=wid2.date.minute();
this->second=wid2.date.second();
this->milsec=wid2.date.milsec();
this->micsec=wid2.date.micsec();
this->year=wid2.date.year();
this->month=wid2.date.month();
this->day=wid2.date.day();
this->calib=wid2.calib;
this->calper=wid2.calper;
this->dt=wid2.dt;
this->nsamples=wid2.nsamples;
this->vang=wid2.vang;
this->hang=wid2.hang;
} // void WID2container::WID2struct::set(const ::sff::WID2& wid2)
/*----------------------------------------------------------------------*/
::sff::WID2 WID2container::WID2struct::get() const
{
::sff::WID2 retval;
libtime::TAbsoluteTime date(this->year, this->month, this->day,
this->hour, this->minute, this->second,
this->milsec, this->micsec);
retval.date=date;
retval.station=std::string(this->station);
retval.channel=std::string(this->channel);
retval.auxid=std::string(this->auxid);
retval.instype=std::string(this->instype);
retval.dt=this->dt;
retval.nsamples=this->nsamples;
retval.hang=this->hang;
retval.vang=this->vang;
retval.calib=this->calib;
retval.calper=this->calper;
return(retval);
} // ::sff::WID2 WID2container::WID2struct::get() const
} // namespace fapidxx
......
......@@ -32,6 +32,7 @@
* - 18/11/2010 V1.0 Thomas Forbriger
* - 25/11/2010 V1.1 added trimws
* - 01/04/2011 V1.2 provide sff_helper_decode_wid2__
* - 02/04/2011 V1.3 implement WID2container::WID2struct
*
* ============================================================================
*/
......@@ -40,7 +41,7 @@
#ifndef FAPIDXX_HELPER_H_VERSION
#define FAPIDXX_HELPER_H_VERSION \
"FAPIDXX_HELPER_H V1.2"
"FAPIDXX_HELPER_H V1.3"
#define FAPIDXX_HELPER_H_CVSID \
"$Id$"
......@@ -81,11 +82,47 @@ namespace fapidxx {
/*----------------------------------------------------------------------*/
/*! a struct to handle WID2 data
/*! \brief a struct to handle WID2 data
*
* See discussion in \ref sec_comments_prepwid2
*/
struct WID2container {
/* \brief struct to actually store the WID2 data
*/
struct WID2struct {
// static constants
static const char* encodeID;
static const unsigned short idlen=4;
static const unsigned short slen=5;
static const unsigned short clen=3;
static const unsigned short alen=4;
static const unsigned short ilen=6;
// data fields
char ID[idlen]; //!< ID string
libtime::timeint year; //!< date of first sample (year value)
libtime::timeint month; //!< date of first sample (month value)
libtime::timeint day; //!< date of first sample (day value)
libtime::timeint hour; //!< time of first sample (hour)
libtime::timeint minute; //!< time of first sample (minute)
libtime::timeint second; //!< time of first sample (second)
libtime::timeint milsec; //!< time of first sample (millisecond)
libtime::timeint micsec; //!< time of first sample (microsecond)
char station[slen+1]; //!< Station code
char channel[clen+1]; //!< FDSN channel code
char auxid[alen+1]; //!< Auxiliary identification code
int nsamples; //!< number of samples
double dt; //!< sampling interval (sec)
double calib; //!< calibration factor
double calper; //!< calibration reference period
char instype[ilen+1]; //!< instrument type
double hang; //!< horizontal orientation
double vang; //!< veritcal orientation
// member functions
//! set values from WID2
void set(const ::sff::WID2& wid2);
//! return values to WID2
::sff::WID2 get() const;
}; // struct WID2struct
//! \brief construct from C++ string
WID2container(const std::string& line) { setwid2(line); }
//! \brief construct from Fortran character sequence
......@@ -95,7 +132,6 @@ namespace fapidxx {
void setwid2(const std::string& line);
void setwid2(char *fstring, ftnlen slen);
void encode(char *fstring, ftnlen slen) const;
static const char* encodeID;
sff::WID2 wid2;
}; // struct WID2container {
......
Supports Markdown
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