main.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <math.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "common.h"
#include "howto.c"
#include "usage.c"
#include "logdoc.c"
#include "tdbdoc.c"

Include dependency graph for main.c:

Go to the source code of this file.

Defines

#define FILE_MODE   0
#define DAY_MODE   1
#define DISK_MODE   2

Functions

void howto (void)
 for use in SleepIfArm
void usage (void)
void logdoc (void)
void tdbdoc (void)
void SleepIfArm (void)
 sleep 200ms if the second has changed since last call
char * MyGetenv (char *s)
 enhanced getenv
void version (int rel)
 Print the version.
void copyright (void)
 Print the copyright.
int PrintMessages (void)
 shall we print the desync/resync and config change messages ?
int ListToMask (char *ins, int64_t *newmask)
 build a 32(24) bit word representing the a channel list.
int ParseEvent (char *evt)
 Parse the event description string: YYYY.MM.DD.hh.mm.ss.sss,lat,long,dep.
int ParseOptions (int argc, char **argv)
 Parse the command line options.
int GetFrame (void)
 Read the next frame.
void MainCleanUp (int sig)
 Cleanup function This function should remove the open cache file.
void EmergencyExit (void)
 print a warning message and exit
void InitReader (void)
 perform preliminary initialisations
void ResetInput (void)
 reset the input close any open file, read and write and reset the input definition
int main (int argc, char **argv)

Variables

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


Define Documentation

#define DAY_MODE   1

Definition at line 49 of file main.c.

#define DISK_MODE   2

Definition at line 50 of file main.c.

#define FILE_MODE   0

Definition at line 48 of file main.c.


Function Documentation

void copyright ( void   ) 

Print the copyright.

Definition at line 255 of file main.c.

References PROGRAMNAME.

Referenced by ParseOptions().

void EmergencyExit ( void   ) 

print a warning message and exit

Definition at line 1679 of file main.c.

References PrintError.

Referenced by UpdateInfoHeader().

int GetFrame ( void   ) 

Read the next frame.

If the end of file is reached, the next file is selected. This function is the top analysis function. After reading each frame, the frame parser is called and the frame parser will in turn call the appropriate callback for the actions to be performed (extraction, log etc.).

Returns:
<0 if we found some sync, 1 if not (<0 on error, if any ?)

Definition at line 1515 of file main.c.

References CloseInput(), endOfFile, fastSeek, inputOffset, NextFile(), NORMAL_PRINT_TRIGGER, PrintDebug, PrintLog, printTrigger, StrFrame(), StrTimeNS(), titan2File, totalFrameProcessed, and Titan2TimeType::usecond.

Referenced by main(), and SequentialSeek().

Here is the call graph for this function:

void howto ( void   ) 

for use in SleepIfArm

Definition at line 188 of file main.c.

Referenced by ParseOptions().

void InitReader ( void   ) 

int ListToMask ( char *  ins,
int64_t *  newmask 
)

build a 32(24) bit word representing the a channel list.

Parameters:
ins the channel list
newmask the integer representing the mask
Returns:
-1 on error, 0 if ok

Definition at line 293 of file main.c.

References MAX_OSIRIS_CHANNEL, and PrintError.

Referenced by ParseOptions(), and ReadInputParameters().

void logdoc ( void   ) 

Definition at line 198 of file main.c.

Referenced by ParseOptions().

int main ( int  argc,
char **  argv 
)

Definition at line 1766 of file main.c.

References EndSuperFrame(), FlushDataFiles(), FlushNonDataFiles(), GetFrame(), InitCache(), InitReader(), MainCleanUp(), NextWindow(), ParseOptions(), ResetInput(), and startClock.

Here is the call graph for this function:

void MainCleanUp ( int  sig  ) 

Cleanup function This function should remove the open cache file.

Definition at line 1638 of file main.c.

References CloseCacheFile(), FlushDataFiles(), FlushNonDataFiles(), PrintLog, PrintWarning, startClock, timeWarning, and totalFrameProcessed.

Referenced by InitReader(), and main().

Here is the call graph for this function:

char* MyGetenv ( char *  s  ) 

enhanced getenv

Parameters:
s name
Returns:
NULL if the name is not defined or of null length

Definition at line 223 of file main.c.

Referenced by TDBInit().

int ParseEvent ( char *  evt  ) 

Parse the event description string: YYYY.MM.DD.hh.mm.ss.sss,lat,long,dep.

Definition at line 423 of file main.c.

References EventType::dep, EventType::lat, EventType::lon, EventType::OT, PrintError, PrintLog, str2time(), and time2str().

Referenced by ParseOptions().

Here is the call graph for this function:

int ParseOptions ( int  argc,
char **  argv 
)

Parse the command line options.

Parameters:
argc the number of arguments
argv the argv pointer, as received by main()
Returns:
0 if ok, <0 on error

Definition at line 457 of file main.c.

References ARGC, ARGV, ARGV0, auxiliaryMask, beginOfFile, beginWindow, channelMask, channelNameNumber, cmdLineWindow, copyright(), CutDataFile(), cutDtOnReset, DAY_MODE, DISK_MODE, doOffset, DumpTriggerEvents(), EDU_FILE_NAME, endOfFile, endWindow, extractAsc, extractBin, extractGif, Extracting, extracting, extractMSeed, extractSac, extractSeg2, extractSegy, extractSis, extractTit, extractTrig, extractWav, FILE_MODE, fileNameOptions, forceName, forceNameOptions, howto(), iFileInput, ignoreDiscontinuity, InitEventList(), inputChannelMask, inputMode, ListToMask(), localCache, logdoc(), logInfo, manualStationName, MergeTriggers(), minSamplesPerFrame, noCache, noInfo, noTimeCorrection, noWrite, onlyTag, OpenCacheFileRead(), OpenDayDir(), OpenDiskDir(), overWrite, ParseEvent(), ParseImageOptions(), ParseOifOptions(), ParseOmniOptions(), ParseSeedOptions(), ParseTriggerOptions(), postEvent, preEvent, prependdaydir, PrintError, PrintWarning, privateDebug, ProcessOIF(), ProcessOMNI(), ProcessOPF(), PROGRAMNAME, pulseFilter, PulseFilter(), ReadIndex(), ReadOIF(), ReadSize(), removeMean, saveShift, scanAll, skipTime, str2time(), streamList, strJ2time(), tdbdoc(), TDBInit(), tdbName, timeList, timeSegment, usage(), VERBOSE, and version().

Referenced by main(), and ResetInput().

Here is the call graph for this function:

int PrintMessages ( void   ) 

shall we print the desync/resync and config change messages ?

Definition at line 276 of file main.c.

References extractingData, inputOffset, seeking, and VERBOSE.

Referenced by CheckContinuity().

void ResetInput ( void   ) 

reset the input close any open file, read and write and reset the input definition

Definition at line 1730 of file main.c.

References ARGC, ARGV, beginWindow, CloseInput(), dataExtracted, endWindow, Extracting, extractingData, FreeDayDir(), FreeDiskDir(), ParseOptions(), PrintDebug, PrintLog, ResetTimes(), syncWarn, and time2str().

Referenced by main().

Here is the call graph for this function:

void SleepIfArm ( void   ) 

sleep 200ms if the second has changed since last call

Definition at line 209 of file main.c.

References timeCounterSleepIfArm.

void tdbdoc ( void   ) 

Definition at line 203 of file main.c.

Referenced by ParseOptions().

void usage ( void   ) 

Definition at line 193 of file main.c.

Referenced by ParseOptions().

void version ( int  rel  ) 

Print the version.

Parameters:
rel print the release number only if 1

Definition at line 233 of file main.c.

References MAJOR, MINOR, PROGRAMNAME, and VERSION.

Referenced by ParseOptions().


Variable Documentation

int ARGC

copy of argc as global variable

Definition at line 110 of file main.c.

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

char** ARGV = NULL

copy of argv as global variable

Definition at line 108 of file main.c.

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

char ARGV0[128]

the program name

Definition at line 106 of file main.c.

