/* *********************************************************************
 * *	                                                               *
 * *                     IRIS Product Definitions                      *
 * *                                                                   *
 * *********************************************************************
 * File: include/product.h
 *
 *  COPYRIGHT (c) 1989, 1990, 1992, 1995, 1996, 1997, 1998, 1999, 2001, 
 *                    2002, 2003, 2004, 2005, 2006 BY
 *              VAISALA, INC., 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.
 *
 * Include requirements: sigtypes.h
 *                       headers.h
 */
#ifndef SIGMET_PRODUCT_H
#define SIGMET_PRODUCT_H 1

#ifdef __cplusplus
extern "C" {
#endif

/*
 * ==========================================================================
 * ==================== Product Configuration ===============================
 * ==========================================================================
 *
 * The product configuration structure holds information that defines what to
 * do in order to make a product.  It does not hold related information about
 * the particular INGEST data that goes into a particular product.  That info
 * is placed in the product file header, defined in the next section.
 *
 */
#define PRODUCT_CONFIGURATION_SIZE  (320)
struct product_configuration
{
  struct structure_header  hdr;	/* Generic Header */

  UINT2 iptype;			/* Product Type Code */
#define PROD_PPI        1	/*  PPI */
#define PROD_RHI        2	/*  RHI */
#define PROD_CAPPI      3	/*  CAPPI */
#define PROD_CROSS      4	/*  Cross section */
#define PROD_TOPS       5	/*  Echo tops */
#define PROD_TRACK      6	/*  Storm track */
#define PROD_RAIN1      7	/*  Precipitation 1 hour */
#define PROD_RAINN      8	/*  Precipitation n hour */
#define PROD_VVP        9	/*  Velocity Volume processing */
#define PROD_VIL        10	/*  Vertically Integrated Liquid */
#define PROD_SHEAR      11	/*  Wind shear */
#define PROD_WARN       12	/*  Warning (overlay) */
#define PROD_CATCH      13	/*  Rain catchments */
#define PROD_RTI        14	/*  Range-Time-Display */
#define PROD_RAW        15	/*  Raw data set (no display)*/
#define PROD_MAX        16	/*  Maximum with side panels */
#define PROD_USER       17	/*  Earth projection user product */
#define PROD_USERV      18	/*  Section projection user product */
#define PROD_OTHER      19	/*  Other user product (no display) */
#define PROD_STATUS     20	/*  Status product (no display) */
#define PROD_SLINE      21	/*  Shear Line Product */
#define PROD_WIND       22	/*  Horizontal wind field */
#define PROD_BEAM       23	/*  Beam pattern */
#define PROD_TEXT       24	/*  Text */
#define PROD_FCAST      25	/*  Forecast */
#define PROD_NDOP       26	/*  Multi-Doppler */
#define PROD_IMAGE      27	/*  Arbitrary graphics image */
#define PROD_COMP       28	/*  Composite */
#define PROD_TDWR       29	/*  TDWR Wind Alert */
#define PROD_GAGE       30	/*  Raingage product */
#define PROD_DWELL      31	/*  Dwell and bird detection product */
#define PROD_SRI        32	/*  Surface Rainfall Intensity */
#define PROD_BASE       33	/*  Echo bottoms */
#define PROD_HMAX       34	/*  Height of Max Reflectivity */

#define PROD33_RANK     0	/*  BASE */
#define PROD23_RANK     1	/*  BEAM */
#define PROD3_RANK      2	/*  CAPPI */
#define PROD13_RANK     3	/*  CATCH */
#define PROD28_RANK     4	/*  COMP */
#define PROD31_RANK     5	/*  DWELL */
#define PROD25_RANK     6	/*  FCAST */
#define PROD30_RANK     7	/*  GAGE */
#define PROD34_RANK     8	/*  HMAX */
#define PROD27_RANK     9	/*  IMAGE */
#define PROD16_RANK    10	/*  Max */
#define PROD26_RANK    11	/*  NDOP */
#define PROD1_RANK     12	/*  PPI */
#define PROD7_RANK     13	/*  Rain 1 */
#define PROD8_RANK     14	/*  Rain n */
#define PROD15_RANK    15	/*  RAW */
#define PROD2_RANK     16	/*  RHI */
#define PROD14_RANK    17	/*  RTI */
#define PROD11_RANK    18	/*  Shear */
#define PROD21_RANK    19	/*  SLINE */
#define PROD32_RANK    20	/*  SRI */
#define PROD20_RANK    21	/*  Status */
#define PROD29_RANK    22	/*  TDWR */
#define PROD24_RANK    23	/*  TEXT */
#define PROD5_RANK     24	/*  TOPS */
#define PROD6_RANK     25	/*  TRACK */
#define PROD10_RANK    26	/*  VIP */
#define PROD9_RANK     27	/*  VVP */
#define PROD12_RANK    28	/*  WARN */
#define PROD22_RANK    29	/*  Wind */
#define PROD4_RANK     30	/*  XSECT */
#define PROD17_RANK    31	/*  USER */
#define PROD18_RANK    32	/*  USERV */
#define PROD19_RANK    33	/*  OTHER */

#define PROD_RANK_LIST {\
    PROD1_RANK,  PROD2_RANK,  PROD3_RANK,  PROD4_RANK,  PROD5_RANK,  PROD6_RANK, \
    PROD7_RANK,  PROD8_RANK,  PROD9_RANK,  PROD10_RANK, PROD11_RANK, PROD12_RANK,\
    PROD13_RANK, PROD14_RANK, PROD15_RANK, PROD16_RANK, PROD17_RANK, PROD18_RANK,\
    PROD19_RANK, PROD20_RANK, PROD21_RANK, PROD22_RANK, PROD23_RANK, PROD24_RANK,\
    PROD25_RANK, PROD26_RANK, PROD27_RANK, PROD28_RANK, PROD29_RANK, PROD30_RANK,\
    PROD31_RANK, PROD32_RANK, PROD33_RANK, PROD34_RANK}

  /* Product licensing bits */
#define LBIT_BASIC    (0x00000001)  /* Basic product set */
#define LBIT_CAPPI    (0x00000002)  /* Full product set */
#define LBIT_MAX      (0x00000004)  /* Full product set */
#define LBIT_RAIN     (0x00000008)  /* Full product set */
#define LBIT_TOPS     (0x00000010)  /* Full product set */
#define LBIT_VIL      (0x00000020)  /* Full product set */
#define LBIT_VVP      (0x00000040)  /* Full product set */
#define LBIT_WIND     (0x00000080)  /* Full product set */
#define LBIT_COMP     (0x00000100)  /* Optional product set */
#define LBIT_SHEAR    (0x00000200)  /* Optional product set */
#define LBIT_IMAGE    (0x00000400)  /* Special product set */
#define LBIT_TEXT     (0x00000800)  /* Special product set */
#define LBIT_USER     (0x00001000)  /* Special product set */
#define LBIT_LLWAS    (0x00002000)  /* Special product set */
#define LBIT_HYDROMET (0x00004000)  /* Optional product set */
#define LBIT_DWELL    (0x00008000)  /* Optional product set */
#define LBIT_UNUSED   (0x10000000)  /* Unused product set */

#define PROD1_LBIT    LBIT_BASIC    /* PPI */
#define PROD2_LBIT    LBIT_BASIC    /* RHI */
#define PROD3_LBIT    LBIT_CAPPI    /* CAPPI (full) */
#define PROD4_LBIT    LBIT_BASIC    /* Cross section */
#define PROD5_LBIT    LBIT_TOPS     /* Tops */
#define PROD6_LBIT    LBIT_BASIC    /* Track */
#define PROD7_LBIT    LBIT_RAIN     /* Rain1 */
#define PROD8_LBIT    LBIT_RAIN     /* RainN */
#define PROD9_LBIT    LBIT_VVP      /* VVP */
#define PROD10_LBIT   LBIT_VIL      /* VIP */
#define PROD11_LBIT   LBIT_SHEAR    /* Shear */
#define PROD12_LBIT   LBIT_BASIC    /* Warning */
#define PROD13_LBIT   LBIT_HYDROMET /* CATCH */  
#define PROD14_LBIT   LBIT_BASIC    /* RTI */
#define PROD15_LBIT   LBIT_BASIC    /* RAW */
#define PROD16_LBIT   LBIT_MAX      /* Max */
#define PROD17_LBIT   LBIT_USER     /* USER */
#define PROD18_LBIT   LBIT_USER     /* USERV */
#define PROD19_LBIT   LBIT_USER     /* OTHER */
#define PROD20_LBIT   LBIT_BASIC    /* Status */
#define PROD21_LBIT   LBIT_SHEAR    /* SLine */
#define PROD22_LBIT   LBIT_WIND     /* Wind */
#define PROD23_LBIT   LBIT_BASIC    /* Beam */
#define PROD24_LBIT   LBIT_TEXT     /* Text */
#define PROD25_LBIT   LBIT_BASIC    /* Forecast */
#define PROD26_LBIT   LBIT_COMP     /* NDOP */
#define PROD27_LBIT   LBIT_IMAGE    /* Image */
#define PROD28_LBIT   LBIT_COMP     /* COMP */
#define PROD29_LBIT   LBIT_LLWAS    /* LLWAS */
#define PROD30_LBIT   LBIT_HYDROMET /* GAGE */
#define PROD31_LBIT   LBIT_DWELL    /* DWELL */
#define PROD32_LBIT   LBIT_CAPPI    /* SRI */
#define PROD33_LBIT   LBIT_BASIC    /* BASE */
#define PROD34_LBIT   LBIT_BASIC    /* HMAX */

#define PROD_LBIT_LIST {\
    PROD1_LBIT,  PROD2_LBIT,  PROD3_LBIT,  PROD4_LBIT,  PROD5_LBIT,  PROD6_LBIT, \
    PROD7_LBIT,  PROD8_LBIT,  PROD9_LBIT,  PROD10_LBIT, PROD11_LBIT, PROD12_LBIT,\
    PROD13_LBIT, PROD14_LBIT, PROD15_LBIT, PROD16_LBIT, PROD17_LBIT, PROD18_LBIT,\
    PROD19_LBIT, PROD20_LBIT, PROD21_LBIT, PROD22_LBIT, PROD23_LBIT, PROD24_LBIT,\
    PROD25_LBIT, PROD26_LBIT, PROD27_LBIT, PROD28_LBIT, PROD29_LBIT, PROD30_LBIT,\
    PROD31_LBIT, PROD32_LBIT, PROD33_LBIT, PROD34_LBIT}



  /* The following variables are used to schedule the running of this product
   * configuration.  Starting from EPOCH, either the next available data, or
   * all available data (as per ISCH) will be processed.  The various time
   * structures have the following meaning.
   *
   *    1) The "ing_time" time structure has different meaning depending on
   *  the type of product.  TZ determined by iMinutesWest and sTZName.
   *
   *  a) For "immediate" products (i.e., PPI, RHI, SHEAR, and single
   *     sweep RAW), the "ing_time" structure holds the starting time
   *     of the specific sweep that was used to make the product.
   *
   *  b) For "volume scan" products (i.e., all others), the "ing_time"
   *     structure holds the time of the start of the earliest INGEST
   *     volume scan that was used in making the product.  For example,
   *     if a TOPS product is made from two hybrid tasks "TASK_B" and
   *     "TASK_C", then the TOPS "ing_time" would be the starting time
   *     of the "B" volume scan.
   *
   *    2) The "epoch" time structure is used for scheduling the products,
   *  and always has the contents of "b)" above, regardless of whether
   *  the product is an "immediate" or "volume scan" type.  Thus, as an
   *  "immediate" product runs through the individual tilts of a volume
   *  scan, the "epoch" time remains fixed at the volume scan starting
   *  time, whereas the "ing_time" time marchs forward for each sweep
   *  processed.
   *
   *    3) The "prod_time" time structure refers to the time that the product
   *  file was produced on whatever machine originally generated it.
   *  While in the product scheduler, this is the next-data-time.
   *  TZ determined by the setup question.
   */
  UINT2  isch;			/* Scheduling */
