common.h File Reference

#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
#include "util.h"
#include "sac.h"
#include "titan2.h"
#include "frames.h"
#include "gd.h"
#include "tdb.h"

Include dependency graph for common.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  EventType
 source description More...
struct  InfoHeaderType
 information header for the output file of each channel More...

Defines

#define MY_PI   3.14159265358979323846
#define NO_TIME_CORRECTION   -1
#define AUTO_CORRECTION   0
#define LAST_PULSE_CORRECTION   1
#define INTERPOLATION_CORRECTION   2
#define EXTENDED_CORRECTION   3
#define US2S   0.23283064365386962891e-9
#define FILE_MODE   0
#define DAY_MODE   1
#define DISK_MODE   2
#define DEFAULT_STATION   "XXX"
#define DEFAULT_SERIAL   "XXX.XXXX"
#define FILE_BUFFER_SIZE   (12*24*1024)
#define ADD_LOCATION_CODE   (1<<0)
 options for FileName()
#define ADD_NETWORK_CODE   (1<<1)
#define ADD_CHANNEL_CODE   (1<<2)
#define EDU_FILE_NAME   (1<<3)
#define INIT_PRINT_TRIGGER   ((10<<10)/12)
#define NORMAL_PRINT_TRIGGER   ((10<<20)/12)
#define Extracting(a)   (extractMSeed||extractWav||extractTrig||extractGif||extractSeg2||extractSegy||extractAsc||extractSac||extractSis||extractBin)

Functions

int Rename (const char *oldpath, const char *newpath)
 rename a file, also over different filesystem
int OpenTempFile (char *template)
 open a temp file for writing as mkstemp would do
int SendFile (int fdout, int fdin, int len)
 transfer data between file descriptors.
void PulseFilter (char *dtfile, double dtmax)
 read a dt file, filter the time pulses The resulting file is named after the input file, replacing 'dt' by 'flt'
char * FileName (const char *pre, const char *post, int channel, int force)
 generate a file name based on the header information, prefix and postfix
int GetFrame (void)
 Read the next frame.
int GetInterpolatedShift (double t, double *ts, int *age, char *station, char *file)
 scan a dt file and compute the interpolated shift
int InWindow (void)
 test if we are within a segment: tricky
void RewindCache (void)
 rewind the cache file is open for read
int OpenCacheFileRead (char *SN, time_t t)
 look for the cache file corresponding to the current data stream
void FlushNonDataFiles (void)
 close any open output non data file
void InitCache (void)
 initialize the cache directory This function should cleanup the cache by removing the oldest files
void CachePrintCST (void)
 issue a #CST message (continuous segment tag)
void CloseTimeFile (char *sta)
 close any open time file
void CloseCacheFile (int cancel)
 Close the cache file, if open.
void CacheCallBack (void)
 Build the cache for the current input.
char * CacheRead (char *line)
 read a line in the cache file