Referenced by __printerror(), __printlog(), __printwarning(), badarg(), badargnum(), and ParseOptions().

int64_t auxiliaryMask = 0x00000000LL

the aux channels to work on

Definition at line 121 of file main.c.

Referenced by EndSuperFrame(), ParseOptions(), ProcessAux1Frame(), and ProcessDataFrame().

char* baseDir = NULL

name of the root input stream

Definition at line 118 of file main.c.

Referenced by NextFile(), OpenCacheFileWrite(), OpenDayDir(), and OpenDiskDir().

int64_t beginOfFile = -1

start offset in the input file

Definition at line 178 of file main.c.

Referenced by NextFile(), and ParseOptions().

time_t beginWindow = -1

beginning of the time current window

Definition at line 172 of file main.c.

Referenced by CacheCallBack(), EndSuperFrame(), FileName(), InitInfoHeader(), InWindow(), NextWindow(), ParseOptions(), ProcessTimeFrame(), ResetInput(), SeekTime(), and UpdateInfoHeader().

int64_t channelMask = 0x00ffffffLL

the channels to work on

Definition at line 122 of file main.c.

Referenced by CheckDiffConfig(), EndSuperFrame(), ParseOptions(), and ProcessDataFrame().

name the channels using their number, not their name

Definition at line 168 of file main.c.

Referenced by FileName(), and ParseOptions().

int cmdLineWindow = 0

0 if no window is defined in cmdline, 1 if defined, -1 if the window has been processed

Definition at line 174 of file main.c.

Referenced by NextWindow(), and ParseOptions().

struct Titan2TimeType correctedTime = { 0, 0 }

char* currentFile = NULL

char currentTag[16]

current tag

Definition at line 60 of file main.c.

Referenced by EndSuperFrame(), InWindow(), and ProcessMiscFrame().

struct Titan2TimeType currentTime = { 0, 0 }

int cutDtOnReset = 1

should we close the dt file on time reset ?

Definition at line 142 of file main.c.

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

int dataExtracted = 0

are the data expected extracted ?

Definition at line 138 of file main.c.

Referenced by EndSuperFrame(), and ResetInput().

int doOffset = 1

ignore offset frames

Definition at line 100 of file main.c.

Referenced by ParseOptions(), and ProcessOffsetFrame().

int eduseis = 0

mode eduseis

Definition at line 92 of file main.c.

int64_t endOfFile = -1

end offset in the input file

Definition at line 179 of file main.c.

Referenced by GetFrame(), and ParseOptions().

time_t endWindow = -1

end of the time current window

Definition at line 173 of file main.c.

Referenced by EndSuperFrame(), InWindow(), NextFile(), NextWindow(), ParseOptions(), ProcessTimeFrame(), and ResetInput().

struct EventType event = { -12345.0, -12345.0, -12345.0, -1.0 }

Definition at line 166 of file main.c.

int extractAsc = 0

convert to asc

Definition at line 133 of file main.c.

Referenced by EndSuperFrame(), and ParseOptions().

int extractBin = 0

convert to bin

Definition at line 134 of file main.c.

Referenced by EndSuperFrame(), and ParseOptions().

int extractGif = 0

convert to gif

Definition at line 128 of file main.c.

Referenced by EndSuperFrame(), and ParseOptions().

int extracting = 0

synthetic extraction request

Definition at line 139 of file main.c.

Referenced by ParseOptions(), and ProcessDataFrame().

int extractingData = 0

current extraction flag (for printings)

Definition at line 136 of file main.c.

Referenced by CheckContinuity(), CorrectTime(), EndSuperFrame(), PrintMessages(), and ResetInput().

int extractMSeed = 0

convert to mseed

Definition at line 135 of file main.c.

Referenced by EndSuperFrame(), and ParseOptions().

int extractSac = 0

convert to sac

Definition at line 131 of file main.c.

Referenced by EndSuperFrame(), and ParseOptions().

int extractSeg2 = 0

convert to seg2

Definition at line 130 of file main.c.

Referenced by EndSuperFrame(), and ParseOptions().

int extractSegy = 0