#define PSC_HOLD      0		/*  Do not run at all. */
#define PSC_NEXT      1		/*  Run once on next available data */
#define PSC_ALL       2		/*  Run as data becomes available */
#define PSC_AGAIN     3		/*  Run again on data last used */
#define PSC_ONCE      4		/*  Run once then remove from schedule */

  SINT4 isch_skip;		/* # seconds between runs */

  struct ymds_time prod_time;	/* Time product was created */
  struct ymds_time ing_time;	/* Time of ingest data product was made from */
				/* For RAIN1 and RAINN, end of time interval */

  struct ymds_time epoch;	/* Beginning of scheduling time period */

				/* The following text strings must be in upper case: */

  char ipad56x6[6];
  char spname[12];		/* Product configuration name */

  char stname[12];		/* Task configuration name */

  UINT2 iflags;			/* Flags */
  /* Flags in the file, and in the inventory
   */
#define PF_KEEP        (0x0020)  /* Do not remove this file    */
#define PF_CLUTTER     (0x0040)  /* This is a clutter map      */
#define PF_COMPOSITED  (0x0800)  /* This product has been composited*/
#define PF_DWELL       (0x1000)  /* This product is a dwell product*/
#define PF_ZR_SOURCE0  (0x2000)  /* Source of Z/R numbers: */
#define PF_ZR_SOURCE1  (0x4000)  /* 0:TypeIn, 1:Setup, 2:Disdro, 3:Unused */

  /* Product type specific flags in the file, and in the inventory
   */
#define PF_WARN_TDWR   (0x0002)  /* Make TDWR style messages */
#define PF_WARN_SAY    (0x0080)  /* Speak warning messages */

  /* Bits stored in the file
   */
#define PF_IN_FILE (PF_KEEP|PF_CLUTTER|PF_WARN_TDWR|PF_WARN_SAY|PF_COMPOSITED|PF_DWELL|PF_ZR_SOURCE0|PF_ZR_SOURCE1)

  /* Bits controlled by PCF menu
   */
#define PF_IN_PCF  (PF_WARN_TDWR|PF_WARN_SAY|PF_ZR_SOURCE0|PF_ZR_SOURCE1)

  /* Flags in the product schedule
   */
#define PF_RUNNING    (0x0004)  /* This pcf is being run               */
#define PF_HEADER     (0x0008)  /* Header, placeholder only, dont execute  */

  /* Flags in the product inventory only
   */
#define PF_DELETE     (0x0010)  /* Delete this product        */
#define PF_REINGEST   (0x0100)  /* Tagged for reingesting     */
#define PF_TIMEOUT    (0x0200)  /* Status product has timed out*/
#define PF_PENDING    (0x0001)  /* Status product from before startup*/

  /* Flags in server-to-client report */
#define PF_CHECKED    (0x0400)  /* Status product checking enabled for this site*/

  SINT4 ixscale, iyscale, izscale ; /* Scale in cm/pixel  */
  SINT4 ixsize , iysize , izsize  ; /* Size of (up to 3) dimensions     */

#define MIN_PRODUCT_SIZE     (16)   /* Min/Max sizes of X & Y */
#define MAX_PRODUCT_SIZE   (3100)
#define MAX_PRODUCT_SURFACES (50)   /* CAPPI, MAX, etc., horizontal surface bound */

  SINT4 ixrad,  iyrad,  izrad;	/*  Location of radar in pixels*1000 */

  /* The following variable is only used in the version 2.0 structures with
   * version numbers 1 or less.
   */
  SINT4 irange_last_v20;	/* Range of last bin in cm (raw only) */
  char ipad128x2[2];
  UINT2 idata_out;		/* Data type of data generated by product gen */

  /* This section for version 2.1+ products
   */
  char  sprojection_name[12];	/* Projection name, null terminated */
  UINT2 idata_in;		/*  Data type used by the generator */
  UINT1 iprojection_type;	/* Projection type for map */
  char ipad147x1;
  SINT2 iradial_smooth;		/* Range in km*100 over which radial  */
				/* smoothing should be done.  0:none. */
  UINT2 iruns;			/* # of times this pcf has been run   */
  SINT4 izr_const;		/* Z-R or Z-W constant and exponent   */
  SINT4 izr_exp;		/*  in 1/1000 of integers             */
  SINT2 ix_smooth;		/* X-Y Smoothing parameters for 2D */
  SINT2 iy_smooth;		/*  products.  km*100,  0:none */

  /* ---- Product Specific Parameters ----
   * The following area conveys information needed for each specific product.
   */
  PSI psi;

  char ipad244x28[28];
  struct color_scale_def colors;
} ;

typedef struct product_configuration PCF;


/* This is for the client receiving data from the server
 */
struct serv_product_configuration
{
  struct serv_structure_header  hdr; /* Generic Header */

  UINT4 iptype;                      /* Product Type Code */

  struct serv_ymds_time ing_time;  /* Time of ingest data product was made */

  /* For RAIN1 and RAINN, end of time interval
   */
  struct serv_ymds_time epoch;     /* Beginning of scheduling time period */

  UINT4  isch;                     /*  Scheduling */

  SINT4 isch_skip;                 /*  # seconds between runs */

  /* The following text strings must be in upper case
   */
  char spname[12];                 /* Product configuration name */
  char stname[12];                 /* Task configuration name */

  UINT4 iflags;                    /* Flags */

  SINT4 ixscale, iyscale, izscale; /*  Scale in cm/pixel  */
  SINT4 ixsize, iysize, izsize;    /*  Size of (up to 3) dimensions     */
  SINT4 ixrad;                     /*  Location of radar in pixels*1000 */
  char ipad_radpos[8];

  UINT4 idata_out;              /* Data type of data generated by product gen */

  char  sprojection_name[16];	/* Projection name, null terminated */
  UINT4 idata_in;		/*  Data type used by the generator */
  UINT4 iprojection_type;	/* Projection type for map */
  SINT4 iradial_smooth;		/* Range in km*100 over which radial  */
				/*  smoothing should be done.  0:none. */
  SINT4 izr_const;		/* Z-R or Z-W constant and exponent   */
  SINT4 izr_exp;		/*  in 1/1000 of integers             */
  SINT4 ix_smooth;		/* X-Y Smoothing parameters for 2D */
  SINT4 iy_smooth;		/*  products.  km*100,  0:none */

  /* ---- Product Specific Parameters ---- */
  /* The following area conveys information needed for each specific product.
   */
  SPSI spsi;
  struct server_color_scale_def colors;
};
typedef struct serv_product_configuration SPCF;


/* =========================================================================
 * ==================== Product End ========================================
 * =========================================================================
 */
#define PRODUCT_END_SIZE  (308)

struct product_end
{
  char sprod_sitename[16];	/* Name of product generator site, space padded */
  char sprod_version[8];	/* Product IRIS version, null terminated */
  char sing_version[8];		/* Ingest IRIS version, null terminated */
    
  struct ymds_time old_ing;	/* Oldest data in this file */
  char ipad44x28[28];

  SINT2 iLocalWest;             /* # minutes local standard time is west of GMT */
  char  sIngHardwareName[16];	/* Hardware name of ingest site, space padded */

  /* Information about the radar site.  Latitude and Longitude are stored as 
   * 32-bit binary angles, where 20000000 Hex is 45 degrees North Latitude or 
   * East Longitude.  For products of many tasks,
   * these are taken from the first site.  For track product, these are taken
   * from the site making the track.
   */
  char  sing_sitename[16];	/* Name of ingest site, space padded */
  SINT2 iMinutesWest;		/* # minutes recorded standard time is west of GMT */
  BIN4  ilat_center;		/* Latitude of center of product */
  BIN4  ilon_center;		/* Longitude of center of product */
  SINT2 ignd_hgt;		/* Ground height (m above sea level) */
  SINT2 irad_hgt;		/* Radar height (m above ground) */

  /* Signal processing related numbers.  These are mostly copied from the task
   * configuration structure.
   */
  SINT4 iprf;			/* PRF in hertz */
  SINT4 ipw;			/* Pulse width in 1/100 usec */
  UINT2 idsptype;
  UINT2 itrig;			/* Trigger rate scheme */
  SINT2 isamp;			/* # samples used */
  char  sfilter[12];		/* Clutter filter file name */
  UINT2 idop_filter_first;	/* Doppler filter used on first bin */
  SINT4 ilambda;		/* Wavelength in cm*100 */
  SINT4 itrunc;			/* Truncation height (cm above the radar) */
  SINT4 ibin_first;		/* Range of first bin in cm */
  SINT4 ibin_last;		/* Range of last bin in cm */
  SINT4 ibin_out_num;		/* Number of output bins */

  SINT2 iPEFlags;		/* Was iflags */

  /* If the Disdrometer was selected as the Z/R source, but it was not
   * available, then we switch to setup source, and set this bit.
   */
#define PEF_ZR_FALLBACK (0x0001)

  SINT2 input_cnt;              /* Number of ingest and product files
				 * processed to produce this product
				 * (only for accumulating products). */

  UINT2 ipolar;			/* Type of polarization, see dsp_lib.h */
  SINT2 iI0Horiz;               /* I0 number from calibration, 1/100 of dB */
  SINT2 iCalNoiseHoriz;         /* Noise at calibration time, 1/100 of dBm */
  SINT2 iRadarConstantHoriz;    /* Radar constant, 1/100 of dB */
  UINT2 iReceiverBandwidth;     /* Receiver bandwidth, in kHz */
  SINT2 iActNoiseHoriz;         /* Noise level, 1/100 of dBm */

  char ipad184x28[28];

  BIN4  iStdParallel1; /* Standard parallels used in Lambert Conformal Conic */
  BIN4  iStdParallel2;
  UINT4 iEarthRadius;  /* Earth's equitorial radius in cm */
  UINT4 iFlattening;   /* 1/Flattening in 1/1000000 */

  /* System fault status at the time the task was started.  See the
   * 'ICFB_..." macros in ingest.h for the definition of these bits.
   */
  UINT4 iFaultBits ;

  UINT4 iSiteMask;              /* Mask of sites in the product (if PF_COMPOSITED) */
  UINT2 ilog_filter_first;	/* Log filter used on first bin */
  UINT2 lclutmap_used ;		/* Clutter map applied to DSP data */

  BIN4  ilat_ref;		/* Latitude of projection reference point */
  BIN4  ilon_ref;		/* Longitude of projection reference point */

  /* The following sequence number can be used whenever product files
   * need to be ordered or indexed in some way.  For example, when the
   * Nth product is written to a tape, the value is filled in with N.
   */
  UINT2 isequence_num;

  /* Only applicable to picture products, will be zeroed in data products
   */
  UINT2 istep_colors[16];	/* Color #'s for above steps */

  SINT2 iMeltingHeight;         /* Melting height MSB complemented (m above MSL) */
  SINT2 iReferenceOffset;	/* Height of radar above Reference in meters */

  /* The number of results elements at the end of the file.  Used for
   * WARN, SLINE, STAT, TRACK only.  In STAT products, there is always one
   * status_results structure, followed by iresults_count-1 status_one_message
   * structures.
   */
  SINT2 iresults_count;

  /* Wind speed and direction, if available.  Set to zero if unknown.  If
   * the wind speed is known, but is zero, then set direction to 255.  Speed
   * is in nearest 0.5 m/s, and direction is binary angle.
   */
  UINT1 iWindSpeed;
  UINT1 iWindDirection;
  char  ipad290x2[2];
  char  sLocalTZName[8];         /* Name of timezone of local time */
  char  ipad300x8[8];
};

/* =========================================================================
 * ==================== Product Header =====================================
 * =========================================================================
 *
 * The following structure is the header for Product data files.  The header
 * holds the product config structure, plus related information about the files
 * that were used to make the product.  The product header is followed by the
 * data itself.
 */
#define PRODUCT_HDR_SIZE (STRUCT_HEADER_SIZE + PRODUCT_CONFIGURATION_SIZE + \
			  PRODUCT_END_SIZE)
struct product_hdr
{
  struct structure_header      hdr;     /* Generic Header */
  struct product_configuration pcf;     /* Product Config Info */
  struct product_end           end;     /* Product end info */
};
typedef struct product_hdr PHD;

/* ======================================================================
 * These specific_options structures are all long words because they
 * are served out and must be byte swapped correctly.
 */
#if 0
struct generic_specific_options
{
  UINT4 iPType;                    /* Not used in shared memory */
  SINT4 iDeviceIndex;              /* Origin 0 device index, not used in shared memory */
};
#endif

struct vvp_specific_options
{
  UINT4 iPType;                    /* Not used in shared memory */
  SINT4 iDeviceIndex;              /* Origin 0 device index, not used in shared memory */
#define OP_VVP_TIMEHEIGHT (0x00000001)  /* Display as time/height rather than graph */
  UINT4 iflags;
  SINT4 iheight_max;               /* Height max (cm above reference) */
  SINT4 iheight_step;              /* Step in cm */
  UINT4 ithreshold;                /* Threshold value (0 to 100%) */

  /* Options here are for graph display only */
  UINT4 igr_plot_mask;             /* Mask of data to plot */
  SINT4 igr_max_hvel;              /* Units: 2-byte velocity */
  SINT4 igr_max_diverg;
  SINT4 igr_max_vvel;              /* Units: 2-byte velocity */
  SINT4 igr_max_deform;
  SINT4 igr_max_dbz;               /* Units: 2-byte dBZ */

  /* Options here are for time height display only */
  UINT4 ith_time_span;             /* Time span in seconds */
  UINT4 ith_time_step;             /* Min time step in seconds */
  UINT4 ith_under_plot;            /* Data to plot as underlay */
  UINT4 ith_over_plot;             /* Data to plot as overlay */
#define VVP_WIND_BARBS   (1)
#define VVP_WIND_STRINGS (2)
#define VVP_AXDIL_LINES  (3)
};

struct wind_specific_options
{
  UINT4 iPType;                    /* Not used in shared memory */
  SINT4 iDeviceIndex;              /* Origin 0 device index, not used in shared memory */
#define OP_WIND_STRINGS   (0x00000001)  /* Display as strings rather than barbs */
#define OP_WIND_SUBMEAN   (0x00000002)  /* Subtract mean wind before displaying */
  UINT4 iflags;
  SINT4 iHeight;                   /* Height for CAPPIs (cm above reference)*/
  SINT4 iMaxHVel;                  /* Max velocity for strings, Units: 2-byte velocity */
  UINT4 iThreshold;                /* Threshold value (0 to 100%) */
};

struct warn_specific_options
{
  UINT4 iPType;                    /* Not used in shared memory */
  SINT4 iDeviceIndex;              /* Origin 0 device index, not used in shared memory */
  SINT4 iForecastSeconds;          /* Forecast time for arrow, none if <=0 */

  SINT4 iCentroidLabel;            /* How we should label the centroids */
#define CENTROID_LABEL_NONE    (0)
#define CENTROID_LABEL_MAXIMUM (1)
#define CENTROID_LABEL_AVERAGE (2)
#define CENTROID_LABEL_SPEED   (3)

  SINT4 iCentroidFill;             /* How we should fill the centroids */
#define CENTROID_FILLED  0
#define CENTROID_HATCHED 1
#define CENTROID_OPEN    2

};

union  product_specific_options2
{
  struct vvp_specific_options     Vvp;
  struct wind_specific_options    Wind;  /* Also: CAPPI, NDOP, FCAST */
  struct warn_specific_options    Warn;
};


struct apo_spec
{
  UINT4 iptype;
  char  spname[16];   /* Null terminated */
};

/* Output options structure
 */
struct output_options
{
  struct apo_spec apo[3];  /* APO control */
  
  UINT2 iSepFlags;          /* output flags, separate for each product */
#define OP_LEGEND      (0x001)          /*Draw legend on output*/
#define OP_OVERLAY     (0x002)          /*Draw overlay on output*/
#define OP_SHADOW0     (0x004)          /*Drop shadow depth*/
#define OP_SHADOW1     (0x008)
#define OP_APO_LIVE    (0x010)          /* APO is live*/
#define OP_CATCH_LABEL (0x020)          /* Draw catch names on output*/
#define OP_CATCH_ICONS (0x040)          /* Draw catch icons rather than regions*/
#define OP_TIME_UTC    (0x080)          /* Display time in UTC rather than local */
#define OP_TIME_NODEF  (0x100)          /* Do not Display time in default */
#define OP_SEPARATE (OP_LEGEND|OP_OVERLAY|OP_SHADOW0|OP_SHADOW1|OP_APO_LIVE|OP_CATCH_LABEL|OP_CATCH_ICONS)
#define OP_COMMON   (OP_TIME_UTC|OP_TIME_NODEF)
  UINT1 irangering;        /* range ring selection */
#define RING_NONE_P   (0)              /* No ring */
#define RING_ONLY_P   (1)              /* Ring only no numbers */
#define RING_NUMS_P   (2)              /* Ring with numbers */
#define RING_LATLON_P (3)              /* Lat/lon overlay */

  UINT1 ilayer_mask_index; /* Overlay layer control */
};
typedef struct output_options OUT_OPT;

struct device_update
{
  SINT4 iDevice;
  /* Indicate QL window's mode */
#define DEVICE_MODE_AUTO_NOLOOP (0)
#define DEVICE_MODE_AUTO_LOOP   (1)
#define DEVICE_MODE_USER_NOLOOP (2)
#define DEVICE_MODE_USER_LOOP   (3) 
  UINT4 iMode;
  UINT4 iCurrentSiteNum;
  UINT4 iCurrentPType;
  char  sCurrentPName[16];
  struct ymds_time Time;
  char  sTrackPName[16];   /* Track product name, zero indicates not in track mode */
  SINT4 iCrossSize[2];     /* Size of cross product output, zero means not in cross mode */
};

struct ForecastOptions
{
  SINT4  iDeviceIndex;   /* Not used in memory copy */
  char   sPName[16];     /* Product name to use */
  SINT4  iTime;          /* Forecast time in seconds */
  SINT4  iSpeed;         /* Speed in cm/hour */
  BIN4   iDirection;     /* Direction */
  UINT4  iFlags;
#define OP_FCAST_ENABLED    (0x0001)
#define OP_FCAST_USEPRODUCT (0x0002)
};

struct common_options
{
  UINT4  iunits;
  UINT2  iComFlags;              /* output flags, common for each product */
  UINT2  iRingSpacing;           /* Range ring spacing in km, 0=auto */
  char   sRingCenter[16];        /* Range center from home point list */
  struct ForecastOptions Forecast;
};

struct device_output_options
{
  struct output_options ptype[NUM_DEFINED_PRODUCTS];
  struct vvp_specific_options  VvpOptions;
  struct wind_specific_options WindOptions;   /* Used for wind, cappi, ndop, fcast */
  struct warn_specific_options WarnOptions;   /* Used for WARN, TDWR, TRACK */

  struct server_color_scale_def  scales[SERVER_DTYPE_COUNT];
  struct device_update Update;   /* Update state is not saved to disk! */
  struct common_options Common;  /* Options common to all product types */
};