time_t NextWindow (void)
 Look for the next data window The input is parsed for the next data window according to the method used (timelist, timesegment, command line.
int SeekTime (time_t t)
 Seek a time in the input data Scan the cache file, find the offset for the latest time entry before the requested time, open the corresponding file and seek in this file.
FILE * InitEventList (const char *fn)
 Initialize the eventlist file Try to open the file.
int str2time (char *s, double *time)
int strJ2time (char *s, double *time)
void AbortOnTitan1File (char *f, int l)
void EndSuperFrame (void)
 Reset the data buffers for the next superframe This function is called at the end of a time frame sequence The end of the time frame sequence triggers the action to perform with the data.
void ResetTimes (void)
 reset all the time variables
int MergeTriggers (char *cmd)
double DiffTimeT2T1 (struct Titan2TimeType *t1, struct Titan2TimeType *t2, struct Titan2TimeType *td)
 Compute a time difference t2-t1, return the result as a double If td is null, the paramer is simply ignored.
double ADCDelay (struct DigitizerType *digitizer, int ch)
 return the static delay time for the given ADC (digitizer)
double FilterDelayTime (struct DigitizerType *digitizer, struct Titan2SRType *sr, int ch)
 return the delay time for a given frequency
unsigned int FilterChain (struct DigitizerType *digitizer, struct Titan2SRType *sr, int ch)
 return the delay time for a given frequency
int PrimaryChannel (int channel)
int PrintMessages (void)
 shall we print the desync/resync and config change messages ?
int CheckDiffConfig ()
 Issue a message for changing parameters.
void ChangeStreamConfig ()
char * StrFrame (const unsigned char *frame)
 Generate a string representing a frame This function uses a statically allocated buffer.
char * StrTime (struct Titan2TimeType *t)
 Generate a string representing a titan2 time This function uses a statically allocated buffer.
char * StrTimeNS (struct Titan2TimeType *t)
 Generate a string representing a titan2 time without subsecond part This function uses a statically allocated buffer.
int OpenDayDir (const char *path)
 Open a day directory, reads the content and build the file list The list will be used by NextFile().
int OpenDiskDir (const char *path)
 Open a disk directory, reads the content and build the day dir list The list will be used by NextFile().
void FreeDayDir (void)
 free the file list
void FreeDiskDir (void)
 free the dayDir table
FILE * NextFile (void)
 Determine the next file to open In file mode, the iFileInput defines the index of the next file.
void CloseInput (void)
 close the input file
char * ADCName (int id)
 ADC name as a string.
void LogPrint (const char *format,...)
 print a formatted line in the log file, open it if neccessary
void EmergencyExit (void)
 print a warning message and exit
void SetAuxChannel2 (int ch, int32_t val)
void SetAuxChannel1 (int ch, int32_t val)
 the last segment output in case of ts=
void AddTitFrame (const unsigned char *frame)
 process one channel
void AddTriggerData (int i)
void AddSeg2Data (int i)
 process one channel
void AddSegyData (int i)
 process one channel
void AddSacData (int i)
 process one channel
void AddSisData (int i)
 process one channel
void AddAscData (int i)
 process one channel
void AddBinData (int i)
 process one channel
void AddGifData (int channel)
void AddWavData (int channel)
 process one channel
void AddMSeedData (int channel)
 process one channel
void CloseTitFile (void)
 end a tit file
void CloseSeg2File (int channel)
 end a SEG2 channel file The seg2 header is updated according to the previous information structure
void CloseFullSeg2File (void)
void CloseSegyFile (int channel)
 end a SEGY channel file The segy header is updated according to the previous information structure
void CloseSacFile (int channel)
 end a SAC channel file The sac header is updated according to the previous information structure
void CloseSisFile (void)
 end a binary file After closing the file, the image is built and the bin file is removed.
void CloseAscFile (int channel)
 end a ASC channel file The asc header is updated according to the previous information structure
void CloseBinFile (int channel)
 end a BIN channel file The bin header is updated according to the previous information structure
void CloseWavFile (int channel)
 end a WAV channel file The wav header is updated according to the previous information structure
void CloseMSeedFile (int channel)
 process one channel
void CloseGifFile (void)
void ResetInput (void)
 reset the input close any open file, read and write and reset the input definition
int ParseTriggerOptions (char *cmd)
int ParseSeedOptions (char *cmd)
void ReadSize (char *fsize)
 read the file size.siz
void ReadIndex (char *findex)
 read the index file
void CutDataFile (char *fdata)
 read the data file and dump the usefull part
char * MaskToList (int64_t mask)
void SleepIfArm (void)
 sleep 200ms if the second has changed since last call
int ListToMask (char *ins, int64_t *newmask)
 build a 32(24) bit word representing the a channel list.
int DumpTriggerEvents (char *file)
 read the TiggerEvent file and print the content in a human readable form
int ParseOifOptions (char *cmd)
 parse the oif option
int ParseOmniOptions (char *cmd)
void ProcessOIF (char *file)
 dump the HTML file set
void ProcessOMNI (char *sta)
void ProcessOPF (int m, int lower)
 filter and print the OPF input
char * MyGetenv (char *s)
 enhanced getenv
void FlushDataFiles (void)
 close any open output data file
int InitInfoHeader (int ch)
 initialize the channel information header Here the information data are read from HWConfig since it the function opens a new data segment.
double UpdateInfoHeader (int ch)
 update the channel information header This function fetches the information data in oldHWConfig since it is called to close a data segment.
char * time2name (double temps, const char *pref, const char *suf)
char * time2str (double temps)
int __alphasort (const void *_a, const void *_b)
int __scandir (const char *dirname, struct dirent ***ret_namelist, int(*select)(const struct dirent *), int(*compar)(const void *, const void *))

Variables

char forceName [128]
 force the name of the output file (single extraction)
struct HWConfigType HWConfig
 global structure describing the current configuration
struct HWConfigType oldHWConfig
 global structure describing the previous configuration
struct Titan2TimeType correctedTime
 corrected time
struct Titan2TimeType currentTime
 current time
struct Titan2TimeType pulseTime
 last pulse time
struct Titan2TimeType gpsExtTime
 gps external time
struct Titan2TimeType gpsIntTime
 gps internal time
struct EventType event
char currentTag [16]
 current tag
char onlyTag [16]
 only extract data tagged by this tag
struct InfoHeaderType infoHeader [MAX_CHANNEL]
int fileNameOptions
int forceNameOptions
 force the name options
int noWrite
 do not write data files
int noInfo
 do not create info files
int doOffset
 ignore offset frames
int noTimeCorrection
 do not correct from delta
int test0
 test for null data
char tdbName []
 TDB name.
int noCache
 do not output the cache
int scanAll
 force the complete scan of all the input data
int localCache
 process the input as a unique data clock
int prependdaydir
 create files in a JJJ/ direcory
int timeWarning
 number of time warnings
char ARGV0 []
 the program name
char ** ARGV
 copy of argv as global variable
int VERBOSE
 verbose level
int inputMode
 the type of input mode (2: disk, 1: daydir, 0: file list)
char * currentFile
 the current file name beeing processed
char * baseDir
 name of the root input stream
int iFileInput
 if in file mode, this is the index of the filename in argv
int ARGC
 copy of argc as global variable
int64_t printTrigger
 shall we print something (frame counter)
int64_t totalFrameProcessed
 total number of processed frame
time_t beginWindow
 beginning of the time current window
time_t endWindow
 end of the time current window
int cmdLineWindow
 0 if no window is defined in cmdline, 1 if defined, -1 if the window has been processed
int saveShift
 is the time shift requested ?
int extractTit
 extract a tit segment
int extractWav
 convert to wav
int extractGif
 convert to gif
int extractTrig
 extract a trigger list
int extractSegy
 convert to segy
int extractSeg2
 convert to seg2
int extractSac
 convert to sac
int extractSis
 convert to sismalp
int extractAsc
 convert to asc
int extractBin
 convert to bin
int extractMSeed
 convert to mseed
int removeMean
 remove mean (for sismalp only, yet)
int64_t channelMask
 the channels to work on
int64_t auxiliaryMask
 the aux channels to work on
char * streamList
 the stream list to work on
int cutDtOnReset
 should we close the dt file on time reset ?
int pulseFilter
 should we pas the dt through a pulse filter ?
int seedBlockSizePowerOf2
 blocksize for seed: 0=512b 1=1k 2=2k 3=4k
int channelNameNumber
 name the channels using their number, not their name
int overWrite
 overwrite output
int readNdx
int ndx2tl
 convert the index to time list
int ndx2cache
 build a cache based on index
int eduseis
 mode eduseis
int logInfo
 is the log requested ?
int extractingData
 current extraction flag (for printings)
int dataExtracted
 are the data expected extracted ?
int timeSegment
 length of constant length files
int timeList
 time list requested
int minSamplesPerFrame
 minimum number of samples to validate a frame
int seeking
 are we seeking ? (for printings)
int fastSeek
 silently seek
int64_t beginOfFile
 start offset in the input file
int64_t endOfFile
 end offset in the input file
int skipTime
 ignore data before that time (for day gif)
int globalStationChange
 flag indicating that a module has detected a station change
int ignoreDiscontinuity
 ignore time discontinuity (for gif)
char manualStationName [64]
 force the station name
int privateDebug
 private debug, do not use
int preEvent
 pre event for tl
int postEvent
 post event for tl
FILE * titan2File
 the current file beeing processed
int64_t inputOffset
 the current offset in the file
int extracting
 synthetic extraction request


Define Documentation

#define ADD_CHANNEL_CODE   (1<<2)

Definition at line 67 of file common.h.

Referenced by CloseSisFile(), CloseTitFile(), FileName(), OpenFullSeg2(), and TDBInit().

#define ADD_LOCATION_CODE   (1<<0)

options for FileName()

Definition at line 65 of file common.h.

Referenced by FileName(), OpenMSeedChannel(), and TDBInit().

#define ADD_NETWORK_CODE   (1<<1)

Definition at line 66 of file common.h.

Referenced by FileName(), OpenFullSeg2(), OpenMSeedChannel(), and TDBInit().

#define AUTO_CORRECTION   0

Definition at line 48 of file common.h.

Referenced by CorrectTime(), GetApproximatedShift(), and InitInfoHeader().

#define DAY_MODE   1

Definition at line 56 of file common.h.

Referenced by NextFile(), OpenDayDir(), ParseOptions(), and SeekTime().

#define DEFAULT_SERIAL   "XXX.XXXX"

Definition at line 60 of file common.h.

Referenced by CheckDiffConfig(), EndSuperFrame(), InitReader(), and SeekTime().

#define DEFAULT_STATION   "XXX"

Definition at line 59 of file common.h.

Referenced by CheckDiffConfig(), EndSuperFrame(), and InitReader().

#define DISK_MODE   2

Definition at line 57 of file common.h.

Referenced by NextFile(), OpenDiskDir(), ParseOptions(), and SeekTime().

#define EDU_FILE_NAME   (1<<3)

Definition at line 68 of file common.h.

Referenced by FileName(), and ParseOptions().

#define EXTENDED_CORRECTION   3

Definition at line 51 of file common.h.

Referenced by GetInterpolatedShift().

Definition at line 364 of file common.h.

Referenced by EndSuperFrame(), ParseOptions(), and ResetInput().

#define FILE_BUFFER_SIZE   (12*24*1024)

#define FILE_MODE   0

Definition at line 55 of file common.h.

Referenced by NextFile(), and ParseOptions().

#define INIT_PRINT_TRIGGER   ((10<<10)/12)

Definition at line 155 of file common.h.

Referenced by NextFile().

#define INTERPOLATION_CORRECTION   2

Definition at line 50 of file common.h.

Referenced by CloseMSeedInt32File(), CorrectTime(), and GetInterpolatedShift().

#define LAST_PULSE_CORRECTION   1

Definition at line 49 of file common.h.

Referenced by CorrectTime(), and GetApproximatedShift().

#define MY_PI   3.14159265358979323846

Definition at line 45 of file common.h.

Referenced by ProcessInfoFrame(), and ProcessMiscFrame().

#define NO_TIME_CORRECTION   -1

#define NORMAL_PRINT_TRIGGER   ((10<<20)/12)

Definition at line 156 of file common.h.

Referenced by GetFrame().

#define US2S   0.23283064365386962891e-9


Function Documentation

int __alphasort ( const void *  _a,
const void *  _b 
)

Definition at line 25 of file scandir.c.

Referenced by OpenCacheFileRead(), OpenDayDir(), OpenDiskDir(), and TimeFileSort().

int __scandir ( const char *  dirname,
struct dirent ***  ret_namelist,
int(*)(const struct dirent *)  select,
int(*)(const void *, const void *)  compar 
)

void AbortOnTitan1File ( char *  f,
int  l 
)

double ADCDelay ( struct DigitizerType digitizer,
int  ch 
)

return the static delay time for the given ADC (digitizer)

Parameters:
digitizer the digitizer
ch the channel number used for titan1 only
Returns:
the delay time

Definition at line 648 of file time.c.

References DigitizerType::adcDelay, DigitizerType::adcFrequency, Titan2SRType::base, Titan2SRType::div, infoHeader, MAX_OSIRIS_CHANNEL, DigitizerType::ok, PrimaryChannel(), and InfoHeaderType::sr.

Referenced by AddMSeedData(), and CorrectChannelStartTime().

Here is the call graph for this function:

char* ADCName ( int  id  ) 

ADC name as a string.

Parameters:
id the ADC id
Returns:
the ADC name

Definition at line 66 of file frames.c.

References AD7710, ADS1251, CS5321, CS5323, and HI7190.

Referenced by CheckDiffConfig(), and PrintIdentification().

void AddAscData ( int  i  ) 

process one channel

Definition at line 168 of file asc.c.

References AbortAscFile(), ascChannelFile, ascChannelFileName, HWConfigType::data, HWConfig, infoHeader, InfoHeaderType::npts, Titan2SRType::npts, OpenAscChannel(), PrintError, HWConfigType::srExp, and HWConfigType::srObs.

Referenced by EndSuperFrame().

Here is the call graph for this function:

void AddBinData ( int  i  ) 

process one channel

Definition at line 111 of file bin.c.

References AbortBinFile(), binChannelFile, binChannelFileName, HWConfigType::data, HWConfig, infoHeader, InfoHeaderType::npts, Titan2SRType::npts, OpenBinChannel(), PrintError, HWConfigType::srExp, and HWConfigType::srObs.

Referenced by EndSuperFrame().

Here is the call graph for this function:

void AddGifData ( int  channel  ) 

Definition at line 1032 of file gd.c.

References PrintError.

Referenced by EndSuperFrame().

void AddMSeedData ( int  channel  ) 

process one channel

Parameters:
channel the channel to append the sample

Definition at line 850 of file seed.c.

References ADCDelay(), AddMSeedDataInt32(), AddMSeedDataSteim1(), HWConfigType::digitizer, FilterDelayTime(), HWConfig, DigitizerType::ok, seedDataFormat, HWConfigType::srExp, and staticDt.

Referenced by EndSuperFrame().

Here is the call graph for this function:

void AddSacData ( int  channel  ) 

process one channel

Parameters:
channel the channel to process

Definition at line 341 of file sac.c.

References AbortSacFile(), currentFile, currentTime, HWConfigType::data, HWConfig, infoHeader, noWrite, InfoHeaderType::npts, Titan2SRType::npts, OpenSacChannel(), PrintError, PrintLog, privateDebug, sacChannelFile, sacChannelFileName, sacHeader, HWConfigType::srExp, HWConfigType::srObs, StrTime(), test0, and titan2File.

Referenced by EndSuperFrame().

Here is the call graph for this function:

void AddSeg2Data ( int  i  ) 

process one channel

Definition at line 466 of file seg2.c.

References AbortSeg2File(), HWConfigType::data, HWConfig, infoHeader, InfoHeaderType::npts, Titan2SRType::npts, OpenSeg2Channel(), PrintError, seg2ChannelFile, seg2ChannelFileName, HWConfigType::srExp, and HWConfigType::srObs.

Referenced by EndSuperFrame().

Here is the call graph for this function:

void AddSegyData ( int  i  ) 

process one channel

Definition at line 306 of file segy.c.

References AbortSegyFile(), HWConfigType::data, HWConfig, infoHeader, InfoHeaderType::npts, Titan2SRType::npts, OpenSegyChannel(), PrintError, segyChannelFile, segyChannelFileName, HWConfigType::srExp, and HWConfigType::srObs.

Referenced by EndSuperFrame().

Here is the call graph for this function:

void AddSisData ( int  channel  ) 

process one channel

Parameters:
channel the channel to process

Definition at line 101 of file sis.c.

References AbortSisBinFile(), avg, CloseSisFile(), HWConfigType::data, HWConfig, infoHeader, MAX_CHANNEL, ndata, InfoHeaderType::npts, Titan2SRType::npts, OpenSisBinFile(), PrintError, removeMean, sisBinFile, sisBinFileName, HWConfigType::srExp, and HWConfigType::srObs.

Referenced by EndSuperFrame().

Here is the call graph for this function:

void AddTitFrame ( const unsigned char *  frame  ) 

process one channel

Parameters:
frame the frame to dump

Definition at line 88 of file tit.c.

References firstFrame, GPST_FRAME, OpenTitBinFile(), synchro, TIME_FRAME, and titBinFile.

Here is the call graph for this function:

void AddTriggerData ( int  i  ) 

Definition at line 319 of file trigger.c.

References HWConfigType::data, FilterT2K(), hp, HWConfig, lp, lta, Titan2SRType::npts, HWConfigType::srExp, HWConfigType::srObs, sta, trigger, and TriggerOneSample().

Referenced by EndSuperFrame().

Here is the call graph for this function:

void AddWavData ( int  channel  ) 

process one channel

Definition at line 223 of file wav.c.

References HWConfigType::data, HWConfig, infoHeader, InfoHeaderType::npts, Titan2SRType::npts, OpenWavChannel(), HWConfigType::srExp, HWConfigType::srObs, Vavg, Vmax, Vmin, and wavChannelFile.

Referenced by EndSuperFrame().

Here is the call graph for this function:

void CacheCallBack ( void   ) 

Build the cache for the current input.

Definition at line 508 of file cache.c.

References beginWindow, cacheOutput, CachePrintTIME(), currentTime, HWConfig, lastCacheOffset, lastCacheTime, noCache, OpenCacheFileRead(), HWConfigType::serialNumber, totalFrameProcessed, and Titan2TimeType::usecond.

Referenced by ProcessTimeFrame().

Here is the call graph for this function:

void CachePrintCST ( void   ) 

issue a #CST message (continuous segment tag)

Definition at line 478 of file cache.c.

References cacheOutput.

Referenced by EndSuperFrame(), and ProcessTimeFrame().

char* CacheRead ( char *  line  ) 

read a line in the cache file

Parameters:
line the output char buffer
Returns:
the status of fgets

Definition at line 180 of file cache.c.

References cacheFile, and cacheOutput.

Referenced by SeekTime().

void ChangeStreamConfig (  ) 

Definition at line 304 of file frames.c.

References streamChange.

Referenced by CheckContinuity(), and ProcessTimeFrame().

int CheckDiffConfig ( void   )