GeopsyCore/GuralpCompressedBlock.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of GeopsyCore.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2007-10-12
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef GURALPCOMPRESSEDBLOCK_H
00029 #define GURALPCOMPRESSEDBLOCK_H
00030 
00031 #include <QGpCoreTools.h>
00032 
00033 #include "GeopsyCoreDLLExport.h"
00034 #include "TimeRange.h"
00035 #include "Signal.h"
00036 
00037 namespace GeopsyCore {
00038 
00039   class GEOPSYCORE_EXPORT GuralpCompressedBlock
00040   {
00041     TRANSLATIONS("GuralpCompressedBlock")
00042   public:
00043     GuralpCompressedBlock();
00044     GuralpCompressedBlock(const GuralpCompressedBlock& o);
00045     ~GuralpCompressedBlock();
00046 
00047     void operator=(const GuralpCompressedBlock& o);
00048     bool operator==(const GuralpCompressedBlock& o) const;
00049 
00050     enum StreamType {Data, MuxChannel, Status, ChannelData, BytePipe, Information, Unknown};
00051 
00052     inline bool readHeader(QFile& f);
00053     inline bool readBody(QFile& f);
00054     inline void skipBody(QFile& f);
00055 
00056     bool parseHeader(const char * gcfHeader);
00057     bool parseBody(const char * gcfBody);
00058 
00059     StreamType streamType() const;
00060     const char * streamTypeString() const;
00061     int nSamples() const {return _nSamples;}
00062     double samplingFrequency() const {return _samplingFrequency;}
00063     QString name() const {return _device;}
00064     QDateTime startTime() const {return _startTime;}
00065     TimeRange timeRange(const QDateTime& refTime) const;
00066     Signal::Components component() const;
00067     bool isData() const {return _component!='0' && _component!='I';}
00068     int compressionCode() {return _compressionCode;}
00069     int sample(int index) const {return _samples[index];}
00070     uint hash() const {return _hash;}
00071 
00072     void debugPrint() const;
00073   private:
00074     inline static void base36ToAscii(qint32 b, char * str);
00075     uint _hash;
00076     char _systemID[7];
00077     char _device[5];
00078     char _component;
00079     char _channel;
00080     QDateTime _startTime;
00081     double _samplingFrequency;
00082     int _compressionCode;
00083     int _nSamples;
00084     int * _samples;
00085   };
00086 
00087   inline uint qHash(const GuralpCompressedBlock& b) {
00088     return b.hash();
00089   }
00090 
00091   inline bool GuralpCompressedBlock::readHeader(QFile& f)
00092   {
00093     // Read the 16 bytes header
00094     char header[16];
00095     qint64 n=f.read(header, 16);
00096     if(n!=16) return false;
00097     return parseHeader(header);
00098   }
00099 
00100   inline bool GuralpCompressedBlock::readBody(QFile& f)
00101   {
00102     char body[1008];
00103     qint64 n=f.read(body,1008);
00104     if(n!=1008) return false;
00105     return parseBody(body);
00106   }
00107 
00108   inline void GuralpCompressedBlock::skipBody(QFile& f)
00109   {
00110     f.seek(f.pos()+1008); // 1024-byte blocks less 16-byte header
00111   }
00112 
00113 } // namespace GeopsyCore
00114 
00115 #endif // GURALPCOMPRESSEDBLOCK_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines