fapid_sff_ropens.cc 4.11 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
6
7
8
9
10
11
12
/*! \file fapid_sff_ropens.cc
 * \brief mimic Fortran subroutine sff_ROpenS (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * $Id$
 * \author Thomas Forbriger
 * \date 18/11/2010
 * 
 * mimic Fortran subroutine sff_ROpenS (implementation)
 * 
 * Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach) 
thomas.forbriger's avatar
thomas.forbriger committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 *
 * ----
 * 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
 * ----
 *
thomas.forbriger's avatar
thomas.forbriger committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 * 
 * REVISIONS and CHANGES 
 *  - 18/11/2010   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define TF_FAPID_SFF_ROPENS_CC_VERSION \
  "TF_FAPID_SFF_ROPENS_CC   V1.0   "
#define TF_FAPID_SFF_ROPENS_CC_CVSID \
  "$Id$"

#include <fapidxx/fapidsff.h>
#include <fapidxx/fileunit.h>
#include <fapidxx/helper.h>
#include <sffxx.h>

using namespace fapidxx;

48
49
50
/*! \brief Open SFF file and return source line
 *
 * \ingroup implemented_functions
thomas.forbriger's avatar
thomas.forbriger committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
 *
 * Description from stuff.f:
 * \code
c----------------------------------------------------------------------
      subroutine sff_ROpenS(lu, filename,
     &                      version, timestamp, code,
     &                      type, cs, c1, c2, c3, date, time, ierr)
c 
c Open file for reading. Read STAT line and SRCE line.
c 
c input:
c   lu              logical file unit
c   filename        name of file
c ouput:
c   version         version of writing library
c   timestamp       time and date file was written
c   code            indicates optional blocks
c   ierr            error status (ok: ierr=0)
c   type            type of source
c   cs              coordinate system
c   c1, c2, c3      coordinates of source
c   date, time      date and time of source signal
c
      integer lu, ierr
      real version
      character timestamp*(*), code *(*)
      character filename*(*), type*(*), date*(*), time*(*), cs*1
      real c1, c2, c3
c----------------------------------------------------------------------
 * \endcode
 */
int sff_ropens__(integer *lu, char *filename, real *version, char *timestamp,
                 char *code, char *type__, char *cs, real *c1, real *c2, 
                 real *c3, char *date, char *time, integer *ierr,
                 ftnlen filename_len, ftnlen timestamp_len, ftnlen code_len, 
                 ftnlen type_len, ftnlen cs_len, ftnlen date_len, 
                 ftnlen time_len)
{
  int retval=0;
  *ierr=0;
  try {
92
    datrw::ianystream &is=
93
94
      istreammanager.open(static_cast<int>(*lu),
                          stringfromfstring(filename, filename_len));
thomas.forbriger's avatar
thomas.forbriger committed
95
    sff::SRCE srce;
96
97
98
99
    std::string ocode("");
    if (is.hasfree()) { ocode.append("F"); }
    if (is.hassrce()) { ocode.append("S"); }
    if (is.hassrce()) { is >> srce; }
thomas.forbriger's avatar
thomas.forbriger committed
100
101
102
103
104
105
    // set output
    std::string srceline=srce.line();
    fillfstring(ocode, code, code_len);
    fillfstring(srce.type, type__, type_len);
    char thecs=sff::coosysID(srce.cs);
    fillfstring(std::string(&thecs, 1), cs, cs_len);
106
107
108
    *c1=static_cast<real>(srce.cx);
    *c2=static_cast<real>(srce.cy);
    *c3=static_cast<real>(srce.cz);
thomas.forbriger's avatar
thomas.forbriger committed
109
110
111
112
113
    fillfstring(srceline.substr(74,6), date, date_len);
    fillfstring(srceline.substr(81,10), time, time_len);
    // timestamp and version got lost
    sff::STAT stat;
    fillfstring(stat.timestamp, timestamp, timestamp_len);
114
115
    *version=static_cast<real>(sff::STAT::libversion);
//    std::cerr << "leaving sff_ropens__" << std::endl;
thomas.forbriger's avatar
thomas.forbriger committed
116
117
118
119
120
121
122
123
  }
  catch(...) {
    *ierr=1;
  }
  return retval;
} // int sff_ropens__

/* ----- END OF fapid_sff_ropens.cc ----- */