/* *******************************
 * *                             *
 * *  UF format definition file  *
 * *                             *
 * *******************************
 * File: include/uf.h
 *
 *                   COPYRIGHT (c) 2000, 2001, 2004  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.
 */

#define SIGMET_UF_H 1

/* Must include <arpa/nameser.h> if you want to use this variable */
#define LITTLE_END (BYTE_ORDER==LITTLE_ENDIAN)

#define UF_NO_DATA  (0x8000)
#define UF_SWEEP_CALIBRATION  (0)
#define UF_SWEEP_PPI          (1)
#define UF_SWEEP_COPLANE      (2)
#define UF_SWEEP_RHI          (3)
#define UF_SWEEP_VERTICAL     (4)
#define UF_SWEEP_TARGET       (5)
#define UF_SWEEP_MANUAL       (6)
#define UF_SWEEP_IDLE         (7)
struct uf_mandatory_header2
{
  char  sID[2];
  SINT2 iRecordSize;
  SINT2 iOptionalHeaderPosition; /* Offset to start of optional header, origin 1*/
  SINT2 iLocalUseHeaderPosition; /* Offset to start of local use header, origin 1*/
  SINT2 iDataHeaderPosition;     /* Offset to start of data header, origin 1*/
  SINT2 iRecordNumber;           /* Record number within the file, origin 1 */
  SINT2 iVolumeNumber;           /* Volume scan number on the tape, N/A for disk */
  SINT2 iRayNumber;
  SINT2 iRecordInRay;            /* Record number within the ray */
  SINT2 iSweepNumber;
  char  sRadarName[8];
  char  sSiteName[8];
  SINT2 iLatDegrees;
  SINT2 iLatMinutes;
  SINT2 iLatSeconds;
  SINT2 iLonDegrees;
  SINT2 iLonMinutes;
  SINT2 iLonSeconds;         /* Seconds in 1/64 ths */
  SINT2 iAltitude;           /* Height of antenna above sea level in meters */
  SINT2 iYear;               /* Time of the ray */
  SINT2 iMonth;
  SINT2 iDay;
  SINT2 iHour;
  SINT2 iMinute;
  SINT2 iSecond;
  char  sTimeZone[2];
  SINT2 iAzimuth;            /* Azimuth in 1/64 of a degree */
  SINT2 iElevation;          /* Elevation in 1/64 of a degree */
  SINT2 iSweepMode;          /* Sweep mode, 1=PPI */
  SINT2 iFixedAngle;         /* Sweep desired angle in 1/64 of a degree */
  SINT2 iSweepRate;          /* Antenna scan rate in 1/64 of ? */
  SINT2 iConvertYear;        /* Current time when the converter was run, GMT */
  SINT2 iConvertMonth;
  SINT2 iConvertDay;
  char  sConvertName[8];
  SINT2 iNoDataValue;
};

struct uf_optional_header
{
  char  sProjectName[8];
  SINT2 iBaselineAzimuth;
  SINT2 iBaselineElevation;
  SINT2 iVolumeScanHour;    /* Time of start of current volume scan */
  SINT2 iVolumeScanMinute;  
  SINT2 iVolumeScanSecond;  
  char  sFieldTapeName[8];      
  SINT2 iFlag;
};

struct uf_dsi2
{
  char  sDataType[2];
  SINT2 iFieldHeaderPosition;
};

#define UF_MAX_MOMENTS (16)
struct uf_data_header2
{
  SINT2 iFieldsThisRay;
  SINT2 iRecordsThisRay;
  SINT2 iFieldsThisRecord;
  struct uf_dsi2 Dsi[UF_MAX_MOMENTS];
};

struct uf_field_ve
{
  SINT2 iNyquistVelocity;
  SINT2 ipad1;
};

struct uf_field_dm
{
  SINT2 iRadarConstant;
  SINT2 iNoisePower;
  SINT2 iReceiverGain;
  SINT2 iPeakPower;
  SINT2 iAntennaGain;
  SINT2 iPulseDuration;
};

union uf_fsi2
{
  struct uf_field_ve VE;
  struct uf_field_dm DM;
};
#define UF_POL_HORIZONTAL (0)
#define UF_POL_VERTICAL   (1)
#define UF_POL_CIRCULAR   (2)
#define UF_POL_ELLIPTICAL (3)
struct uf_field_header2
{
  SINT2 iDataPosition;       /* Origin 1 offset of data from start of record */
  SINT2 iScaleFactor;        /* Met units = file value/ScaleFactor */
  SINT2 iStartRangeKm;
  SINT2 iStartRangeMeters;
  SINT2 iBinSpacing;         /* Bin spacing in meters */
  SINT2 iBinCount;
  SINT2 iPulseWidth;         /* Pulse width in 1/64 of meters?*/
  SINT2 iBeamWidthH;         /* Horizontal Beam width in 1/64 of degree */
  SINT2 iBeamWidthV;
  SINT2 iBandWidth;          /* Receiver bandwidth in 1/64 Mhz */
  SINT2 iPolarization;
  SINT2 iWaveLength;         /* Wavelength in 1/64 of a cm */
  SINT2 iSampleSize;         /* Sample size */
  char  sThresholdData[2];   /* Type of data used to threshold */
  SINT2 iThresholdValue;
  SINT2 iScale;
  char  sEditCode[2];
  SINT2 iPRT;                /* PRT in microseconds */
  SINT2 iBitsPerBin;         /* Must be 16 */
  /* Some of the fields are optional */
  union uf_fsi2 Fsi;
};

/* Used to define a custom UF data type map */
struct uf_data_map
{
  char  sUfDataType[3];
  UINT1 iIrisDataType;
  /* Additional scale and offset applied to data when converting from UF
   * to IRIS.  UF value (after UF scale applied) is converted to IRIS
   * with IRIS = (fScale*UF) + fOffset.
   */
  FLT4  fScale;
  FLT4  fOffset;
};
