/* **********************************************************************
 * *                                                                    *
 * *          Rainbow converter header file                             *
 * *                                                                    *
 * **********************************************************************
 * File: utils/rainbow/rainbow_h.h
 *
 *                  COPYRIGHT (c) 2002, 2003, 2005  BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */

struct convert_task_list
{
  char  sRainbowSitename[16]; /* Rainbow sitename to use, null terminated*/
  char  sRainbowScanFile[FILENAME_SIZE]; /* Rainbow scan file (F8), null term.*/
  FLT8  fFirstFixedAngle;     /* First fixed angle */
  char  sIrisTaskName[16];    /* IRIS task name, null terminated */
  FLT4  fIrisZCalib;          /* Calibration reflectivity */
  SINT2 iProductType;         /* Rainbow N label */
  UINT1 lWildData;            /* Data does not matter, otherwise must match flags: */
  UINT1 lZData;               /*  Volume contains Z data  */
  UINT1 lVData;               /*  Volume contains V data  */
  UINT1 lWData;               /*  Volume contains W data  */
  UINT1 lTData;               /*  Volume contains T data */
  UINT1 lZdrData;             /*  Volume contains ZDR data */
};
struct convert_site_list
{
  char  sRainbowSitename[16]; /* Rainbow sitename to use, null terminated */
  char  sIrisSitename[16];    /* Ingest sitename to use, space padded */
  UINT1 lIrisUtc;             /* IRIS output time is UTC, else local */
  UINT1 lRainbowUtc;          /* Rainbow input time is UTC, else local */
  SINT2 iLocalWest;           /* Local time offset */
  char  sLocalTZName[TZNAME_SIZE]; /* Name of local time */
  FLT4  fAltitude;            /* Altitude of the radar in meters */
};
#define MAX_CONVERT_SITES (20)
#define MAX_CONVERT_TASKS (40)
struct convert_config
{
  struct convert_site_list Sites[MAX_CONVERT_SITES];
  struct convert_task_list Tasks[MAX_CONVERT_TASKS];
  FLT4  fPwList[2];            /* List of pulse widths in microseconds */
  SINT4 iSiteCount;            /* Number of sites in the list */
  SINT4 iTaskCount;            /* Number of tasks in the list */
  FILE *iLogFile;              /* Open file descriptor to log file */
  UINT1 lLogToFile;
  UINT1 lLogToTerm;
  UINT1 lVerbose;              /* Log more details */
  UINT1 lAppendToLog;          /* Append to previous log file */
  UINT1 lF4LatitudeFirst;      /* F4 values are reversed from the spec */
  UINT1 lNoZdrSupport;         /* Old version does not include ZDR */
  UINT1 lRainbowView;          /* Program is RainbowView */
  UINT1 lAllowTData;           /* W* arg 9 means T not Z if P12=0 */
};

#define RAINBOW_MAX_SWEEPS (20)
/* Sweep info almost all from W label */
struct rainbow_sweep_info8
{
  FLT8  fFixedAngle;       /* Fixed angle in degrees  #1*/
  FLT8  fSectorStart;      /* Starting angle of the sector  #2 */
  FLT8  fSectorEnd;        /* Ending angle of the sector  #3 */
  FLT8  fSectorStep;       /* Angle step in sector  #4 */
  FLT8  fScanSpeed;        /* Scan speed in degrees/second  #5 */
  struct ymds_time SweepTime;
  SINT4 iPrfHigh;          /* High PRF #7 */
  SINT4 iPrfLow;           /* Low PRF (0 if single PRF) #8 */
  UINT1 iPulseWidth;       /* Pulsewidth index #6 */
  UINT1 iDualCase;         /* Dual PRF case #12 */
  UINT1 lZData;            /* Volume contains Z data  #9 */
  UINT1 lVData;            /* Volume contains V data  #10 */
  UINT1 lWData;            /* Volume contains W data  #11 */
  UINT1 lTData;            /* Volume contains T data  #9 */
  UINT1 lZdrData;          /* Volume contains ZDR data #15 */
  char  ipad_end[5];
};

