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

dropped Daniel main code

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/any2matlab0.1
SVN Revision: 3106
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent c261fe75
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id$
#
# Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach)
#
# compile mex files
#
# REVISIONS and CHANGES
# 15/07/2010 V1.0 Thomas Forbriger & Daniel Armbruster
#
# ============================================================================
#
OS := $(shell uname -m)
MEXFLAGS =-cxx
ifeq ($(OS),x86_64)
TYPE:=mexa64
else
TYPE:=mexglx
endif
install: any2matlab
flist: Makefile $(wildcard *.cc)
echo $^ | tr ' ' '\n' | sort > $@
.PHONY: edit
edit: flist; vim $<
.PHONY: clean
clean: ;
-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
-find . -name \*.mexglx | xargs --no-run-if-empty /bin/rm -v
-find . -name \*.mexa64 | xargs --no-run-if-empty /bin/rm -v
#======================================================================
# installation part
# # ------------------
# depends on operating system $(OS)
.PHONY: any2matlab
any2matlab: any2matlab.cc
mex $< $(MEXFLAGS) -output $(LOCBINDIR)/$@.$(TYPE) -L$(LOCLIBDIR) -I$(LOCINCLUDEDIR) -ldatreadxx\
-lsffxx -lgsexx -laff -ltime++
#======================================================================
# documentation part
# # ------------------
DOXYWWWPATH=$(WWWBASEDIR)/mex
.PHONY: doxyclean
doxyclean:
/bin/rm -rfv $(WWWBASEDIR)/mex
/bin/rm -rfv doc
doc/%: doxyfull.cfg
mkdir -vp $(DOXYWWWPATH)
/bin/rm -rfv doc
ln -sfv $(DOXYWWWPATH) doc
doxygen $<
doxyfullview:
$(TF_BROWSER) file:$(DOXYWWWPATH)/html/index.html &
# ----- END OF Makefile -----
%{
* ========================================================================
*
* Filename: any2kasop.m
*
* Description: Conversion of a MATLAB-struct which had been created by any2matlab.mexa64
* any2matlab.mexa64 supports the import of seismic data from Thomas
* Forbriger's software library.
* For further information:
* http://www.rz.uni-karlsruhe.de/~bi77/txt/mycode.html
*
* Version: 1.0
* Created: 10.06.2010 20:02:02
* Revision: none
*
* Author: Daniel Armbruster (HiWi of Joern ;-)
* Usage: kasopstruct = any2kasop(tfstruct)
*
* ========================================================================
%}
function [outstruct]=any2kasop(instruct)
% checking input data
if (nargin==0 || ~isstruct(instruct))
error('ERROR: No struct given!')
outstruct=0;
return
end
if (~isfield(instruct,'date') && ~isfield(instruct,'time') && ~isfield(instruct,'tdate') && ~isfield(instruct,'station') && ~isfield(instruct,'channel') && ~isfield(instruct,'auxid') && ~isfield(instruct,'dt') && ~isfield(instruct,'calper') && ~isfield(instruct,'instype'))
outstruct=0;
error('ERROR: input data is not a valid struct!')
return
end
% copy data from instruct to kasop-struct
for i=1:length(instruct)
% create outstruct
outstruct(i) = gettimeseriesdatastruct;
% set tsn-field
outstruct(i).tsn = datenum(instruct(i).tdate);
% set staname-field
outstruct(i).staname = strtrim(instruct(i).station);
% set channel-field
channel = strtrim(instruct(i).channel);
outstruct(i).channel = channel;
% set comp-field
outstruct(i).comp = channel(3);
% set npts-field
outstruct(i).npts = instruct(i).samps;
% set delta-field
outstruct(i).delta = instruct(i).dt;
% set trace-field
outstruct(i).trace = instruct(i).trace;
end
clear(channel);
outstruct = checktimeseriesdatastruct(outstruct);
return
% EOF any2kasop.m
/*!
* \file any2matlab.cc
* \brief This es a MEX-file using Thomas Forbriger's datread library importing seismic dataformats
* to MATLAB.
*
* Currently supported formats are:
* \li mseed: MiniSEED (SeisComP, EDL, etc.)
* \li pdas: PDAS100 (i.e. DaDisp)
* \li sac: SAC binary format
* \li sff: Stuttgart File Format
* \li gse: raw GSE format
* \li hpmo: HP-MO data format defined by W. Grossmann (BFO)
* \li bonjer: K2 ASCII data format (defined by K. Bonjer?)
*
*
* \author Daniel Armbruster
* \version V1.0
* \date 01/07/2010
*
* ----
* 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
* ----
*
* \section general General
*
* - For information how to use go to \ref usage .
* - For \ref info how the program works.
*
* \brief The gateway routine to every MEX-file is called <b>mexFunction</b>.
*
* \param nrhs: Number of inputs (Right Hand Side)
* \param prhs: Array of pointers to input data.
*
* The input data is read-only and should not be altered by your mexFunction .
* \return nlhs Number of expected mxArrays (Left Hand Side)
* \return plhs: Array of pointers to expected outputs
*
* The variables nrhs and \c nlhs are the number of variables that MATLAB requested at this instance.
* They are analogous to \c NARGIN and \c NARGOUT in MATLAB.
* \n
*
* The variables \c prhs and \c plhs are not mxArrays. They are arrays of pointers to mxArrays. So if a
* function is given three inputs, \c prhs will be an array of three pointers to the mxArrays that
* contain the data passed in. The variable \c prhs is declared as \c const. This means that the values
* that are passed into the MEX-file should not be altered. Doing so can cause segmentation
* violations in MATLAB. The values in \c plhs are invalid when the MEX-file begins. The mxArrays they
* point to must be explicitly created before they are used. Compilers will not catch this issue,
* but it will cause incorrect results or segmentation violations.
*
* \section usage Usage
* <tt>tfstruct = any2matlab('fname.ftype');\n</tt>
* or: <tt>tfstruct = any2matlab('fname', 'ftype');\n</tt>
* or: <tt>tfstruct = any2matlab('ftype', 'fname');\n</tt>
*
* - \p fname is the filename of the datafile. A "." seperates \p fname from \p ftype
* e.g. \p data.sff
* - \p fname is the filename of the datafile in an arbitrary form. \p ftype is one of the options
* below.
* - Same as the previous one, with different order.
* - \p ftype is one of the following filetypes:
* -# pdas
* -# sff
* -# hpmo
* -# bonjer
* -# mseed
* -# sac
* -# gse
* - \p tfstruct is a MATLAB struct with the following fields:
* -# \c date: date of first sample. format: \c 'YYYY/MM/DD'
* -# \c time: time of the first sample. format: \c 'hh:mm:ss.milsec'
* -# \c tdate: timevector: <tt>[YYYY MM DD hh mm ss.milsec]</tt>
* -# \c station: Station code. type: \c string
* -# \c channel: FDSN channel code. type: \c string
* -# \c auxid: Auxiliary identification code. type: \c string
* -# \c samps: Number of samples. type: \c int
* -# \c dt: Sampling interval (sec). type: \c double
* -# \c calib: Calibration factor. type: \c double
* -# \c calper: Calibration reference period. type: \c double
* -# \c instype: Instrument type. type: \c string
* -# \c trace: [<tt>samps</tt>x1 \c double]
*
* For further information watch sff::WID2
*
* \section info Detailed Information
*
* To allocate sufficient memory any2matlab has to open a first time the desired datafile to get the
* number of traces and the number of samps per trace.\n
* While opening the datafile a second time any2matlab will read one trace and write it immediately
* to \c tfstruct until there are no traces left.\n
* With this method you are able to read as much traces as fit to your machines memory.
*
*/
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <ctype.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <datreadxx/readany.h>
#include <libtime++.h>
#include <aff/series.h>
#include <gsexx.h>
#include <sffxx.h>
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
const char *field_names[] = {"date", "time", "tdate", "station", "channel", "auxid", "samps", "dt",
"calib", "calper", "instype", "trace"};
int number_of_fields;
int date_field, time_field, tdate_field, station_field, channel_field;
int auxid_field, samps_field, dt_field, calib_field, calper_field;
int instype_field, trace_field;
std::vector<int> ntraces;
ntraces.reserve(100);
// calculate number of fields
number_of_fields = sizeof(field_names) / sizeof(*field_names);
// check: if input is correct
if (nrhs == 0)
mexErrMsgTxt("ERROR: missing input filename!");
// check: more than 2 arguments
else if (nrhs > 2)
mexErrMsgTxt("ERROR: too many input arguments!");
// check: one argument and string
else if ((nrhs == 1) && (mxIsChar(prhs[0]) != 1))
mexErrMsgTxt("ERROR: input must be a string!");
// check: 2 arguments and string
else if ((nrhs == 2) && (((mxIsChar(prhs[0]) != 1) || (mxIsChar(prhs[1])) != 1)))
mexErrMsgTxt("Error: input must be a string!");
// input must be a row vectors
else if ((nrhs == 2) && ((mxGetM(prhs[0]) != 1) || mxGetM(prhs[1]) != 1))
mexErrMsgTxt("Error: input isn't valid!");
int trace = 0;
bool hot;
std::string infile;
std::string filetype;
// If only one argument is given to any2matlab.mexa64
if (nrhs == 1) {
infile = std::string(mxArrayToString(prhs[0]));
/*
* Important note:
* If only one argument is given to any2matlab.mexa64 the given filename must contain at least one
* dot. After the the dot there must be one of the following endings.
*/
if (infile.rfind(".") != string::npos) {
filetype = infile.substr(infile.rfind(".") + 1);
}
else
mexErrMsgTxt("Error: not a valid filename!");
}
// check: 2 arguments
if (nrhs == 2) {
std::string arg0 = std::string(mxArrayToString(prhs[0]));
std::string arg1 = std::string(mxArrayToString(prhs[1]));
// check: if one contains a dot
if (!(arg0.rfind(".") == string::npos)) {
infile = arg0;
filetype = arg1;
}
else {
infile = arg1;
filetype = arg0;
}
}
// set filetype to lower case
transform(filetype.begin(), filetype.end(), filetype.begin(), tolower);
datread::Eformat format = datread::anyID(filetype);
{
std::ifstream ifs(infile.c_str());
datread::ianystream is(ifs, format);
/* get number of traces in infile */
/* while skipping series */
hot=is.good();
while (hot) {
datread::Tdseries series;
is.skipseries();
sff::WID2 wid2;
// read the WID2 header
is >> wid2;
ntraces.push_back(wid2.nsamples);
trace++;
hot=(!is.last());
}
}
int dims[2] = {1, trace};
// create a 1-by-n array of strucntraces.
plhs[0] = mxCreateStructArray(2, dims, number_of_fields, field_names);
date_field = mxGetFieldNumber(plhs[0], "date");
time_field = mxGetFieldNumber(plhs[0], "time");
tdate_field = mxGetFieldNumber(plhs[0], "tdate");
station_field = mxGetFieldNumber(plhs[0], "station");
auxid_field = mxGetFieldNumber(plhs[0], "auxid");
channel_field = mxGetFieldNumber(plhs[0], "channel");
samps_field = mxGetFieldNumber(plhs[0], "samps");
dt_field = mxGetFieldNumber(plhs[0], "dt");
calib_field = mxGetFieldNumber(plhs[0], "calib");
calper_field = mxGetFieldNumber(plhs[0], "calper");
instype_field = mxGetFieldNumber(plhs[0], "instype");
trace_field = mxGetFieldNumber(plhs[0], "trace");
{
std::ifstream ifs(infile.c_str());
datread::ianystream is(ifs, format);
hot = is.good();
int i = 0;
while(hot) {
mxArray *field_value;
datread::Tdseries series;
// read the series
is >> series;
// set trace-field
field_value = mxCreateDoubleMatrix(ntraces[i], 1, mxREAL);
memcpy(mxGetPr(field_value), series.pointer(), ntraces[i] * sizeof(double));
mxSetFieldByNumber(plhs[0], i, trace_field, field_value);
sff::WID2 wid2;
// read the WID2 header
is >> wid2;
// set date-field
{
std::ostringstream str;
str << wid2.date.year() << "/" << wid2.date.month() << "/" << wid2.date.day() << std::ends;
std::string datestring;
datestring.append(str.str());
mxSetFieldByNumber(plhs[0],i,date_field,mxCreateString(datestring.c_str()));
}
// set date-field
{
std::ostringstream str;
std::string timestring;
str << wid2.date.hour() << ":" << wid2.date.minute() << ":" << wid2.date.second() <<
"." << wid2.date.milsec() << std::ends;
timestring.append(str.str());
mxSetFieldByNumber(plhs[0],i,time_field,mxCreateString(timestring.c_str()));
}
// set tdate-field
double time [6];
time [0] = wid2.date.year();
time [1] = wid2.date.month();
time [2] = wid2.date.day();
time [3] = wid2.date.hour();
time [4] = wid2.date.minute();
time [5] = wid2.date.second() + wid2.date.milsec() * 0.001;
field_value = mxCreateDoubleMatrix(1, sizeof(time) / sizeof(time[0]), mxREAL);
memmove(mxGetPr(field_value), &time, sizeof(time) / sizeof(time[0]) * sizeof(double));
mxSetFieldByNumber(plhs[0], i, tdate_field, field_value);
// set station-field
mxSetFieldByNumber(plhs[0],i,station_field,mxCreateString(wid2.station.c_str()));
// set channel-field
mxSetFieldByNumber(plhs[0],i,channel_field,mxCreateString(wid2.channel.c_str()));
// set auxid-field
mxSetFieldByNumber(plhs[0],i,auxid_field,mxCreateString(wid2.auxid.c_str()));
// set samps-field
field_value = mxCreateDoubleMatrix(1, 1, mxREAL);
*mxGetPr(field_value) = wid2.nsamples;
mxSetFieldByNumber(plhs[0], i, samps_field, field_value);
// set dt-field
field_value = mxCreateDoubleMatrix(1, 1, mxREAL);
*mxGetPr(field_value) = wid2.dt;
mxSetFieldByNumber(plhs[0], i, dt_field, field_value);
// set calib-field
field_value = mxCreateDoubleMatrix(1, 1, mxREAL);
*mxGetPr(field_value) = wid2.calib;
mxSetFieldByNumber(plhs[0], i, calib_field, field_value);
// set calper-field
field_value = mxCreateDoubleMatrix(1, 1, mxREAL);
*mxGetPr(field_value) = wid2.calper;
mxSetFieldByNumber(plhs[0], i, calper_field, field_value);
// set instype-field
mxSetFieldByNumber(plhs[0],i, instype_field,mxCreateString(wid2.instype.c_str()));
i++;
hot=(!is.last());
}
}
}
# Doxyfile 1.5.8
# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project
#
# All text after a hash (#) is considered a comment and will be ignored
# The format is:
# TAG = value [value, ...]
# For lists items can also be appended using:
# TAG += value [value, ...]
# Values that contain spaces should be placed between quotes (" ")
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
# This tag specifies the encoding used for all characters in the config file
# that follow. The default is UTF-8 which is also the encoding used for all
# text before the first occurrence of this tag. Doxygen uses libiconv (or the
# iconv built into libc) for the transcoding. See
# http://www.gnu.org/software/libiconv for the list of possible encodings.
DOXYFILE_ENCODING = UTF-8
# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
# by quotes) that should identify the project.
PROJECT_NAME = any2matlab.cc
# The PROJECT_NUMBER tag can be used to enter a project or revision number.
# This could be handy for archiving the generated documentation or
# if some version control system is used.
PROJECT_NUMBER =
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
# If a relative path is entered, it will be relative to the location
# where doxygen was started. If left blank the current directory will be used.
OUTPUT_DIRECTORY = doc
# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
# 4096 sub-directories (in 2 levels) under the output directory of each output
# format and will distribute the generated files over these directories.
# Enabling this option can be useful when feeding doxygen a huge amount of
# source files, where putting all generated files in the same directory would
# otherwise cause performance problems for the file system.
CREATE_SUBDIRS = NO
# The OUTPUT_LANGUAGE tag is used to specify the language in which all
# documentation generated by doxygen is written. Doxygen will use this
# information to generate all constant output in the proper language.
# The default language is English, other supported languages are:
# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek,
# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages),
# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish,
# Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, Slovene,
# Spanish, Swedish, and Ukrainian.
OUTPUT_LANGUAGE = English
# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
# include brief member descriptions after the members that are listed in
# the file and class documentation (similar to JavaDoc).
# Set to NO to disable this.
BRIEF_MEMBER_DESC = YES
# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
# the brief description of a member or function before the detailed description.
# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
# brief descriptions will be completely suppressed.
REPEAT_BRIEF = YES
# This tag implements a quasi-intelligent brief description abbreviator
# that is used to form the text in various listings. Each string
# in this list, if found as the leading text of the brief description, will be
# stripped from the text and the result after processing the whole list, is
# used as the annotated text. Otherwise, the brief description is used as-is.
# If left blank, the following values are used ("$name" is automatically
# replaced with the name of the entity): "The $name class" "The $name widget"
# "The $name file" "is" "provides" "specifies" "contains"
# "represents" "a" "an" "the"
ABBREVIATE_BRIEF =
# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
# Doxygen will generate a detailed section even if there is only a brief
# description.
ALWAYS_DETAILED_SEC = NO
# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
# inherited members of a class in the documentation of that class as if those
# members were ordinary class members. Constructors, destructors and assignment
# operators of the base classes will not be shown.
INLINE_INHERITED_MEMB = NO
# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
# path before files name in the file list and in the header files. If set
# to NO the shortest path that makes the file name unique will be used.
FULL_PATH_NAMES = YES
# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
# can be used to strip a user-defined part of the path. Stripping is
# only done if one of the specified strings matches the left-hand part of
# the path. The tag can be used to show relative paths in the file list.
# If left blank the directory from which doxygen is run is used as the
# path to strip.
STRIP_FROM_PATH =
# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
# the path mentioned in the documentation of a class, which tells
# the reader which header file to include in order to use a class.
# If left blank only the name of the header file containing the class
# definition is used. Otherwise one should specify the include paths that
# are normally passed to the compiler using the -I flag.
STRIP_FROM_INC_PATH =
# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
# (but less readable) file names. This can be useful is your file systems
# doesn't support long names like on DOS, Mac, or CD-ROM.
SHORT_NAMES = NO
# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
# will interpret the first line (until the first dot) of a JavaDoc-style
# comment as the brief description. If set to NO, the JavaDoc
# comments will behave just like regular Qt-style comments
# (thus requiring an explicit @brief command for a brief description.)
JAVADOC_AUTOBRIEF = NO
# If the QT_AUTOBRIEF tag is set to YES then Doxygen will
# interpret the first line (until the first dot) of a Qt-style
# comment as the brief description. If set to NO, the comments
# will behave just like regular Qt-style comments (thus requiring
# an explicit \brief command for a brief description.)