struct server_output_options
{
  UINT4 iptype;
  SINT4 idevice_index;
  struct apo_spec apo[3];
  UINT4 irangering;
  UINT4 iout_flags;
#define OP_SET_LAYER_ONLY  (0x10000)
  UINT4 ilayer_mask_index;
  UINT4 iunits;
  UINT4 iRingSpacing;
  char  sRingCenter[16];        /* Range center from home point list */
};
typedef struct server_output_options SOUT_OPT;

struct tabulation_list_header
{
  SINT4 isend_num;
  char  soverlay_file[16];
};

struct tabulation_list_item
{
  char  slayer[20];
  char  sname_short[20];
  char  sname_full[40];
};

struct tabulation_list
{
  struct tabulation_list_header lhdr;
  struct tabulation_list_item   items[1];
};

/* =========================================================================
 * =============== Miscellaneous Definitions ===============================
 * =========================================================================
 *
 * The following header is written at the beginning of each "sweep block" in
 * the Raw Product files.  It is included primarily for error recovery
 * in the context of retrieving those files from tape.
 */

#define RAW_PROD_BHDR_SIZE  (12)

struct raw_prod_bhdr
{
  SINT2 irec;                       /*  Record # */
  SINT2 isweep;                     /*  Sweep # */
  SINT2 iray_ptr;                   /*  Byte offset (from BHdr) of first ray */
  SINT2 iray_num;                   /*  Ray number of above first ray */
  UINT2 iflags;                     /*  Flags */
#define APB_NOGOOD    (0x0001)	    /*    Block has invalid data */
  UINT1 ipad10x2[2];
};

/* Blocks of sweep data in the Raw file look like the following */

#define RAW_PROD_SDATA_SIZE (TAPE_RECORD_LEN - RAW_PROD_BHDR_SIZE)

struct raw_prod_block
{
  struct raw_prod_bhdr hdr;
  UINT1 ibytes[ RAW_PROD_SDATA_SIZE ];
};

#define CATCH_RESULTS_SIZE (100 + 2*96)
struct catch_results
{
  char  sName[16];     /* Name of catchment area, null terminated */
  UINT4 iNumber;       /* Number of catchment area */
  BIN4  iLabelLat;     /* Lat/Long of the label (where label is drawn) */
  BIN4  iLabelLon;
  SINT4 iArea;         /* Area of catchment in 1/100 of square km */
  SINT4 iPixelCount;   /* Number of pixels in the catchment */
  SINT4 iCoverCount;   /* Min number of pixels in the catchment scanned by the radar */
#define CATCHRES_FLG_WARN_ON  (0x01)  /* Warnings enabled for the catchment */
#define CATCHRES_FLG_WARN     (0x02)  /* Warning triggered for the catchment */
  UINT4 iFlags;

  UINT2 iRain;         /* Average rain depth in the catchment area */

  char ipad46x54[54];
  UINT2 iRainHourly[96]; /* Hourly rain inputs, most recent first,
			  * missing slots with DV_NOSCAN2 */
} ;

struct server_catch_results
{
  char  sName[16];     /* Name of catchment area, null terminated */
  UINT4 iNumber;       /* Number of catchment area */
  BIN4  iLabelLat;     /* Lat/Long of the label (where label is drawn) */
  BIN4  iLabelLon;
  UINT4 iHoursAndFlags;  /* Number of hours in low 16-bits, flags in high 16-bits */
  UINT4 iSpan;           /* Span in seconds of each input */
  UINT4 iRain;           /* Average rain depth in the catchment area.
			  * If DISDRO and NORAIN set, then ZRConst in low, ZRExp in high */
  UINT4 iRainHourly[96]; /* Hourly rain inputs, most recent first,
			  * missing slots with DV_NOSCAN2. */
} ;

#define GAGE_RESULTS_SIZE (40)
struct gage_results
{
  char  sName[16];     /* Name of gage, null terminated */
  BIN4  iLabelLat;     /* Lat/Long of the sensor */
  BIN4  iLabelLon;
  UINT2 iRainRate;     /* Average rainrate in DB_RAINRATE2 for the time span */
  UINT2 iCorrection;   /* Correction factor in dB, DB_DBZ2 format, DV_THRESH0 if none */
  UINT1 iDataQuality;  /* Data quality flag, range 0-10 */
#define GAGE_FLG_SKIP   (0x01)  /* Skip using this sensor */
#define GAGE_FLG_DISDRO (0x02)  /* Sensor has Z/R numbers (is a Disdrometer) */
#define GAGE_FLG_NORAIN (0x04)  /* Sensor does not have Rainrate (is not a gauge) */
  UINT1 iFlag;
  UINT2 iZrConst;      /* Z-R constant in 1/10 */
  UINT2 iZrExp;        /* Z-R exponent in 1/1000  */

  char  ipad34x6[6];
} ;

/* --------------------
 * The VVP product consists of an array of the following structures, one for
 * each height interval that was computed.  There are 32 possible int*2 values
 * and a 32-bit mask in the PSI structure telling which of them were actually
 * computed and filled in.
 */
#define VVP_RESULTS_SIZE  (20 + 2*32)

struct vvp_results
{
  SINT4 icount;                     /* Number of data points used here */
  SINT4 iheight;                    /* Center interval height (cm above reference) */
  SINT4 iZCount;                    /* Number of data points used for Z*/
  char ipad12x8[8] ;

#define VVP_UNFOLD       0x80000000 /* Use unfolding VVP algorithm */
#define VVP_HVEL         0x00000001 /* Horizontal Wind velocity and standard deviation */
#define VVP_HVEL_STD     0x00000002 /*  in cm/sec */
  SINT2 ihvel, ihvel_std;

#define VVP_HDIR         0x00000004 /* Wind direction and standard deviation */
#define VVP_HDIR_STD     0x00000008 /*  in degrees*10 */
  SINT2 ihdir, ihdir_std;

#define VVP_VVEL         0x00000010 /* Vertical speed and standard deviation */
#define VVP_VVEL_STD     0x00000020 /*  in cm/sec */
  SINT2 ivvel, ivvel_std;

#define VVP_DIVERG       0x00000040 /* Horizontal divergence in 1E7/sec, and its */
#define VVP_DIVERG_STD   0x00000080 /*  standard deviation. */
  SINT2 idiverg, idiverg_std;

#define VVP_RVEL_STD     0x00000100 /* Std deviation of radial velocity points*/
  SINT2 irvel_std;                  /*  in cm/sec */

#define VVP_LINDBZ       0x00000200 /* Reflectivity in standard 2-byte format */
#define VVP_LOGDBZ_STD   0x00000400
  SINT2 iLindBZ, iLogdBZ_std;

#define VVP_DEFORM       0x00000800 /* Deformation in 1E7/sec, and its */
#define VVP_DEFORM_STD   0x00001000 /*  standard deviation. */
  SINT2 ideform, ideform_std;

#define VVP_AXDIL        0x00002000 /* Axis of dilatation (0-180 degrees) */
#define VVP_AXDIL_STD    0x00004000 /*  in degrees*10. */
  SINT2 iaxdil, iaxdil_std;

#define VVP_LOGDBZ       0x00008000 /* Reflectivity in standard 2-byte format */
#define VVP_LINDBZ_STD   0x00010000
  SINT2 iLogdBZ, iLindBZ_std;

  char ipad54x30[30] ;
};
#define VVP_ALL_PARAMS   (VVP_HVEL | VVP_HVEL_STD | VVP_HDIR   | VVP_HDIR_STD | \
			  VVP_VVEL | VVP_VVEL_STD | VVP_DIVERG | VVP_DIVERG_STD | \
			  VVP_RVEL_STD | VVP_LINDBZ | VVP_LINDBZ_STD | \
			  VVP_LOGDBZ | VVP_LOGDBZ_STD | VVP_DEFORM | VVP_DEFORM_STD |\
			  VVP_AXDIL | VVP_AXDIL_STD )

     /* --------------------
 * The WIND product data section consists of:
 *
 * 1) A single VVP_RESULTS structure that holds the overall wind infor-
 *    mation for the entire volume.
 *
 * 2) An array of the following structures, organized in BSCAN format,
 *    i.e., all of the ranges for the first azimuth, followed by all of
 *    the ranges for the second azimuth, etc.
 */
#define WIND_RESULTS_SIZE (32)

struct wind_results
{
  SINT4 igeom_count ;		/* Number of possible hits by geometry */
  SINT4 idata_count ;		/* Number of data points used here */
  SINT4 icenter_range ;		/* Sector center range in cm */
  BIN2  icenter_az ;		/* Sector center azimuth as binary angle */

  SINT2 ixvel ;			/* East-West Wind velocity and standard */
  SINT2 ixvel_std ;		/*  deviation in cm/sec */

  SINT2 iyvel ;			/* North-South Wind velocity and standard */
  SINT2 iyvel_std ;		/*  deviation in cm/sec */

  char ipad22x10[10] ;
} ;

/* ----------------------------------------------
 * Results structure used for NDOP and FCAST products.
 */
struct ndop_results
{
  UINT2 iXVel;		/* East-West Wind velocity, DB_VEL2 format */
  UINT2 iYVel;		/* North-South Wind velocity */
  UINT2 iChangeRate;    /* Rate of change in dB/minute DB_DBZ2 format */
  UINT1 iSqi;           /* Fit quality index */
  char ipad7x5[5] ;
} ;
/* ----------------------------------------------
 * Structures used for LLWAS input.
 */
#define LLWAS_HEADER_INPUT_SIZE (18)
struct llwas_header_input
{
  char  sSourceID[4];
  UINT2 iMessageID;
  char  sSystemID;
  UINT1 ipad7x1;
  UINT2 iMessageLength;
  char  sLlwasStatus;
  char  sCFDirection[3];
  char  sCFSpeed[2];
  char  sCFGustSpeed[2];
};
#define LLWAS_RUNWAY_INPUT_SIZE (19)
struct llwas_runway_input
{
  char sCorridor[4];
  char sAlertType[3];
  char sLossGain[3];
  char sLossGainSign;
  char sLocation[3];   /* Location number, not arena name */
  char sThresholdDirection[3];
  char sThresholdSpeed[2];
};
#define LLWAS_INPUT_MAX (16)  /* Maximum number of runways in LLWAS input */
#define LLWAS_INPUT_SIZE (LLWAS_HEADER_INPUT_SIZE + (LLWAS_INPUT_MAX*LLWAS_RUNWAY_INPUT_SIZE))
struct llwas_input
{
  struct llwas_header_input Header;      /* Header size implies runway count below */
  struct llwas_runway_input Runway[LLWAS_INPUT_MAX];  /* Optional entry for each runway */
};

