/* *********************************
 * *                               *
 * * Definitions for Public Domain *
 * *      ASCOPE Structures        *
 * *                               *
 * *********************************
 */
#define ASC_VERSION_NUMBER (3)	/* Version of struct asc_stats */
#define ASC_STATS_SIZE  (1280)	/* Size of struct asc_stats */

/* ======================================================================
 * ASCOPE status structure.  This structure is the saved state of the
 * utility, and also appears as the header of each recorded data file
 * that the user may make.
 */
#ifdef SIGMET_SETUP_H
#ifdef SIGMET_DSP_H

struct ascThreshLevels {	/* Packed threshold levels */
  UINT1 iLogDB20 ;		/*   LOG power, in deciBels * 20 */
  UINT1 iCltDB4 ;		/*   Clutter correction, in deciBels * 4 */
  UINT1 iPowDB10 ;		/*   Signal power, in deciBels * 10 */
  UINT1 iSqiFrac ;		/*   SQI, as unsigned fraction N/255 */
} ;

struct asc_stats		/* Saved control/status info */
{
  /* This is associated with ASC_VERSION_NUMBER which is manually
   * incremented every time the asc_stats structure changes.  This
   * is because we save the asc_stats structure as a public file
   * and other user's code may need to track the changes.
   */
  SINT4 iversion_number ;
  char  sVersion[8];               /* IRIS version when saved */
  char  sLocalTZName[TZNAME_SIZE]; /* Local timezone name */
  SINT2 iLocalWest;                /* Offset from local standard time to UTC */
  char ipad22x18[18] ;

  /* DSP Manual Setup Structure.  Note that this is the original
   * legacy structure that was being used when asc_stats was
   * originally defined.
   */
  struct dsp_manual_setup722 dspsetup ;
  char ipad440x82[82] ;

  /* Logical flags that affect the contents of the options word
   * for call to dspw_options().
   */
  UINT2 lrngnorm ;		/* Range normalized reflectivity display */
  UINT2 lspeckle ;		/* Speckle Remove is enabled */
  UINT2 lclutrms ;		/* Clutter microsuppression */
  UINT2 lr2algor ;		/* R2 processing algorithms */

  char ipad530x50[50] ;

  /* Information about which time series data are available, and how
   * they are to be used.
   */
  UINT4 its_outputs_avail ;	/* Which DSP time series outputs are available */
  UINT4 its_format_inuse ;	/* Which time series format to use now */

  SINT4 ispec_type ;		/* Type of DSP spectra (one of SPEC_... constants) */

  UINT2 lspec_from_dsp ;	/* Get spectra from dsp (else do internal FFT) */
  SINT2 ispec_up_limit ;        /* spectra plot upper limit */
  char ipad596x16[16] ;

  /* Major processing modes of the DSP.
   */
  UINT4 ipmodes_avail ;		/* Which processing modes are available */
  UINT4 ipmode_inuse ;		/* Which mode is inuse now */

  /* This array contains the type of data assigned to each possible
   * slot.  Only the first several selections will be plotted, but all
   * will be processed and possibly recorded.
   */
#define ASC_PLOTTYPES_SIZE 16
  UINT1 iplottypes[ ASC_PLOTTYPES_SIZE ] ;

#define ASC_PLOT_UNUSED          (0)
#define ASC_PLOT_Z_DATA          (1)
#define ASC_PLOT_T_DATA          (2)
#define ASC_PLOT_V_DATA          (3)
#define ASC_PLOT_W_DATA          (4)
#define ASC_PLOT_ZDR_DATA        (5)
#define ASC_PLOT_KDP_DATA        (6)
#define ASC_PLOT_AL_SERIES       (7)
#define ASC_PLOT_AI_SERIES       (8)
#define ASC_PLOT_AQ_SERIES       (9)
#define ASC_PLOT_MAG_AIQ_SERIES  (10)
#define ASC_PLOT_ARG_AIQ_SERIES  (11)
#define ASC_PLOT_L_SERIES        (12)
#define ASC_PLOT_I_SERIES        (13)
#define ASC_PLOT_Q_SERIES        (14)
#define ASC_PLOT_MAG_IQ_SERIES   (15)
#define ASC_PLOT_ARG_IQ_SERIES   (16)
#define ASC_PLOT_MAG_SPEC        (17)
#define ASC_PLOT_PHIDP_DATA      (18)
#define ASC_PLOT_RHOHV_DATA      (19)
#define ASC_PLOT_SQI_DATA        (20)
#define ASC_PLOT_ARG_SPEC        (21)
#define ASC_PLOT_LDRH_DATA       (22)
#define ASC_PLOT_LDRV_DATA       (23)
#define ASC_PLOT_PHIH_DATA       (24)
#define ASC_PLOT_PHIV_DATA       (25)
#define ASC_PLOT_RHOH_DATA       (26)
#define ASC_PLOT_RHOV_DATA       (27)
#define ASC_PLOT_FLAGS_DATA      (28)

#define ASC_MAX_PLOTTYPES        (29)

