/******************************************************************
 *  File Theta.h                                                  *
 *                                                                *
 *  Include file for theta.c code.                                *
 ******************************************************************/

#include <trace_buf.h>
#include <earlybirdlib.h>

#ifndef _WINNT
typedef void *HANDLE;
#endif

/* Definitions
   ***********/
#define MAX_FFT_ORDER        25   /* Max order of FFT (2**MAX_FFT_ORDER) */
#define TAPER_WIDTH        0.05   /* Time Fraction window tapered at each end */
#define MAX_SAMPLE_RATE    200.   /* Maximum expected sample rate */
#define MAX_THETABUFF_SIZE 16344  /* Max number samples in data arrays */

typedef struct                    /* GParm structure */
{
   double   dFiltHi;              /* High-cut filter (Hz) */
   double   dFiltLo;              /* Low-cut filter  (Hz) */
   double   dMagThreshForAuto;    /* Lowest magnitude to autostart Theta proc.*/
   double   dMaxDelta;            /* Stn won't be considered if delta > this */
   double   dMinDelta;            /* Stn won't be considered if delta < this */
   SHM_INFO HRegion;              /* Info structure for Hypocenter region */
   SHM_INFO InRegion;             /* Info structure for input region */
   int      iAutoStart;           /* If 1, Start based on msgs in HYPO_RING */
   int      iDebug;               /* If 1, print debug messages */
   int      iFileSize;            /* Length of disk_wcatwc data files */
   int      iHeartbeatInt;        /* Heartbeat interval in seconds */
   int      iMinutesInBuff;       /* Number of minutes data to save per trace */
   int      iNumStnForAuto;       /* Minimum # of stns to trigger autostart */
   int      iWindowLength;        /* # sec following P used for energy calc. */
   long     lHKey;                /* Key to ring where hypocenters will live */
   long     lInKey;               /* Key to ring where waveforms live */
   unsigned char MyModId;         /* Module id of this program */
   char     szArchiveDir[64];     /* Archive Data File for archived data */
   char     szATPLineupFileBB[64];/* Optional command when used with ATPlayer */
   char     szDataDirectory[64];  /* Disk file folder for old data */
   char     szDiskPFile[64];      /* P-time file from EQCentral */
   char     szDummyFile[64];      /* Hypocenter parameter disk file */
   char     szFileSuffix[8];      /* File suffix (disk data) */
   char     szLocFilePath[64];    /* Path for disk logs of phase times */
   char     szQuakeFile[64];      /* File with recent auto-located quakes */
   char     szResponseFile[64];   /* Broadband station response file */
   char     szStaDataFile[64];    /* Station information file */
   char     szStaFile[64];        /* Name of file with SCN info */
   char     szThetaFile[64];      /* Theta results file */
} GPARM;

typedef struct 
{
   unsigned char GetThisInstId;   /* Get messages from this inst id */
   unsigned char GetThisModId;    /* Get messages from this module */
   unsigned char MyInstId;        /* Local installation */
   unsigned char TypeError;       /* Error message id */
   unsigned char TypeHeartBeat;   /* Heartbeat message id */
   unsigned char TypeHypoTWC;     /* Hypocenter message - TWC format*/
   unsigned char TypeWaveform;    /* Earthworm waveform messages */
} EWH;

/* Function declarations for Theta
   *******************************/
int     GetEwh( EWH * );                                           /* Theta.c */

int     ComputeDC( STATION *, long );                   /* Theta_processing.c */
int     CompTheta( HYPO *, STATION [], int, int, char *, int, char *, 
                   double, double, int, double, double, int );
void    coolb( int, fcomplex [], double );              
int     GetEnergy( double, double, int, double *, long, STATION * );
void    GetLDC( long, long *, double *, long );
void    HanningTaper( double *, int, double );
void    PadBuffer( long, double, long *, long *, long );
int     PatchDummyWithTheta( HYPO *, char * );
void    PutDataInBuffer( TRACE2_HEADER *, long *, long *, long *, long );
void    resgeo( double, STATION *, fcomplex * );

int     GetConfig( char *, GPARM * );                       /* Theta_config.c */
void    LogConfig( GPARM * );

thr_ret HThread( void * );                                 /* Theta_threads.c */
thr_ret ThThread( void * );
thr_ret WThread( void * );