convert to segy

Definition at line 129 of file main.c.

Referenced by EndSuperFrame(), and ParseOptions().

int extractSis = 0

convert to sismalp

Definition at line 132 of file main.c.

Referenced by EndSuperFrame(), and ParseOptions().

int extractTit = 0

extract a tit segment

Definition at line 126 of file main.c.

Referenced by EndSuperFrame(), InitInfoHeader(), InWindow(), ParseOptions(), and UpdateInfoHeader().

int extractTrig = 0

extract a trigger list

Definition at line 125 of file main.c.

Referenced by EndSuperFrame(), and ParseOptions().

int extractWav = 0

convert to wav

Definition at line 127 of file main.c.

Referenced by EndSuperFrame(), and ParseOptions().

int fastSeek = 0

silently seek

Definition at line 141 of file main.c.

Referenced by CheckDiffConfig(), GetFrame(), and SequentialSeek().

char forceName[128] = ""

force the name of the output file (single extraction)

Definition at line 155 of file main.c.

Referenced by FileName(), and ParseOptions().

int forceNameOptions = -1

force the name options

Definition at line 56 of file main.c.

Referenced by FileName(), and ParseOptions().

flag indicating that a module has detected a station change

Definition at line 182 of file main.c.

Referenced by CheckDiffConfig(), and ProcessTimeFrame().

struct Titan2TimeType gpsExtTime = { 0, 0 }

gps external time

Definition at line 163 of file main.c.

Referenced by ProcessTimeFrame(), and ResetTimes().

struct Titan2TimeType gpsIntTime = { 0, 0 }

gps internal time

Definition at line 164 of file main.c.

Referenced by ProcessTimeFrame(), and ResetTimes().

int iFileInput = 0

if in file mode, this is the index of the filename in argv

Definition at line 116 of file main.c.

Referenced by NextFile(), and ParseOptions().

ignore time discontinuity (for gif)

Definition at line 151 of file main.c.

Referenced by CheckContinuity(), and ParseOptions().

int64_t inputChannelMask = 0x00ffffffLL

the channels to work on, as asked

Definition at line 123 of file main.c.

Referenced by ParseOptions().

int inputMode

the type of input mode (2: disk, 1: daydir, 0: file list)

Definition at line 114 of file main.c.

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

int64_t inputOffset = 0

the current offset in the file

Definition at line 77 of file main.c.

Referenced by GetFrame(), NextFile(), PrintMessages(), and TriggerOneSample().

unsigned char lastSync = 0

the last synchronization character (nibble: 0x50 or 0xa0)

Definition at line 71 of file main.c.

int localCache = 0

process the input as a unique data clock

Definition at line 144 of file main.c.

Referenced by CloseCacheFile(), OpenCacheFileRead(), OpenCacheFileWrite(), and ParseOptions().

int logInfo = 0

is the log requested ?

Definition at line 112 of file main.c.

Referenced by CheckDiffConfig(), LogPrint(), and ParseOptions().

char manualStationName[64] = ""

force the station name

Definition at line 184 of file main.c.

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

minimum number of samples to validate a frame

Definition at line 58 of file main.c.

Referenced by EndSuperFrame(), and ParseOptions().

int ndx2cache = 0

build a cache based on index

Definition at line 158 of file main.c.

Referenced by ReadIndex().

int ndx2tl = 0

convert the index to time list

Definition at line 157 of file main.c.

Referenced by ReadIndex().

int noCache = 0

do not output the cache

Definition at line 176 of file main.c.

Referenced by CacheCallBack(), CachePrint(), InitCache(), and ParseOptions().

int noInfo = 0

do not create info files

Definition at line 98 of file main.c.

Referenced by ParseOptions(), and UpdateInfoHeader().

do not correct from delta

Definition at line 102 of file main.c.

Referenced by CorrectChannelStartTime(), ParseOptions(), and UpdateInfoHeader().

int noWrite = 0

char onlyTag[16]

only extract data tagged by this tag

Definition at line 61 of file main.c.

Referenced by EndSuperFrame(), InWindow(),