/* Results structure used for TDWR products. */
#define TDWR_RESULTS_SIZE (100)
#define TDWR_RUNWAY_MAX (16)  /* Maximum number of runways in IRIS TDWR product */
struct tdwr_results
{
  char  sCorridor[16];
  char  sArena[8];
  char  sAlertType[3];
  UINT1 ipad27x1;
  char  sThresholdDirection[3];
  UINT1 ipad31x1;
  char  sThresholdSpeed[2];
  UINT1 ipad34x2[2];
  SINT4 iLossGain;             /* Wind speed change in mm/sec, neg=loss */
  UINT4 iProtectMask;          /* Protected areas checked for this corridor */
  UINT4 iProtectHit;           /* Protected area hit for this corridor */
  UINT1 ipad48x52[52];
};

#define SLINE_RESULTS_SIZE  (1000)
/* Shearline product: */
#define SLINE_FLG_FCST   (0x01)
#define SLINE_FLG_WINDS  (0x02)

struct sline_results
{
  SINT4 icenter_east;		/* East coordinate of center point (cm) */
  SINT4 icenter_north;		/* North coordinate of center point (cm) */
  BIN4  irotation;		/* Angle (-90 to 90) to XY axis of curve fit polynomial */
  SINT4 ixleft;			/* X coordinate of left of curve (cm) */
  SINT4 ixright;		/* X coordinate of right of curve (cm) */
  SINT4 icoefs[6];		/* Six polynomial coefficients (cm) */
  SINT4 ifit_std;		/* Standard deviation of fit (cm) */

  SINT4 iprop_speed;		/* Propagation speed (mm/sec) */
  BIN4  iprop_direction;	/* Propagation direction (AZ) */

  SINT4 iref_wind_speed;	/* Reference side wind speed (mm/sec) */
  BIN4  iref_wind_direction;	/* Reference side wind direction (AZ) */
  SINT4 iother_wind_speed;	/* Other side wind speed (mm/sec) */
  BIN4  iother_wind_direction;	/* Other side wind direction (AZ) */

  SINT4 iprotect_etas[32];	/* ETA (seconds) to each prot area (-1 if none) */
  UINT4 iflags;
  char  ipad_end[796];

};

#define TRACK_RESULTS_SIZE  (300)
/* Track product: */
#define TRACK_FLG_FCST   (0x01)
#define TRACK_FLG_MANUAL (0x02)
#define TRACK_FLG_TEXT   (0x04)
#define TRACK_FLG_ICON   (0x08)

struct track_results
{
  /* Position of the center of the centroid */
  BIN4  ilat;
  BIN4  ilong;
  SINT4 iheight;		/* Height (cm above reference) */

  UINT4 iflags;
  SINT4 iarea;			/* Area in 1/100 of square km */
  SINT4 iEllipseMajor;		/* Major axis of equal area ellipse (cm) */
  SINT4 iEllipseMinor;		/* Minor axis of equal area ellipse (cm) */
  BIN4  iEllipseAngle;		/* Orientation angle of ellipse (azimuth) */

  UINT4 iprotect_mask;		/* Protected area mask of areas hit */
  SINT4 imax_value ;		/* Maximum value of data within the area */
  char ipad_40x8[8] ;
  SINT4 iaverage_value ;	/* Average value of data within the area */
  char ipad_52x8[8] ;
  SINT4 iscale;			/* Scale factor of input data (cm/pixel) */

  SINT4 index;			/* Track index (for connecting points) */
  char  stext[32];		/* Text, NULL terminated, icon name if icon */

  struct ymds_time time;	/* Time of this centroid point */
  SINT4 iprotect_etas[32];	/* ETA (seconds) to each prot area (-1 if none) */
  UINT4 idtype[3];              /* Data type of input data, only first slot used */
  SINT4 iprop_speed;		/* Propagation speed (mm/sec) */
  BIN4  iprop_direction;	/* Propagation direction (AZ) */
  UINT4 iTextSize;
  UINT4 iColor;
  char  ipad_268x32[32];

};

/* --------------------
 * The Warning product consists of an array of the following structures, one for
 * each warning found.
 */
#define MAX_WARNINGS_STORED (300)
#define WARNING_RESULTS_SIZE  (300)

struct warning_results
{
  /* Position of the center of the warning area */
  BIN4  ilatitude; 
  BIN4  ilongitude;
  SINT4 iheight;		/* Height (cm above reference) */

#define WARN_FLG_NOLABEL   (0x0001)
  UINT4 iWarnFlags;
  SINT4 iarea;			/* Area in 1/100 of square km */
  SINT4 iEllipseMajor;		/* Major axis of equal area ellipse (cm) */
  SINT4 iEllipseMinor;		/* Minor axis of equal area ellipse (cm) */
  BIN4  iEllipseAngle;		/* Orientation angle of ellipse (azimuth) */

  UINT4 iprotect_mask;		/* Protected area mask of areas hit */
  SINT4 imax_value[3];		/* Maximum value of data in area (1/100 of user units) */
  SINT4 iaverage_value[3];	/* Average value of data in area (1/100 of user units) */
  SINT4 iscale;			/* Scale factor of input data (cm/pixel) */
  char  ipad_64x4[4] ;
  char  stext[16];		/* Text, NULL terminated */
  char  ipad_84x156[156];
  UINT4 idtype[3];              /* Data type of input data */
  SINT4 iprop_speed;		/* Propagation speed (mm/sec) */
  BIN4  iprop_direction;	/* Propagation direction (AZ) */
  char  ipad_260x40[40];
};


#define STATUS_ANTENNA_INFO_SIZE (100)
struct status_antenna_info
{
  /* Current antenna position, in binary angles */
  BIN4 iazpos;
  BIN4 ielpos;

  /* Current antenna velocity, in binary angles/second * by 180/2**31 to go to deg/sec */
  BIN4 iazvel;
  BIN4 ielvel;

  /* Current antenna command bits */
  UINT4 icommand;
  UINT4 icommand_mask;

  /* Current antenna status bits */
  UINT4 istatus;
  UINT4 istatus_mask;

  /* Current Bite flag, nonzero if there is a fault */
  UINT4 ibite_flag;
  SINT4 ibite_field;  /*Lowest field number generating the fault */

  /* Antenna status bits which can make a critical fault */
  UINT4 iStatusCritical;
  /* Mask showing the state of all reported bits from BITE */
  UINT4 iBiteMask[3];
  /* Mask showing all possible faults reported from BITE */
  UINT4 iBiteFaults[3];

  char ipad_end[32];
};

struct status_one_device
{
  UINT4 itype;
  SINT4 iunit;
  UINT4 istatus;
  UINT1 ipad12x4[4];
  UINT4 imode;
  char  sname[16];   /*null terminated*/
  char  ipad_end[4];
};

/* Contains information about all the devices */
#define STATUS_DEVICE_INFO_SIZE (800)
struct status_device_info
{
  struct status_one_device   dsp;
  struct status_one_device   antenna;
  struct status_one_device   output[18];
};

#define STATUS_MESSAGE_INFO_SIZE (200)
struct status_message_info
{
  SINT4 index;                     /*Error entry count since IRIS started */
  MESSAGE imessage;                    /*Message number */
  SINT4 irepeat_count;             /*# of successive occurrences */
  char  sprocess[16];              /*Process that got the error, null terminated */
  char  stext[80];                 /*Error description text, null terminated */
  char  sname[32];                 /*Name of the signal, null terminated */
  struct serv_ymds_time time;      /*Time first one happened */
  UINT4 imsg_type;                 /*Type of message */
  char ipad_end[36];
};

#define STATUS_MISC_INFO_SIZE (200)
struct status_misc_info
{
  char srst_name[16];      /*null terminated*/
  char stsc_name[16];      /*null terminated*/
  char spsc_name[16];      /*null terminated*/
  char spom_name[16];      /*null terminated*/
  char sactive_tname[16];  /*null terminated*/
  char sactive_pname[16];  /*null terminated*/
  UINT4 iris_style;
  SINT4 inetwork_count;
  SINT4 iclient_count;
  char ipad108x4[4];
  SINT4 idevice_count;
  UINT4 iflags;
#define STAT_FLG_AMS_ENABLED (0x00000001)
#define STAT_FLG_FAULT       (0x00000002)  /* Site has a normal fault */
#define STAT_FLG_CRITICAL    (0x00000004)  /* Site has a Critical fault */
#define STAT_FLG_CRIT_MSG    (0x00000010)  /* Site has a Critical fault message */
  char snst_fault_site[4];
  struct ymds_time ing_time;               /* Time of start of currently running task */
  char ipad_end[64];
};

struct status_one_process
{
  UINT4 icommand;
  UINT4 imode;
  char  ipad_end[12];
};

/* Contains information about all the processes */
#define STATUS_PROCESS_INFO_SIZE (400)
struct status_process_info
{
  struct status_one_process ingest;
  struct status_one_process ingfio;
  struct status_one_process pad;  /* Unused, was rtdisp before 8.02 */
  struct status_one_process output_master;
  struct status_one_process product;
  struct status_one_process watchdog;
  struct status_one_process reingest;
  struct status_one_process network;
  struct status_one_process nordrad;
  struct status_one_process server;
  struct status_one_process ribbon;
  struct status_one_process input_master;
  char ipad_end[160];
};


/* This is the structure contained in the status product */
#define STATUS_RESULTS_SIZE (1700)
struct status_results
{
  struct status_misc_info    misc;
  struct status_process_info process;
  struct status_device_info  device;
  struct status_antenna_info antenna;
  struct status_message_info message;
};
#define STATUS_PROD_OK       (0)
#define STATUS_PROD_FAULT    (1)
#define STATUS_PROD_TIMEOUT  (2)
#define STATUS_PROD_PENDING  (3)
#define STATUS_PROD_CRITICAL (4)

#define STATUS_MAX_MESSAGES (8)
#define STATUS_ONE_MESSAGE_SIZE (320)
struct status_one_message
{
  char sText[STATUS_ONE_MESSAGE_SIZE];
};

/* TEXT product */
#define TEXT_RESULTS_SIZE  (512)
struct text_results
{
  char string[TEXT_RESULTS_SIZE];
};