  /* This is the number of samples in the coherent processing
   * interval.
   */
  SINT4 iassamples ;

  /* The number of frequency terms, i.e., length of, power spectra.
   * For RVP6 and RVP7 systems this will always be the greatest power
   * of 2 that is less than or equal to the sample size above.  For
   * RVP8 systems the spectrum size may simply be equal to the sample
   * size if the user has allowed that.
   */
  SINT4 ispecsize ;

  /* This conveys the averaging time for the power spectra.  For
   * averages greater than 1, this is the time constant of the
   * exponential decay of a single entry.
   */
  FLT4 faverage ;

  /* Window type to use for power spectra.  Values are WIN_RECT,
   * WIN_HAMMING, WIN_BLACKMAN, etc.
   */
  SINT4 iwindow ;

  char ipad652x28[28] ;

  /* Step between range bins in kilometers, and range strobe from
   * which single bin's data are taken.
   */
  FLT4 fstep ;
  FLT4 frange ;

  /* Number of range bins input/output in DSP.
   */
  SINT4 in_bin_count ;
  SINT4 iout_bin_count ;

  SINT4 irange_average ;  /* Range averaging (1:None, 2:Pairs, etc) */

  /* The Doppler and Z clutter filter numbers to use.  Also the
   * count of the number of fill pulses that are supposed to be
   * inserted to allow the filters to stabilize.
   */
  SINT4 idopfilter, izfilter ;
  SINT4 ifillcount ;

  /* Flag to indicate that thresholds are either disabled, enabled
   * with fixed values for all parameters, or enabled with separate
   * values for individual parameters.
   */
  UINT2 ithresh ;		/* Formerly 'lthresh' just for enab/disab */
#define ASCTHR_ENABLED   0x0001	/* Thresholds are enabled */
#define ASCTHR_SEPARATE  0x0002	/* Separate thresholds for five basic params */

  /* Threshold control flags for the five most commonly viewed DSP
   * parameters.  These flags are valid in all of the non-disabled
   * thresholding modes of 'ithresh'.
   */
  UINT2 iuzthresh ;
  UINT2 iczthresh ;
  UINT2 ivthresh ;
  UINT2 iwthresh ;
  UINT2 izdrthresh ;

  /* Range smoothing (1:None, 2:Pairs, etc)
   */
  SINT2 irange_smooth ;

  /* The threshold comparison values are stored in two possible ways
   * depending on whether each parameter is operating with its own
   * private threshold according to 'ithresh'
   *
   *   If not ASCTHR_SEPARATE, then the four FLT4 legacy threshold
   *   values are applied to all parameters.  This is the original
   *   file format that has always been supported.
   *
   *   If ASCTHR_SEPARATE, then the FLT4 threshold values (along with
   *   iOtherTCF) apply to all parameters other than the five whose
   *   specific threshold values are conveyed in the ascThreshLevels
   *   structures below, with their TCF flags still coming from the
   *   five UINT2 masks above.
   */ 
  struct ascThreshLevels  uzThr ; /* \    These five threshold   */
  struct ascThreshLevels  czThr ; /*  \   comparison levels tell */
  struct ascThreshLevels   vThr ; /*   >  the individual values  */
  struct ascThreshLevels   wThr ; /*  /    to use for each of    */
  struct ascThreshLevels zdrThr ; /* /      these parameters.    */

  UINT2 iOtherTCF ; /* Threshold control flags for 'other' parameters */

  FLT4 flogthresh ;		/* \   These threshold comparison   */
  FLT4 fclutterthresh ;		/*  \  values either apply to all   */
  FLT4 fsqithresh ;		/*  /  of the parameters, or to all */
  FLT4 fpowerthresh ;		/* /    but the five listed above.  */

  /* PRF mode (fixed vs. various dual PRFs), and rate in Hertz.
   */
  SINT4 iprfmode ;
  SINT4 iasprf ;

  /* AGC configuration.
   */
  UINT2 ldsp_has_agc ;		/* DSP has the ability to generate AGC */
  UINT2 lagcgain ;		/* AGC is in use */
  UINT2 ldigital_gain ;		/* All conditions were met for using digital gain */
  UINT2 lfixedgain ;		/* controls whether AGC is fixed or variable */

