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

new gremlin1 model read access

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.
small correction in wave (scope resolution)


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1248
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent c5b2f2de
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: polymodel.cc,v 1.2 2002-12-30 16:04:32 forbrig Exp $
* $Id: polymodel.cc,v 1.3 2002-12-30 18:08:29 forbrig Exp $
* \author Thomas Forbriger
* \date 30/12/2002
*
......@@ -19,13 +19,14 @@
#define TF_POLYMODEL_CC_VERSION \
"TF_POLYMODEL_CC V1.0"
#define TF_POLYMODEL_CC_CVSID \
"$Id: polymodel.cc,v 1.2 2002-12-30 16:04:32 forbrig Exp $"
"$Id: polymodel.cc,v 1.3 2002-12-30 18:08:29 forbrig Exp $"
#include <gremlin1/polymodel.h>
#include <tfxx/error.h>
#include <aff/shaper.h>
#include <stdio.h>
#include <string>
#include <fstream>
namespace gremlin1 {
......@@ -46,6 +47,15 @@ namespace gremlin1 {
}
/*----------------------------------------------------------------------*/
//! read from file
PolynomialModelFile::PolynomialModelFile(const char* filename)
{
std::ifstream ifs(filename);
read_from_stream(ifs);
}
/*----------------------------------------------------------------------*/
//! check consistency
void PolynomialModelFile::check_consistency() const
......@@ -54,15 +64,15 @@ namespace gremlin1 {
try {
// check Mpara
TFXX_assert(((Mpara.f(0)==1)&&(Mpara.l(0)==3)), message);
TFXX_assert(((Mpara.f(1)==0)&&(Mpara.l(1)>Mpara.f(1))), message);
TFXX_assert(((Mpara.f(1)==1)&&(Mpara.l(1)>=Mpara.f(1))), message);
TFXX_assert(((Mpara.f(2)==1)&&(Mpara.l(2)==5)), message);
// check Mdepth
TFXX_assert(((Mdepth.f(0)==0)&&(Mdepth.l(0)>Mdepth.f(0))), message);
// check Mfollow
TFXX_assert(((Mfollow.f(0)==0)&&(Mfollow.l(0)>Mfollow.f(0))), message);
TFXX_assert(((Mfollow.f(0)==1)&&(Mfollow.l(0)>=Mfollow.f(0))), message);
TFXX_assert(((Mfollow.f(1)==1)&&(Mfollow.l(1)==5)), message);
// check Mnpol
TFXX_assert(((Mnpol.f(0)==0)&&(Mnpol.l(0)>Mnpol.f(0))), message);
TFXX_assert(((Mnpol.f(0)==1)&&(Mnpol.l(0)>=Mnpol.f(0))), message);
TFXX_assert(((Mnpol.f(1)==1)&&(Mnpol.l(1)==5)), message);
// check for consistent number of sections
TFXX_assert(((Mpara.l(1)==Mdepth.l(0))&&(Mfollow.l(0)==Mdepth.l(0))&&
......@@ -134,7 +144,7 @@ namespace gremlin1 {
{
int i=valid_section_index(isec);
TFXX_assert((!(ishalfspace(i))), "isec is in halfpsace");
return(depth-0.5*(Mdepth(i)-Mdepth(i-1)));
return(depth-0.5*(Mdepth(i)+Mdepth(i-1)));
}
/*----------------------------------------------------------------------*/
......@@ -210,7 +220,7 @@ namespace gremlin1 {
TFXX_assert((isec!=Mpara.f(1)),
"first section has nothing to follow!");
// calculate value at bottom of upper section
Tvalue vup=value(ipar, Mdepth(isec-1), isec-1);
Tvalue vup=value(ipar, Mdepth(isec-1), (isec-1));
// calculate value at top of this section
Tvalue vlo=value(ipar, Mdepth(isec-1), isec);
// correct mean of this section
......@@ -229,8 +239,9 @@ namespace gremlin1 {
os << TF_POLYMODEL_CC_CVSID << std::endl << std::endl;
os << modversion2 << std::endl;
os.width(5);
os << nsections()
<< " <-- number of sections" << std::endl << std::endl;
os << nsections();
os.width(15);
os << " " << "<-- number of sections" << std::endl << std::endl;
os << " Vp Vs density Qp Qs"
<< std::endl;
const int bufsize=15;
......@@ -240,8 +251,11 @@ namespace gremlin1 {
os << std::endl;
std::snprintf(buffer, bufsize, "%12.4f", Mdepth(isec));
os.width(12);
os << buffer << " <-- bottom of section " << isec
<< " polynomial expansion:" << std::endl;
os << buffer;
os.width(8);
os << " " << "<-- bottom of section";
os.width(5);
os << isec << " / polynomial expansion:" << std::endl;
for (int ipar=1; ipar<6; ++ipar)
{
os.width(12);
......@@ -256,14 +270,14 @@ namespace gremlin1 {
{
if (ipar<4)
{
std::snprintf(buffer, bufsize, "%12.4g", Mpara(ipol,isec,ipar));
std::snprintf(buffer, bufsize, "%12.6f", Mpara(ipol,isec,ipar));
} else {
std::snprintf(buffer, bufsize, "%12.4f", Mpara(ipol,isec,ipar));
}
os.width(12);
os << buffer << " ";
}
os << std::endl << std::endl;
os << std::endl;
}
}
}
......@@ -274,35 +288,42 @@ namespace gremlin1 {
void PolynomialModelFile::read_from_stream(std::istream& is)
{
// skip comment
is.ignore(500,'\n');
is.ignore(500,'\n');
const int maxskip=500;
is.ignore(maxskip,'\n');
is.ignore(maxskip,'\n');
std::string identifier;
is >> identifier;
TFXX_assert((identifier == std::string(modversion2)),
getline(is, identifier);
TFXX_assert((identifier.find(modversion2)==0),
"missing or wrong identifier!");
is.ignore(500,'\n');
// number of sections
int nsec;
is >> nsec;
is.ignore(500,'\n');
is.ignore(maxskip,'\n');
// prepare arrays
Mpara=Tarray(3,nsec+1,5);
Mdepth=Tarray(aff::Shaper(0,nsec+1));
Mfollow=Tbarray(nsec+1,5);
Mnpol=Tiarray(nsec+1,5);
try {
Mpara=Tarray(3,nsec+1,5);
Mdepth=Tarray(aff::Shaper(0,nsec+1));
Mfollow=Tbarray(nsec+1,5);
Mnpol=Tiarray(nsec+1,5);
}
catch ( ... ) {
std::cerr << "PolynomialModelFile: could not create arrays for "
<< nsec << " sections!" << std::endl;
TFXX_abort("aborting...");
}
Mdepth=0.;
Mpara=0.;
Mfollow=false;
Mnpol=1;
// skip headline
is.ignore(500,'\n');
is.ignore(500,'\n');
is.ignore(maxskip,'\n');
is.ignore(maxskip,'\n');
// read
for (int isec=1; isec<=nsec; ++isec)
{
is.ignore(500,'\n');
is.ignore(maxskip,'\n');
is >> Mdepth(isec);
is.ignore(500,'\n');
is.ignore(maxskip,'\n');
for (int ipar=1; ipar<6; ++ipar)
{
is >> Mnpol(isec, ipar);
......@@ -323,6 +344,6 @@ namespace gremlin1 {
// finalize
clean_unused_and_check();
}
}
} // namespace gremlin1
/* ----- END OF polymodel.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: polymodel.h,v 1.2 2002-12-30 16:04:32 forbrig Exp $
* $Id: polymodel.h,v 1.3 2002-12-30 18:08:29 forbrig Exp $
* \author Thomas Forbriger
* \date 30/12/2002
*
......@@ -23,7 +23,7 @@
#define TF_POLYMODEL_H_VERSION \
"TF_POLYMODEL_H V1.0 "
#define TF_POLYMODEL_H_CVSID \
"$Id: polymodel.h,v 1.2 2002-12-30 16:04:32 forbrig Exp $"
"$Id: polymodel.h,v 1.3 2002-12-30 18:08:29 forbrig Exp $"
#include<iostream>
#include<aff/array.h>
......@@ -66,6 +66,8 @@ namespace gremlin1 {
//! default constructor
PolynomialModelFile();
//! create from file
PolynomialModelFile(const char* filename);
//! read model from stream
void read_from_stream(std::istream& is);
......@@ -73,7 +75,7 @@ namespace gremlin1 {
void write_to_stream(std::ostream& os) const;
//! return number of sections
int nsections() const { return(Mpara.size(1)-2); }
int nsections() const { return(Mpara.size(1)-1); }
//! lower interface of section \p i
Tvalue bottom(const int& i) const;
//! is this section index the half-space
......@@ -148,16 +150,18 @@ namespace gremlin1 {
/*----------------------------------------------------------------------*/
//! output operator
inline
std::ostream& operator<<(std::ostream& os,
const PolynomialModelFile& pmf)
{ pmf.write_to_stream(os); return(os); }
//! output operator
inline
std::istream& operator>>(std::istream& is,
PolynomialModelFile& pmf)
{ pmf.read_from_stream(is); return(is); }
}
} // namespace gremlin1
#endif // TF_POLYMODEL_H_VERSION (includeguard)
......
#
# Makefile for src/green/gremlin1/tools
#
# $Id: Makefile,v 1.11 2001-11-28 17:34:33 forbrig Exp $
# $Id: Makefile,v 1.12 2002-12-30 18:08:29 forbrig Exp $
#
# 26/05/2000 - thof - new dependency generator (fdep.sh)
# 19/01/2001 reactivated them all
#
FLAGS=
LIBGIN=-lgin
FFLAGS=-ffixed-line-length-0 -Wall -fno-backslash -O2
TFLIB=-ltf -L$(LOCLIBDIR)
......@@ -21,12 +23,18 @@ F2CFLAGS=-u -f -I../
CFLAGS=-I$(LOCINCLUDEDIR) -I$(SERVERINCLUDEDIR) -O3
LIBF2C=-lf2c -lm -L$(SERVERLIBDIR)
CXXFLAGS=-Wall $(FLAGS)
LDFLAGS=-L$(LOCLIBDIR)
CPPFLAGS=-I$(LOCINCLUDEDIR)
CXXSRC=mocox.cc
.f.o:
f2c $(F2CFLAGS) $<
$(CC) $(CFLAGS) $(<:.f=.c) -c
@rm $(<:.f=.c)
all: grereso polex moche moval motab clemo splimo mocon mop pmotra
all: grereso polex moche moval motab clemo splimo mocon mop pmotra mocox
clean:
-/bin/rm *.o *.bak *.o77 *.d
......@@ -45,6 +53,14 @@ edit: flist; vim $<
-include $(subst .f,.d,$(wildcard *.f))
%.d: %.cc
$(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $(TMPPARDEF) $< \
| sed '\''s,\($(notdir $*)\)\.o[ :]*,$(dir $@)\1.o $@ : ,g'\'' \
> $@; \
[ -s $@ ] || rm -f $@'
-include $(patsubst %.cc,%.d,$(CXXSRC))
#make.incdep: *.f
# incdep > make.incdep
#
......@@ -81,6 +97,10 @@ pmotra: %: %.o
$(F2CPGLIB) $(LIBF2C)
newprog $@
$(CXXSRC:.cc=): %: %.o
$(CXX) -o $@ $< $(LDFLAGS) -lgremlin1xx -ltfxx -laff
newprog $@
%77: %.f
g77 -o $@ $< -O3 -I.. $(FFLAGS) $(LIBGIN) $(TFLIB77) \
$(LIBNUMREC77) $(PGLIB77) -static
......
/*! \file mocox.cc
* \brief convert gremlin1 model (modversion2)
*
* ----------------------------------------------------------------------------
*
* $Id: mocox.cc,v 1.1 2002-12-30 18:08:29 forbrig Exp $
* \author Thomas Forbriger
* \date 30/12/2002
*
* convert gremlin1 model (modversion2)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 30/12/2002 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define MOCOX_VERSION \
"MOCOX V1.0 convert gremlin1 model (modversion2)"
#define MOCOX_CVSID \
"$Id: mocox.cc,v 1.1 2002-12-30 18:08:29 forbrig Exp $"
#include <iostream>
#include <fstream>
#include <gremlin1/polymodel.h>
#include <tfxx/commandline.h>
#include <tfxx/error.h>
using std::cout;
using std::cerr;
using std::endl;
int main(int iargc, char* argv[])
{
// define usage information
char usage_text[]=
{
MOCOX_VERSION "\n"
"usage: mocox file [-w file]" "\n"
" or: mocox --help|-h" "\n"
};
// define full help text
char help_text[]=
{
"Read a gremlin1 model file and operate on it." "\n"
"\n"
"file file name of model file" "\n"
"\n"
"-w file write model to gremlin1 format \"file\"" "\n"
"\n"
MOCOX_CVSID
};
// define commandline options
using namespace tfxx::cmdline;
static Declare options[]=
{
// 0: print help
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: verbose mode
{"w",arg_yes,"-"},
{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);
}
/*----------------------------------------------------------------------*/
// extract options
bool opt_verbose=cmdline.optset(1);
bool opt_writeg1=cmdline.optset(2);
std::string arg_writeg1=cmdline.string_arg(2);
TFXX_assert(cmdline.extra(), "ERROR (mocox): missing file name!");
std::string filename=cmdline.next();
/*----------------------------------------------------------------------*/
// read file
if (opt_verbose) cout << "read model from \""
<< filename << "\"" << endl;
gremlin1::PolynomialModelFile modelfile(filename.c_str());
if (opt_verbose)
{
cout << endl;
cout << "Model values are:" << endl
<< "-----------------" << endl << endl
<< modelfile;
}
/*----------------------------------------------------------------------*/
// write to file
if (opt_writeg1)
{
if (opt_verbose) cout << endl << "write model to \""
<< arg_writeg1 << "\"" << endl;
std::ofstream ofs(arg_writeg1.c_str());
ofs << modelfile;
}
}
/* ----- END OF mocox.cc ----- */
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