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 */