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

SAC reading is nice

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: 2329
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 19cc7bb5
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.30 2007-06-29 10:33:22 tforb Exp $
# $Id: Makefile,v 1.31 2007-06-29 11:09:13 tforb Exp $
#
# Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
#
......@@ -176,7 +176,7 @@ doxyview: doxyfullview doxybrief
# test code
# ---------
hpmotest mseedtest pdastest sfftest: %: tests/%.o libdatreadxx.a
sactest hpmotest mseedtest pdastest sfftest: %: tests/%.o libdatreadxx.a
$(CXX) $(FLAGS) -o $@ $< -I$(LOCINCLUDEDIR) \
-ldatreadxx -lsffxx -lgsexx -ltsxx -ltfxx -laff -ltime++ \
-L$(LOCLIBDIR)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sacread.cc,v 1.4 2007-06-29 10:33:22 tforb Exp $
* $Id: sacread.cc,v 1.5 2007-06-29 11:09:13 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2004
*
......@@ -35,12 +35,23 @@
#define TF_SACREAD_CC_VERSION \
"TF_SACREAD_CC V1.0 "
#define TF_SACREAD_CC_CVSID \
"$Id: sacread.cc,v 1.4 2007-06-29 10:33:22 tforb Exp $"
"$Id: sacread.cc,v 1.5 2007-06-29 11:09:13 tforb Exp $"
#include <datreadxx/sacread.h>
namespace datread {
namespace sac {
// read SAC header from stream
void read_sac_header(std::istream& is, SACheader* sh)
{
typedef char* Pchar;
is.read(Pchar(sh), sizeof(SACheader));
}
} // namespace sac
} // namespace datread
/* ----- END OF sacread.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sacread.h,v 1.3 2006-03-28 16:07:48 tforb Exp $
* $Id: sacread.h,v 1.4 2007-06-29 11:09:13 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2004
*
......@@ -39,10 +39,206 @@
#define TF_SACREAD_H_VERSION \
"TF_SACREAD_H V1.0 "
#define TF_SACREAD_H_CVSID \
"$Id: sacread.h,v 1.3 2006-03-28 16:07:48 tforb Exp $"
"$Id: sacread.h,v 1.4 2007-06-29 11:09:13 tforb Exp $"
#include<istream>
namespace datread {
namespace sac {
/*======================================================================*/
/* this is <sac.h>
*
* this file comes along with the source of rdseed4.12 from IRIS DMC
*
*/
/*===========================================================================*/
/* SEED reader | sac.h | header file */
/*===========================================================================*/
/*
Name: sac.h
Purpose: structure for header of a SAC (Seismic Analysis Code) data file
Usage: #include "sac.h"
Input: not applicable
Output: not applicable
Warnings: not applicable
Errors: not applicable
Called by: output_data
Calls to: none
Algorithm: not applicable
Notes: Key to comment flags describing each field:
Column 1:
R = required by SAC
= (blank) optional
Column 2:
A = settable from a priori knowledge
D = available in data
F = available in or derivable from SEED fixed data header
T = available in SEED header tables
= (blank) not directly available from SEED data, header
tables, or elsewhere
Problems: none known
References: O'Neill, D. (1987). IRIS Interim Data Distribution Format
(SAC ASCII), Version 1.0 (12 November 1987). Incorporated
Research Institutions for Seismology, 1616 North Fort Myer
Drive, Suite 1440, Arlington, Virginia 22209. 11 pp.
Tull, J. (1987). SAC User's Manual, Version 10.2, October 7,
1987. Lawrence Livermore National Laboratory, L-205,
Livermore, California 94550. ??? pp.
Language: C, hopefully ANSI standard
Author: Dennis O'Neill
Revisions:07/15/88 Dennis O'Neill Initial preliminary release 0.9
11/21/88 Dennis O'Neill Production release 1.0
09/19/89 Dennis O'Neill corrected length of char strings
*/
struct SACheader
{
float delta; /* RF time increment, sec */
float depmin; /* minimum amplitude */
float depmax; /* maximum amplitude */
float scale; /* amplitude scale factor */
float odelta; /* observed time inc */
float b; /* RD initial value, ampl. */
float e; /* RD final value, amplitude */
float o; /* event start, sec > 0 */
float a; /* 1st arrival time */
float internal1; /* internal use */
float t0; /* user-defined time pick */
float t1; /* user-defined time pick */
float t2; /* user-defined time pick */
float t3; /* user-defined time pick */
float t4; /* user-defined time pick */
float t5; /* user-defined time pick */
float t6; /* user-defined time pick */
float t7; /* user-defined time pick */
float t8; /* user-defined time pick */
float t9; /* user-defined time pick */
float f; /* event end, sec > 0 */
float resp0; /* instrument respnse parm*/
float resp1; /* instrument respnse parm*/
float resp2; /* instrument respnse parm*/
float resp3; /* instrument respnse parm*/
float resp4; /* instrument respnse parm*/
float resp5; /* instrument respnse parm*/
float resp6; /* instrument respnse parm*/
float resp7; /* instrument respnse parm*/
float resp8; /* instrument respnse parm*/
float resp9; /* instrument respnse parm*/
float stla; /* T station latititude */
float stlo; /* T station longitude */
float stel; /* T station elevation, m */
float stdp; /* T station depth, m */
float evla; /* event latitude */
float evlo; /* event longitude */
float evel; /* event elevation */
float evdp; /* event depth */
float unused1; /* reserved for future use*/
float user0; /* available to user */
float user1; /* available to user */
float user2; /* available to user */
float user3; /* available to user */
float user4; /* available to user */
float user5; /* available to user */
float user6; /* available to user */
float user7; /* available to user */
float user8; /* available to user */
float user9; /* available to user */
float dist; /* stn-event distance, km */
float az; /* event-stn azimuth */
float baz; /* stn-event azimuth */
float gcarc; /* stn-event dist, degrees*/
float internal2; /* internal use */
float internal3; /* internal use */
float depmen; /* mean value, amplitude */
float cmpaz; /* T component azimuth */
float cmpinc; /* T component inclination */
float unused2; /* reserved for future use*/
float unused3; /* reserved for future use*/
float unused4; /* reserved for future use*/
float unused5; /* reserved for future use*/
float unused6; /* reserved for future use*/
float unused7; /* reserved for future use*/
float unused8; /* reserved for future use*/
float unused9; /* reserved for future use*/
float unused10; /* reserved for future use*/
float unused11; /* reserved for future use*/
float unused12; /* reserved for future use*/
long nzyear; /* F zero time of file, yr */
long nzjday; /* F zero time of file, day */
long nzhour; /* F zero time of file, hr */
long nzmin; /* F zero time of file, min */
long nzsec; /* F zero time of file, sec */
long nzmsec; /* F zero time of file, msec*/
long internal4; /* internal use */
long internal5; /* internal use */
long internal6; /* internal use */
long npts; /* RF number of samples */
long internal7; /* internal use */
long internal8; /* internal use */
long unused13; /* reserved for future use*/
long unused14; /* reserved for future use*/
long unused15; /* reserved for future use*/
long iftype; /* RA type of file */
long idep; /* type of amplitude */
long iztype; /* zero time equivalence */
long unused16; /* reserved for future use*/
long iinst; /* recording instrument */
long istreg; /* stn geographic region */
long ievreg; /* event geographic region*/
long ievtyp; /* event type */
long iqual; /* quality of data */
long isynth; /* synthetic data flag */
long unused17; /* reserved for future use*/
long unused18; /* reserved for future use*/
long unused19; /* reserved for future use*/
long unused20; /* reserved for future use*/
long unused21; /* reserved for future use*/
long unused22; /* reserved for future use*/
long unused23; /* reserved for future use*/
long unused24; /* reserved for future use*/
long unused25; /* reserved for future use*/
long unused26; /* reserved for future use*/
long leven; /* RA data-evenly-spaced flag*/
long lpspol; /* station polarity flag */
long lovrok; /* overwrite permission */
long lcalda; /* calc distance, azimuth */
long unused27; /* reserved for future use*/
char kstnm[8]; /* F station name */
char kevnm[16]; /* event name */
char khole[8]; /* man-made event name */
char ko[8]; /* event origin time id */
char ka[8]; /* 1st arrival time ident */
char kt0[8]; /* time pick 0 ident */
char kt1[8]; /* time pick 1 ident */
char kt2[8]; /* time pick 2 ident */
char kt3[8]; /* time pick 3 ident */
char kt4[8]; /* time pick 4 ident */
char kt5[8]; /* time pick 5 ident */
char kt6[8]; /* time pick 6 ident */
char kt7[8]; /* time pick 7 ident */
char kt8[8]; /* time pick 8 ident */
char kt9[8]; /* time pick 9 ident */
char kf[8]; /* end of event ident */
char kuser0[8]; /* available to user */
char kuser1[8]; /* available to user */
char kuser2[8]; /* available to user */
char kcmpnm[8]; /* F component name */
char knetwk[8]; /* network name */
char kdatrd[8]; /* date data read */
char kinst[8]; /* instrument name */
}; // struct SACheader
/*======================================================================*/
// functions
//! read SAC header from stream
void read_sac_header(std::istream& is, SACheader* sh);
} // namespace sac
} // namespace datread
#endif // TF_SACREAD_H_VERSION (includeguard)
......
/*! \file sactest.cc
* \brief test SAC reading code
*
* ----------------------------------------------------------------------------
*
* $Id: sactest.cc,v 1.3 2007-06-29 10:33:23 tforb Exp $
* \author Thomas Forbriger
* \date 29/06/2007
*
* tes SAC reading code
*
* Copyright (c) 2007 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
* - 29/06/2007 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define SACTEST_VERSION \
"SACTEST V1.0 test SAC reading code"
#define SACTEST_CVSID \
"$Id: sactest.cc,v 1.3 2007-06-29 10:33:23 tforb Exp $"
#include <iostream>
#include <tfxx/commandline.h>
using std::cout;
using std::cerr;
using std::endl;
int main(int iargc, char* argv[])
{
// define usage information
char usage_text[]=
{
SACTEST_VERSION "\n"
"usage: sactest" "\n"
" or: sactest --help|-h" "\n"
};
// define full help text
char help_text[]=
{
SACTEST_CVSID
};
// define commandline options
using namespace tfxx::cmdline;
static Declare options[]=
{
// 0: print help
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
{NULL}
};
// no arguments? print usage...
if (iargc<2)
{
cerr << usage_text << endl;
exit(0);
}
// collect options from commandline
Commandline cmdline(iargc, argv, options);
// help requested? print full help text...
if (cmdline.optset(0))
{
cerr << usage_text << endl;
cerr << help_text << endl;
exit(0);
}
// dummy operation: print option settings
for (int iopt=0; iopt<2; iopt++)
{
cout << "option: '" << options[iopt].opt_string << "'" << endl;
if (cmdline.optset(iopt)) { cout << " option was set"; }
else { cout << "option was not set"; }
cout << endl;
cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
cout << " argument (bool): '";
if (cmdline.bool_arg(iopt))
{ cout << "true"; } else { cout << "false"; }
cout << "'" << endl;
}
while (cmdline.extra()) { cout << cmdline.next() << endl; }
// dummy operation: print rest of command line
while (cmdline.extra()) { cout << cmdline.next() << endl; }
}
/*! \file sactest.cc
* \brief test SAC reading functions
*
* ----------------------------------------------------------------------------
*
* $Id: sactest.cc,v 1.3 2007-06-29 10:33:23 tforb Exp $
* $Id: sactest.cc,v 1.4 2007-06-29 11:09:14 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2004
*
......@@ -149,15 +35,23 @@ int main(int iargc, char* argv[])
#define SACTEST_VERSION \
"SACTEST V1.0 test SAC reading functions"
#define SACTEST_CVSID \
"$Id: sactest.cc,v 1.3 2007-06-29 10:33:23 tforb Exp $"
"$Id: sactest.cc,v 1.4 2007-06-29 11:09:14 tforb Exp $"
#include <iostream>
#include <string>
#include <fstream>
#include <tfxx/commandline.h>
#include <tfxx/error.h>
#include <datreadxx/sacread.h>
using std::cout;
using std::cerr;
using std::endl;
struct Options {
bool verbose, dumpheader;
}; // struct Options
int main(int iargc, char* argv[])
{
......@@ -165,13 +59,17 @@ int main(int iargc, char* argv[])
char usage_text[]=
{
SACTEST_VERSION "\n"
"usage: sactest" "\n"
"usage: sactest file [-h]" "\n"
" or: sactest --help|-h" "\n"
};
// define full help text
char help_text[]=
{
"file name of SAC file to read" "\n"
"\n"
"-h read and dump header only" "\n"
"\n"
SACTEST_CVSID
};
......@@ -183,6 +81,8 @@ int main(int iargc, char* argv[])
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: dump header
{"h",arg_no,"-"},
{NULL}
};
......@@ -205,6 +105,7 @@ int main(int iargc, char* argv[])
}
// dummy operation: print option settings
/*
for (int iopt=0; iopt<2; iopt++)
{
cout << "option: '" << options[iopt].opt_string << "'" << endl;
......@@ -225,8 +126,52 @@ int main(int iargc, char* argv[])
// dummy operation: print rest of command line
while (cmdline.extra()) { cout << cmdline.next() << endl; }
}
*/
/* ----- END OF sactest.cc ----- */
Options opt;
opt.verbose=cmdline.optset(1);
opt.dumpheader=cmdline.optset(2);
TFXX_assert(cmdline.extra(), "missing SAC file name");
std::string filename=cmdline.next();
if (opt.verbose)
{
cout << "file to process: " << filename << endl;
}
if (opt.dumpheader) {
if (opt.verbose)
{
cout << "dump header" << endl;
cout << "-----------" << endl;
}
datread::sac::SACheader hd;
std::ifstream ifs(filename.c_str());
datread::sac::read_sac_header(ifs, &hd);
cout << "sampling interval: " << hd.delta << " s" << endl;
cout << "initial value: " << hd.b << endl;
cout << "final value: " << hd.e << endl;
cout << "station latitude: " << hd.stla << " N" << endl;
cout << "station longitude: " << hd.stlo << " E" << endl;
cout << "station elevation: " << hd.stel << " m" << endl;
cout << "station depth: " << hd.stdp << " m" << endl;
cout << "component azimuth: " << hd.cmpaz << " " << endl;
cout << "component inclination: " << hd.cmpinc << " " << endl;
cout << "zero time of file, year: " << hd.nzyear << endl;
cout << "zero time of file, doy: " << hd.nzjday << endl;
cout << "zero time of file, hour: " << hd.nzhour << endl;
cout << "zero time of file, minute: " << hd.nzmin << endl;
cout << "zero time of file, second: " << hd.nzsec << endl;
cout << "zero time of file, millisecond: " << hd.nzmsec << endl;
cout << "number of samples: " << hd.npts << endl;
cout << "station name: " << std::string(hd.kstnm,8) << endl;
cout << "component name: " << std::string(hd.kcmpnm,8) << endl;
cout << "network name: " << std::string(hd.knetwk,8) << endl;
cout << "man-made event name: " << std::string(hd.khole,8) << endl;
cout << "type of file: " << hd.iftype << endl;
cout << "even sampling flag: " << hd.leven << endl;
}
}
/* ----- END OF sactest.cc ----- */
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