#include <SignalFile.h>
Public Member Functions | |
SignalDB * | database () const |
const SignalFileFormat & | format () const |
bool | isOriginalFile () |
bool | load () |
bool | loadGeopsySignal (const SubSignalPool &subPool) |
QString | name (int len) const |
QString | name () const |
SignalFile & | operator= (const SignalFile &p) |
void | removeFile () |
bool | save (const QDir &d) |
void | setDatabase (SignalDB *db) |
void | setFormat (const SignalFileFormat &f) |
void | setFormat (QString f) |
void | setName (QString n) |
void | setOriginalFile (bool b) |
QString | shortName () const |
SignalFile (SignalDB *db, QString fileName="", const SignalFileFormat &format=SignalFileFormat::Unknown) | |
SignalFile (SignalDB *db, SignalFile &f, QDir &d) | |
virtual const QString & | xml_tagName () const |
~SignalFile () | |
Static Public Member Functions | |
static void | setSignalName (Signal *sig, QString stationName, QString sufix, int recNum, QString fileName) |
static bool | setTimeReference (double &t0, QDateTime &timeRef, QDateTime timeTrue) |
Static Public Attributes | |
static const QString | xmlSignalFileTag = "File" |
Protected Member Functions | |
virtual XMLMember | xml_member (XML_MEMBER_ARGS) |
virtual void | xml_polish (XML_POLISH_ARGS) |
virtual bool | xml_setProperty (XML_SETPROPERTY_ARGS) |
virtual void | xml_writeChildren (XML_WRITECHILDREN_ARGS) const |
virtual void | xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const |
GeopsyCore::SignalFile::SignalFile | ( | SignalDB * | db, |
QString | fileName = "" , |
||
const SignalFileFormat & | format = SignalFileFormat::Unknown |
||
) |
GeopsyCore::SignalFile::SignalFile | ( | SignalDB * | db, |
SignalFile & | f, | ||
QDir & | d | ||
) |
Construct a new file from an existing one f, store it in directory d. The format of the created file will always be of type GeopsySignal. The file name is automatically indexed to avoid overwriting existing files. isOriginalFile() is always set to false. sigs are added to the list of signal to load
References GeopsyCore::SignalDB::addFile(), GeopsyCore::SignalFileFormat::GeopsySignal, shortName(), and TRACE.
{ TRACE; _name=File::uniqueName (f.shortName(), d); _format=SignalFileFormat::GeopsySignal; _isOriginalFile=false; _db=db; db->addFile(this); }
SignalDB* GeopsyCore::SignalFile::database | ( | ) | const [inline] |
Referenced by GeopsyCore::SignalDB::addFile(), and MatFormat::load().
{return _db;}
const SignalFileFormat& GeopsyCore::SignalFile::format | ( | ) | const [inline] |
Referenced by GeopsyCore::Signal::compare(), GeopsyCore::Signal::header(), GeopsyCore::SignalDB::isModified(), SignalFile(), and GeopsyCore::XMLSignal::xml_writeProperties().
{return _format;}
bool GeopsyCore::SignalFile::isOriginalFile | ( | ) | [inline] |
{return _isOriginalFile;}
bool GeopsyCore::SignalFile::load | ( | ) |
References GeopsyCore::SignalFileFormat::Ascii, GeopsyCore::SignalFileFormat::AsciiGeoSig, GeopsyCore::SignalFileFormat::AsciiOneColumn, GeopsyCore::SignalFileFormat::City2, GeopsyCore::SignalFileFormat::Custom, GeopsyCore::SignalFileFormat::customFormat(), QGpCoreTools::endl(), GeopsyCore::SignalFileFormat::FormatCount, GeopsyCore::SignalFileFormat::Fourier, GeopsyCore::SignalFileFormat::GeopsySignal, GeopsyCore::SignalFileFormat::Gse2, GeopsyCore::SignalFileFormat::GuralpGcf, GeopsyCore::SignalFileFormat::id(), GeopsyCore::AbstractFileFormat::load(), loadGeopsySignal(), GeopsyCore::SignalFileFormat::MiniSeed, GeopsyCore::SignalFileFormat::Multi, GeopsyCore::SignalFileFormat::MultiGse2, GeopsyCore::SignalFileFormat::NiSismo, GeopsyCore::SignalFileFormat::PasscalSegYBigEndian, GeopsyCore::SignalFileFormat::PasscalSegYLittleEndian, GeopsyCore::SignalFileFormat::Radan, GeopsyCore::SignalFileFormat::RD3, GeopsyCore::SignalFileFormat::SacBigEndian, GeopsyCore::SignalFileFormat::SacLittleEndian, GeopsyCore::SignalFileFormat::Saf, SAFE_UNINITIALIZED, GeopsyCore::SignalFileFormat::Seg2, GeopsyCore::SignalFileFormat::SegD, GeopsyCore::SignalFileFormat::SegYBigEndian, GeopsyCore::SignalFileFormat::SegYLittleEndian, GeopsyCore::SignalFileFormat::Single, GeopsyCore::SignalFileFormat::Sismalp, GeopsyCore::SignalFileFormat::SuBigEndian, GeopsyCore::SignalFileFormat::SuLittleEndian, GeopsyCore::SignalFileFormat::SyscomSmr, GeopsyCore::SignalFileFormat::SyscomVmrx, GeopsyCore::SignalFileFormat::SyscomXmr, GeopsyCore::SignalFileFormat::Temporary, GeopsyCore::SignalFileFormat::Tomo, QGpCoreTools::tr(), TRACE, GeopsyCore::SignalFileFormat::Unknown, and GeopsyCore::SignalFileFormat::Wav.
Referenced by GeopsyCore::SignalFilePool::load().
{ TRACE; bool ret; SAFE_UNINITIALIZED(ret,0); switch (_format.id()) { case SignalFileFormat::GeopsySignal: ret=loadGeopsySignal(); break; case SignalFileFormat::Seg2: ret=loadSeg2(); break; case SignalFileFormat::SegD: ret=loadSegD(); break; case SignalFileFormat::SuLittleEndian: ret=loadSu(QDataStream::LittleEndian); break; case SignalFileFormat::SuBigEndian: ret=loadSu(QDataStream::BigEndian); break; case SignalFileFormat::RD3: ret=loadRD3(); break; case SignalFileFormat::NiSismo: ret=loadNiSismo(); break; case SignalFileFormat::SacLittleEndian: ret=loadSac(QDataStream::LittleEndian); break; case SignalFileFormat::SacBigEndian: ret=loadSac(QDataStream::BigEndian); break; case SignalFileFormat::Radan: ret=loadRadan(); break; case SignalFileFormat::Tomo: ret=loadTomo(); break; case SignalFileFormat::Gse2: ret=loadGse2(SignalFileFormat::Single); break; case SignalFileFormat::MultiGse2: ret=loadGse2(SignalFileFormat::Multi); break; case SignalFileFormat::City2: ret=loadCity2(); break; case SignalFileFormat::Saf: ret=loadSaf(); break; case SignalFileFormat::Ascii: ret=loadAscii(); break; case SignalFileFormat::AsciiOneColumn: ret=loadAsciiOneColumn(); break; case SignalFileFormat::Sismalp: ret=loadSismalp(); break; case SignalFileFormat::Wav: ret=loadWav(); break; case SignalFileFormat::SegYLittleEndian: ret=loadSegY(QDataStream::LittleEndian); break; case SignalFileFormat::SegYBigEndian: ret=loadSegY(QDataStream::BigEndian); break; case SignalFileFormat::PasscalSegYLittleEndian: ret=loadPasscalSegY(QDataStream::LittleEndian); break; case SignalFileFormat::PasscalSegYBigEndian: ret=loadPasscalSegY(QDataStream::BigEndian); break; case SignalFileFormat::SyscomXmr: ret=loadSyscomXmr(); break; case SignalFileFormat::SyscomSmr: ret=loadSyscomSmr(); break; case SignalFileFormat::SyscomVmrx: ret=loadSyscomVmrx(); break; case SignalFileFormat::GuralpGcf: ret=loadGuralpGcf(); break; case SignalFileFormat::MiniSeed: ret=loadMiniSeed(); break; case SignalFileFormat::AsciiGeoSig: ret=loadAsciiGeoSig(); break; case SignalFileFormat::Custom: ret=_format.customFormat()->load(this); break; case SignalFileFormat::Fourier: ret=loadFourier(); break; case SignalFileFormat::Unknown: case SignalFileFormat::Temporary: case SignalFileFormat::FormatCount: ret=false; break; } if(!ret) { App::stream() << tr(" ### Error while loading file %1").arg(_name) << endl; } return ret; }
bool GeopsyCore::SignalFile::loadGeopsySignal | ( | const SubSignalPool & | subPool | ) |
See SubSignalPool::saveGeopsySignal() for file fomat.
Contrary to loadGeopsySignal() no new signal are created. Read signals are just affected to signals of subPool. Version 1 is not supported.
References GeopsyCore::SubSignalPool::at(), GeopsyCore::SubSignalPool::count(), QGpCoreTools::endl(), GeopsyCore::GeopsySignalHeader::field, GEOPSYSIGNAL_HEADERSIZE, GeopsyCore::Signal::id(), GeopsyCore::GeopsySignalHeader::isValid(), GeopsyCore::SignalTemplate< sampleType >::nSamples(), GeopsyCore::GeopsySignalHeader::raw, GeopsyCore::Signal::setFile(), GeopsyCore::Signal::setNumberInFile(), GeopsyCore::Signal::setOffsetInFile(), QGpCoreTools::tr(), and TRACE.
Referenced by load().
{ TRACE; QFile f(_name); if( !f.open(QIODevice::ReadOnly) ) { App::stream() << tr( "Loading Geopsy Signal: unable to open file %1" ).arg(_name) << endl; return false; } // Load header GeopsySignalHeader h; f.read(h.raw, GEOPSYSIGNAL_HEADERSIZE); if( !h.isValid()) { App::stream() << tr( "Loading Geopsy Signal: wrong format for file %1" ).arg(_name) << endl; return false; } int * nSamples=new int [ h.field.nSignals ]; f.read((char *)nSamples, h.field.nSignals*sizeof(qint32) ); f.close(); if(h.field.nSignals!=subPool.count()) { App::stream() << tr( "Loading Geopsy Signal: number of signals does not match." ).arg(_name) << endl; return false; } for(int i=0;i < h.field.nSignals;i++ ) { Signal * sig=subPool.at(i); if(nSamples[ i ]!=sig->nSamples()) { App::stream() << tr( "Loading Geopsy Signal: number of samples does not match for signal id %1." ).arg(sig->id()) << endl; return false; } } for(int i=0;i < h.field.nSignals;i++ ) { Signal * sig=subPool.at(i); sig->setFile(this); sig->setNumberInFile(i); sig->setOffsetInFile(h.field.offset); h.field.offset += sizeof(double) * nSamples[ i ]; } delete [] nSamples; return true; }
QString GeopsyCore::SignalFile::name | ( | int | len | ) | const |
Referenced by GeopsyCore::Signal::compare(), GeopsyGui::SignalFileItem::data(), GeopsyCore::SignalFilePool::find(), GeopsyCore::Signal::header(), MatFormat::load(), and Process::run().
{ TRACE; QDir d; QChar sep=d.separator(); QString str; int compLen=_name.length(); int toDel=compLen - len; if(toDel <= 0) { str=_name; return str; } toDel += 3; int posEnd=compLen - 1; while(posEnd && _name[ posEnd ]!=sep) posEnd--; if(compLen - posEnd + 3 >= len) { str="..." + _name.right(len - 3); return str; } int half=(len - (compLen - posEnd) - 3)/2; str=_name.left(half) + "..." + _name.right(compLen - posEnd + half); return str; }
QString GeopsyCore::SignalFile::name | ( | ) | const [inline] |
Referenced by xml_setProperty().
{return _name;}
SignalFile & GeopsyCore::SignalFile::operator= | ( | const SignalFile & | p | ) |
void GeopsyCore::SignalFile::removeFile | ( | ) |
References TRACE.
Referenced by GeopsyCore::SignalDB::removeFile().
{ TRACE; if( !_isOriginalFile) { QFileInfo fi(_name); QDir d(fi.dir()); d.remove(fi.fileName()); } }
bool GeopsyCore::SignalFile::save | ( | const QDir & | d | ) |
Save the file to a permanent storage (in directory d) and convert it to an original file. This function is called by SignalDB::save() for storing temporary signals.
See SubSignalPool::saveGeopsySignal() for file fomat.
References GeopsyCore::SubSignalPool::addFile(), GeopsyCore::SubSignalPool::at(), GeopsyCore::SubSignalPool::count(), GeopsyCore::SignalFileFormat::GeopsySignal, GEOPSYSIGNAL_HEADERSIZE, MSG_ID, GeopsyCore::SignalTemplate< sampleType >::nSamples(), GeopsyCore::SubSignalPool::saveGeopsySignal(), GeopsyCore::Signal::setOffsetInFile(), QGpCoreTools::tr(), and TRACE.
{ TRACE; _name=File::uniqueName(_name, d); SubSignalPool subPool; subPool.addFile(this); if(subPool.saveGeopsySignal(_name) ) { // Set members as if it was normally loaded _format=SignalFileFormat::GeopsySignal; _isOriginalFile=true; int nSignals=subPool.count(); int offset=GEOPSYSIGNAL_HEADERSIZE+nSignals*4; for(int i=0;i < nSignals;i++ ) { Signal * sig=subPool.at(i); sig->setOffsetInFile(offset); offset += sizeof(double) * sig->nSamples(); } return true; } else { Message::warning(MSG_ID, tr( "Saving Geopsy signals ..." ), tr( "Cannot write to file: %1\n" "(Permission, disk space,...)" ). arg(_name), Message::ok(), true); return false; } }
void GeopsyCore::SignalFile::setDatabase | ( | SignalDB * | db | ) | [inline] |
Referenced by GeopsyCore::SignalFilePool::add().
{_db=db;}
void GeopsyCore::SignalFile::setFormat | ( | const SignalFileFormat & | f | ) | [inline] |
Referenced by xml_setProperty().
{_format=f;}
void GeopsyCore::SignalFile::setFormat | ( | QString | f | ) | [inline] |
References GeopsyCore::SignalFileFormat::fromString().
{_format=SignalFileFormat::fromString(f);}
void GeopsyCore::SignalFile::setName | ( | QString | n | ) | [inline] |
Referenced by xml_setProperty().
{_name=n;}
void GeopsyCore::SignalFile::setOriginalFile | ( | bool | b | ) | [inline] |
{_isOriginalFile=b;}
void GeopsyCore::SignalFile::setSignalName | ( | Signal * | sig, |
QString | stationName, | ||
QString | sufix, | ||
int | recNum, | ||
QString | fileName | ||
) | [static] |
References GeopsyCore::geopsyCore, GeopsyCore::GeopsyCoreEngine::preferences(), GeopsyCore::Signal::setName(), GeopsyCore::GeopsyPreferences::stationNameFile(), GeopsyCore::GeopsyPreferences::stationNameRxxx(), and TRACE.
Referenced by GeopsyCore::CitySignal::loadSignals().
{ TRACE; if(geopsyCore->preferences() ->stationNameFile()) sig->setName(stationName + sufix); else if(geopsyCore->preferences() ->stationNameRxxx()) { sig->setName(QString().sprintf( "R%03i", recNum) ); } else sig->setName(fileName + sufix); }
bool GeopsyCore::SignalFile::setTimeReference | ( | double & | t0, |
QDateTime & | timeRef, | ||
QDateTime | timeTrue | ||
) | [static] |
References GeopsyCore::GeopsyCoreEngine::askTimeReference(), QGpCoreTools::endl(), GeopsyCore::GeopsyPreferences::fixedDate(), GeopsyCore::GeopsyPreferences::fixedTime(), GeopsyCore::geopsyCore, GeopsyCore::GeopsyPreferences::isFixedDate(), GeopsyCore::GeopsyPreferences::isFixedTime(), GeopsyCore::GeopsyPreferences::isFixedTimeReference(), GeopsyCore::GeopsyPreferences::isNoCommonTimeReference(), GeopsyCore::GeopsyCoreEngine::preferences(), QGpCoreTools::tr(), and TRACE.
Referenced by GeopsyCore::CitySignal::loadSignals().
{ TRACE; if(!timeTrue.isValid()) { App::stream() << tr("Invalid date or time read from file") << endl; timeTrue=QDateTime(QDate(2000, 1, 1), QTime(0,0)); } GeopsyPreferences& prefs=*geopsyCore->preferences(); QSettings * reg=new QSettings; reg->beginGroup( "DialogOptions" ); reg->beginGroup( "TimeReference" ); if(prefs.isFixedTimeReference()) { timeRef=timeTrue; if(prefs.isFixedDate()) { timeRef.setDate(prefs.fixedDate()); } if(prefs.isFixedTime()) { timeRef.setTime(prefs.fixedTime()); } t0 += (double) timeRef.secsTo(timeTrue); } else if(prefs.isNoCommonTimeReference()) { timeRef=timeTrue; } else if( !reg->value( "again" ).toBool()) { timeRef=QDateTime::fromString(reg->value( "refDateTime" ).toString(), "dd/MM/yyyy hh:mm:ss" ); if(timeRef.isValid()) { t0 += (double) timeRef.secsTo(timeTrue); } } delete reg; if( !timeRef.isValid()) return geopsyCore->askTimeReference(t0, timeRef, timeTrue); else return true; }
QString GeopsyCore::SignalFile::shortName | ( | ) | const |
References TRACE.
Referenced by GeopsyCore::SubSignalPool::addFile(), GeopsyCore::Signal::compare(), GeopsyGui::SignalFileItem::data(), GeopsyCore::SignalFilePool::find(), GeopsyCore::Signal::header(), MatFormat::load(), MonoStation::AbstractStation::shortFileName(), and SignalFile().
{ TRACE; QFileInfo fi(_name); return fi.fileName(); }
XMLMember GeopsyCore::SignalFile::xml_member | ( | XML_MEMBER_ARGS | ) | [protected, virtual] |
Re-implement this function to offer XML restore (children and properties) support to your class.
From tag and map (with contains the attibute value) return a unique identifier under the format of a XMLMember. XMLMember is initialized with 3 types of contructors:
Map of attributes can be inspected in this way (can be achived also in xml_setProperty()):
static const QString tmp("childrenName"); XMLRestoreAttributeIterator it=map.find(tmp); if(it!=map.end()) { // found attribute "childrenName" }
If the map of attributes is not used:
Q_UNUSED(attributes); if(tag=="x1") return XMLMember(0); else if(tag=="y1") return XMLMember(1); else if(tag=="x2") return XMLMember(2); else if(tag=="y2") return XMLMember(3); else return XMLMember(XMLMember::Unknown);
Arithmetic operations + and - apply to XMLMember to avoid confusion of property id numbers between inherited objects. Offset 3 corresponds to the number of properties defined in this object.
if(tag=="anInteger") return XMLMember(0); else if(tag=="aString") return XMLMember(1); else if(tag=="aDouble") return XMLMember(2); return AbstractLine::xml_member(tag, attributes, context)+3;
For the arguments of this function use Macro XML_MEMBER_ARGS.
Reimplemented from QGpCoreTools::XMLClass.
References GeopsyCore::Signal::setFile().
{ Q_UNUSED(attributes); Q_UNUSED(context); if(tag=="Signal") { Signal * sig=new Signal(_db); sig->setFile(this); return XMLMember(sig); } if(tag=="name") return XMLMember(0); else if(tag=="format") return XMLMember(1); else if(tag=="original") return XMLMember(2); return XMLMember(XMLMember::Unknown); }
void GeopsyCore::SignalFile::xml_polish | ( | XML_POLISH_ARGS | ) | [protected, virtual] |
Reimplemented from QGpCoreTools::XMLClass.
References GeopsyCore::SubSignalPool::addFile(), GeopsyCore::SubSignalPool::at(), GeopsyCore::SubSignalPool::count(), GeopsyCore::Signal::numberInFile(), GeopsyCore::Signal::setNumberInFile(), and TRACE.
{ TRACE; Q_UNUSED(context); // Bug in all release before 20070511, NumberInFile not initialized in Signal properties list in xml file // -1 is the uninitialized value of the NumberInFile SubSignalPool subPool; subPool.addFile(this); int n=subPool.count(); for(int i=0; i<n;i++) { Signal& sig=*subPool.at(i); if(sig.numberInFile()==-1) { sig.setNumberInFile(i); } } }
bool GeopsyCore::SignalFile::xml_setProperty | ( | XML_SETPROPERTY_ARGS | ) | [protected, virtual] |
Re-implement this function to offer XML restore properties support to your class.
From memberID set the corresponding property with value content. The map of attributes is given as a supplementary information (not useful in all cases).
For a general case:
Q_UNUSED(attributes); double val=content.toDouble(); switch (memberID) { case 0: _x1=val; return true; case 1: _y1=val; return true; case 2: _x2=val; return true; case 3: _y2=val; return true; default: return false; }
For classes inheriting other classes (see also xml_member())
switch (memberID) { case 0: _anInteger=content.toString(); return true; case 1: _aString=content.toInt(); return true; case 2: _aDouble=content.toDouble(); return true; default: return AbstractLine::xml_setProperty(memberID-3, map, content);
For the arguments of this function use Macro XML_SETPROPERTY_ARGS.
Reimplemented from QGpCoreTools::XMLClass.
References MSG_ID, name(), setFormat(), setName(), and QGpCoreTools::tr().
{ Q_UNUSED(tag); Q_UNUSED(attributes); Q_UNUSED(context); switch (memberID) { case 0: { setName(content.toString()); QFileInfo fi(name()); if(!fi.exists()) { QString fn=CoreApplication::instance()->translatePath(name(), tr( "Opening Database ..." ), tr( "Signal file (%1)" )); fi.setFile(fn); if( !fn.isEmpty() && fi.exists()) { setName(fi.filePath()); } else { if(Message::warning(MSG_ID, tr( "Opening Database ..." ), tr( "Cannot find file %1" ).arg(fi.filePath()), Message::ignore(), Message::cancel(), true)==Message::Answer1) return false; } } return true; } case 1: setFormat(content.toString()); return true; case 2: _isOriginalFile=content.toBool(); return true; default: return false; } }
virtual const QString& GeopsyCore::SignalFile::xml_tagName | ( | ) | const [inline, virtual] |
Implements QGpCoreTools::XMLClass.
{return xmlSignalFileTag;}
void GeopsyCore::SignalFile::xml_writeChildren | ( | XML_WRITECHILDREN_ARGS | ) | const [protected, virtual] |
Reimplemented from QGpCoreTools::XMLClass.
References GeopsyCore::SubSignalPool::addFile(), GeopsyCore::SubSignalPool::begin(), and GeopsyCore::SubSignalPool::end().
{ SubSignalPool subPool; subPool.addFile(this); for(SubSignalPool::iterator it=subPool.begin(); it!=subPool.end(); ++it) { ( * it) ->xml_save(s, context); } }
void GeopsyCore::SignalFile::xml_writeProperties | ( | XML_WRITEPROPERTIES_ARGS | ) | const [protected, virtual] |
Reimplemented from QGpCoreTools::XMLClass.
References GeopsyCore::SignalFileFormat::toString(), and QGpCoreTools::XMLClass::writeProperty().
{ Q_UNUSED(context); writeProperty(s, "name", _name); writeProperty(s, "format", _format.toString()); writeProperty(s, "original", _isOriginalFile); }
const QString GeopsyCore::SignalFile::xmlSignalFileTag = "File" [static] |