Fortran SFF API to data I/O streams in C++
fapid_sff_ropenfs.cc
Go to the documentation of this file.
1 
35 #define TF_FAPID_SFF_ROPENFS_CC_VERSION \
36  "TF_FAPID_SFF_ROPENFS_CC V1.0 "
37 
38 #include <fapidxx/fapidsff.h>
39 #include <fapidxx/fileunit.h>
40 #include <fapidxx/helper.h>
41 #include <sffxx.h>
42 
43 using namespace fapidxx;
44 
84 int sff_ropenfs__(integer *lu, char *filename, real *version,
85  char *timestamp, char *code,
86  integer *nline, char *lines, integer *lenmax,
87  integer *lindim,
88  char *type__, char *cs, real *c1, real *c2, real *c3,
89  char *date, char *time, integer *ierr,
90  ftnlen filename_len, ftnlen timestamp_len, ftnlen code_len,
91  ftnlen lines_len, ftnlen type_len, ftnlen cs_len,
92  ftnlen date_len, ftnlen time_len)
93 {
94  int retval=0;
95  *ierr=0;
96  try {
97  datrw::ianystream &is=
98  istreammanager.open(static_cast<int>(*lu),
99  stringfromfstring(filename, filename_len));
100  sff::SRCE srce;
101  std::string ocode("");
102  if (is.hasfree()) { ocode.append("F"); }
103  if (is.hassrce()) { ocode.append("S"); }
104  if (is.hassrce()) { is >> srce; }
105  // set SRCE data
106  std::string srceline=srce.line();
107  fillfstring(ocode, code, code_len);
108  fillfstring(srce.type, type__, type_len);
109  char thecs=sff::coosysID(srce.cs);
110  fillfstring(std::string(&thecs, 1), cs, cs_len);
111  *c1=static_cast<real>(srce.cx);
112  *c2=static_cast<real>(srce.cy);
113  *c3=static_cast<real>(srce.cz);
114  fillfstring(srceline.substr(74,6), date, date_len);
115  fillfstring(srceline.substr(81,10), time, time_len);
116  // set free block
117  sff::FREE free;
118  if (is.hasfree()) { is >> free; }
119  freeblock(free, nline, lines, lindim, lenmax, lines_len);
120  // timestamp and version got lost
121  sff::STAT stat;
122  fillfstring(stat.timestamp, timestamp, timestamp_len);
123  *version=static_cast<real>(sff::STAT::libversion);
124 // std::cerr << "leaving sff_ropens__" << std::endl;
125  }
126  catch(...) {
127  *ierr=1;
128  }
129  return retval;
130 } // int sff_ropenfs__
131 
132 /* ----- END OF fapid_sff_ropenfs.cc ----- */
This is the interface usually expected by Fortran programs linking to libsff.a (prototypes) ...
Definition: error.cc:44
sff::FREE freeblock(integer *nline, char *lines, ftnlen lines_len)
create C++ FREE block from Fortran FREE lines
Definition: helper.cc:150
long int integer
Fortran integer type.
Definition: fapidsff.h:66
void fillfstring(const std::string &s, char *fstring, ftnlen slen)
fill a Fortran string with a C++ string
Definition: helper.cc:60
float real
Fortran real type (single precision)
Definition: fapidsff.h:73
datrw::ianystream & open(const int &unit, const std::string &filename)
open a new file
Definition: fileunit.cc:77
int sff_ropenfs__(integer *lu, char *filename, real *version, char *timestamp, char *code, integer *nline, char *lines, integer *lenmax, integer *lindim, 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 lines_len, ftnlen type_len, ftnlen cs_len, ftnlen date_len, ftnlen time_len)
Open SFF file and return source line and FREE block.
long int ftnlen
Fortran string size type.
Definition: fapidsff.h:70
std::string stringfromfstring(char *fstring, ftnlen slen)
create a C++ string from a Fortran string
Definition: helper.cc:51
a file unit interface to libdatrwxx (prototypes)
::fapidxx::IFileUnits istreammanager
the global istream manager
Definition: fileunit.cc:48
some helper functions (prototypes)