struct one_file_only
{
  char sfile_name[24];                  /*File name, null terminated*/
  PSI psi;

  /* List of the current state of output of this product to various devices. */
  UINT1 iState[ MAX_OUT_DEVICES ]; 
#define OPO_NULL        (0)             /*Do not send */
#define OPO_SEND        (3)             /*Send this file*/
#define OPO_SENT        (4)             /*File has been sent successfully*/
#define OPO_ERROR       (5)             /*Error in sending file*/
#define OPO_SENDING     (6)             /*File is being sent*/
#define OPO_CANCEL      (7)             /*Cancel the output request*/
#define OPO_CANCELLED   (8)             /*Output request has been cancelled*/

  struct ymds_time ing_time ;           /* Date and Time of newest INGEST */
  struct ymds_time file_time ;          /* File system time of last modification */
  struct ymds_time epoch_time ;         /* Scheduling epoch */

  UINT4 isite_num;                      /*Site number */

  char stname[12];                      /*Name of task used as input*/


  /* Information essentially copied from the task configuration: */

  SINT4 ixscale, iyscale;               /*Scale factors*/
  SINT2 ixsize, iysize, izsize;         /*Geometric dimensions*/
  UINT2 idata_out;                      /*Data type code*/

  SINT2 inuse_count;                    /*Count of # of processes using this file*/
  SINT2 iLocalWest;                     /*TZ offset to local time of product */

};
struct one_header_only
{
  /* The low 31 bits are used to indicate requests for the first 31 sites */
  UINT4 iOutput[ MAX_OUT_DEVICES ]; 
#define OPO_NEXTBIT     (0X80000000)    /*Send next only (for all sites)*/

  UINT4 iSendTime[ MAX_OUT_DEVICES ];   /*Time in seconds of the last product sent */
#define OPFH_SEND_NEVER (0xffffffff);   /*Files were never sent since siris time*/

  UINT1 iHeadFlags[MAX_OUT_DEVICES];
#define OPFH_SKIPBIT     (0x01)         /*Enable skip for this product/device*/

};

union one_product_file_union
{
  /* If ibytes is zero, then this is a header, else file. */
  struct one_file_only File;
  struct one_header_only Head;
};

/* -------------------- Product Directory Summary --------------------
 * The following structure is used to keep track of PRODUCT file directory
 * information.  IRIS maintains this structure itself, rather than relying
 * on system-level directory searches.  This makes the directory management
 * more independent of the processor being used.
 *
 * The directory is a linear list of one_product_file structures.
 * The list is sorted:
 *
 *        1) Numerically by product type
 *  then, 2) Alphabetically by product configuration file name
 *  then, 3) By time of INGEST data used to make the product
 *  then, 4) Numerically by site number
 *
 * Note that header entries are sorted only by product type and product name.
 *
 * Structure defining one file entry.  Many of these entries are the same as
 * the corresponding values in the product configuration structure, and the
 * associated parameters should be referenced from there.
 */
struct one_product_file
{
  SINT4 ibytes;                         /*File size in bytes*/
  UINT2 iptype;                         /*Product type code*/
  UINT2 iflags;                         /*Flag bits, see product_config*/
  char spname[12];                      /*Product configuration name (space padded)*/

  union one_product_file_union u;

};

#define MAX_HOME_POINTS (16)
struct home_point
{
  char sName[16];
  UINT4 iFlags;
  BIN4  iLat;
  BIN4  iLon;
  SINT4 iHeight;   /* cm above reference */
};
struct home_inventory
{
  struct home_point home[MAX_HOME_POINTS];
};

#define MAX_DEFINED_STRINGS (16)
struct string_inventory
{
  char string[32];
};

/* Product Directory Structure itself. */
#ifdef SIGMET_SETUP_H
struct product_inventory
{
  struct device_output_options device[MAX_OUT_DEVICES];
  struct overlay_mask_dir      overlay;
  struct home_inventory        HomeInv;
  struct string_inventory      StringInv[MAX_DEFINED_STRINGS];

  SINT4 ioffset_to_OPF;
  char spom_file[12];     /* Space padded */
  char soverlay_list[SITE_LIST_SIZE][16];  /* NULL terminated */

  /* The following arrays hold information grouped by each product type.
   * The corresponding variable with "_tot" suffix represents the sum
   * of all elements in each array.
   */
  struct kilo_count prod_bytes[NUM_DEFINED_PRODUCTS] ; /* Total size of products */
  struct kilo_count prod_bytes_tot ;
  SINT4            iprod_count[NUM_DEFINED_PRODUCTS] ; /* Total number of products */
  SINT4            iprod_count_tot ;
  struct kilo_count keep_bytes[NUM_DEFINED_PRODUCTS] ; /* Total size of kept products */
  struct kilo_count keep_bytes_tot ;
  SINT4            ikeep_count[NUM_DEFINED_PRODUCTS] ; /* Total number of kept products */
  SINT4            ikeep_count_tot ;

  UINT2 ldelete;                        /*Something has been marked for deletion*/
  char  ipad10x2[2];

  struct linear_list_header LHead;
  SINT4                iLList[ 1 ];

  /*  struct one_product_file  file[ * ]; */

};
#endif  /* #ifdef SIGMET_SETUP_H */

struct serv_product_header_only
{
  UINT4 iHeadFlags; /*See definitions in one_product_header_only above */
  UINT4 iOutput; /*See definitions in one_product_header_only above */
};

struct serv_product_file_only
{
  UINT4 isite_num;

  char stname[16];      /*Null terminated*/
  char spsi_text[28];   /*Null terminated*/
  UINT4 idata;          /*Data type of the product*/
  UINT4 ixsize, iysize, ixscale;  /* Only filled in for POM FIND command */
  struct serv_ymds_time ing_time;

  UINT4 iState;    /*See definitions in one_product_file_only above */

};

union serv_product_union
{
  struct serv_product_header_only Head;
  struct serv_product_file_only   File;
};
/* Product header summary used for communication with the iris client interface.
 */
struct serv_product_header_summary
{ 
  SINT4 ibytes;         /*Number of bytes */
  char spname[16];      /*Null terminated*/

  UINT4 iptype;
  UINT4 iflags;         /*Flag bits */
  union serv_product_union u;
};

typedef struct serv_product_header_summary SPHD_SUM;


/* Header structure used just for the POM menu */
struct pom_list_header
{
  struct server_list_header lhdr;
  char sfile_name[16];     /* Name of file, null terminated */
  UINT4 ilayer_mask_indicies[MAX_OUT_DEVICES][NUM_DEFINED_PRODUCTS];
};

/* Data can be cast this way for client-server transfer */
struct pom_list
{
  struct pom_list_header hdr;
  struct serv_product_header_summary list[1];
};


/* Structure used to save send requests in the POM */
struct pom_save_sends
{
  UINT4 iPType;
  char  sPName[16];
  UINT4 iOutput[MAX_OUT_DEVICES];
  UINT1 iHeadFlags[MAX_OUT_DEVICES];
};

#define MAX_POM_SENDS_SAVED (200)
struct pom_save_sends_list
{
  struct pom_save_sends Sends[MAX_POM_SENDS_SAVED];
};


struct ServProductCursor
{
  BIN4  iLat;     /* Cursor location, only used for CATCH & GAGE */
  BIN4  iLon;
};

union ServProductOptions
{
  struct ServProductCursor Cursor;
  UINT4  iOutput;
};

/* Used for product loading in the window process, and POM menu
 */
struct ServProductLoad
{                 
  SINT4 idevice;        /* Device number */
  UINT4 iptype;         /* Product type */
  char spname[16];      /* Null terminated*/
  struct serv_ymds_time ing_time; /* Year to YEAR_MOST_RECENT means send most recent */
  UINT4 isite_num;      /* Can be SITE_WILD */
  union ServProductOptions Options;
};

/* Used to request the slide show info from the server */
struct  SlideShowList
{
  UINT4 iSiteNumber;    /* Site number, can be SITE_WILD */
  UINT4 iPType;         /* Product type */
  char  sPName[16];     /* Product name, null terminated */
  UINT4 iTimeLag;       /* Lag of product, 0=most recent, 1=next older, etc. */
  UINT4 iDwellTime;     /* How long to display the product, seconds */
};

/* Product List Structure */

#define PCF_LINKED_LIST_SIZE ( LINKED_LIST_HEADER_SIZE + \
			       (LINKED_LIST_ITEM_SIZE * MAX_PSC_SLOTS) )
struct pcf_linked_list
{
  struct linked_list_header lhdr;
  struct linked_list_item   llst[ MAX_PSC_SLOTS ];
};

#define PSC_ENTRY_SIZE (PRODUCT_CONFIGURATION_SIZE + 4)
struct psc_entry
{
  PCF pcf;
  UINT4 isite_num;
};

/* Product schedule stored in shared memory. */

#define PRODUCT_SCHEDULE_SIZE ( (PSC_ENTRY_SIZE * MAX_PSC_SLOTS) + \
				PCF_LINKED_LIST_SIZE + 12 + 4 )
struct product_schedule
{
  struct psc_entry entry[MAX_PSC_SLOTS];
  struct pcf_linked_list pcf_l;
  char spsc_file[12];
  UINT4 isite_group_mask;
};
typedef struct product_schedule PSC;

/* product schedule summary structure used for server communication */

struct serv_product_schedule_summary
{
  UINT4            iptype;	/*product type */
  char             spname[16];  /*product configuration name(null terminated) */
  char             stname[16];	/*task configuration name(null terminated) */
  char             sDataOut[8]; /* product data generated */
  /* UINT4            idata_out; */ /* product data generated */
  UINT4            isch;	/* scheduling */
  struct serv_ymds_time epoch;	/* beginning of period */
  SINT4            isch_skip;	/* # seconds between runs */
  UINT4            iflags;	/* flags */
  UINT4            iruns;	/* # of times has being run */
  UINT4            isite_num;   /* Site number (includes special codes) */
  UINT4            isite_mask;  /* Mask of all sites in the inventory */
};

#define PSC_SITE_ALL     (0xFFFFFFFF)
#define PSC_SITE_MASTER  (0xFFFFFFFE)
#define PSC_SITE_GROUP   (0xFFFFFFFC)

typedef struct serv_product_schedule_summary SPSC_SUM;

/* Possible replys to server check request */
#define PSC_MISSING   (1)
#define PSC_IDLE      (2)
#define PSC_SCHEDULED (3)
#define PSC_RUNNING   (4)

