files.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 "common.h"

Include dependency graph for files.c:

Go to the source code of this file.

Functions

void CloseInput (void)
 close the input file
FILE * InitEventList (const char *fn)
 Initialize the eventlist file Try to open the 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 SequentialSeek (time_t t)
 seek a time using a sequential search in a sorted list (day or daydir)
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.
int TitanFileSelect (const struct dirent *t)
 Select filenames matching the titan2 file pattern: hh.mm.ss.
int DayDirSelect (const struct dirent *t)
 Select filenames matching the titan2 day dir pattern: YYYY.MM.DD.
void FreeDiskDir (void)
 free the dayDir table
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
int OpenDayDir (const char *path)
 Open a day directory, reads the content and build the file list The list will be used by NextFile().
FILE * NextFile (void)
 Determine the next file to open In file mode, the iFileInput defines the index of the next file.
int OpenTempFile (char *template)
 open a temp file for writing as mkstemp would do
int Rename (const char *oldpath, const char *newpath)
 rename a file, also over different filesystem

Variables

int nFiles = 0
int trySeek = -1
struct dirent ** titanList = NULL
 the list of titan files to be processed
int titanListLen = 0
 the number of files in titanList
int titanListIndex = 0
 the index of the next file to read
struct dirent ** dayDir = NULL
 the list of day directory to be processed
int dayDirLen = 0
 the number of day directory in dayDir
int dayDirIndex = 0
 the index of the next directory to open
char fullName [256]
 work buffer for the name of the currently processed file
FILE * eventList = NULL
 event list: tl=
int segmentLength = 0
 segment length: ts=


Function Documentation

void CloseInput ( void   ) 

close the input file

Definition at line 54 of file files.c.

References titan2File.

Referenced by EndSuperFrame(), GetFrame(), NextFile(), and ResetInput().

int DayDirSelect ( const struct dirent *  t  ) 

Select filenames matching the titan2 day dir pattern: YYYY.MM.DD.

Parameters:
t the element to check
Returns:
1 if the dir matches a titan2 dirname, 0 if not

Definition at line 451 of file files.c.

Referenced by OpenDiskDir().

void FreeDayDir ( void   ) 

free the file list

Definition at line 518 of file files.c.

References titanList, and titanListLen.

Referenced by OpenDayDir(), and ResetInput().

void FreeDiskDir ( void   ) 

free the dayDir table

Definition at line 478 of file files.c.

References dayDir, and dayDirLen.

Referenced by OpenDiskDir(), and ResetInput().

FILE* InitEventList ( const char *  fn  ) 

Initialize the eventlist file Try to open the file.

If it is not possible, just let eventList=NULL

Parameters:
fn the file name
Returns:
eventList, just to detect an error

Definition at line 67 of file files.c.

References eventList, and PrintError.

Referenced by ParseOptions().

FILE* NextFile ( void   ) 

Determine the next file to open In file mode, the iFileInput defines the index of the next file.

After opening the file, iFileInput is increased by 1. In daydir mode, the iFileInput defines the index whithin the day directory and we stop if the iFileInput points after the last file. In disk mode, iFileInput defines the index whithin the day directory. If iFileInput points after the last file, the next daydir is processed. If the current daydir was the last one, we stop.

Returns:
a pointer to FILE* on success, NULL on error (or end of data)

Definition at line 563 of file files.c.

References ARGC, ARGV, baseDir, beginOfFile, CloseInput(), correctedTime, currentFile, DAY_MODE, dayDir, dayDirIndex, dayDirLen, DISK_MODE, endWindow, FILE_BUFFER_SIZE, FILE_MODE, FlushDataFiles(), fullName, iFileInput, INIT_PRINT_TRIGGER, inputMode, inputOffset, nFiles, OpenDayDir(), PrintDebug, PrintError, printTrigger, scanAll, titanList, titanListIndex, titanListLen, totalFrameProcessed, and Titan2TimeType::usecond.

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

Here is the call graph for this function:

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.

..). The global variables windowBegin and windowEnd are set accordingly and the begin time is returned.

Returns:
the begin time, -1 if no more window is requested

Definition at line 86 of file files.c.

References beginWindow, cmdLineWindow, endWindow, eventList, postEvent, preEvent, PrintError, PrintLog, str2time(), time2str(), timeSegment, and trySeek.

Referenced by EndSuperFrame(), and main().

Here is the call graph for this function:

int OpenDayDir ( const char *  path  ) 

Open a day directory, reads the content and build the file list The list will be used by NextFile().

Parameters:
path the directory to read
Returns:
the number of entries

Definition at line 537 of file files.c.