struct rainbow_info8
{
  struct rainbow_sweep_info8 Sweep[RAINBOW_MAX_SWEEPS];
  FLT8  fRadarLatitude;    /* Radar location (F4) */
  FLT8  fRadarLongitude;
  struct convert_site_list *pSite;  /* Pointer to site mapping entry for our file */
  struct convert_task_list *pTask;  /* Pointer to task mapping entry for our file */
  struct dsp_data_mask DataMask;    /* Mask of data found in the whole scan */
  SINT4 iFileSize;         /* Size of the full file */
  SINT4 iEtbCount;         /* Number of ETB's found */
  SINT4 iEtxOffset;        /* Offset to byte after the ETX */
  SINT4 iFileType;         /* File type (H3) */
  char  sRadarId[16];      /* Radar ID, null terminated (H8) */
  char  sScanFile[FILENAME_SIZE]; /* Scan file, null terminated (F8) */

#define RB_PROD_AZ_SCAN (100)
#define RB_PROD_EL_SCAN (101)
  SINT4 iProductType;      /* Product type (N) */
  SINT4 iSweepCount;       /* Number of sweeps in task (A9) */
  FLT4  fRangeStart;       /* Start range in km (P3) */
  FLT4  fRangeStop;        /* Stop range in km (P4) */
  FLT4  fRangeStep;        /* Range step in km (R2)*/
  SINT4 iRangeBinCount;    /* Number of range bins (R1) */
  SINT4 iSampleSize;       /* Sample size (P6) */
  SINT4 iRangeAvg;         /* Range averaging (P7) */
  SINT4 iClutterFilter;    /* Clutter filter number (P12) */
  FLT4  fMinZdr;           /* Minimum ZDR (P1) */
  FLT4  fMaxZdr;           /* Maximum ZDR (p2) */
  FLT4  fNyquistVel;       /* Nyquist velocity (P2) */
  FLT4  fSqiThreshold;     /* SQI Threshold (P21) */
  FLT4  fCsrThreshold;     /* CSR Threshold (P22) */
  FLT4  fLogThreshold;     /* Log Threshold (P92) */
  SINT4 iYear;             /* Date (F5) */
  SINT4 iMonth;
  SINT4 iDay;
  SINT4 iHour;             /* Time (F6) */
  SINT4 iMinute;
  SINT4 iSecond;
#define RB_DATA_V (0)
#define RB_DATA_Z (1)
#define RB_DATA_W (2)
#define RB_DATA_T (3)
#define RB_DATA_C (4)
#define RB_DATA_D (5)
  UINT4 iRbDataType;       /* Data type of file (F9) */
  SINT4 iDataBytes;        /* Number of bytes of data after header (R8) */
  struct ymds_time VolumeTime;
  UINT1 lParsingDone;      /* Parsing of the header is done */
  UINT1 lSohFound;         /* SOH found as the first character */
  UINT1 lSohInWrongPlace;  /* SOH found somewhere else */
  UINT1 lUnknownLabel;     /* Unknown label found */
  UINT1 lLabelOffEnd;
  UINT1 lLabelTooLong;
  char  sUnknownLabel;     /* Then unknown label which was found */
  UINT1 lLogSpeckle;       /* Log speckle remover is on (P19) */
  UINT1 lDopSpeckle;       /* Doppler speckle remove is on (P20) */
  UINT1 iIrisDataType;     /* Data type of file */
  UINT1 lHeaderSyntaxError; /* Syntax error in rainbow header */
  char  ipad_end[5];
};

void LoadSetup                  /* File: RainbowParse.C */
( struct convert_config *pCSetup_a );

void RainbowParse                /* File: RainbowParse.C */
( const char *sData_a,                   /* Rainbow data pointer */
  SINT4 iDataSize_a,                     /* Size of rainbow data */
  struct rainbow_info8 *pInfo_a,         /* Fill in this structure */
  const struct convert_config *pCSetup_a /* Info from config file */
  );

UINT1 RainbowWarnings             /* File: RainbowParse.C */
( const struct rainbow_info8 *pInfo_a, 
  const struct convert_config  *pCSetup_a );

void Lprintf                     /* File: RainbowParse.C */
( const struct convert_config *pCSetup_a,  /* Optional */
  const char *sString_a );