struct lat_lon_bin4
{
  BIN4 iLatitude;
  BIN4 iLongitude;
};
struct projection_configuration
{
  UINT4 iprojection_type;
  struct lat_lon_bin4 Center;
  struct lat_lon_bin4 Reference;
  UINT4 ixsize;   /* Horizontal size in pixels */
  UINT4 ipad_24x4;
  UINT4 ideast;   /* Distance from center to East edge of the area in cm */
  UINT4 idnorth;  /* Distance from center to North edge of the area in cm */
  BIN4  iStdParallel1; /* Standard parallels used in Lambert Conformal Conic */
  BIN4  iStdParallel2;
  UINT4 iEarthRadius;  /* Earth's equitorial radius in cm */
  UINT4 iFlattening;   /* 1/Flattening in 1/1000000 */
  char  ipad_end[48];
};

#ifdef SIGMET_SETUP_H
struct pom_scale
{
  char  sname[20];
  UINT4 iset_number;
  UINT4 icolcnt;
  UINT4 iFlags;
};

/* Structure used for pom options
 */
struct server_pom_scale_def
{
  SINT4 idevice_index;  /* Index and dtype not used in product configuration */
  UINT4 idtype;

  UINT4 iflags;
  SINT4 icolcnt;
  SINT4 istart;
  SINT4 istep;
  UINT4 iset_number;    /* Origin 1 */
  UINT4 iscale_number;  /* Custom scale number, Origin 0 */
  /* Information about each set */
  char  set_list[COLOR_SET_COUNT][20];
  /* information about each scale */
  struct pom_scale scales[COLOR_SCALE_COUNT];
};

/* Structure used for pcf scales
 */
struct server_scales_setup
{
  struct pom_scale scale[SETUP_DTYPE_COUNT][COLOR_SCALE_COUNT];
};
#endif  /* #ifdef SIGMET_SETUP_H */


/* ============================================================
 * Output process layout control.
 */
struct layout_control
{
  /* The size of the final image: */
  SINT4 ifinal_size[2];

  /* Base position for the legend in the final image.  Note that
   * only one axis is used here at a time.
   */
  SINT4 ilegend_pos[2];

  /* Base position for the product image in the final image. */
  SINT4 iproduct_pos[2];

  /* Size of the product image in the final image. */
  SINT4 iproduct_size[2];

  /* Size on the main panel in the final image of the product image. */
  /* This is the same as the product_size, except for max products, in which case it
   * is the product_size minus the side panel size in the final image.  The
   * apo_image is drawn to this size. */
  SINT4 iproduct_size_main[2];

  /* Size on the source product image in the file. */
  SINT4 isrc_size[2];

  /* The variables below are used only for the merge operation to copy the
   * cartesian APO product into the display window.  Because the product size
   * does not need to match, this operation is more complicated.
   */
  /* Size of area in source product to copy from. */
  SINT4 iapo_src_size[2];
  /* Offset within the source product image to copy from. */
  SINT4 iapo_src_offset[2];
  /* Size of area in final image to copy to. */
  SINT4 iapo_prod_size[2];
  /* Offset within the final image to copy to. */
  SINT4 iapo_prod_offset[2];

#define LEGEND_ON         (0x01)
#define LEGEND_SMALL      (0x02)
#define LEGEND_MEDIUM     (0x04)
#define LEGEND_HORIZONTAL (0x08)
#define LEGEND_VERTICAL   (0x10)
  UINT2 iLegendFlags;
  /* Flag to indicate that the merge being done is for the APO.  This means that
   * the APO variables control what to do.
   */
  UINT2 lapo_copy;

};

/* =========================================================================
 * ================== On Screen Pictures ===================================
 * =========================================================================
 *
 * The following structures are used internally to represent the contents of
 * a display screen, on which is drawn text and data of any sort.  These
 * structures are used by the Output and Window processes.
 *
 * An "On Screen Picture" is made up of rectangular
 * "Data Images", which represent the parameter(s) available for view.
 * Outside of these images there can appear text and annotations of any kind.
 * However, within the Image the pixels represent data in one of several
 * available projections and data types.
 *
 * The concept of images within the picture makes it possible to perform
 * pixel-level post processing of the display.  For example there is sufficient
 * information to place a user-selected overlay on top of any existing image.
 * Likewise it would be possible to report the range, height, bearing, and
 * data level in scientific units for any pixel chosen via, for example, a mouse
 * cursor.
 *
 * The following structure defines a Data Image within a larger picture.
 */

/* size can be freely changed */
struct data_image
{
  /* Coordinates of the image in pixles */
  FLT4 fwin_pos[2];
  FLT4 fwin_size[2];  /* size is from center to center of pixels. */

};

/* The on screen picture structure gives information about the full screen
 * and holds several data image records.
 */
#define PICTURE_MAX_IMAGES      (4)
/* Size can be freely changed */

#define GEOM_VOID      (0)  /* indicates no picture here */
#define GEOM_PPI       (1)  /* used for ppi */
#define GEOM_RHI       (2)  /* used for rhi */
#define GEOM_EARTH     (3)  /* used for tops, rain1, rainn, vil, shear */
#define GEOM_CROSS     (4)  /* used for cross */
#define GEOM_CAPPI     (5)  /* used for cappi */
#define GEOM_OTHER     (6)  /* used for vvp and raw and warn and track */
#define GEOM_BEAM      (7)  /* used for beam */
#define GEOM_RTI       (8)  /* used for RTI */

#ifdef SIGMET_PROJECTION_H
struct on_screen_picture8
{
  struct mpj_projection8 projection;
  struct mpj_region8     region;

  /* First section contains things derived from the product inventory */
  SINT4 ixsize;                         /* x and y dimensions of the */
  SINT4 iysize;                         /*  full picture array */

  UINT4 isite_num;                      /*  radar site number*/

  /* Type of geometry for the data.  note that this is required mainly to
   * support the user cursor.  For some data this does not apply.
   */
  UINT4 igeom;
  
  struct product_hdr pheader;           /* Header for the base product */
  struct product_hdr ApoPheaders[3];    /* Headers for the possible APO products */
  struct latlon8 RadarLatLon;           /* Position of the radar in radians */
  FLT8          fTower;                 /* Height of radar (km above reference) */

  /* Information related to the method of display */
  char   soverlay[12];                  /* overlay file name to use, based on site */
  UINT4  ilayer_mask;                   /* Overlay layer mask */
  struct latlon8 RingCenter;            /* Position of ring center in radians */
  struct output_options options;        /* output options */
  union  product_specific_options2 PSO;
  struct common_options Common;

  /* Everything below here is not initialized until the product file is actually
   * loaded into memory.
   */

  /* Display scale in cm/pixel */
  SINT4 ixscale;
  SINT4 iyscale;

  SINT4 image_count;                 /* number of images defined */

  /*Image pixel location corresponding to the radar location for image 0.
   * Not applicable for some geometries.  
   * These are in 1/1000 of pixels, relative to the defined window.
   */
  SINT4 ixrad, iyrad;

  struct data_image img[PICTURE_MAX_IMAGES];
  struct layout_control layout;
  char sPsiText1[20];    /* PSI legend text strings.  Max 17 characters used */
  char sPsiText2[20];
  char sPsiText3[20];
  char sPsiText4[20];
  char sPsiText5[20];
  char sPsiText6[20];

  SINT4 iDataSize;       /* Size of data portion of file (excludes product header) */

  /* Time and zone to use on the legend */
  struct ymds_time DisplayYmds;
  char  sDisplayTZName[TZNAME_SIZE];

  union level_control Level;

  /* Color maps to map the picture to RGB */
  struct color_def CurrentColormap[256];

  SINT2 iDisplayOffset;  /* Display offset in minutes to default time */
  char  ipad_end[2];
};
#endif  /* #ifdef SIGMET_PROJECTION_H */

/* Structure used for some communication between the output and window processes
 * in shared memory.
 */
#ifdef SIGMET_SETUP_H
#ifdef SIGMET_PROJECTION_H
struct output_to_window_info8
{

  SINT4 idevice;     /* Device number for the output process */
  SINT4 ievent_flag; /* Event flag number for the output process */
  UINT4 iwidth;      /* Width of the image */
  UINT4 iheight;     /* Height of the image */
  UINT2 lack_image;  /* Image is acknowledged by window process */
  UINT2 lready;      /* Window process is ready to go */
  char ipad20x76[76];

  struct window_device wDevice;
  struct color_def StandardColormap[256];  /* IRIS colormap from colorsetup */
  struct class_label_setup ClassLabels;  /* Custom class labels */
  struct on_screen_picture8 onscreen;  /* Describes what is in the image */
};
#endif  /* #ifdef SIGMET_PROJECTION_H */
#endif  /* #ifdef SIGMET_SETUP_H */

/* Structure used for communication between the output and window processes
 * via pipes.
 */
#define OtoWNop      (0)
#define OtoWNewImage (1)

struct OtoWPipe
{
  UINT4 icommand;
  UINT4 ispare1;
  UINT4 iwidth;
  UINT4 iheight;
  UINT4 ispare2;
};

/* Used for saving state of quick look window.
** Ascii data saved in file /usr/sigmet/config/window.conf
*/
#define MAX_SLIDES_IN_SHOW 16
struct WindowSetup
{
  char sVersion[8];
  UINT4  iSlidesInShow;
  struct SlideShowList slideShowList[MAX_SLIDES_IN_SHOW];
};


struct cartesian_product
{
  struct product_hdr Header;
  UINT1              Data[1];  /* Number and dimensions are variable! */
};

struct catch_product      /* For CATCH products */
{
  struct product_hdr Header;
  struct catch_results Results[1];  /* Number is variable! */
};

struct fcast_product      /* For FCAST and NDOP products */
{
  struct product_hdr Header;
  struct ndop_results Results[1];  /* Number is variable! */
};

struct gage_product      /* For GAGE products */
{
  struct product_hdr Header;
  struct gage_results Results[1];  /* Number is variable! */
};

struct ndop_product      /* For FCAST and NDOP products */
{
  struct product_hdr Header;
  struct ndop_results Results[1];  /* Number is variable! */
};

#ifdef SIGMET_INGEST_HEADER_DEFINED
#define SIGMET_TAPE_RECORD_DEFINED 1
union  tape_record
{
  SINT2 Data2[TAPE_RECORD_LEN/2];
  struct product_hdr   PHeader;  /* Only for first record */
  struct ingest_header IHeader;  /* Only for second record */
};
#endif  /* #ifdef SIGMET_INGEST_HEADER_DEFINED */

