/* ***************************************************************************
********** FrameL.h **************************** FrameL.h ********************
********** FrameL.h **************************** FrameL.h ********************
*************************************************************************** */
/*  by B.Mours LAPP (Annecy); October 22, 2002*/
#if !defined(FRAMELIB_DEFINED)
#define FRAMELIB_DEFINED

#define FRAMELIB_VERSION  6.02
#define FR_VERS           6002
#define FRPI              3.14159265358979
#define FRTWOPI           6.2831853071795864769

#ifdef __cplusplus
extern "C" {
#endif

#include <time.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "FrIO.h"

#if CHAR_MAX == 127
#define FRSCHAR char
#else
#define FRSCHAR signed char     
#endif

typedef enum  {FR_NO, FR_YES} FRBOOL;  /*this set FR_NO=0, FR_YES=1 */

typedef  enum {FRNATIVE,
               FRSWAP,
               FRCONTRACT,
               FREXPAND,
               FRCONTRACT_AND_SWAP,
               FREXPAND_AND_SWAP} FRFORMAT;

typedef  enum {FRTSADC,
               FRTSSIM,
               FRTSPROC} FRTSTYPE;

typedef enum {FR_OK,
              FR_ERROR_NO_FRAME,
              FR_ERROR_NO_FILE,
              FR_ERROR_MALLOC_FAILED,
              FR_ERROR_BUFF_OVERFLOW,
              FR_ERROR_WRITE_ERROR,
              FR_ERROR_READ_ERROR,
              FR_ERROR_FRSET,
              FR_ERROR_BAD_END_OF_FRAME,
              FR_ERROR_OPEN_ERROR,
              FR_ERROR_CHECKSUM} FRERROR;

typedef unsigned short  FRVECTTYPES; 
             
enum     {FR_VECT_C,     /* vector of char                           */
          FR_VECT_2S,    /* vector of short                          */
          FR_VECT_8R,    /* vector of double                         */
          FR_VECT_4R,    /* vector of float                          */
          FR_VECT_4S,    /* vector of int                            */
          FR_VECT_8S,    /* vector of long                           */
          FR_VECT_8C,    /* vector of complex float                  */
          FR_VECT_16C,   /* vector of complex double                 */
          FR_VECT_STRING,/* vector of string                         */
          FR_VECT_2U,    /* vector of unsigned short                 */
          FR_VECT_4U,    /* vector of unsigned int                   */
          FR_VECT_8U,    /* vector of unsigned long                  */
          FR_VECT_1U,    /* vector of unsigned char                  */
          FR_VECT_8H,    /* halfcomplex vectors (float) (FFTW order) */
          FR_VECT_16H,   /* halfcomplex vectors (double)(FFTW order) */
          FR_VECT_END};  /* vector of unsigned char                  */

#define FR_VECT_C8  FR_VECT_8C
#define FR_VECT_C16 FR_VECT_16C
#define FR_VECT_H8  FR_VECT_8H
#define FR_VECT_H16 FR_VECT_16H
#define FRMAPMAXSH 100
#define FRMAPMAXREF 4
#define FRMAPMAXINSTANCE 500
/*--------------------------- time define ----------------------------------*/
#define FRGPSOFF 315964800
#define FRGPSDELTA     13
#define FRGPSTAI    19
#define FRGPSLEAPS (19+13)
/* Just some rules about time .......                                       */
/* the GPS time origin is Sun Jan  6 00:00:00 1980                          */
/* the C function time origin is Jan 1 00:00:00 1970 (no leap seconds)      */
/*       (C time - GPS time = 3600*24*3567 = 315964800 seconds)             */
/*  TAI is ahead of GPS by 19 seconds                                       */
/*  TAI is ahead of UTC by 32 seconds (July 2001)                           */
 /*---- GPS time = UTC - 3600*24*3657 + delta ------------------------------*/
/*from 1997 01 Jul, UTC to 1999 01 January, UTC:  delta = +12s              */
/*from 1999 01 Jan, UTC until further notice:     delta = +13s              */
/*See http://tycho.usno.navy.mil/time.html or http://hpiers.obspm.fr/eop-pc */
/*--------------------------------------------------------------------------*/

struct FrameH;
struct FrAdcData;
struct FrBasic;
struct FrDetector;
struct FrEndOfFrame;
struct FrEndOfFile;
struct FrEvent;
struct FrMsg;
struct FrFile;
struct FrFileH;
struct FrHistory;
struct FrObject;
struct FrRawData;
struct FrProcData;
struct FrSE;
struct FrSH;
struct FrSimData;
struct FrSerData;
struct FrStatData;
struct FrSummary;
struct FrSimEvent;
struct FrTable;
struct FrTag;
struct FrTOC;
struct FrTOCdet;
struct FrTOCevt;
struct FrTOCstat;
struct FrTOCts;
struct FrTOCtsH;
struct FrVect;

typedef struct FrAdcData    FrAdcData;
typedef struct FrameH       FrameH;
typedef struct FrBasic      FrBasic;
typedef struct FrCList      FrCList;
typedef struct FrDetector   FrDetector;
typedef struct FrEndOfFrame FrEndOfFrame;
typedef struct FrEndOfFile  FrEndOfFile;
typedef struct FrEvent      FrEvent;
typedef struct FrMsg        FrMsg;
typedef struct FrFile       FrFile;
typedef struct FrFileH      FrFileH;
typedef struct FrHistory    FrHistory;
typedef struct FrProcData   FrProcData;
typedef struct FrRawData    FrRawData;
typedef struct FrSerData    FrSerData;
typedef struct FrSE         FrSE;
typedef struct FrSH         FrSH;
typedef struct FrSimData    FrSimData;
typedef struct FrSimEvent   FrSimEvent;
typedef struct FrStatData   FrStatData;
typedef struct FrSummary    FrSummary;
typedef struct FrTable      FrTable;
typedef struct FrTag        FrTag;
typedef struct FrTOC        FrTOC;  
typedef struct FrTOCdet     FrTOCdet;
typedef struct FrTOCevt     FrTOCevt;
typedef struct FrTOCstat   FrTOCstat;
typedef struct FrTOCts      FrTOCts;
typedef struct FrTOCtsH     FrTOCtsH;
typedef struct FrVect       FrVect;

/*---------------------------------------------------------------------------*/
struct FrameH {              /* Frame header structure                       */
  FrSH *classe;              /* class information (internal structure)       */
  char *name;                /* frame name (experiment name)                 */
  int   run;                 /* run number                                   */
  unsigned int frame;        /* frame number                                 */
  unsigned int dataQuality;  /* data quality word                            */
  unsigned int GTimeS;       /* frame starting Time(GPS:s.since 6/1/80)      */
  unsigned int GTimeN;       /* frame starting Time(nsec modulo 1 sec)       */
  unsigned short ULeapS;     /* leap seconds between GPS and UTC             */
  double dt;                 /* frame length (sec)                           */
  FrVect *type;              /* Array used to store general info like trigger*/
                             /* type. Their meaning will  be define later.   */
  FrVect *user;              /*    Array used to store user data             */
  FrDetector *detectSim;     /* detector used for simulation                 */
  FrDetector *detectProc;    /* detector used for reconstruction             */
                             /* (reconstruction = off line processing)       */
  FrHistory  *history;       /* pointer to the history bank                  */
  FrRawData  *rawData;       /* pointer to the raw data structure            */
  FrProcData *procData;      /* pointer to the reconstructed data            */
  FrSimData  *simData;       /* pointer to the simulated data buffers        */
  FrEvent    *event;         /* pointer to the first event structure         */
  FrSimEvent *simEvent;      /* pointer to the simulated events              */
  FrSummary  *summaryData;   /* pointer to statistical summary data          */
  FrVect     *auxData;       /* pointer to the auxiliary data                */
  FrTable    *auxTable;      /* pointer to the auxiliary table               */
                             /* ------ end_of_SIO parameters ----------------*/
  FrProcData *procDataOld;   /* pointer to the proc data        (used by tag)*/
  FrSimData  *simDataOld;    /* pointer to the simulated data   (used by tag)*/
  FrEvent    *eventOld;      /* pointer to the event data       (used by tag)*/
  FrSummary  *summaryDataOld;/* pointer to statistical summary  (used by tag)*/
};

void    FrameCompress   (FrameH *frame, int compress, int gzipLevel);
FrameH *FrameCopy       (FrameH *frame);
void    FrameDump       (FrameH *frame, FILE *fp, int debugLvl);
char   *FrameDumpToBuf  (FrameH *frame, int dbgLvl, char *buf, FRLONG bufSize);
void    FrameExpand     (FrameH *frame);
void    FrameFree       (FrameH *frame);
int     FrameGetLTOffset(FrameH *frame, char *channelName);
FrVect *FrameGetV       (FrameH *frame, char *name);
void    FrameMerge      (FrameH *frame1, FrameH *frame2);
FrameH *FrameNew   (char *name);
FrameH *FrameRead       (FrFile *iFile);
FrameH *FrameReadN      (FrFile *iFile, int rNumber, int fNumber);
FrameH *FrameReadRecycle(FrFile *iFile, FrameH *frame);
FrameH *FrameReadT      (FrFile *iFile, double gtime);
FrameH *FrameReadTAdc   (FrFile *iFile, double gtime, char *tag);
FrameH *FrameReadTChnl  (FrFile *iFile, double gtime, char *tag);
FrameH *FrameReadTProc  (FrFile *iFile, double gtime, char *tag);
FrameH *FrameReadTSer   (FrFile *iFile, double gtime, char *tag);
FrameH *FrameReadTSim   (FrFile *iFile, double gtime, char *tag);
FrameH *FrameReadFromBuf(char *buf, FRLONG nBytes, int comp);
void    FrameRemoveUntaggedData(FrameH *frame);
int     FrameReshapeAdd(FrameH *frame1, FrameH *frame2);
int     FrameReshapeEnd(FrameH *frame);
FrameH *FrameReshapeNew(FrameH *frame, int nFrame, int position);
int     FrameStat    (FrameH *frame, FILE *fp);
void    FrameTag     (FrameH *frame, char *tag);
void    FrameTagAdc  (FrameH *frame, char *tag);
void    FrameTagBasic(FrBasic**root, FrBasic**rootOld,char *tag);
void    FrameTagEvent(FrameH *frame, char *tag);
void    FrameTagProc (FrameH *frame, char *tag);
void    FrameTagSer  (FrameH *frame, char *tag);
void    FrameTagSim  (FrameH *frame, char *tag);
void    FrameTagSum  (FrameH *frame, char *tag);
void    FrameUntag   (FrameH *frame);
void    FrameUntagAdc(FrameH *frame);
void    FrameUntagBasic(FrBasic **root, FrBasic **rootOld);
void    FrameUntagEvent(FrameH *frame);
void    FrameUntagProc (FrameH *frame);
void    FrameUntagSer  (FrameH *frame);
void    FrameUntagSim  (FrameH *frame);
void    FrameUntagSum  (FrameH *frame);
int     FrameWrite     (FrameH *frame, FrFile *oFile);
FRLONG  FrameWriteToBuf(FrameH *frame, int comp, char *buf, FRLONG nBytes);
/*---------------------------------------------------------------------------*/
FrameH *FrameHCopy(FrameH *in);
FrSH   *FrameHDef();    
FrameH *FrameHRead (FrFile *iFile);
FrameH *FrameHReadN(FrFile *iFile,int rNumber, int fNumber);
FrameH *FrameHReadT(FrFile *iFile,double gtime);
FrameH *FrameHNew(char *name);
void    FrameHWrite(FrameH *frameH, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrAdcData {               /* hold ADC data (or image)                 */
  FrSH *classe;                  /* class information (internal structure)   */
  char   *name;                  /* signal name                              */
  FrVect *data;                  /* array of data                            */
  FrVect *aux;                   /* array of auxiliary data if needed.       */
  FrAdcData *next;               /* next adc structure                       */
  FrAdcData *nextOld;            /* used by the tag/untag functions          */
                                 /*------- enf of the FrBasic structure------*/
  char   *comment;               /* signal description;  Adc units are 
                                      stored in adc->data->unit[0]           */
  unsigned int channelGroup;     /* crate number                             */
  unsigned int channelNumber;    /* channel number within a crate            */
  unsigned int nBits;            /* number of bits                           */
  float bias;                    /* DC bias on channel.  the step 
                                     size is stored in adc->data->dx;        */
  float slope;                   /* ADC calibration: input units/count       */
  char *units;                   /* ADC calibration: input units for slope   */
  double sampleRate;             /* sampling frequency (unit = Hz)           */
  double timeOffset;             /* offset from the frame starting time (sec)*/
  double fShift;                 /* frequency shift if the signal was 
                                         heterodyne (Hz) (0->no shift)       */
  float  phase;                  /* phase of heterodyning signal.            */
  unsigned short dataValid;      /* flag used to specify if the ADC input was 
                                   out of range (0=ok) during this frame     */
}; 

FrAdcData *FrAdcDataCopy(FrAdcData *adc, FrameH *frame);
int        FrAdcDataDecimate(FrAdcData *adc, int nGroup);
FrSH      *FrAdcDataDef();
void       FrAdcDataDump(FrAdcData *adc, FILE *fp, int debugLvl);
FrAdcData *FrAdcDataFind(FrameH *frame, char *adcName); 
void       FrAdcDataFree(FrAdcData *adc);
FrVect    *FrAdcDataGetV(FrameH *frame,  char *adcName);
FrAdcData *FrAdcDataNew (FrameH *frame, char *name, 
                         double sampleRate, FRLONG nData, int nBits);
FrAdcData *FrAdcDataNewF(FrameH *frame, char *name,char *comment,
                 unsigned int channelGroup, unsigned int channelNumber, 
                 int nBits, float bias, float slope, char *units,
		 double sampleRate, FRLONG nData);
FrAdcData *FrAdcDataRead (FrFile *iFile);
FrAdcData *FrAdcDataReadT(FrFile *iFile, char *name, double gtime);
void       FrAdcDataWrite(FrAdcData *adc, FrFile *oFile);

/*---------------------------------------------------------------------------*/
struct FrCList {       /* channel list                                       */
  int nChannels;       /* number of channel in the list                      */
  int nameSize;        /* space reserved for the name                        */
  int rowSize;         /* size (bytes) of one row = nameSize + sizeof(void *)*/
  void *table;         /* Array of size nChannels * rowSize                  */
};

FrCList *FrCListBldAdc(FrameH *frame);
FrCList *FrCListBldSer(FrameH *frame);
void    *FrCListFind(FrCList *list, char *name);
void     FrCListFree(FrCList *list);

/*---------------------------------------------------------------------------*/
struct FrDetector { 
  FrSH   *classe;                /* class information (internal structure)   */
  char   *name;                  /* detector name                            */
  char   prefix[2];              /* channel prefix for this detector
				              "**" means prefix are not used */
  double longitude;              /* detector longitude(est of greenwich)     */
  double latitude;               /* detector latitude                        */
  float  elevation;              /* detector altitude (meter)                */
  float  armXazimuth;            /* orient. of X arm in radian CCW from East */
  float  armYazimuth;            /* orient. of Y arm in radian CCW from East */
  float  armXaltitude;           /* altitude (pitch) of the X arm            */
  float  armYaltitude;           /* altitude (pitch) of the Y arm            */
  float  armXmidpoint;           /* vertex to  middle of the X arm distance  */
  float  armYmidpoint;           /* vertex to  middle of the Y arm distance  */
  int    localTime;              /* local time - UTC time (second)           */
  FrVect *aux;                   /* more data for this detector              */
  FrTable *table;                /* additional table                         */
  FrDetector *next;              /* next detector structure                  */
                                 /* ------ end_of_SIO parameters ------------*/
  FrStatData *sData;             /* first static data bloc                   */
};

FrSH       *FrDetectorDef();    
void        FrDetectorDump(FrDetector *detector, FILE *fp, int debugLvl);
FrDetector *FrDetectorNew(char *name);
void        FrDetectorFree (FrDetector *detector);
FrDetector *FrDetectorRead(FrFile *iFile);
void        FrDetectorWrite(FrDetector *detector, FrFile *oFile);
/*---------------------------------------------------------------------------*/
/* template class for FrAdcData, FrProcData, FrSerData, FrSimData,           */
/*                FrSimEvent, FrStatData, FrSummary and FrEvent              */
/*---------------------------------------------------------------------------*/
struct FrBasic {                                                             
  FrSH    *classe;              /* class information (internal structure)    */
  char    *name;                /* object name                               */
  FrVect  *data;                /* vector of data                            */
  FrVect  *aux;                 /* could be an FrVect or FrTable             */
  FrBasic *next;                /* next structure                            */
  FrBasic *nextOld;             /* used by the tag/untag functions           */
}; 

/*---------------------------------------------------------------------------*/
struct FrEndOfFrame {            /* End of Frame Marker                      */
  FrSH *classe;                  /* class information (internal structure)   */
  int run;                       /* run number                               */
  unsigned int frame;            /* frame number                             */
  unsigned int chkType;          /* checkSum type                            */
  unsigned int chkSum;           /* checkSum value                           */
                                 /* ------------- end_of_SIO parameters ---- */
};
FrSH *FrEndOfFrameDef();    
void  FrEndOfFrameRead (FrFile *iFile);
void  FrEndOfFrameWrite(FrameH *frameH, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrEndOfFile {             /* End of File Marker                       */
  FrSH *classe;                  /* class information (internal structure)   */
  unsigned int  nFrames;         /* number of frame                          */
  FRULONG       nBytes;          /* number of bytes                          */
  unsigned int  chkType;         /* flag for checksum                        */
  unsigned int  chkSum;          /* checksum                                 */
  FRULONG       seekTOC;         /* seek for the TOC                         */
                                 /* ------------- end_of_SIO parameters ---- */
};
FrSH *FrEndOfFileDef();
void  FrEndOfFileRead (FrFile *iFile);
void  FrEndOfFileWrite(FrFile *oFile);

/*---------------------------------------------------------------------------*/
struct FrEvent {     
  FrSH *classe;                  /* class information (internal structure)   */
  char   *name;                  /* event name                               */
  FrVect *data;                  /* vector containing additional event info  */
  FrTable *table;                /* table for additional info                */
  FrEvent *next;                 /* next FrEvent structure                   */
  FrEvent *nextOld;              /* used by the tag/untag functions          */
                                 /*------- enf of the FrBasic structure------*/
  char   *comment;               /* comment                                  */
  char   *inputs;                /* input channels                           */
  unsigned int GTimeS;           /* Event occurrence time (second) (GPS time)*/
  unsigned int GTimeN;           /* Event occurrence time (nano second)      */
  float timeBefore;              /* signal duration before GTime             */
  float timeAfter;               /* signal duration after GTime              */
  unsigned int eventStatus;      /* defined by event                         */
  float  amplitude;              /* value returned by the trigger            */
  float  probability;            /* lieklihood estimate of event             */
  char *statistics;              /* Statisrical description of event         */
  unsigned short nParam;         /* number of additional parameters          */
  float  *parameters;            /* array of events parameters (size nParam) */
  char   **parameterNames;       /* array of parameters names  (size nParam) */
                                 /* -------- end_of_SIO parameters ----------*/
}; 
FrEvent *FrEventAddParam(FrEvent *event,  char *name,  double value);
FrSH    *FrEventDef();
void     FrEventDump(FrEvent *event, FILE *fp, int debugLvl);
FrEvent *FrEventFind(FrameH *frameH, char *name, FrEvent *last);
void     FrEventFree(FrEvent *event);
double   FrEventGetParam(FrEvent *event, char *paramName);
FrEvent *FrEventNew (FrameH *frameH,  
                 char *name,  char *comment, char *inputs, 
                 double gime, float  timeBefore, float  timeAfter,
                 float  amplitude,  float  probability, char   *stat,
                 FrVect *data, int nParam, ...);
FrEvent *FrEventRead (FrFile *iFile);
FrEvent *FrEventReadT(FrFile *iFile,char *name,
                      double t0, double len, double aMin, double aMax);
void     FrEventWrite(FrEvent *event, FrFile *oFile);

#define FRMAXREF 50
/*---------------------------------------------------------------------------*/
struct FrFile{                   /* standard header for i/o file             */
  FrFileH *fileH;                /* fileHeader linked list                   */
  FrFileH *current;              /* current fileHeader pointer               */
  FRBOOL inMemory;               /* if YES file output is put in memory      */
  int  compress;                 /* type of compression used for this file   */
  unsigned short gzipLevel;      /* compression level used by gzip           */
  FrSH **sh;                     /* pointer to the sh struct. Used for read  */
  FrSH *firstSH ;
  FrSH *curSH;
  int maxSH;                     /* size of FrSHlist vector                  */
  FRFORMAT fmType;               /* give format conversion type              */
  FRFORMAT fmLong;               /* give format conversion type for long     */
  FRBOOL endOfFrame;             /* tell if we reach the end of frame ord    */
  FrameH *curFrame;              /* current frameH pointer for this file     */
  int fmtVersion;                /* format version                           */
  unsigned char header[40];      /* header for format type                   */
  int run;                       /* current run number on file               */
  unsigned int nFrames;          /* total number of frames                   */
  FRULONG nBytes;                /* total number of bytes                    */
  FRULONG nBytesF;               /* number of bytes at the frame begining    */
  FrIO *frfd;                    /* pseudo file descriptor                   */
  FRERROR error;                 /* error flag                               */
  char *buf;                     /* pointer to the output sting. The current
                                    buffer length = FrFile->buf - FrFile->p  */
  char *p;                       /* current pointer to the output string     */
  char *pStart;                  /* pointer to the begining of a ord         */
  char *pMax;                    /* maximum value for the output string p.   */
  FRLONG  bufSize;               /* output buffer size                       */
  FrStatData *sDataSim;          /* static data                              */
  FrStatData *sDataProc;         /* static data                              */
  FrStatData *sDataCur;          /* all static data for the current frame    */
  FRBOOL dicWrite[FRMAPMAXSH];   /* tell if the dict. info has been written  */
  int oldLocalTime;              /* Old Time offset (for frame file verion 4)*/
  FRLONG length;                 /* current record length read               */
  unsigned short vectorType;     /* SH id for FrVect structure when using TOC*/
  unsigned short detectorType;   /* type for the FrDetector structures       */
  unsigned short type;           /* current record type read                 */
  unsigned int instance;         /* current record instance read             */
  unsigned int instanceH;        /* current instance header read             */
  unsigned int vectInstance;     /* vector instance used by random read      */
  int nSH;                       /* FrSH struct count for the current frame  */
  int nSE;                       /* FrSE struct count for the current frame  */
  FrTOC *toc;                    /* file table of content                    */
  FRBOOL noTOCts;                /* tell if we dont write TOC for time serie */
  char *historyMsg;              /* history message to be added at output    */
                                 /* ------- checksum variables---------------*/
  FRBOOL       chkSumFiFlag;     /* if = YES compute file cksum              */
  FRBOOL       chkSumFrFlag;     /* if = YES compute frame cksum             */
  unsigned int chkSumFi;         /* computed file checksum                   */
  unsigned int chkSumFr;         /* computed frame checksum                  */
  unsigned int chkSumFiRead;     /* file checksum read                       */
  unsigned int chkSumFrRead;     /* frame checksum read                      */
  unsigned int chkTypeFiRead;    /* file checksum flag read                  */
  unsigned int chkTypeFrRead;    /* frame checksum flag read                 */
                                 /*------- data used for address relocation--*/
  FRBOOL relocation;             /* tell if we skip relocation mechanism     */
  int lastInstance[FRMAPMAXSH];  /* last instance assigned for an FrSH type  */
  int    refType    [FRMAXREF];  /* temporary array of FrSH type             */
  int    refInstance[FRMAXREF];  /* temporary array of instance values       */
  void  *address    [FRMAXREF];  /* temporary array of address               */
  void **refAddress [FRMAXREF];  /* temporary array of referenced address    */
  int nRef;                      /* size of the 4 previous vectors           */
};

void    FrFileBreakName(FrFile *file, char *fullName);
void    FrFileDbg      (FrFile *file);
void    FrFileFree     (FrFile *file);
FrFile *FrFileNew(char *fileName, int compress, char *buf, FRLONG bufSize);

char   *FrFileIChannelList(FrFile *iFile, int mode);
void    FrFileIClose   (FrFile *iFile);
void    FrFileIDump    (FrFile *iFile, FILE *fp, int debugLvl, char *tag);
void    FrFileIDumpEvt (FrFile *iFile, FILE *fp, int debugLvl); 
void    FrFileIDumpFr  (FrFile *iFile, FILE *fp, int debugLvl,
			                    double tStart, double length);
void    FrFileIEnd             (FrFile *iFile);
FrVect *FrFileIGetAdcNames     (FrFile *iFile);
FrVect *FrFileIGetDetectorNames(FrFile *iFile);
FrVect *FrFileIGetEventInfo (FrFile *iFile,char *tag,
                           double tStart,double len, double aMin, double aMax);
FrVect *FrFileIGetEventNames(FrFile *iFile);
FrVect *FrFileIGetFrameInfo (FrFile *iFile, double tStart,double length);
FrVect *FrFileIGetFrameInfo1(FrFile *iFile, double tStart,double length);
FrVect *FrFileIGetProcNames (FrFile *iFile);
FrVect *FrFileIGetSimEventInfo(FrFile *iFile,char *tag,
                           double tStart,double len, double aMin, double aMax);
FrVect *FrFileIGetSimEventNames(FrFile *iFile);
FrVect *FrFileIGetSimNames  (FrFile *iFile);
FrVect *FrFileIGetStatNames (FrFile *iFile);
FrVect *FrFileIGetV    (FrFile *iFile, char *name, double tStart, double len);
FrVect *FrFileIGetVAdc (FrFile *iFile, char *name, double tStart, double len, 
                                       int   group);
FrVect *FrFileIGetVProc(FrFile *iFile, char *name, double tStart, double len,
                                       int   group);
FrVect *FrFileIGetVSim (FrFile *iFile, char *name, double tStart, double len,
		                       int   group);
FrVect *FrFileIGetVType(FrFile *iFile, char *name, double tStart, double len,
                                       int   group, FRTSTYPE type);
int     FrFileIGoToNextRecord(FrFile *iFile);
FrFile *FrFileINew  (char *fileName);
FrFile *FrFileINewFd(FrIO *frfd);
int     FrFileINext  (FrFile *iFile,double tStart,double len,
                                FrFileH *firstFH, FRBOOL event);
void    FrFileIncSH  (FrFile *iFile, unsigned short id);
void    FrFileIOpen  (FrFile *file);
FrFile *FrFileIRewind(FrFile *iFile);
void    FrFileIStat  (FrFile *iFile, FILE *fp);
double  FrFileITEnd      (FrFile *iFile);
double  FrFileITFirstEvt (FrFile *iFile);
double  FrFileITLastEvt  (FrFile *iFile);
double  FrFileITNextFrame(FrFile *iFile,double gtime);
double  FrFileITStart    (FrFile *iFile);

int     FrFileOEnd(FrFile *file);
FrFile *FrFileONew (char *fileName, int compress);
FrFile *FrFileONewH(char *fileName, int compress, char *program);
FrFile *FrFileONewFd   (FrIO *frfd, int compress);
FrFile *FrFileONewFdH  (FrIO *frfd, int compress, char *program);
void    FrFileOOpen        (FrFile *oFile);
int     FrFileORealloc     (FrFile *oFile, char *name, int size);
void    FrFileOSetMsg      (FrFile *oFile, char *msg);
void    FrFileOSetGzipLevel(FrFile *oFile, unsigned short level);

/*---------------------------------------------------------------------------*/
struct FrFileH{                  /* header for each file                     */
  char *fileName;                /* file name                                */
  double tStart;                 /* starting GPS time for this file          */
  double length;                 /* time length for this file                */
  double tFirstEvt;              /* GPS time for earliest event in file      */
  double tLastEvt;               /* GPS time for the latest event in file    */
  FrFileH* next;                 /* next FrFileH in the linked list          */
};

/*---------------------------------------------------------------------------*/
struct FrHistory {               /* Describes data history info.             */
  FrSH *classe;                  /* class information (internal structure)   */
  char *name;                    /* name of history ord                      */
  unsigned int time;             /* time of reprocessing(GPS)                */
  char *comment;                 /* program name and comment                 */
  FrHistory *next;               /* pointer to the next history struct       */
                                 /* ------------- end_of_SIO parameters -----*/
};

FrHistory *FrHistoryAdd(FrameH *frame, char *comment);
FrSH      *FrHistoryDef();    
void       FrHistoryFree(FrHistory *history);
FrHistory *FrHistoryNew(char *name, unsigned int mytime, char *comment);
void       FrHistoryRead(FrFile *iFile);
void       FrHistoryWrite(FrHistory *history, FrFile *oFile);

/*---------------------------------------------------------------------------*/
void   FrSetAll(FrFile *file);
void   FrSetBAT(FrFile *file, unsigned short instance, void *add);
void   FrSetBRT(FrFile *file, unsigned int   instance, 
                              unsigned short type, void *add);
void   FrSetIni(FrFile *file);
/*---------------------------------------------------------------------------*/
struct FrMsg {                   /* hold  message      information           */
  FrSH *classe;                  /* class information (internal structure)   */
  char   *alarm;                 /* name of the alarm                        */
  char   *message;               /* error message                            */
  unsigned int severity;         /* severity (to be defined)                 */
  unsigned int GTimeS;           /* message occurrence time (GPS seconds)    */
                                 /* if GTimeS=0, the FrameH value is be used */
  unsigned int GTimeN;           /* message occurrence time (GPS nano second)*/
  FrMsg *next;                   /* next structure                           */
                                 /* -------- end_of_SIO parameters ----------*/
}; 
FrMsg *FrMsgAdd(FrameH *frame, char *alarm, char *message, 
                               unsigned int severity);
FrSH  *FrMsgDef();
void   FrMsgDump(FrMsg *msg,FILE *fp, int debugLvl);
FrMsg *FrMsgFind(FrameH *frame, char *alarm, FrMsg *msg);
void   FrMsgFree(FrMsg *msg);
FrMsg *FrMsgRead(FrFile *iFile);
void   FrMsgWrite(FrMsg *msg, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrObject {                /* prototype of FrameLib structure          */
  FrSH *classe;                  /* class information (internal structure)   */
  char *name;                    /* name for this element                    */
}; 

FrSH *FrObjectDef();
/*---------------------------------------------------------------------------*/
struct FrProcData {              /* process and reconstructed data           */
  FrSH *classe;                  /* class information (internal structure)   */
  char   *name;                  /* data name                                */
  FrVect *data;                  /* main data like the metric perturbation(h)*/
  FrVect *aux;                   /* auxillary data like for h: a vector of 6
                                    values: the detector equatorial position 
                                   (x,y,z) and speed (vx,vy,vz) at the first 
                                    sampling.                                */
  FrProcData *next;              /* next bloc of onstructed data             */
  FrProcData *nextOld;           /* used by the tag/untag functions          */
                                 /*------- enf of the FrBasic structure------*/
  unsigned short type;           /* vector type                              */
  unsigned short subType;        /* vector subType                           */
  char   *comment;               /* comment                                  */
  double timeOffset;             /* offset from the frame starting time (sec)*/
  double tRange;                 /* duration of sampled data (tStop-tStart)  */
  double fShift;                 /* frequency shift if the signal was 
                                             heterodyne (Hz) (0->no shift)   */
  float  phase;                  /* phase for heterodyning signal            */
  double fRange;                 /* duration of sampled data (tStop-tStart)  */
  double BW;                     /* resolution BW                            */
  unsigned short nAuxParam;      /* number of auxiliary parameters           */
  double *auxParam;              /* auxiliary parameters values              */
  char  **auxParamNames;         /* auxiliary parameters names               */
  FrTable *table;                /* auxiallary data                          */
  FrHistory *history;            /* history for this proc data               */
                                 /* ------ end_of_SIO parameters ------------*/
};

FrHistory  *FrProcDataAddHistory(FrProcData *proc,char *comment,int nPrev,...);
FrSH       *FrProcDataDef();
void        FrProcDataDump(FrProcData *proc, FILE *fp,  int debugLvl);
FrProcData *FrProcDataFind(FrameH *frame, char *name);
void        FrProcDataFree(FrProcData *procData);
FrVect     *FrProcDataGetV(FrameH *frameH, char *name);
FrProcData *FrProcDataNew (FrameH *frame, char *name, 
                           double sampleRate, FRLONG nData, int nBits);
FrProcData *FrProcDataRead (FrFile *iFile);
FrProcData *FrProcDataReadT(FrFile *iFile, char *name, double gtime);
void        FrProcDataWrite(FrProcData *procData, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrRawData {               /* Hold raw data                            */
  FrSH *classe;                  /* class information (internal structure)   */
  char   *name;                  /* name                                     */
  FrSerData *firstSer;           /* pointer to the first slow mon. station   */
  FrAdcData *firstAdc;           /* pointer to the first adc structure       */
  FrTable *firstTable;           /* pointer to the first table               */
  FrMsg *logMsg;                 /*pointer to the error message structure    */
  FrVect *more;                  /*pointer aditional data                    */
                                 /* ------------- end_of_SIO parameters -----*/
  FrAdcData *firstAdcOld;        /* used by the tag/untag function           */
  FrSerData *firstSerOld;        /* used by the tag/untag function           */
};

FrSH      *FrRawDataDef();    
void       FrRawDataDump(FrRawData *rawData, FILE *fp, int debugLvl);
void       FrRawDataFree(FrRawData *rawData);
FrRawData *FrRawDataNew(FrameH *frame);
FrRawData *FrRawDataRead(FrFile *iFile);
void       FrRawDataUntagAdc(FrRawData *rawData);
void       FrRawDataUntagSer(FrRawData *rawData);
void       FrRawDataWrite   (FrRawData *rawData, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrSE {                    /* hold structure information(one per line) */
  FrSH *classe;                  /* class information (internal structure)   */
  char        *name;             /* name for this element                    */
  char        *type;             /* element type                             */
  char        *comment;          /* comment                                  */
                                 /* ------------ end_of_SIO parameters ------*/
  FrSE *next;                    /* next struct E                            */
};
FrSH *FrSEDef();
void  FrSENew(FrSH *structH, char *type, char *name, char *comment);
void  FrSERead(FrFile *iFile);
void  FrSEWrite(FrSE *structE, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrSerData {               /* slow monitoring station data             */
  FrSH *classe;                  /* class information (internal structure)   */
  char *name;                    /* slow monitoring station name             */
  FrVect *serial;                /* additional s.m. data for this station    */
  FrTable *table;                /* additional s.m. data for this station    */
  FrSerData *next;               /* next slow monitoring station             */
  FrSerData *nextOld;            /* used by the tag/untag functions          */
                                 /*------- enf of the FrBasic structure------*/
  unsigned int timeSec;          /* F.B. collection time (GPS)               */
  unsigned int timeNsec;         /* F.B. collection time (GPS)               */
  float sampleRate;              /* sample/s.                                */
  char *data;                    /* pointer to the data block                */
};

FrSH      *FrSerDataDef();  
void       FrSerDataDump(FrSerData *serData, FILE *fp, int debugLvl);
FrSerData *FrSerDataFind(FrameH *frameH,char *smsName, FrSerData *sms);
void       FrSerDataFree(FrSerData *smsData);
int        FrSerDataGet (FrameH *FrameH, char *smsName, 
                             char *smsParam, double *value); 
FrSerData *FrSerDataNew (FrameH *frame, char *smsName, 
                         unsigned int serTime, char *data, double sampleRate);
FrSerData *FrSerDataRead (FrFile *iFile);
FrSerData *FrSerDataReadT(FrFile *iFile, char *name,double gtime);
void       FrSerDataWrite(FrSerData *smsData, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrSH {                    /* hold info for this type of struct        */
  FrSH *classe;                  /* class information (internal structure)   */
  char   *name;                  /* name for this type of structure          */
  unsigned short  id;            /* is structure when written on tape        */
  char   *comment;               /* comment                                  */
  FRLONG nBytes;                 /* total number of bytes for this structure */
  int    nInstances;             /* total number of instances for this struct*/
                                 /* ------------ end_of_SIO parameters ------*/
  FrSE *firstE;                  /* first structure element                  */
  void (*objRead)();             /* function to read the object on file      */
  int nSE;                       /* number of element for this structure     */
  FrSH *shRef;                   /* reference SH struct (used for in. file)  */
};

FrSH *FrSHDef();
void  FrSHMatch(FrFile *iFile);
FrSH *FrSHNew(char *name, char *comment);
void  FrSHRead(FrFile *iFile);
void  FrSHWrite(FrSH *structH, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrSimData {               /* hold Simulated data                      */
  FrSH *classe;                  /* class information (internal structure)   */
  char   *name;                  /* name                                     */
  FrVect *data;                  /*buffer for the data                       */
  FrVect *input;                 /* input signal                             */
  FrSimData *next;               /* next structure                           */
  FrSimData *nextOld;            /* used by the tag/untag functions          */
                                 /*------- enf of the FrBasic structure------*/
  char   *comment;               /* comment                                  */
  float   sampleRate;            /* sampling rate  (unit= Hz)                */
  double timeOffset;             /* offset from the frame starting time (sec)*/
  double fShift;                 /* frequency shift if the signal was 
                                         heterodyne (Hz) (0->no shift)       */
  float  phase;                  /* phase of heterodyning signal.            */
  FrTable *table;                /* data stored in table                     */
                                 /* ------ end_of_SIO parameters ------------*/
}; 

FrSH      *FrSimDataDef();    
void       FrSimDataDump(FrSimData *simData, FILE *fp, int debugLvl);
FrSimData *FrSimDataFind(FrameH *frame, char *name);
void       FrSimDataFree(FrSimData *simData);
FrVect    *FrSimDataGetV(FrameH *frame, char *name);
FrSimData *FrSimDataNew (FrameH *frame, char *name, 
                         double sampleRate, FRLONG nData, int nBits);
FrSimData *FrSimDataRead (FrFile *iFile);
FrSimData *FrSimDataReadT(FrFile *iFile, char *name, double gtime);
void       FrSimDataWrite(FrSimData *adcData, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrSimEvent {     
  FrSH *classe;                  /* class information (internal structure)   */
  char   *name;                  /* name of event type                       */
  char   *comment;               /* comment                                  */
  char   *inputs;                /* input channels                           */
  unsigned int GTimeS;           /* Event occurrence time (second) (GPS time)*/
  unsigned int GTimeN;           /* Event occurrence time (nano second)      */
  float  timeBefore;             /* signal duration before GTimeS            */
  float  timeAfter;              /* signal duration after GTimeS             */
  float  amplitude;              /* signal amplitude                         */
  unsigned short nParam;         /* number of additional parameters          */
  float  *parameters;            /* array of events parameters (size nParam) */
  char   **parameterNames;       /* array of parameters names  (size nParam) */
  FrVect *data;                  /* vector containing additional event info  */
  FrTable *table;                /* table containing additional info.        */
  FrSimEvent *next;              /* next event structure                     */
                                 /* -------- end_of_SIO parameters ----------*/
}; 
FrSimEvent *FrSimEventAddParam(FrSimEvent *event,  char *name,  double value);
FrSH       *FrSimEventDef();
void        FrSimEventDump(FrSimEvent *simEvent,FILE *fp, int debugLvl);
FrSimEvent *FrSimEventFind(FrameH *frameH, char *name, FrSimEvent *last);
void        FrSimEventFree(FrSimEvent *simEvent);
double      FrSimEventGetParam(FrSimEvent *event, char *paramName);
FrSimEvent *FrSimEventNew(FrameH *frameH, char *name, char *comment,
                 char *inputs, double time, float timeBefore, float timeAfter,
                 float amplitude, int nParam, ...);
FrSimEvent *FrSimEventRead (FrFile *iFile);
FrSimEvent *FrSimEventReadT(FrFile *iFile, char *name,
                            double gtime, double dt, double aMin, double aMax);
void        FrSimEventWrite(FrSimEvent *simEvent, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrStatData { /*-- this structure is used to hold quasi permanent data. 
                This data stay has long they are valid compare to the frame 
             starting time (GPS), or as long there is not a new bloc of data 
     	          with the same name more ent or with  an higgest version 
     	           number ---------------------------------------------------*/
  FrSH *classe;                  /* class information (internal structure)   */
  char   *name;                  /* data type                                */
  char   *comment;               /* comment 	                             */
  char   *representation;        /* type of representation                   */
  unsigned int timeStart;        /* data validity starting time (GPS time)   */
  unsigned int timeEnd;          /* data validity end time (GPS time)        */
  unsigned int version;          /* version number                           */
  FrDetector *detector;          /* detector owning static data              */
  FrVect *data;                  /* data for this bloc                       */
  FrTable *table;                /* additional data bloc                     */
                                 /* ------ end_of_SIO parameters ------------*/
  FrStatData *next;              /* next static data bloc                    */
  int  overlap;
};

void        FrStatDataAdd(FrDetector *detector, FrStatData *sData);
void        FrStatDataAddR(FrStatData **root,   FrStatData *sData);
void        FrStatDataChkT(FrStatData **root, 
                       unsigned int timeStart, unsigned int timeEnd);
FrStatData *FrStatDataCopy(FrStatData *sData, FrDetector *detector);
FrSH       *FrStatDataDef();    
FrStatData *FrStatDataFind(FrDetector *detector, char *name,
                       unsigned int timeNow);
void        FrStatDataFree(FrStatData *sData);
FrStatData *FrStatDataFreeOne(FrStatData *sData);
FrVect     *FrStatDataGetV(FrameH *frame, char * name);
FrStatData *FrStatDataNew(char *name, char *comment,char *represent,
                  unsigned int tStart, unsigned int tEnd,unsigned int version,
                  FrVect *data, FrTable *table);
FrStatData *FrStatDataRead(FrFile *iFile);
void        FrStatDataRemove(FrDetector *detector, char *name);
void        FrStatDataTouch(FrStatData *sData);
void        FrStatDataWrite(FrStatData *sData, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrSummary {     
  FrSH *classe;                  /* class information (internal structure)   */
  char   *name;                  /* summary name                             */
  FrVect *moments;               /* vector containing statistical description*/
  FrTable *table;                /* data stored in table                     */
  FrSummary *next;               /* next summary structure                   */
  FrSummary *nextOld;            /* used by the tag/untag functions          */
                                 /*------- enf of the FrBasic structure------*/
  char   *comment;               /* comment                                  */
  char   *test;                  /* statistical test(s) used on raw data     */
  unsigned int GTimeS;           /* FrSummary time (GPS seconds)             */
  unsigned int GTimeN;           /* FrSummary time (GPS nano second)         */
                                 /* -------- end_of_SIO parameters ----------*/
}; 
FrSH      *FrSummaryDef();
void       FrSummaryDump(FrSummary *summary, FILE *fp, int debugLvl);
FrSummary *FrSummaryFind(FrameH *frame, char *name);
void       FrSummaryFree(FrSummary *summary);
FrVect    *FrSummaryGetV(FrameH *frame, char *name);
FrSummary *FrSummaryNew (FrameH *frame, char *name, char *comment,  
                          char *test, FrVect *moments, FrTable *table);
FrSummary *FrSummaryRead (FrFile *iFile);
FrSummary *FrSummaryReadT(FrFile *iFile, char *name, double gtime);
void       FrSummaryWrite(FrSummary *summary, struct FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrTable {     
  FrSH *classe;                  /* class information (internal structure)   */
  char   *name;                  /* table name                               */
  char   *comment;               /* comment                                  */
  unsigned short nColumn;        /* number of column                         */
  unsigned int nRow;             /* number of row                            */
  char   **columnName;           /* name of each column                      */
  FrVect  *column;               /* first column of the table                */
  FrTable *next;                 /* next table if any                        */
                                 /* -------- end_of_SIO parameters ----------*/
};
void     FrTableCompress(FrTable *table, int compType, int gzipLevel);
FrTable *FrTableCopy    (FrTable *table);
FrSH    *FrTableDef();
void     FrTableDump  (FrTable *table, FILE *fp, int debugLvl);
void     FrTableExpand(FrTable *table);
FrVect*  FrTableGetCol(FrTable *table, char *colName);
void     FrTableFree  (FrTable *table);
FrTable *FrTableNew(char *name, char *comment, int  nRow, int  nColumn, ...);
void     FrTableRead(FrFile *iFile);
void     FrTableWrite(FrTable *table, FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrTag {                   /* data for tag match (internal structure)  */
  char  *start;                  /* start of each tag segment                */
  int    length;                 /* length of each tag segment               */
  FrTag *next;                   /* next FrTag structure                     */
  FRBOOL returnValue;            /* = FR_NO for antitag (start by '-')       */
};

void   FrTagFree (FrTag *tag);
FRBOOL FrTagMatch(FrTag *tag, char *name);
FRBOOL FrTagMatch1(char *name, int   nameL, char *tag, int   tagL);
FrTag *FrTagNew(char *tag);
 
/*---------------------------------------------------------------------------*/
struct FrTOC {                   /* File Table Of Content                    */
  struct FrSH *classe;           /* class information (internal structure)   */
  short  ULeapS; 
  int nFrame;
  unsigned int *dataQuality;
  unsigned int *GTimeS;
  unsigned int *GTimeN;
  double *dt;
  int    *runs;
  int    *frame;
  FRULONG *positionH;
  FRULONG *nFirstADC;
  FRULONG *nFirstSer;
  FRULONG *nFirstTable;
  FRULONG *nFirstMsg;
  unsigned int nSH;
  unsigned short *SHid;
  char **SHname;
  FrTOCdet *detector;
  int nStatType;
  FrTOCstat *stat;
  FrTOCts *adc;
  FrTOCts *proc;
  FrTOCts *sim;
  FrTOCts *ser;
  FrTOCts *summary;
  FrTOCtsH *adcH;
  FrTOCtsH *procH;
  FrTOCtsH *simH;
  FrTOCtsH *serH;
  FrTOCtsH *summaryH;
  FrTOCevt *event;
  FrTOCevt *simEvt;
  int maxFrame;
  int position;
};
FrSH  *FrTOCDef();
void   FrTOCDump(FrTOC *toc, FILE *fp, int debugLvl, char *tag);
void   FrTOCFFLBuild(FrFile *iFile);
void   FrTOCFree(FrTOC *toc);
void   FrTOCFrame     (FrFile *oFile, FrameH *frame);
int    FrTOCFrameFindN(FrFile *iFile, int run, int frame);
int    FrTOCFrameFindNext(FrFile *iFile, double gtime);
int    FrTOCFrameFindNT(FrFile *iFile, double gtime);
int    FrTOCFrameFindT (FrFile *iFile, double gtime);
int    FrTOCFrameFindT1(FrFile *iFile, double gtime);
int    FrTOCGetLTOffset(FrFile *iFile, char *channelName);
void   FrTOCGetTimes  (FrFile *iFile);
void   FrTOCNew       (FrFile *oFile, FrameH *frame);
FrTOC *FrTOCRead      (FrFile *iFile,  int nFrame);
FrTOC *FrTOCReadFull  (FrFile *iFile);
int    FrTOCSetPos    (FrFile *iFile, FRULONG position);
void   FrTOCSH        (FrFile *oFile, char *name, unsigned short id);
void   FrTOCSort      (FrFile *iFile);
int    FrTOCSort1  (char **dataIn, int *index, int nData, int size);
int    FrTOCStatD     (FrFile *oFile, FrStatData *sData);
void   FrTOCStatDGet  (FrFile *iFile, FrameH *frame);
void   FrTOCWrite     (FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrTOCdet {
  char         *name;      /* name for this class of detector                */
  int           localTime; /* local time offset for this detector            */
  FRULONG       position;  /* position position in the file                  */
  FrTOCdet      *next;     /* next FrTOC event in the lnked list             */
};
void      FrTOCdetFree(FrTOCdet *det);
void      FrTOCdetMark(FrFile *oFile,  char *name);
FrTOCdet *FrTOCdetRead(FrFile *iFile);
void      FrTOCdetWrite(FrFile *oFile);
/*---------------------------------------------------------------------------*/
struct FrTOCevt {
  char         *name;      /* name for this class of events                  */
  int           nEvent;    /* number of event of this type                   */
  unsigned int *GTimeS;    /* GPS for these events       (array size: nEvent)*/
  unsigned int *GTimeN;    /* GPS time (nanoseconds)     (array size: nEvent)*/
  float        *amplitude; /* event amplitude            (array size: nEvent)*/
  FRULONG      *position;  /* event position in the file (array size: nEvent)*/
  int           maxEvent;  /* size of the arrays                             */
  FrTOCevt      *next;     /* next FrTOC event in the lnked list             */
};
void      FrTOCevtDump(FrTOCevt *evt, FILE *fp, int maxPrint, int ULeapS);
void      FrTOCevtFree(FrTOCevt *evt);
FrVect   *FrTOCevtGetEventInfo(FrTOCevt *root,char *tag,
                               double tStart, double length,
                               double amplitudeMin,double amplitudeMax);
FrTOCevt *FrTOCevtMark(FrFile *oFile, FrTOCevt **root, char *name,
                  unsigned int GTimeS, unsigned int GTimeN, float amplitude);
FrTOCevt *FrTOCevtNew(char *name, int maxEvent);
FrTOCevt *FrTOCevtRead (FrFile *iFile);
void      FrTOCevtWrite(FrFile *oFile, FrTOCevt *evt);
/*---------------------------------------------------------------------------*/
struct FrTOCstat {            /* direct access data for FrStatData           */
  char *name;                 /* static data bloc name                       */
  char *detector;             /* detector name                               */
  int nStat;                  /* number of instance                          */
  unsigned int *tStart;       /* array (nStat) of starting time (GPS time)   */
  unsigned int *tEnd;         /* array (nStat) of validity end time(GPS time)*/
  unsigned int *version;      /* array (nStat) of version number             */
  FRLONG *position;           /* array (nStat) of position in the file       */
			      /* ------ end_of_SIO parameters ---------------*/
  int maxStat;                /* maximum number of instance                  */
  struct FrTOCstat *next;     /* next static data bloc                       */
 };
/*---------------------------------------------------------------------------*/
struct FrTOCts {                   /*table of content info for time series   */
  char           *name;
  unsigned int   channelID;          /* only for adc                         */
  unsigned int   groupID;            /* only for adc                         */
  FRULONG        *position; 
  struct FrTOCts *next;
};
void     FrTOCtsFree(FrTOCts *ts);
void     FrTOCtsMark(FrFile *oFile, FrTOCtsH **root,
                 char *name, unsigned int groupID, unsigned int channelID);
void     FrTOCtsDump(FrTOCts *root, FILE *fp, char *type,char *tag,int nFrame);
FrTOCts *FrTOCtsRead(FrFile *iFile, char *type, int nFrame);
void     FrTOCtsRealloc(FrTOCtsH *tsh, FrFile *oFile, int oldSize);
void     FrTOCtsWrite(FrFile *oFile, FrTOCtsH *root, char *type, int n);
/*---------------------------------------------------------------------------*/
struct FrTOCtsH{         /* Intermediate structure to speed up FrTOCts access*/
  int nElement;          /* number of FrTOCts strcuture attached             */
  struct FrTOCts *first; /* first FrTOCts structure                          */
  struct FrTOCtsH *next; /* next FrTOCtsH                                    */
};
void   FrTOCtsHFree(struct FrTOCtsH *tsh);
/*---------------------------------------------------------------------------*/

struct FrVect {
  FrSH *classe;                  /* class information (internal structure)   */
  char          *name;           /* vector name                              */
  unsigned short compress;       /* 0 = no compression; 1 = gzip             */
  FRVECTTYPES    type;           /* vector type  (see bellow)                */
  FRULONG        nData;          /* number of elements=nx[0].nx[1]..nx[nDim] */
  FRULONG        nBytes;         /* number of bytes                          */
  char          *data;           /* pointer to the data area.                */
  unsigned int   nDim;           /* number of dimension                      */
  FRULONG *nx;                   /* number of element for this dimension     */
  double *dx;                    /* step size value (express in above unit)  */
  double *startX;                /* offset for the first x value             */
  char   **unitX;                /* unit name for (used for printout)        */
  char    *unitY;                /* unit name for (used for printout)        */
  FrVect *next;                  /* hook for additional data                 */
                                 /* ------- end_of_SIO parameters -----------*/
  short  *dataS;                 /* pointer to the data area (same as *data) */
  int    *dataI;                 /* pointer to the data area (same as *data) */
  FRLONG *dataL;                 /* pointer to the data area (same as *data) */
  float  *dataF;                 /* pointer to the data area (same as *data) */
  double *dataD;                 /* pointer to the data area (same as *data) */
  unsigned char  *dataU;         /* pointer to the data area (same as *data) */
  unsigned short *dataUS;        /* pointer to the data area (same as *data) */
  unsigned int   *dataUI;        /* pointer to the data area (same as *data) */
  FRULONG        *dataUL;        /* pointer to the data area (same as *data) */
  char  **dataQ;                 /* pointer to the data area (same as *data) */
  int  wSize;                    /* size of one word                         */
  FRULONG space;                 /* variable for internal use                */
                                 /* the following variables are only fill    */
                                 /* when a vector is used in stand alonemode */
  double GTime;                  /* vector GPS time origin(second)           */
  unsigned short ULeapS;         /* leap seconds between GPS and UTC         */
  int localTime;                 /* Time offset = Local time - UTC (sec)     */
  char    *dataUnzoomed;         /* initial (before zoom) pointer to data    */
  FRULONG nDataUnzoomed;         /* initial (before zoom) nData              */
  double startXUnzoomed;         /* initial (before zoom) startX             */
};

int     FrVectCtoH   (FrVect *vect);
unsigned short FrVectCompData(FrVect *vect, int compType, int gzipLevel, 
                       unsigned char **result, FRULONG *nBytes);
void    FrVectCompress(FrVect *vect,int compress, int gzipLevel);
FrVect *FrVectConcat(FrVect *vect, double tStart, double len);
FrVect *FrVectCopy    (FrVect *in);
FrVect *FrVectDecimate(FrVect *vect, int nGroup, FrVect *outVect);
FrSH   *FrVectDef();    
char   *FrVectDiff   (FrVect *vect);
void    FrVectDump   (FrVect *vect, FILE *fp, int debugLvl);
void    FrVectExpand (FrVect *vect);
void    FrVectExpandF(FrVect *vect);
int     FrVectFillC  (FrVect *vect,  char value);
int     FrVectFillD  (FrVect *vect,double value);
int     FrVectFillF  (FrVect *vect, float value);
int     FrVectFillI  (FrVect *vect,   int value);
int     FrVectFillQ  (FrVect *vect, char *value);
int     FrVectFillS  (FrVect *vect, short value);
int     FrVectFindQ  (FrVect *vect, char *name);
void    FrVectFree   (FrVect *vect);
double  FrVectGetV   (FrVect *vect, FRULONG i);
int     FrVectHtoC   (FrVect *vect);
void    FrVectInt    (FrVect *vect);
int     FrVectIsValid(FrVect *vect);
void    FrVectMap    (FrVect *vect);
FrVect *FrVectMergeT (FrVect **vectIn, int nVect);
int     FrVectMinMax (FrVect *vect, double *min, double *max);
FrVect *FrVectNew  (int type, int nDim, ...);
FrVect *FrVectNewL (int type, int nDim, ...);
FrVect *FrVectNewTS(char *name,double sampleRate, FRLONG nData, int nBits);
FrVect *FrVectNew1D(char *name,int type, FRLONG nData, 
                           double dx, char *unitx, char *unity);
FrVect *FrVectRead    (FrFile *iFile);
FrVect *FrVectReadNext(FrFile *iFile, double gtime, char *name);

char   *FrVectStat    (FrVect *vect);
void    FrVectWrite   (FrVect *vect, FrFile *oFile);
int     FrVectFComp(short *out, FRULONG *compL,
                    float *data, FRULONG nData, int bSize);
void    FrVectFExpand(float *out, short  *data, FRULONG nData);
int     FrVectUComp(FrVect *vect, unsigned char *out, 
                    FRULONG *compL, int *compType);
void    FrVectUExpand(FrVect *vect, unsigned char *out);
int     FrVectZComp (unsigned short *out, FRULONG *compL,
                   short *data, FRULONG nData, int bSize);
int     FrVectZCompI(unsigned   int *out, FRULONG *compL, 
                 int *data,  FRULONG nData, int bSize);
void    FrVectZExpand(short *out, unsigned short *data, FRULONG nData);
void    FrVectZExpandI( int *out, unsigned   int *data, FRULONG nData);
int     FrVectZoomIn (FrVect *vect, double xStart, double length);
int     FrVectZoomOut(FrVect *vect);
/*--------------------------------------------------------------------------*/
/*  General functions                                                       */
/*--------------------------------------------------------------------------*/
FILE *FrLibIni(char *outFile, FILE *fOut, int dbglvl);
void  FrLibShortIni();
void  FrLibSetLvl(int dbglvl);
float FrLibVersion(FILE *fOut);
/*--------------------------------------------------------------------------*/
char *FrError(int level, char *subroutine, char *message);
char *FrErrorGetHistory();
void  FrErrorDefHandler(int level, char *lastMessage);
void  FrErrorSetHandler(void  (*handler)(int, char *));
/*--------------------------------------------------------------------------*/
unsigned int FrChkSum(FRSCHAR *buf, int nBytes, int start);
void FrCksumGnu (char *buf, FRLONG nBytes, unsigned int *crc);
/*---------------------------------------------------------------------------*/
FrSH *FrDicAddS(char *type, void (*funRead)());         
int   FrDicAssignId(struct FrFile *file, unsigned short type, void *address);
int   FrDicGetId   (struct FrFile *file, unsigned short type, void *address);
void  FrDicIni     (struct FrFile *file);
/*---------------------------------------------------------------------------*/

char  *FrStrCpy(char **copy, char *old);
char  *FrStrGTime(unsigned int in);
char  *FrStrUTC(unsigned int gps, int uLeapS);
/*---------------------------------------------------------------------------*/

/*------------------ here we have the I/O package. ------------------------- */
   
void FrPutNewRecord(FrFile *oFile, void    *instance, FRBOOL withInstanceId);
void FrPutChar  (FrFile *oFile, char           value); 
void FrPutDouble(FrFile *oFile, double         value);
void FrPutFloat (FrFile *oFile, float          value);
void FrPutInt   (FrFile *oFile, int            value);
void FrPutIntU  (FrFile *oFile, unsigned int   value);
void FrPutLong  (FrFile *oFile, FRLONG         value);
void FrPutShort (FrFile *oFile, short           value);
void FrPutShortU(FrFile *oFile, unsigned short value);
void FrPutSChar (FrFile *oFile, char          *value);
void FrPutStruct(FrFile *oFile, void       *instance);

void FrPutVC(FrFile *oFile, char      *data, int nData);
void FrPutVD(FrFile *oFile, double    *data, int nData);
void FrPutVF(FrFile *oFile, float     *data, int nData);
void FrPutVI(FrFile *oFile, int       *data, int nData);
void FrPutVL(FrFile *oFile, FRLONG    *data, int nData);
void FrPutVQ(FrFile *oFile, char     **data, int nData);
void FrPutVS(FrFile *oFile, short     *data, int nData);

void FrPutWriteRecord(FrFile *oFile);

/*---------------------------------------------------------------------------*/

void FrReadHeader(FrFile *iFile, void *instance);

FRLONG FrRead    (FrFile *iFile, char *buf, FRULONG n);
void FrReadDouble(FrFile *iFile,       double *value);
void FrReadFloat (FrFile *iFile,        float *value);
void FrReadInt   (FrFile *iFile,          int *value);
void FrReadIntU  (FrFile *iFile, unsigned int *value);
void FrReadLong  (FrFile *iFile,       FRLONG *value);
void FrReadRecord(FrFile *iFile);
void FrReadSChar (FrFile *iFile,  char **value);
void FrReadShort (FrFile *iFile,  short *value);
void FrReadShortU(FrFile *iFile,  unsigned short *value);
void FrReadSkipRecord(FrFile *iFile);
void FrReadStruct(FrFile *iFile, void *add);
void FrReadVC    (FrFile *iFile, char      **data, FRULONG nData);
void FrReadVD    (FrFile *iFile, double    **data, FRULONG nData);
void FrReadVF    (FrFile *iFile, float     **data, FRULONG nData);
void FrReadVI    (FrFile *iFile, int       **data, FRULONG nData);
void FrReadVL    (FrFile *iFile, FRLONG    **data, FRULONG nData);
void FrReadVQ    (FrFile *iFile, char     ***data, FRULONG nData);
void FrReadVS    (FrFile *iFile, short     **data, FRULONG nData);

/*---------------------------------------------------------------------------*/
FrDetector *FrBack3DetectorRead(FrFile *iFile);
FrameH     *FrBack3FrameHRead  (FrFile *iFile);
FrProcData *FrBack3ProcDataRead(FrFile *iFile);
FrRawData  *FrBack3RawDataRead (FrFile *iFile);
FrSimData  *FrBack3SimDataRead (FrFile *iFile);
FrStatData *FrBack3StatDataRead(FrFile *iFile);
FrSummary  *FrBack3SummaryRead (FrFile *iFile);
FrEvent    *FrBack3EventRead   (FrFile *iFile);
FrVect     *FrBack3VectRead    (FrFile *iFile);

FrDetector   *FrBack4DetectorRead  (FrFile *iFile);
void          FrBack4EndOfFrameRead(FrFile *iFile);
FrEvent      *FrBack4EventRead     (FrFile *iFile);
FrMsg        *FrBack4MsgRead       (FrFile *iFile);
FrProcData   *FrBack4ProcDataRead  (FrFile *iFile);
FrSimData    *FrBack4SimDataRead   (FrFile *iFile);
FrSimEvent   *FrBack4SimEventRead  (FrFile *iFile);
FrSummary    *FrBack4SummaryRead   (FrFile *iFile);
FrTOCevt     *FrBack4TOCevtRead    (FrFile *iFile);

FrProcData  *FrBack5ProcDataRead(FrFile *iFile);

#ifdef __cplusplus
}
#endif

#endif


















- ROOT page - VEGA page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to , or contact with any questions or problems regarding ROOT or VEGA.