  /* Fixed gain (or gain sequence) to use, if the gain is fixed:
   */
#define  ASC_GAIN_STATES 3
  FLT4 fixedgain[ASC_GAIN_STATES] ;
  SINT4 ifgcount ;

  /* Polarization switching mode:
   * Choices are POL_FIXED_HORZ, POL_FIXED_VERT, POL_ALT, POL_DUAL
   */
  SINT4 ipolmode ;

  /* This indicates which pulse width is in use (0-3)
   */
  SINT4 ipwnumber ;

  /* The available choices of phase control, and the actual phase
   * control sequence, are given here.
   */
  UINT1 iXmtPhaseChoices ;	/* DSP_PHASE_FIXED,  DSP_PHASE_RANDOM */
				/*   or DSP_PHASE_CONTROLLED */
  UINT1 iXmtPhaseSequence ;	/* PHSEQ_FIXED, PHSEQ_RANDOM, or PHSEQ_SZ8_64 */

  char ipad806x6[6] ;

  /* The maximum number of range bins that can be requested for this
   * signal processor.
   */
  SINT4 icurrent_max_bins ;

  char ipad816x40[40] ;

  /* Variables defining the simulated time series.
   */
  FLT4 fsim_power[2] ;		/* Signal power [-80,0] */
  FLT4 fsim_noise[2] ;		/* Noise power [-80,0] */
  FLT4 fsim_clutter[2] ;	/* Clutter power [-80,0] */
  FLT4 fsim_velocity[2] ;	/* Velocity [-1,1] */
  FLT4 fsim_width[2] ;		/* Spectral Width [0,0.5] */
  FLT4 fsim_rmsphase ;		/* Transmit/Receive phase jitter [0,20] */
  FLT4 fsim_rmspower ;		/* Transmit/Receive power jitter [0,6] */

  UINT2 isim_txphase ;		/* Type of phase modulation to use */
#define ISIMTXPH_COHERENT  (0)	/*   No modulation, both trips coherent */
#define ISIMTXPH_RANDOM    (1)	/*   Random phase (Magnetron) */
#define ISIMTXPH_SZ8_64    (2)	/*   The NSSL SZ(8/64) code */
#define ISIMTXPH_03078387  (3)	/*   Two more codes having the spectral */
#define ISIMTXPH_256D2D65  (4)	/*     replication properties of SZ(8/64). */
#define ISIMTXPH_044C0C44  (5)	/*   Two eight term codes using only */
#define ISIMTXPH_44844C8C  (6)	/*     multiples of 90 degrees. */

  UINT2 isim_trip ;		/* Which trip gets which signal */
#define ISIMTRIP1_2  (0)	/*   One signal in each trip */
#define ISIMTRIP12_  (1)	/*   Both signals in first trip */
#define ISIMTRIP_12  (2)	/*   Both signals in second trip */

  UINT2 lsim_continuous ;	/* Continuously update simulated waveform */

  char ipad910x30[30] ;

  /* Variables related to the record/play functions.
   */
  char  srec_play_path[160] ;	/* Common directory for record/playback */

  SINT4 irec_tsbins ;		/* Number of Time Series bins to record */
  SINT4 irec_rays ;		/* Desired number of rays to record */
  FLT4  frec_period ;		/* Desired time between recorded rays (sec) */
  FLT4  frec_startrange ;	/* Starting range of recorded data */

  char ipad1116x8[8] ;

  SINT4 irec_rays_actual ;	/* Actual # of recorded rays   \ Filled in at */
  SINT4 irec_ray_size ;		/* Size of each ray (bytes)    / record time. */

  /* Physical target simulation parameters
   */
  struct dspPhysTargSim physTargSims[ DSPPHYSTARGSIMCOUNT ] ;

  /* Checksum for detecting bogus files
   */
  char ipad1212x64[64] ;
  UINT4 iuniquesum ;
} ;
#endif /* #ifdef SIGMET_DSP_H */
#endif /* #ifdef SIGMET_SETUP_H */

/* ======================================================================
 * Special ray header that appears at the start of every recorded ray.
 */
#define ASC_RAY_HEADER_SIZE (200) /* Size of struct asc_ray_header */

struct asc_ray_header
{
  /* Antenna positions at the start and end of the ray are stored
   * as 16-bit binary angles.
   */
  BIN2 iaz_start, iel_start ;	/* AZ and EL at start of ray */
  BIN2 iaz_end  , iel_end   ;	/* AZ and EL at end of ray */

  /* Time of the end of the ray
   */
  struct ymds_time time ;

  /* The GPARM structure that was read from the DSP in the course
   * of generating the data ray. 
   */
  UINT2 idsp_parm[64] ;

  char ipad148x52[52] ;
} ;