References __alphasort(), __scandir(), baseDir, DAY_MODE, FreeDayDir(), inputMode, TitanFileSelect(), titanList, titanListIndex, and titanListLen.

Referenced by NextFile(), and ParseOptions().

Here is the call graph for this function:

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().

Parameters:
path the directory to read
Returns:
the number of entries

Definition at line 497 of file files.c.

References __alphasort(), __scandir(), baseDir, dayDir, dayDirIndex, dayDirLen, DayDirSelect(), DISK_MODE, FreeDiskDir(), and inputMode.

Referenced by ParseOptions().

Here is the call graph for this function:

int OpenTempFile ( char *  template  ) 

open a temp file for writing as mkstemp would do

Parameters:
template the same argument as mkstemp
Returns:
a file descriptor

Definition at line 701 of file files.c.

Referenced by OpenAscChannel(), OpenBinChannel(), OpenCacheFileWrite(), OpenMSeedChannel(), OpenSacChannel(), OpenSeg2Channel(), OpenSegyChannel(), OpenSisBinFile(), OpenTimeFile(), OpenTitBinFile(), and OpenWavChannel().

int Rename ( const char *  oldpath,
const char *  newpath 
)

rename a file, also over different filesystem

Parameters:
oldpath the source
newfile the destination
Returns:
0 on success, -1 on error

Definition at line 721 of file files.c.

References PrintError, and SendFile().

Referenced by CheckAlerts(), CloseAscFile(), CloseBinFile(), CloseCacheFile(), CloseMSeedInt32File(), CloseSacFile(), CloseSeg2File(), CloseSegyFile(), CloseTimeFile(), CloseTitFile(), CloseWavFile(), DumpGpsMap(), and DumpTile().

Here is the call graph for this function:

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.

Returns:
0 if OK, -1 on error
Parameters:
t the file to seek to

ce test doit-il rester ???

Definition at line 268 of file files.c.

References beginWindow, CacheRead(), correctedTime, currentFile, DAY_MODE, DEFAULT_SERIAL, DISK_MODE, HWConfig, inputMode, NextFile(), OpenCacheFileRead(), PrintDebug, PrintLog, printTrigger, RewindCache(), seeking, SequentialSeek(), HWConfigType::serialNumber, time2str(), titan2File, trySeek, and Titan2TimeType::usecond.

Referenced by ProcessTimeFrame().

Here is the call graph for this function:

int SequentialSeek ( time_t  t  ) 

seek a time using a sequential search in a sorted list (day or daydir)

Definition at line 186 of file files.c.

References correctedTime, currentFile, fastSeek, GetFrame(), NextFile(), PrintDebug, PrintError, printTrigger, seeking, str2time(), titan2File, and Titan2TimeType::usecond.

Referenced by SeekTime().

Here is the call graph for this function:

int TitanFileSelect ( const struct dirent *  t  ) 

Select filenames matching the titan2 file pattern: hh.mm.ss.

Parameters:
t the element to check
Returns:
1 if the file matches a titan2 filename, 0 if not

Definition at line 421 of file files.c.

Referenced by OpenDayDir().


Variable Documentation

struct dirent** dayDir = NULL

the list of day directory to be processed

Definition at line 45 of file files.c.

Referenced by FreeDiskDir(), NextFile(), and OpenDiskDir().

int dayDirIndex = 0

the index of the next directory to open

Definition at line 47 of file files.c.

Referenced by NextFile(), and OpenDiskDir().

int dayDirLen = 0

the number of day directory in dayDir

Definition at line 46 of file files.c.

Referenced by FreeDiskDir(), NextFile(), and OpenDiskDir().

FILE* eventList = NULL

event list: tl=

Definition at line 50 of file files.c.

Referenced by InitEventList(), and NextWindow().

char fullName[256]

work buffer for the name of the currently processed file

Definition at line 48 of file files.c.

Referenced by NextFile().

int nFiles = 0

Definition at line 39 of file files.c.

Referenced by NextFile().

int segmentLength = 0

segment length: ts=

Definition at line 51 of file files.c.

struct dirent** titanList = NULL

the list of titan files to be processed

Definition at line 42 of file files.c.

Referenced by FreeDayDir(), NextFile(), and OpenDayDir().

int titanListIndex = 0

the index of the next file to read

Definition at line 44 of file files.c.

Referenced by NextFile(), and OpenDayDir().

int titanListLen = 0

the number of files in titanList

Definition at line 43 of file files.c.

Referenced by FreeDayDir(), NextFile(), and OpenDayDir().

int trySeek = -1

Definition at line 41 of file files.c.

Referenced by NextWindow(), and SeekTime().


Generated on Tue Jul 22 23:11:56 2008 for Titan2Reader by  doxygen 1.5.6