UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
trset.h
1 /* trset.h */
2 /* $Id: trset.h,v 1.25 2008/12/25 07:38:19 vlad Exp $ */
3 
4 /*********************************************************************
5  *
6  * UNIVERS
7  * (C) ООО "ГЕОВЕРС", 2001
8  *
9  * Все права защищены * * Использование, копирование или передача регулируются законами * Российской Федерации "Об авторском праве и смежных правах", "О * правовой охране программ для электронных вычислительных машин и баз * данных" * * Encoding: ISO-8859-5 (GOST) * *********************************************************************/ #ifndef __trset_h #define __trset_h #include <mix/Types.h> #include <mix/trace_file.h> #include <mix/mod_table.h> #include <mix/wenv.h> #include <mix/trans.h> #include <ldb/vsp_trace.h> #include <ldb/dbtc.h> #include <mix/locks.h> #include <mix/mutex.h> #ifndef O_BINARY /* for UNIX open() operates in binary mode by default */ #define O_BINARY 0 #endif /* O_BINARY */ /** Name used to mark project of temporal seismic modifications. */ #define TEMP_PROJECT "/tmp" /** Modification table structures */ typedef struct { int size; /**< size of modification table in bytes */ ModTableMain *mtab; /**< the whole area with INTL, INTX and INTY */ ModTableIntL *intl; /**< may points as inside mtab as well outside */ ModTableIntX *intx; /**< may points as inside mtab as well outside */ ModTableIntY *inty; /**< may points as inside mtab as well outside */ } TrMtable; /** Index table for virtual trace file representation */ typedef struct { int count; /**< count of entries in table */ int *table; /**< table of indexes */ void *hds_ptr; /**< HDS database pointer. */ } TrIndexTable; #define HDR_R4 0 #define HDR_I4 1 #define HDR_C1 2 /** One header entry description */ typedef struct { char *name; /**< text name of field */ int offset; /**< offset in longs (4byte) from the begin of header */ char *fmt; /**< format of input/output */ int type; /**< type of field: 0 - R4, 1 - I4, 2 - C1 */ int count; /**< count of element (in array) */ int bsize; /**< size (bytes) for array */ } TrHdrField; /** Representation of any header field value */ typedef union { float R4[1]; /**< REAL*4 */ int I4[3]; /**< INTEGER*4 */ char C1[12]; /**< CHAR_1*1 */ } TrHdrFieldValue; #define STARTUP_TRACE_BUFFER 7 /**< ib_vol */ #define HDR_BUF_GROW_QUANT 20 /**< for hdr_buf and hdr_avail grow */ /** Main control structure */ typedef struct { /* PUBLIC: */ char *project; /**< project */ char *nmod; /**< modification */ int fildes; /**< data file I/O handle */ TrMtable mt; /**< the whole modification table */ /* input trace size factor */ int in_traces_count; /**< count of traces in input file */ int in_trace_size; /**< raw size of trace in bytes */ int in_body_size; /**< raw size of samples in bytes */ int in_hdr_size; /**< raw size of header in bytes */ SampleFormat in_format; /**< raw format of samples */ /* internal trace size factor */ int traces_count; /**< count of traces in index table */ int trace_size; /**< size of trace in bytes */ int body_size; /**< size of samples in bytes */ int hdr_size; /**< size of header in bytes */ /* application oriented "size" factor */ int samples_count; /**< count of samples */ float Tb, Te, Dt; /**< times, ms */ TrIndexTable itable; /**< representation table */ Logic use_itable; /**< TRUE to use index tranlation or FALSE don't do it; TRUE-default */ /* PRIVATE: */ char mode; /**< 'c'reate, 'o'pen, 'e'dit, 'n'ew */ char *in_buf; /**< buffer for input traces (raw format with hdrs) */ int ib_vol; /**< input trace buffer volume (must be odd) */ int ib_range[2]; /**< the first and the last raw indexes in in_buf; ib_range[1] - ib_range[0] + 1 <= ib_vol */ int prev_index; /**< raw index of previously called trace */ int prev_im; /**< monotonicity of previously called trace */ int kp; /**< predictivity number: -(ib_vol/2)..+(ib_vol/2) */ int hdr_allocated; /**< maximum count of headers in hdr_buf & hdr_avail */ char *hdr_buf; /**< table of headers or NULL */ Logic *hdr_avail; /**< state of headers availability in hdr_buf */ int cur_index; /**< index of cur_trace */ float *cur_body; /**< buffer for one trace body (REAL*4) holding */ TrHeader *cur_hdr; /**< header of cur_trace */ LockId lock_id;/**< lock identifier to unlock on close */ Logic heModifyData_added;/**< TRUE in case of heModifyData had been added once to processing history */ /* LDB v.4.4 */ Logic use_dbh;/**< using LDB v.4.4 feature of duplicating trace headers; copied from TrDbHdrs variable on TrSet creation. */ dbHandle hdr_dbh;/**< table with trace headers; NULL or 1 if not used; 1 is a special value to mark case when db with headers was removed already */ MutexId mutex_id;/**< Mutex to provide MT-Safe operations */ int ext_nmod; /**< Real id of seismic file. May be greater than 999 allowed by standard Sxxx/Mxxx convension. */ void *hds_ptr; /**< HDS database pointer. */ } TrSet; /* Methods */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /************************************************************* * Base input/output toolkit *************************************************************/ /* Open/close operations */ void TrOpen (TrSet* handle, const char* szProject, const char* szNmod); void TrEdit (TrSet* handle, const char* szProject, const char* szNmod); void TrCreate (TrSet* handle, const char* szProject, const char* szNmod, TrMtable* base); void TrClose (TrSet* handle); void TrReopen (TrSet* handle, const char new_mode); void TrRestoreLock (TrSet* handle); /** Create temporal modification which will be removed on TrClose(). */ void TrTemp (TrSet* handle, TrMtable* base); /* Create partially initialized object to be completed by TrInitMtable(). */ void TrNew (TrSet* handle, const char* szProject, const char* szNmod); void TrNewTemp (TrSet* handle); /** Check for temporary seismic trace set. Returns TRUE on success and FALSE otherwise. */ Logic TrIsTemp (TrSet* handle); /** Save given modification (maybe, temporal) to the pointed project and modification. Index table is taken into account. */ void TrCopy (TrSet* handle, const char* szProject, const char* szNmod); /* Bufferization control */ void TrBufferHdrs (TrSet* handle, Logic flag); void TrBuffer (TrSet* handle, int count); /* Representation tools */ void TrUseIndexTable (TrSet* handle, Logic use_it); void TrRawIndexTable (TrSet* handle); void TrSetIndexTable (TrSet* handle, const TrIndexTable* table); void TrGetIndexTable (TrSet* handle, TrIndexTable* table); void TrFreeIndexTable (TrIndexTable* table); /* Get raw index. Can Throw() error code! */ int TrRawIndex (TrSet* handle, int index); /* Direct access to header and body until next Tr* call */ TrHeader* TrHdr (TrSet* handle, int index); float* TrBody (TrSet* handle, int index); /* Read trace and header */ void TrRead (TrSet* handle, int index, TrHeader* hdr, float* body); /* Write trace and header */ void TrWrite (TrSet* handle, int index, TrHeader* hdr, float* body); void TrAppend (TrSet* handle, TrHeader* hdr, float* body); /************************************************************* * Auxiliary tools *************************************************************/ /* Assign important fields of header: TBC,TEC,SIZE,FTR,DT */ void TrPrepareHdr (TrSet* handle, TrHeader* hdr); /* Smart memory allocation (malloc(), calloc(), free() compatible) */ float* TrAlloc (TrSet* handle, int n); char* TrAllocHdrs (TrSet* handle, int n); /* Mod. table file input/output */ void TrReadMtable (const char* szPath, TrMtable* place); void TrWriteMtable (const char* szPath, TrMtable* place); /* Create new modification table. Use MTYPE_Sxxx, DTYPE_Seismic, LTYPE_VSP for VSP data. */ TrMtable* TrBaseMtable (int mtype, int dtype, int ltype, float Tb, float Te, float Dt); /* Initialize main parameters of new handle created by TrNew. It should be called before any other operations with handle. Use MTYPE_Sxxx, DTYPE_Seismic, LTYPE_VSP for VSP data. */ void TrInitMtable (TrSet* handle, int mtype, int dtype, int ltype, float Tb, float Te, float Dt); /* Return pointer at TrHdrField or NULL */ TrHdrField* TrHdrFieldName (const char* szName); /************************************************************* * Byte-order translation procedures *************************************************************/ /* Translate trace header between architectures in-place. Only first defined 60 lwords are converted! */ void TrTransHdr (TrHeader* pHdr, ByteOrder eTarget, ByteOrder eSource); /* Translate trace body between architectures in-place. Atom type of sample and number of samples are given here. */ void TrTransBody (void* pBody, ByteOrder eTarget, ByteOrder eSource, AtomType eType, unsigned nCount); /* Translate modification table between architectures in-place. Static part and INT* variable size parts are converted. */ void TrTransMtab (TrMtable* mt, ByteOrder eTarget, ByteOrder eSource); /************************************************************* * Support for duplicating information from header in special * db table. *************************************************************/ /** Prepare TrSet::use_dbh and TrSet::hdr_dbh fields on trace set open in different modes. */ void TrPrepareDbHdrs (TrSet* handle); /** Return nmod number or -1 in case of error. */ int TrFileNumber (const char* nmod); /** Put given header into db line. */ void TrHdrToDb (const TrHeader* hdr, dbHandle dbh, DbIndex i); /** Fill header from db line and return its index in the file. */ int TrHdrFromDb (TrHeader* hdr, dbHandle dbh, DbIndex i); /** Read all headers in the buffer at one optimized step. */ void TrAllHdrsFromDb (TrSet* handle); /************************************************************* * Work with header fields identified by taid. *************************************************************/ /** Return type of header word or __NO_TYPE__ if taid is not found. */ AtomType TrHdrFieldType (TraceAttrId taid); /** Return dimension of given header word or -1 taid is not found. */ int TrHdrFieldDim (TraceAttrId taid); /** Return symbolic label of given header word or NULL if taid is not found. */ const char* TrHdrFieldLabel (TraceAttrId taid); /** Access to header word of INT_4 type marked by given TraceAttrId. Returns NULL in case of wrong type. */ int* TrHdrFieldI4 (TrHeader* hdr, TraceAttrId taid); /** Access to header word of REAL_4 type marked by given TraceAttrId. Returns NULL in case of wrong type. */ float* TrHdrFieldR4 (TrHeader* hdr, TraceAttrId taid); /** Access to header word of CHAR_1 type marked by given TraceAttrId. Returns NULL in case of wrong type. */ char* TrHdrFieldC1 (TrHeader* hdr, TraceAttrId taid); /************************************************************* * Provide information string for given seismic file. *************************************************************/ /** Return length needed for char buffer used for info string. mode=0 and it's reserved for future usage. */ int TrInfoLen (int mode); /** Compose head line. mode=0 and it's reserved for future usage. */ void TrInfoHead (int mode, char* szHeadLine); /** Compose line with information. mode=0 and it's reserved for future usage. */ void TrInfoLine (int mode, const char* szProject, const char* szSeismic, char* szInfoLine); /** Extract information about seismic. NULL pointers may be specified for pMtable and pFileSize if they are not needed to calling code. */ ErrCode TrInfoSeismic (const char* szProject, const char* szSeismic, TrMtable* pMtable, off_t* pFileSize); #ifdef __cplusplus }; #endif /* __cplusplus */ #ifndef __TrSetVars /**< Status of the last Tr* method */ extern TLStorage int TrStatus; /**< Table of textual representation of VSP header fields. Ordered by name!!! MT-Safe because they are implicitly constant. */ extern TrHdrField TrFields[]; extern int TrFieldsCount; /* count of elements in TrFields */ /**< The way of db header reading/writing: TRUE- LDB v.4.4; FALSE - old */ extern TLStorage Logic TrDbHdrs; /** Local process counter for temporal modifications. The declaration is not thread safe. I hope ++nTrTemp will be atomic with 0.999999 probability since it is too short to be broken by different threads. */ extern volatile int nTrTemp; #endif /* __TrSetVars */ #endif /* trset.h */
10  *
11  * Использование, копирование или передача регулируются законами
12  * Российской Федерации "Об авторском праве и смежных правах", "О * правовой охране программ для электронных вычислительных машин и баз * данных" * * Encoding: ISO-8859-5 (GOST) * *********************************************************************/ #ifndef __trset_h #define __trset_h #include <mix/Types.h> #include <mix/trace_file.h> #include <mix/mod_table.h> #include <mix/wenv.h> #include <mix/trans.h> #include <ldb/vsp_trace.h> #include <ldb/dbtc.h> #include <mix/locks.h> #include <mix/mutex.h> #ifndef O_BINARY /* for UNIX open() operates in binary mode by default */ #define O_BINARY 0 #endif /* O_BINARY */ /** Name used to mark project of temporal seismic modifications. */ #define TEMP_PROJECT "/tmp" /** Modification table structures */ typedef struct { int size; /**< size of modification table in bytes */ ModTableMain *mtab; /**< the whole area with INTL, INTX and INTY */ ModTableIntL *intl; /**< may points as inside mtab as well outside */ ModTableIntX *intx; /**< may points as inside mtab as well outside */ ModTableIntY *inty; /**< may points as inside mtab as well outside */ } TrMtable; /** Index table for virtual trace file representation */ typedef struct { int count; /**< count of entries in table */ int *table; /**< table of indexes */ void *hds_ptr; /**< HDS database pointer. */ } TrIndexTable; #define HDR_R4 0 #define HDR_I4 1 #define HDR_C1 2 /** One header entry description */ typedef struct { char *name; /**< text name of field */ int offset; /**< offset in longs (4byte) from the begin of header */ char *fmt; /**< format of input/output */ int type; /**< type of field: 0 - R4, 1 - I4, 2 - C1 */ int count; /**< count of element (in array) */ int bsize; /**< size (bytes) for array */ } TrHdrField; /** Representation of any header field value */ typedef union { float R4[1]; /**< REAL*4 */ int I4[3]; /**< INTEGER*4 */ char C1[12]; /**< CHAR_1*1 */ } TrHdrFieldValue; #define STARTUP_TRACE_BUFFER 7 /**< ib_vol */ #define HDR_BUF_GROW_QUANT 20 /**< for hdr_buf and hdr_avail grow */ /** Main control structure */ typedef struct { /* PUBLIC: */ char *project; /**< project */ char *nmod; /**< modification */ int fildes; /**< data file I/O handle */ TrMtable mt; /**< the whole modification table */ /* input trace size factor */ int in_traces_count; /**< count of traces in input file */ int in_trace_size; /**< raw size of trace in bytes */ int in_body_size; /**< raw size of samples in bytes */ int in_hdr_size; /**< raw size of header in bytes */ SampleFormat in_format; /**< raw format of samples */ /* internal trace size factor */ int traces_count; /**< count of traces in index table */ int trace_size; /**< size of trace in bytes */ int body_size; /**< size of samples in bytes */ int hdr_size; /**< size of header in bytes */ /* application oriented "size" factor */ int samples_count; /**< count of samples */ float Tb, Te, Dt; /**< times, ms */ TrIndexTable itable; /**< representation table */ Logic use_itable; /**< TRUE to use index tranlation or FALSE don't do it; TRUE-default */ /* PRIVATE: */ char mode; /**< 'c'reate, 'o'pen, 'e'dit, 'n'ew */ char *in_buf; /**< buffer for input traces (raw format with hdrs) */ int ib_vol; /**< input trace buffer volume (must be odd) */ int ib_range[2]; /**< the first and the last raw indexes in in_buf; ib_range[1] - ib_range[0] + 1 <= ib_vol */ int prev_index; /**< raw index of previously called trace */ int prev_im; /**< monotonicity of previously called trace */ int kp; /**< predictivity number: -(ib_vol/2)..+(ib_vol/2) */ int hdr_allocated; /**< maximum count of headers in hdr_buf & hdr_avail */ char *hdr_buf; /**< table of headers or NULL */ Logic *hdr_avail; /**< state of headers availability in hdr_buf */ int cur_index; /**< index of cur_trace */ float *cur_body; /**< buffer for one trace body (REAL*4) holding */ TrHeader *cur_hdr; /**< header of cur_trace */ LockId lock_id;/**< lock identifier to unlock on close */ Logic heModifyData_added;/**< TRUE in case of heModifyData had been added once to processing history */ /* LDB v.4.4 */ Logic use_dbh;/**< using LDB v.4.4 feature of duplicating trace headers; copied from TrDbHdrs variable on TrSet creation. */ dbHandle hdr_dbh;/**< table with trace headers; NULL or 1 if not used; 1 is a special value to mark case when db with headers was removed already */ MutexId mutex_id;/**< Mutex to provide MT-Safe operations */ int ext_nmod; /**< Real id of seismic file. May be greater than 999 allowed by standard Sxxx/Mxxx convension. */ void *hds_ptr; /**< HDS database pointer. */ } TrSet; /* Methods */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /************************************************************* * Base input/output toolkit *************************************************************/ /* Open/close operations */ void TrOpen (TrSet* handle, const char* szProject, const char* szNmod); void TrEdit (TrSet* handle, const char* szProject, const char* szNmod); void TrCreate (TrSet* handle, const char* szProject, const char* szNmod, TrMtable* base); void TrClose (TrSet* handle); void TrReopen (TrSet* handle, const char new_mode); void TrRestoreLock (TrSet* handle); /** Create temporal modification which will be removed on TrClose(). */ void TrTemp (TrSet* handle, TrMtable* base); /* Create partially initialized object to be completed by TrInitMtable(). */ void TrNew (TrSet* handle, const char* szProject, const char* szNmod); void TrNewTemp (TrSet* handle); /** Check for temporary seismic trace set. Returns TRUE on success and FALSE otherwise. */ Logic TrIsTemp (TrSet* handle); /** Save given modification (maybe, temporal) to the pointed project and modification. Index table is taken into account. */ void TrCopy (TrSet* handle, const char* szProject, const char* szNmod); /* Bufferization control */ void TrBufferHdrs (TrSet* handle, Logic flag); void TrBuffer (TrSet* handle, int count); /* Representation tools */ void TrUseIndexTable (TrSet* handle, Logic use_it); void TrRawIndexTable (TrSet* handle); void TrSetIndexTable (TrSet* handle, const TrIndexTable* table); void TrGetIndexTable (TrSet* handle, TrIndexTable* table); void TrFreeIndexTable (TrIndexTable* table); /* Get raw index. Can Throw() error code! */ int TrRawIndex (TrSet* handle, int index); /* Direct access to header and body until next Tr* call */ TrHeader* TrHdr (TrSet* handle, int index); float* TrBody (TrSet* handle, int index); /* Read trace and header */ void TrRead (TrSet* handle, int index, TrHeader* hdr, float* body); /* Write trace and header */ void TrWrite (TrSet* handle, int index, TrHeader* hdr, float* body); void TrAppend (TrSet* handle, TrHeader* hdr, float* body); /************************************************************* * Auxiliary tools *************************************************************/ /* Assign important fields of header: TBC,TEC,SIZE,FTR,DT */ void TrPrepareHdr (TrSet* handle, TrHeader* hdr); /* Smart memory allocation (malloc(), calloc(), free() compatible) */ float* TrAlloc (TrSet* handle, int n); char* TrAllocHdrs (TrSet* handle, int n); /* Mod. table file input/output */ void TrReadMtable (const char* szPath, TrMtable* place); void TrWriteMtable (const char* szPath, TrMtable* place); /* Create new modification table. Use MTYPE_Sxxx, DTYPE_Seismic, LTYPE_VSP for VSP data. */ TrMtable* TrBaseMtable (int mtype, int dtype, int ltype, float Tb, float Te, float Dt); /* Initialize main parameters of new handle created by TrNew. It should be called before any other operations with handle. Use MTYPE_Sxxx, DTYPE_Seismic, LTYPE_VSP for VSP data. */ void TrInitMtable (TrSet* handle, int mtype, int dtype, int ltype, float Tb, float Te, float Dt); /* Return pointer at TrHdrField or NULL */ TrHdrField* TrHdrFieldName (const char* szName); /************************************************************* * Byte-order translation procedures *************************************************************/ /* Translate trace header between architectures in-place. Only first defined 60 lwords are converted! */ void TrTransHdr (TrHeader* pHdr, ByteOrder eTarget, ByteOrder eSource); /* Translate trace body between architectures in-place. Atom type of sample and number of samples are given here. */ void TrTransBody (void* pBody, ByteOrder eTarget, ByteOrder eSource, AtomType eType, unsigned nCount); /* Translate modification table between architectures in-place. Static part and INT* variable size parts are converted. */ void TrTransMtab (TrMtable* mt, ByteOrder eTarget, ByteOrder eSource); /************************************************************* * Support for duplicating information from header in special * db table. *************************************************************/ /** Prepare TrSet::use_dbh and TrSet::hdr_dbh fields on trace set open in different modes. */ void TrPrepareDbHdrs (TrSet* handle); /** Return nmod number or -1 in case of error. */ int TrFileNumber (const char* nmod); /** Put given header into db line. */ void TrHdrToDb (const TrHeader* hdr, dbHandle dbh, DbIndex i); /** Fill header from db line and return its index in the file. */ int TrHdrFromDb (TrHeader* hdr, dbHandle dbh, DbIndex i); /** Read all headers in the buffer at one optimized step. */ void TrAllHdrsFromDb (TrSet* handle); /************************************************************* * Work with header fields identified by taid. *************************************************************/ /** Return type of header word or __NO_TYPE__ if taid is not found. */ AtomType TrHdrFieldType (TraceAttrId taid); /** Return dimension of given header word or -1 taid is not found. */ int TrHdrFieldDim (TraceAttrId taid); /** Return symbolic label of given header word or NULL if taid is not found. */ const char* TrHdrFieldLabel (TraceAttrId taid); /** Access to header word of INT_4 type marked by given TraceAttrId. Returns NULL in case of wrong type. */ int* TrHdrFieldI4 (TrHeader* hdr, TraceAttrId taid); /** Access to header word of REAL_4 type marked by given TraceAttrId. Returns NULL in case of wrong type. */ float* TrHdrFieldR4 (TrHeader* hdr, TraceAttrId taid); /** Access to header word of CHAR_1 type marked by given TraceAttrId. Returns NULL in case of wrong type. */ char* TrHdrFieldC1 (TrHeader* hdr, TraceAttrId taid); /************************************************************* * Provide information string for given seismic file. *************************************************************/ /** Return length needed for char buffer used for info string. mode=0 and it's reserved for future usage. */ int TrInfoLen (int mode); /** Compose head line. mode=0 and it's reserved for future usage. */ void TrInfoHead (int mode, char* szHeadLine); /** Compose line with information. mode=0 and it's reserved for future usage. */ void TrInfoLine (int mode, const char* szProject, const char* szSeismic, char* szInfoLine); /** Extract information about seismic. NULL pointers may be specified for pMtable and pFileSize if they are not needed to calling code. */ ErrCode TrInfoSeismic (const char* szProject, const char* szSeismic, TrMtable* pMtable, off_t* pFileSize); #ifdef __cplusplus }; #endif /* __cplusplus */ #ifndef __TrSetVars /**< Status of the last Tr* method */ extern TLStorage int TrStatus; /**< Table of textual representation of VSP header fields. Ordered by name!!! MT-Safe because they are implicitly constant. */ extern TrHdrField TrFields[]; extern int TrFieldsCount; /* count of elements in TrFields */ /**< The way of db header reading/writing: TRUE- LDB v.4.4; FALSE - old */ extern TLStorage Logic TrDbHdrs; /** Local process counter for temporal modifications. The declaration is not thread safe. I hope ++nTrTemp will be atomic with 0.999999 probability since it is too short to be broken by different threads. */ extern volatile int nTrTemp; #endif /* __TrSetVars */ #endif /* trset.h */
13  * правовой охране программ для электронных вычислительных машин и баз * данных" * * Encoding: ISO-8859-5 (GOST) * *********************************************************************/ #ifndef __trset_h #define __trset_h #include <mix/Types.h> #include <mix/trace_file.h> #include <mix/mod_table.h> #include <mix/wenv.h> #include <mix/trans.h> #include <ldb/vsp_trace.h> #include <ldb/dbtc.h> #include <mix/locks.h> #include <mix/mutex.h> #ifndef O_BINARY /* for UNIX open() operates in binary mode by default */ #define O_BINARY 0 #endif /* O_BINARY */ /** Name used to mark project of temporal seismic modifications. */ #define TEMP_PROJECT "/tmp" /** Modification table structures */ typedef struct { int size; /**< size of modification table in bytes */ ModTableMain *mtab; /**< the whole area with INTL, INTX and INTY */ ModTableIntL *intl; /**< may points as inside mtab as well outside */ ModTableIntX *intx; /**< may points as inside mtab as well outside */ ModTableIntY *inty; /**< may points as inside mtab as well outside */ } TrMtable; /** Index table for virtual trace file representation */ typedef struct { int count; /**< count of entries in table */ int *table; /**< table of indexes */ void *hds_ptr; /**< HDS database pointer. */ } TrIndexTable; #define HDR_R4 0 #define HDR_I4 1 #define HDR_C1 2 /** One header entry description */ typedef struct { char *name; /**< text name of field */ int offset; /**< offset in longs (4byte) from the begin of header */ char *fmt; /**< format of input/output */ int type; /**< type of field: 0 - R4, 1 - I4, 2 - C1 */ int count; /**< count of element (in array) */ int bsize; /**< size (bytes) for array */ } TrHdrField; /** Representation of any header field value */ typedef union { float R4[1]; /**< REAL*4 */ int I4[3]; /**< INTEGER*4 */ char C1[12]; /**< CHAR_1*1 */ } TrHdrFieldValue; #define STARTUP_TRACE_BUFFER 7 /**< ib_vol */ #define HDR_BUF_GROW_QUANT 20 /**< for hdr_buf and hdr_avail grow */ /** Main control structure */ typedef struct { /* PUBLIC: */ char *project; /**< project */ char *nmod; /**< modification */ int fildes; /**< data file I/O handle */ TrMtable mt; /**< the whole modification table */ /* input trace size factor */ int in_traces_count; /**< count of traces in input file */ int in_trace_size; /**< raw size of trace in bytes */ int in_body_size; /**< raw size of samples in bytes */ int in_hdr_size; /**< raw size of header in bytes */ SampleFormat in_format; /**< raw format of samples */ /* internal trace size factor */ int traces_count; /**< count of traces in index table */ int trace_size; /**< size of trace in bytes */ int body_size; /**< size of samples in bytes */ int hdr_size; /**< size of header in bytes */ /* application oriented "size" factor */ int samples_count; /**< count of samples */ float Tb, Te, Dt; /**< times, ms */ TrIndexTable itable; /**< representation table */ Logic use_itable; /**< TRUE to use index tranlation or FALSE don't do it; TRUE-default */ /* PRIVATE: */ char mode; /**< 'c'reate, 'o'pen, 'e'dit, 'n'ew */ char *in_buf; /**< buffer for input traces (raw format with hdrs) */ int ib_vol; /**< input trace buffer volume (must be odd) */ int ib_range[2]; /**< the first and the last raw indexes in in_buf; ib_range[1] - ib_range[0] + 1 <= ib_vol */ int prev_index; /**< raw index of previously called trace */ int prev_im; /**< monotonicity of previously called trace */ int kp; /**< predictivity number: -(ib_vol/2)..+(ib_vol/2) */ int hdr_allocated; /**< maximum count of headers in hdr_buf & hdr_avail */ char *hdr_buf; /**< table of headers or NULL */ Logic *hdr_avail; /**< state of headers availability in hdr_buf */ int cur_index; /**< index of cur_trace */ float *cur_body; /**< buffer for one trace body (REAL*4) holding */ TrHeader *cur_hdr; /**< header of cur_trace */ LockId lock_id;/**< lock identifier to unlock on close */ Logic heModifyData_added;/**< TRUE in case of heModifyData had been added once to processing history */ /* LDB v.4.4 */ Logic use_dbh;/**< using LDB v.4.4 feature of duplicating trace headers; copied from TrDbHdrs variable on TrSet creation. */ dbHandle hdr_dbh;/**< table with trace headers; NULL or 1 if not used; 1 is a special value to mark case when db with headers was removed already */ MutexId mutex_id;/**< Mutex to provide MT-Safe operations */ int ext_nmod; /**< Real id of seismic file. May be greater than 999 allowed by standard Sxxx/Mxxx convension. */ void *hds_ptr; /**< HDS database pointer. */ } TrSet; /* Methods */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /************************************************************* * Base input/output toolkit *************************************************************/ /* Open/close operations */ void TrOpen (TrSet* handle, const char* szProject, const char* szNmod); void TrEdit (TrSet* handle, const char* szProject, const char* szNmod); void TrCreate (TrSet* handle, const char* szProject, const char* szNmod, TrMtable* base); void TrClose (TrSet* handle); void TrReopen (TrSet* handle, const char new_mode); void TrRestoreLock (TrSet* handle); /** Create temporal modification which will be removed on TrClose(). */ void TrTemp (TrSet* handle, TrMtable* base); /* Create partially initialized object to be completed by TrInitMtable(). */ void TrNew (TrSet* handle, const char* szProject, const char* szNmod); void TrNewTemp (TrSet* handle); /** Check for temporary seismic trace set. Returns TRUE on success and FALSE otherwise. */ Logic TrIsTemp (TrSet* handle); /** Save given modification (maybe, temporal) to the pointed project and modification. Index table is taken into account. */ void TrCopy (TrSet* handle, const char* szProject, const char* szNmod); /* Bufferization control */ void TrBufferHdrs (TrSet* handle, Logic flag); void TrBuffer (TrSet* handle, int count); /* Representation tools */ void TrUseIndexTable (TrSet* handle, Logic use_it); void TrRawIndexTable (TrSet* handle); void TrSetIndexTable (TrSet* handle, const TrIndexTable* table); void TrGetIndexTable (TrSet* handle, TrIndexTable* table); void TrFreeIndexTable (TrIndexTable* table); /* Get raw index. Can Throw() error code! */ int TrRawIndex (TrSet* handle, int index); /* Direct access to header and body until next Tr* call */ TrHeader* TrHdr (TrSet* handle, int index); float* TrBody (TrSet* handle, int index); /* Read trace and header */ void TrRead (TrSet* handle, int index, TrHeader* hdr, float* body); /* Write trace and header */ void TrWrite (TrSet* handle, int index, TrHeader* hdr, float* body); void TrAppend (TrSet* handle, TrHeader* hdr, float* body); /************************************************************* * Auxiliary tools *************************************************************/ /* Assign important fields of header: TBC,TEC,SIZE,FTR,DT */ void TrPrepareHdr (TrSet* handle, TrHeader* hdr); /* Smart memory allocation (malloc(), calloc(), free() compatible) */ float* TrAlloc (TrSet* handle, int n); char* TrAllocHdrs (TrSet* handle, int n); /* Mod. table file input/output */ void TrReadMtable (const char* szPath, TrMtable* place); void TrWriteMtable (const char* szPath, TrMtable* place); /* Create new modification table. Use MTYPE_Sxxx, DTYPE_Seismic, LTYPE_VSP for VSP data. */ TrMtable* TrBaseMtable (int mtype, int dtype, int ltype, float Tb, float Te, float Dt); /* Initialize main parameters of new handle created by TrNew. It should be called before any other operations with handle. Use MTYPE_Sxxx, DTYPE_Seismic, LTYPE_VSP for VSP data. */ void TrInitMtable (TrSet* handle, int mtype, int dtype, int ltype, float Tb, float Te, float Dt); /* Return pointer at TrHdrField or NULL */ TrHdrField* TrHdrFieldName (const char* szName); /************************************************************* * Byte-order translation procedures *************************************************************/ /* Translate trace header between architectures in-place. Only first defined 60 lwords are converted! */ void TrTransHdr (TrHeader* pHdr, ByteOrder eTarget, ByteOrder eSource); /* Translate trace body between architectures in-place. Atom type of sample and number of samples are given here. */ void TrTransBody (void* pBody, ByteOrder eTarget, ByteOrder eSource, AtomType eType, unsigned nCount); /* Translate modification table between architectures in-place. Static part and INT* variable size parts are converted. */ void TrTransMtab (TrMtable* mt, ByteOrder eTarget, ByteOrder eSource); /************************************************************* * Support for duplicating information from header in special * db table. *************************************************************/ /** Prepare TrSet::use_dbh and TrSet::hdr_dbh fields on trace set open in different modes. */ void TrPrepareDbHdrs (TrSet* handle); /** Return nmod number or -1 in case of error. */ int TrFileNumber (const char* nmod); /** Put given header into db line. */ void TrHdrToDb (const TrHeader* hdr, dbHandle dbh, DbIndex i); /** Fill header from db line and return its index in the file. */ int TrHdrFromDb (TrHeader* hdr, dbHandle dbh, DbIndex i); /** Read all headers in the buffer at one optimized step. */ void TrAllHdrsFromDb (TrSet* handle); /************************************************************* * Work with header fields identified by taid. *************************************************************/ /** Return type of header word or __NO_TYPE__ if taid is not found. */ AtomType TrHdrFieldType (TraceAttrId taid); /** Return dimension of given header word or -1 taid is not found. */ int TrHdrFieldDim (TraceAttrId taid); /** Return symbolic label of given header word or NULL if taid is not found. */ const char* TrHdrFieldLabel (TraceAttrId taid); /** Access to header word of INT_4 type marked by given TraceAttrId. Returns NULL in case of wrong type. */ int* TrHdrFieldI4 (TrHeader* hdr, TraceAttrId taid); /** Access to header word of REAL_4 type marked by given TraceAttrId. Returns NULL in case of wrong type. */ float* TrHdrFieldR4 (TrHeader* hdr, TraceAttrId taid); /** Access to header word of CHAR_1 type marked by given TraceAttrId. Returns NULL in case of wrong type. */ char* TrHdrFieldC1 (TrHeader* hdr, TraceAttrId taid); /************************************************************* * Provide information string for given seismic file. *************************************************************/ /** Return length needed for char buffer used for info string. mode=0 and it's reserved for future usage. */ int TrInfoLen (int mode); /** Compose head line. mode=0 and it's reserved for future usage. */ void TrInfoHead (int mode, char* szHeadLine); /** Compose line with information. mode=0 and it's reserved for future usage. */ void TrInfoLine (int mode, const char* szProject, const char* szSeismic, char* szInfoLine); /** Extract information about seismic. NULL pointers may be specified for pMtable and pFileSize if they are not needed to calling code. */ ErrCode TrInfoSeismic (const char* szProject, const char* szSeismic, TrMtable* pMtable, off_t* pFileSize); #ifdef __cplusplus }; #endif /* __cplusplus */ #ifndef __TrSetVars /**< Status of the last Tr* method */ extern TLStorage int TrStatus; /**< Table of textual representation of VSP header fields. Ordered by name!!! MT-Safe because they are implicitly constant. */ extern TrHdrField TrFields[]; extern int TrFieldsCount; /* count of elements in TrFields */ /**< The way of db header reading/writing: TRUE- LDB v.4.4; FALSE - old */ extern TLStorage Logic TrDbHdrs; /** Local process counter for temporal modifications. The declaration is not thread safe. I hope ++nTrTemp will be atomic with 0.999999 probability since it is too short to be broken by different threads. */ extern volatile int nTrTemp; #endif /* __TrSetVars */ #endif /* trset.h */
14  * данных"
15  *
16  * Encoding: ISO-8859-5 (GOST)
17  *
18  *********************************************************************/
19 
20 #ifndef __trset_h
21 #define __trset_h
22 
23 #include <mix/Types.h>
24 #include <mix/trace_file.h>
25 #include <mix/mod_table.h>
26 #include <mix/wenv.h>
27 #include <mix/trans.h>
28 #include <ldb/vsp_trace.h>
29 #include <ldb/dbtc.h>
30 #include <mix/locks.h>
31 #include <mix/mutex.h>
32 
33 #ifndef O_BINARY
34 /* for UNIX open() operates in binary mode by default */
35 #define O_BINARY 0
36 #endif /* O_BINARY */
37 
38 
40 #define TEMP_PROJECT "/tmp"
41 
42 
44 typedef struct
45 {
46  int size;
52 } TrMtable;
53 
54 
56 typedef struct
57 {
58  int count;
59  int *table;
60  void *hds_ptr;
62 } TrIndexTable;
63 
64 
65 #define HDR_R4 0
66 #define HDR_I4 1
67 #define HDR_C1 2
68 
69 typedef struct
70 {
71  char *name;
72  int offset;
73  char *fmt;
74  int type;
75  int count;
76  int bsize;
78 } TrHdrField;
79 
80 
82 typedef union
83 {
84  float R4[1];
85  int I4[3];
86  char C1[12];
89 
90 
91 #define STARTUP_TRACE_BUFFER 7
93 #define HDR_BUF_GROW_QUANT 20
96 typedef struct
97 {
98  /* PUBLIC: */
99 
100  char *project;
101  char *nmod;
103  int fildes;
108  /* input trace size factor */
113  SampleFormat in_format;
115  /* internal trace size factor */
118  int body_size;
119  int hdr_size;
121  /* application oriented "size" factor */
123  float Tb, Te, Dt;
126  Logic use_itable;
129  /* PRIVATE: */
130 
131  char mode;
133  char *in_buf;
134  int ib_vol;
135  int ib_range[2];
139  int prev_im;
140  int kp;
143  char *hdr_buf;
144  Logic *hdr_avail;
146  int cur_index;
147  float *cur_body;
150  LockId lock_id;
154  /* LDB v.4.4 */
155  Logic use_dbh;
158  dbHandle hdr_dbh;
162  MutexId mutex_id;
164  int ext_nmod;
168  void *hds_ptr;
170 } TrSet;
171 
172 
173 /* Methods */
174 
175 #ifdef __cplusplus
176 extern "C" {
177 #endif /* __cplusplus */
178 
179 /*************************************************************
180  * Base input/output toolkit
181  *************************************************************/
182 
183 /* Open/close operations */
184 void TrOpen (TrSet* handle, const char* szProject, const char* szNmod);
185 void TrEdit (TrSet* handle, const char* szProject, const char* szNmod);
186 void TrCreate (TrSet* handle, const char* szProject, const char* szNmod,
187  TrMtable* base);
188 void TrClose (TrSet* handle);
189 void TrReopen (TrSet* handle, const char new_mode);
190 void TrRestoreLock (TrSet* handle);
191 
193 void TrTemp (TrSet* handle, TrMtable* base);
194 
195 /* Create partially initialized object to be completed by TrInitMtable(). */
196 void TrNew (TrSet* handle, const char* szProject, const char* szNmod);
197 void TrNewTemp (TrSet* handle);
198 
201 Logic TrIsTemp (TrSet* handle);
202 
205 void TrCopy (TrSet* handle, const char* szProject, const char* szNmod);
206 
207 
208 /* Bufferization control */
209 void TrBufferHdrs (TrSet* handle, Logic flag);
210 void TrBuffer (TrSet* handle, int count);
211 
212 /* Representation tools */
213 void TrUseIndexTable (TrSet* handle, Logic use_it);
214 void TrRawIndexTable (TrSet* handle);
215 void TrSetIndexTable (TrSet* handle, const TrIndexTable* table);
216 void TrGetIndexTable (TrSet* handle, TrIndexTable* table);
217 void TrFreeIndexTable (TrIndexTable* table);
218 
219 /* Get raw index. Can Throw() error code! */
220 int TrRawIndex (TrSet* handle, int index);
221 
222 /* Direct access to header and body until next Tr* call */
223 TrHeader* TrHdr (TrSet* handle, int index);
224 float* TrBody (TrSet* handle, int index);
225 
226 /* Read trace and header */
227 void TrRead (TrSet* handle, int index, TrHeader* hdr, float* body);
228 
229 /* Write trace and header */
230 void TrWrite (TrSet* handle, int index, TrHeader* hdr, float* body);
231 void TrAppend (TrSet* handle, TrHeader* hdr, float* body);
232 
233 /*************************************************************
234  * Auxiliary tools
235  *************************************************************/
236 
237 /* Assign important fields of header: TBC,TEC,SIZE,FTR,DT */
238 void TrPrepareHdr (TrSet* handle, TrHeader* hdr);
239 
240 /* Smart memory allocation (malloc(), calloc(), free() compatible) */
241 float* TrAlloc (TrSet* handle, int n);
242 char* TrAllocHdrs (TrSet* handle, int n);
243 
244 /* Mod. table file input/output */
245 void TrReadMtable (const char* szPath, TrMtable* place);
246 void TrWriteMtable (const char* szPath, TrMtable* place);
247 
248 /* Create new modification table.
249  Use MTYPE_Sxxx, DTYPE_Seismic, LTYPE_VSP for VSP data. */
250 TrMtable* TrBaseMtable (int mtype, int dtype, int ltype,
251  float Tb, float Te, float Dt);
252 
253 /* Initialize main parameters of new handle created by TrNew. It
254  should be called before any other operations with handle. Use
255  MTYPE_Sxxx, DTYPE_Seismic, LTYPE_VSP for VSP data. */
256 void TrInitMtable (TrSet* handle,
257  int mtype, int dtype, int ltype,
258  float Tb, float Te, float Dt);
259 
260 /* Return pointer at TrHdrField or NULL */
261 TrHdrField* TrHdrFieldName (const char* szName);
262 
263 /*************************************************************
264  * Byte-order translation procedures
265  *************************************************************/
266 
267 /* Translate trace header between architectures in-place.
268  Only first defined 60 lwords are converted! */
269 void TrTransHdr (TrHeader* pHdr, ByteOrder eTarget, ByteOrder eSource);
270 
271 /* Translate trace body between architectures in-place.
272  Atom type of sample and number of samples are given here. */
273 void TrTransBody (void* pBody, ByteOrder eTarget, ByteOrder eSource,
274  AtomType eType, unsigned nCount);
275 
276 /* Translate modification table between architectures in-place.
277  Static part and INT* variable size parts are converted. */
278 void TrTransMtab (TrMtable* mt, ByteOrder eTarget, ByteOrder eSource);
279 
280 
281 /*************************************************************
282  * Support for duplicating information from header in special
283  * db table.
284  *************************************************************/
285 
288 void TrPrepareDbHdrs (TrSet* handle);
289 
291 int TrFileNumber (const char* nmod);
292 
294 void TrHdrToDb (const TrHeader* hdr, dbHandle dbh, DbIndex i);
295 
297 int TrHdrFromDb (TrHeader* hdr, dbHandle dbh, DbIndex i);
298 
300 void TrAllHdrsFromDb (TrSet* handle);
301 
302 /*************************************************************
303  * Work with header fields identified by taid.
304  *************************************************************/
305 
307 AtomType TrHdrFieldType (TraceAttrId taid);
308 
310 int TrHdrFieldDim (TraceAttrId taid);
311 
314 const char* TrHdrFieldLabel (TraceAttrId taid);
315 
318 int* TrHdrFieldI4 (TrHeader* hdr, TraceAttrId taid);
319 
322 float* TrHdrFieldR4 (TrHeader* hdr, TraceAttrId taid);
323 
326 char* TrHdrFieldC1 (TrHeader* hdr, TraceAttrId taid);
327 
328 
329 /*************************************************************
330  * Provide information string for given seismic file.
331  *************************************************************/
332 
335 int TrInfoLen (int mode);
336 
338 void TrInfoHead (int mode, char* szHeadLine);
339 
342 void TrInfoLine (int mode, const char* szProject, const char* szSeismic,
343  char* szInfoLine);
344 
348 ErrCode TrInfoSeismic (const char* szProject, const char* szSeismic,
349  TrMtable* pMtable, off_t* pFileSize);
350 
351 
352 #ifdef __cplusplus
353 };
354 #endif /* __cplusplus */
355 
356 
357 #ifndef __TrSetVars
358 
360 extern TLStorage int TrStatus;
361 
364 extern TrHdrField TrFields[];
365 extern int TrFieldsCount; /* count of elements in TrFields */
366 
368 extern TLStorage Logic TrDbHdrs;
369 
374 extern volatile int nTrTemp;
375 
376 #endif /* __TrSetVars */
377 
378 
379 #endif /* trset.h */
char * name
Definition: trset.h:71
Logic * hdr_avail
Definition: trset.h:144
int size
Definition: trset.h:46
int ib_vol
Definition: trset.h:134
Definition: mod_table.h:15
Definition: mod_table.h:95
int trace_size
Definition: trset.h:117
int in_hdr_size
Definition: trset.h:112
Class, describing the geological body.
Definition: vel2dmod_service.hpp:268
int hdr_size
Definition: trset.h:119
TrIndexTable itable
Definition: trset.h:125
Definition: trace_file.h:15
void * hds_ptr
Definition: trset.h:60
LockId lock_id
Definition: trset.h:150
Definition: trset.h:82
int bsize
Definition: trset.h:76
Definition: mod_table.h:112
int prev_index
Definition: trset.h:138
TrHeader * cur_hdr
Definition: trset.h:148
int in_traces_count
Definition: trset.h:109
char * hdr_buf
Definition: trset.h:143
int fildes
Definition: trset.h:103
int body_size
Definition: trset.h:118
ModTableIntL * intl
Definition: trset.h:48
TrMtable mt
Definition: trset.h:106
int ext_nmod
Definition: trset.h:164
int offset
Definition: trset.h:72
int * table
Definition: trset.h:59
int hdr_allocated
Definition: trset.h:142
char mode
Definition: trset.h:131
dbHandle hdr_dbh
Definition: trset.h:158
void * hds_ptr
Definition: trset.h:168
Logic heModifyData_added
Definition: trset.h:151
float * cur_body
Definition: trset.h:147
float Dt
Definition: trset.h:123
char * nmod
Definition: trset.h:101
int count
Definition: trset.h:58
MutexId mutex_id
Definition: trset.h:162
char * project
Definition: trset.h:100
int cur_index
Definition: trset.h:146
int traces_count
Definition: trset.h:116
Definition: trset.h:56
Logic use_itable
Definition: trset.h:126
Logic use_dbh
Definition: trset.h:155
SampleFormat in_format
Definition: trset.h:113
char * fmt
Definition: trset.h:73
int kp
Definition: trset.h:140
int in_trace_size
Definition: trset.h:110
ModTableIntY * inty
Definition: trset.h:50
ModTableMain * mtab
Definition: trset.h:47
int samples_count
Definition: trset.h:122
int type
Definition: trset.h:74
int count
Definition: trset.h:75
int prev_im
Definition: trset.h:139
ModTableIntX * intx
Definition: trset.h:49
Definition: trset.h:44
char * in_buf
Definition: trset.h:133
Definition: trset.h:96
Definition: mod_table.h:103
Definition: trset.h:69
int in_body_size
Definition: trset.h:111