conv/many suite: convert (m)any seismic data format(s)

◆ main()

int main ( int  iargc,
char *  argv[] 
)

Definition at line 66 of file any2sff.cc.

References ANY2SFF_VERSION, Options::debug, Options::format, Options::gsescaling, Options::overwrite, and Options::verbose.

67 {
68 
69  // options
70  Options opt;
71 
72  // define usage information
73  char usage_text[]=
74  {
75  ANY2SFF_VERSION "\n"
76  "usage: any2sff [-v] [-o] [-Fbonjer] [-Fsff] [-Fpdas] [-Fhpmo]" "\n"
77  " [-t type] [-GSE]" "\n"
78  " file [ file [ ... ]] sff-file" "\n"
79  " or: any2sff --help|-h" "\n"
80  };
81 
82  // define full help text
83  char help_text[]=
84  {
85  "file input file of selected format" "\n"
86  "sff-file output file in SFF" "\n"
87  "\n"
88  "-v be verbose" "\n"
89  "-o overwrite output file" "\n"
90  "-t type select input data format" "\n"
91  "-Fsff input format is SFF" "\n"
92  "-Fhpmo input format is multiplexed ASCII format" "\n"
93  " defined by WG for BFO HP-MO data acquisition system" "\n"
94  "-Fpdas input format is PDAS100 (i.e. DaDisp)" "\n"
95  "-Fbonjer input format is defined by K. Bonjer for" "\n"
96  " K2 ASCII data" "\n"
97  "-GSE use GSE compatible scaling, when writing data" "\n"
98  " notice: the dynamic range will be reduced to integer values" "\n"
99  };
100 
101  // define commandline options
102  using namespace tfxx::cmdline;
103  static Declare options[]=
104  {
105  // 0: print help
106  {"help",arg_no,"-"},
107  // 1: verbose mode
108  {"v",arg_no,"-"},
109  // 2: original SFF data
110  {"Fsff",arg_no,"-"},
111  // 3: WG's multiplexed ASCII data (BFO format)
112  {"Fhpmo",arg_no,"-"},
113  // 4: PDAS 100 data (aka DaDisp)
114  {"Fpdas",arg_no,"-"},
115  // 5: K. Bonjer's ASCII data
116  {"Fbonjer",arg_no,"-"},
117  // 6: debug mode
118  {"D",arg_no,"-"},
119  // 7: overwrite mode
120  {"o",arg_no,"-"},
121  // 8: input data format
122  {"t",arg_yes,"-"},
123  // 9: GSE scaling mode
124  {"GSE",arg_no,"-"},
125  {NULL}
126  };
127 
128  /* ---------------------------------------------------------------------- */
129 
130  cerr << ANY2SFF_VERSION "\n"
131  "******************************************************************\n"
132  "THIS PROGRAM IS OBSOLETE\n"
133  "any2sff is no longer maintained and may vanish in the future\n"
134  "consider to use any2any instead\n"
135  "******************************************************************\n";
136 
137  /* ---------------------------------------------------------------------- */
138 
139  // no arguments? print usage...
140  if (iargc<2)
141  {
142  cerr << usage_text << endl;
143  cerr << tfxx::seitosh::repository_reference << endl;
144  exit(0);
145  }
146 
147  // collect options from commandline
148  Commandline cmdline(iargc, argv, options);
149 
150  // help requested? print full help text...
151  if (cmdline.optset(0))
152  {
153  cerr << usage_text << endl;
154  cerr << help_text << endl;
155  datrw::supported_data_types(cerr);
156  datrw::online_help(cerr);
157  cerr << endl << tfxx::seitosh::repository_reference << endl;
158  exit(0);
159  }
160 
161  opt.verbose=cmdline.optset(1);
162  opt.format=datrw::anyID(datrw::Fsff);
163  if (cmdline.optset(3)) { opt.format=datrw::anyID(datrw::Fhpmo); }
164  if (cmdline.optset(4)) { opt.format=datrw::anyID(datrw::Fpdas); }
165  if (cmdline.optset(5)) { opt.format=datrw::anyID(datrw::Fbonjer); }
166  opt.debug=cmdline.optset(6);
167  opt.overwrite=cmdline.optset(7);
168  if (cmdline.optset(8)) { opt.format=cmdline.string_arg(8); }
169  opt.gsescaling=cmdline.optset(9);
170 
171  /* ---------------------------------------------------------------------- */
172 
173  sff::FREE filefree;
174  filefree.append(ANY2SFF_VERSION);
175  filefree.append("input files:");
176  Tvecofstrings infiles;
177  std::string outfile;
178  TFXX_assert(cmdline.extra(), "ERROR: missing input file!");
179  outfile=cmdline.next();
180  // collect input files
181  while (cmdline.extra())
182  {
183  infiles.push_back(outfile);
184  filefree.append(outfile);
185  outfile=cmdline.next();
186  }
187  TFXX_assert((infiles.size()>0), "ERROR: missing output file!");
188 
189  filefree.append("output file:");
190  filefree.append(outfile);
191  filefree.append("any SRCE line or file FREE block in input data is ignored!");
192 
193  if (opt.verbose) { filefree.write(cout); }
194 
195  // check if output file exists and open
196  if (!opt.overwrite)
197  {
198  std::ifstream file(outfile.c_str(),std::ios_base::in);
199  TFXX_assert((!file.good()),"ERROR: output file exists!");
200  }
201  std::ofstream ofs(outfile.c_str());
202  sff::SFFostream<Tseries> os(ofs, opt.debug);
203  if (opt.gsescaling)
204  {
205  if (opt.verbose)
206  { cout << "select GSE compatible scaling" << endl; }
207  os.setnormmode(sff::NM_one);
208  }
209  os << filefree;
210 
211  Tvecofstrings::const_iterator infile=infiles.begin();
212  while( infile!=infiles.end())
213  {
214  if (opt.verbose)
215  { cout << "** open next file: " << *infile << endl; }
216  std::ifstream ifs(infile->c_str(), datrw::ianystream::openmode(opt.format));
217  datrw::ianystream is(ifs, opt.format, opt.debug);
218 
219  while(is.good())
220  {
221  if (opt.verbose)
222  { cout << "**** convert next trace" << endl; }
223  datrw::Tdseries series;
224  if (opt.debug) { cerr << "DEBUG: read series" << endl; }
225  is >> series;
226  if (opt.debug) { cerr << "DEBUG: write series" << endl; }
227  os << series;
228  sff::WID2 wid2;
229  if (opt.debug) { cerr << "DEBUG: read WID2" << endl; }
230  is >> wid2;
231  if (opt.debug) { cerr << "DEBUG: write WID2" << endl; }
232  os << wid2;
233  if (opt.debug) { cerr << "DEBUG: read and write INFO"
234  << " if available" << endl; }
235  if (is.hasinfo()) { sff::INFO info; is >> info; os << info; }
236  if (opt.debug) { cerr << "DEBUG: read and write FREE"
237  << " if available" << endl; }
238  if (is.hasfree()) { sff::FREE free; is >> free; os << free; }
239  }
240  ++infile;
241  }
242 
243 }
bool overwrite
Definition: any2any.cc:57
#define ANY2SFF_VERSION
Definition: any2sff.cc:40
bool debug
Definition: any2any.cc:57
bool verbose
Definition: any2any.cc:57
std::string format
Definition: any2sff.cc:59
std::vector< std::string > Tvecofstrings
Definition: any2sff.cc:62
bool gsescaling
Definition: any2sff.cc:58