#ifdef SIGMET_TAPE_RECORD_DEFINED
#define SIGMET_RAW_PRODUCT_DEFINED 1
struct raw_product
{
  union  tape_record   Record[3];  /* Number is variable! */
};
#endif  /* #ifdef SIGMET_TAPE_RECORD_DEFINED */

#ifdef SIGMET_SETUP_H
struct sline_product
{
  struct product_hdr   Header;
  struct protect_setup Protect;
  struct sline_results Results[1];  /* Number is variable! */
};
#endif  /* #ifdef SIGMET_SETUP_H */

struct stat_product
{
  struct product_hdr        Header;
  struct status_results     Result;
  struct status_one_message Messages[STATUS_MAX_MESSAGES]; /* Number is variable! */
};

#ifdef SIGMET_SETUP_H
struct tdwr_product
{
  struct product_hdr   Header;
  struct protect_setup Protect;
  struct tdwr_results  Results[TDWR_RUNWAY_MAX];  /* Number is variable! */
  /* Actually contains shearlines and llwas results also */
};
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef SIGMET_SETUP_H
struct track_product
{
  struct product_hdr   Header;
  struct protect_setup Protect;
  struct track_results Results[1];  /* Number is variable! */
};
#endif  /* #ifdef SIGMET_SETUP_H */

struct vvp_product
{
  struct product_hdr   Header;
  struct vvp_results   Results[1];  /* Number is variable! */
};

#ifdef SIGMET_SETUP_H
#define SIGMET_WARN_PRODUCT_DEFINED 1
struct warn_product
{
  struct product_hdr     Header;
  struct protect_setup   Protect;
  struct warning_results Results[MAX_WARNINGS_STORED];  /* Number is variable! */
};
#endif  /* #ifdef SIGMET_SETUP_H */

struct wind_product
{
  struct product_hdr    Header;
  struct vvp_results    Vvp;
  struct wind_results   Results[1];  /* Number is variable! */
};

#ifdef SIGMET_WARN_PRODUCT_DEFINED
#ifdef SIGMET_RAW_PRODUCT_DEFINED
#define SIGMET_GENERIC_PRODUCT_DEFINED 1
union generic_product
{
  struct product_hdr       Header;
  struct cartesian_product Cartesian;
  struct catch_product     Catch;
  struct fcast_product     Fcast;
  struct gage_product      Gage; 
  struct ndop_product      Ndop; 
  struct raw_product       Raw;
  struct sline_product     Sline;
  struct stat_product      Stat;
  struct tdwr_product      Tdwr;
  struct track_product     Track;
  struct vvp_product       Vvp;
  struct warn_product      Warn;
  struct wind_product      Wind;
};
#endif  /* #ifdef SIGMET_RAW_PRODUCT_DEFINED */
#endif  /* #ifdef SIGMET_WARN_PRODUCT_DEFINED */


/* ============================================================ */
/* Structures related to making products.  Used internally 
 * within IRIS product generator only.
 */
#define GPPI_MOMENTS       (2)  /* Number of data types openable per sweep */
#define NUM_GPPI_SWEEPS   (40)	/* Max number of sweeps (must be mult of 4) */
struct gppi_psi_beam   /* Information about the beam product generation */
{
  FLT4  fel_low;
  FLT4  fel_high;
  UINT4 int_az_start;
  UINT4 int_az_end;
  SINT4 int_az_cnt;  /* Azimuth count of internal array, could be larger than inrev */
};

struct gppi_psi_cappi
{
  FLT4  fcappi_height;		/* CAPPI height (km above reference) */
  UINT2 lcappi_filled;		/* Fill near and far ranges with best guess */
  char  ipad_end[2];
};

struct gppi_psi_sri
{
  FLT8  fSurfaceHeight;	        /* Height to correct surface to (km above reference) */
  FLT8  fMeltingHeight;         /* Melting height (km above MSL) */
  FLT8  fMeltingThickness;	
  FLT8  fMeltingIntensity;
  FLT8  fGradientAbove;
  FLT8  fGradientBelow;
  FLT8  fMaxHeight;	
  const struct terrain_site_header *pTerrain;
  UINT4 iPsiFlags;              /* Flags copied from sri_psi_struct */
  SINT4 iBinCount;              /* Total number of bins used */
  SINT4 iDataCount;             /* Number of bins which had data */
  SINT4 iCorrCount;             /* Number of data bins passing non-convective test */
  SINT4 iConvectiveZ;           /* Convective Z Threshold in 8*Z 1-byte units */
  UINT1 iConvectiveHeight;      /* Convective height (rel to reference) in 1-byte units */
  UINT1 lApplyProfileCorrection;/* We will do the profile correction */
  char  ipad_end[2];
};

struct gppi_psi_shear
{
  UINT1 lExtraSweepForElShear;  /* An extra sweep is open for elevation shear  */
  char  ipad_end[3];
};

/* Used for TOPS and BASE */
struct gppi_psi_tops
{
  SINT4 iZThresh;		/* Z Threshold in 8 * Z Byte Units */
};

struct gppi_psi_vil
{
  FLT4 fvil_bot, fvil_top;	/* VIL height limits, km above reference */
  FLT4 fvil_a, fvil_b;		/* ZW constants  Z = a R**b */
};

union gppi_psi
{
  struct gppi_psi_beam  Beam;
  struct gppi_psi_cappi cappi;
  struct gppi_psi_sri   Sri;
  struct gppi_psi_tops  tops;
  struct gppi_psi_vil   vil;
  struct gppi_psi_shear Shear;
};

/* The following structure holds information of general interest during the
 * making of generic PPI's.  It is collected into a single structure to make it
 * easier to pass around to routines.
 */
struct GPPI_Global8
{
  UINT2 iptype;                  /* Needed for certain GPPI routines */
  SINT2 isweeps;                 /* # of /GPPI_Sweep/'s available */

  UINT2 iflags;                  /* Processing flags */
#define GPF_UNSIGNED     (0x0001) /* Input data type is unsigned (not velocity)*/
#define GPF_EXTRAPOLATE  (0x0008) /* Extrapolate if one elevation thresholded */
#define GPF_GRADIENT     (0x0002) /* Use gradient extrapolation scheme, else half-way */
#define GPF_MELTING_UNKNOWN (0x0004) /* Melting height is unknown */

  SINT2 inrev;                   /* # angles in one full circle */
  SINT2 isndx;                   /* Starting index of sweep (0 - INREV-1) */
  SINT2 irtotl;                  /* Total # of rays in sweep */

  UINT2 iDataOut;                /* Output Data type */
  SINT2 ibins;                   /* # of bins of cylindrical data */
  FLT4  fstart, fstep;           /* Start and Step in km of those bins */
  FLT8  fRZConst;                /* R-from-Z constant */
  FLT8  fRZExp;                  /* R-from-Z exponent */
  FLT8  fRadarHeight;            /* Height of radar (km above MSL) */
  FLT8  fRadarOffset;            /* Height of radar (km above reference) */
  FLT8  fReferenceHeight;        /* Height of the zero reference (km above MSL) */
  FLT8  fTruncationHeight;       /* Height of truncation (km above radar) */
  FLT4  fZCalib;                 /* Calibration reflectivity (dBZ at 1 km) */
  FLT4  fMeltingHeight;          /* Melting height (km above MSL) */
  FLT8  fVertBeamWidth;          /* Vertical beam width in radians */
  SINT2 ilimits[2];              /* Actual useful data bin limits */

  struct data_convert Convert;   /* Data convert structure */
  union gppi_psi gpsi;
};

/* The GPPI product types open all available Ingest sweeps of a given
 * parameter, and assembles them into an array of /GPPI_Sweep/ records.
 * There is sufficient information in the structure to allow a mixture
 * of hybrid PPI scans, i.e., from a sequence of scans that are not
 * exactly the same geometry.
 */
struct gppi_moment
{
  struct ingest_data_file *pIngest; /* MAP info for Ingest data file */
  SINT4 iSize, iChannel;            /*   (NULL if unused )           */
};

#define GPPI_SWEEP_SIZE (56)
struct GPPI_Sweep
{
  FLT4  fElv;                    /* Elevation angle of sweep in radians */
  struct gppi_moment Moments[GPPI_MOMENTS];
  FLT4  fstart, fstep, fmax;     /* Range start, step, and end in Km */
  SINT2 ibinsmax;                /* Max number of bins / ray */
  SINT2 itask;                   /* task number (for hybrid cases) */
  SINT2 isweep ;                 /* Sweep number within the task */
  SINT2 iGppiIndex;              /* Origin zero sweep number within the GPPI open list */
  FLT4 fNyquist, fnyratio;       /* Nyquist velocity in m/sec, and ratio to 1st task vel. */
};

/* Macro to perform byte interpolation between two values, given
 * a fractional 14-bit scale factor.  The scale tells what
 * fraction of the way to go from the first value to the second
 * value.  Either unsigned or signed (i.e., circular)
 * interpolation is performed.
 */
#define SINTERPOLATE1( mul, a, b ) \
  (a) + (( ((UINT2)(mul)) * (SINT1)( (b) - (a)   ) ) >> 14 )

#define UINTERPOLATE1( mul, a, b ) \
  (a) + (( ((UINT2)(mul)) * ( UFIX1(b) - UFIX1(a) ) ) >> 14 )

#define UINTERPOLATE2( mul, a, b ) \
  (a) + (( ((UINT2)(mul)) * ( UFIX2(b) - UFIX2(a) ) ) >> 14 )

/* Macro to perform byte interpolation between two values, given
 * a fractional 16-bit scale factor.  The scale tells what
 * fraction of the way to go from the first value to the second
 * value.  Either unsigned or signed (i.e., circular)
 * interpolation is performed.
 */
#define BOTH1( FLAGS, MUL, A, B ) ( (FLAGS) & GPF_UNSIGNED ) ? \
  UINTERPOLATE1( MUL, A, B ) : SINTERPOLATE1( MUL, A, B )

/* Macros to extend data without sign extending.
 */
#define UFIX1(w) ((SINT4)(UINT4)(UINT1)(w))
#define UFIX2(w) ((SINT4)(UINT4)(UINT2)(w))


#ifdef __cplusplus
}
#endif
#endif /* #ifndef SIGMET_PRODUCT_H */
