#include "segypp.hh" #include "segyfun.hh" namespace TSOpt { using RVL::RVLException; using RVL::ContentPackage; using RVL::PackageContainer; using RVL::PackageContainerFactory; SEGYDC::SEGYDC(string _hdr, ostream & _outfile) : OCDC(_outfile), hdr(_hdr), fp(NULL), rd(false), off_cur(0L), outfile(_outfile), off_eof(0L) { buf=new ContentPackage; segy tr; buf->initialize(tr); // 18.11.09: for the nonce, the universal tag is "datafile" string tagstr="datafile"; this->setTag(tagstr); // 27.03.10: iwave_fopen based implementation presumes that // datafile is initialized // open header file - should ALWAYS be opened with these permissions // note that if it's already open, this call simply returns the // associated pointer FILE * fph = iwave_const_fopen(hdr.c_str(),"r",NULL,stderr); if (!fph) { RVLException e; e<<"Error: SEGYCFC constructor\n"; e<<"failed to access proto file ptr, filename="<getFilename()<<"\n"; // iwave_fprintall(stderr); /////////////// } void SEGYDC::open_p() const { // no try block as no function calls which might throw exception if (fp) { RVLException e; e<<"Error: SEGYDC::open_p\n"; e<<"error state on call to open_p: file pointer set\n"; throw e; } #ifdef FRUITCAKE outfile<<"SEGYDC::open_p hdr="<getFilename() == "") { char * name = NULL; fp = iwave_fopen(&name,"w+",hdr.c_str(),stderr); if (!fp) { RVLException e; e<<"Error: SEGYDC::open_p\n"; e<<"temp file case: failed to open file\n"; throw e; } if (!name) { RVLException e; e<<"Error: SEGYDC::open_p\n"; e<<"temp file case: failed to set name\n"; throw e; } ////////////// // cerr<<"SEGYDC->open_p->iwave_fopen name="<getFilename().c_str(),"w+",hdr.c_str(),stderr); if (!fp) { RVLException e; e<<"Error: SEGYDC::open_p"; e<<"perm file case: failed to open file\n"; throw e; } ////////////// // cerr<<"SEGYDC->open_p->iwave_const_fopen name = "<getFilename()<<" hdr = "<open_p old file name = "<getFilename()<<" hdr = "<getFilename()<<" failed\n"; throw e; } int nbtmp = fgettr(fp,&tr); if (nb!=nbtmp) { RVLException e; e<<"Error: SEGYDC::open_p\n"; e<<"existing file branch, file = "<getFilename()<<" proto="<getFilename()<<" differs in structure from prototype\n"; e<<"file "<getFilename()<<" failed\n"; throw e; } // end existing file check } // clean up char buffers } segytrace & SEGYDC::get(bool & more) { try { #ifdef FRUITCAKE outfile<<"SEGYDC::get (mutable) -> open_p file="<getFilename()<<" fileptr="<fgettr off_cur = "<getMetadata())))) { outfile<<"SEGYDC::get (mutable) - failure\n"; RVLException e; e<<"Error: SEGYDC::get\n"; e<<"failed to read trace on file "<getFilename()<<"\n"; throw e; } // set rd flag for successful read rd=true; // determine whether this is last trace more=false; #ifdef FRUITCAKE outfile<<"SEGYDC::get_p->ftello\n"; #endif if (ftello(fp) open_p file="<getFilename()<<" fileptr="<fgettr off_cur = "<getMetadata())))) { outfile<<"SEGYDC::get (const) - failure\n"; RVLException e; e<<"Error: SEGYDC::get\n"; e<<"failed to read trace on file "<getFilename()<<"\n"; throw e; } // set rd flag for successful read rd=true; // determine whether this is last trace more=false; #ifdef FRUITCAKE outfile<<"SEGYDC::get_p->ftello\n"; #endif if (ftello(fp) open_p file="<getFilename()<<" fileptr="<getFilename()<<"\n"; throw e; } } off_cur=ftello(fp); #ifdef FRUITCAKE outfile<<"SEGYDC::put_p -> fputtr at "<getMetadata())); fflush(fp); // unset read flag rd=false; /* int i; fprintf(stderr,"at end of SEGYDC::put\n"); scanf("%d",&i); */ #ifdef FRUITCAKE outfile<<"SEGYDC::put_p - return\n"; #endif } catch (RVLException & e) { e<<"\ncalled from SEGYDC::put\n"; throw e; } } void SEGYDC::reset() const { try { #ifdef FRUITCAKE outfile<<"SEGYDC::reset -> open_p file="<getFilename()<<" fileptr="< open_p file="<getFilename()<<" fileptr="<