
#ifndef ZACOMMON_H
#define ZACOMMON_H

#ifdef ZACOMMON_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

#define MIN_PARAM         1
#define MAX_PARAM         2
#define MAX_PM_WIDTH      1500
#define MAX_PM_HEIGHT     1050 
#define IPOINTMAX_P       150
#define FLIMITS_MIN      -200.0
#define FLIMITS_MAX       100.0

#define IF_PWR_LOWER      -130
#define IF_PWR_UPPER        30 

#define FSIMULATED_NOISE      (-90.0)
#define FSIMULATED_SATURATION (  0.0)

EXTERN UINT2 zautoWasTyped; 
EXTERN int  debugMode, noXWin;

EXTERN UINT4 iPulseWidIdx_c; 
EXTERN UINT2 iForcePulseWidIdx_c;  //Used when starting zauto -pw_idx
EXTERN int   lautocalMode_c;
EXTERN float finter_c;
EXTERN SINT4 siggenlimits_c[2];

EXTERN int bGoodNoise_g, bGoodFit_g, bGoodLowRange_g, bGoodHighRange_g;
EXTERN float fpoints_c[IPOINTMAX_P][2];
EXTERN int lokpoints_c[IPOINTMAX_P];
EXTERN short int ipointcnt_c;
EXTERN int lupdate_c;
EXTERN float fconst_c;
EXTERN int bDspUsed_g;
EXTERN int bDspAllowIo_g;  /* Still open DSP for I/O even if bDspUsed_g is FALSE*/
EXTERN int isetting_c;
EXTERN FLT4 factual_setting_c;
EXTERN UINT2 lPolarIsHoriz_c;
EXTERN Dsp *pdsp_c;
EXTERN SINT4 iXLen;
EXTERN SINT4 iYLen;



EXTERN struct dsp_manual_setup  dspsetup1_c;
#define zcal_c zcalfile_g
/* This contains a copy of the file structure.  In the stored section individual
 * bits are updated to match the zcalnew_g structure whenever we push 'update'. */
EXTERN struct dsp_refl_cal      zcalfile_g;  /* Contents of the file */

EXTERN struct dsp_cal_pw        zcaledit_g;  /* Temp values from last run before 'update' */

#define zcalnew_c zcalnew_g
EXTERN struct dsp_cal           zcalnew_g;   /* New values after 'update' */
/* This contains a copy of what we know is in the file on disk.  It is updated
 * from zcalfile_g.Stored whenever we read or write the file.
 */
EXTERN struct dsp_cal           zcalstore_c; 

EXTERN struct dsp_siggen_cal    siggencal_c;

struct ConfigParams
{
  char  sVersion[8] ;        // IRIS version when saved
  UINT4 iPulseWidIdx; 
  UINT2 bUpdateOtherPW;
  UINT2 bPolarIsHoriz; 
  FLT4  fPlotLimitsSigGen[2];
  FLT4  fPlotLimitsIFPower[2];
  FLT4  fFitLimitsSigGen[2];
  FLT4  fAutoLimitsLowerSigGen[2];
  FLT4  fAutoLimitsUpperSigGen[2];
  FLT4  fAutoLowerUpperStepSigGen;
  FLT4  fAutoCenterStepSigGen;
  FLT4  fSlopeTol;
  FLT4  fDBZoTol;
  FLT4  fDBmTol;
  UINT1 bSetNexradButton;
  UINT1 bSendNexradQBite;
  UINT1 ipad_end[2];
  int   iButtonUnit;   /* Control of which button to press */
  int   iButtonByte;
  int   iButtonBit;
};


class Point 
{
  private:
    long getPointDSP(Dsp *pdsp, int isetting_a, FLT4 factual_setting_a);
    /* Return simulated value based on the siggen setting */
    FLT4 simulatedPower( FLT4 fActualSetting_a);
  public:
    void checkPoints(void);
    void getPointXYPos(int ipoint_a, int *ixpos_a, int *iypos_a);
    void getPointPlotPoint(void);
    void getPointNoXWin(void);
};
EXTERN Point point;

class Limits
{
  private:
  public:
    void  getFitLimXPos(int *ixfitlim1_a, int *ixfitlim2_a);
    float chkMinLim(float fval_a);
    float chkMaxLim(float fval_a);
    float chkIFPowerMinLim(float fval_a);
    float chkIFPowerMaxLim(float fval_a);
    float chkMinFit(float fval_a);
    float chkMaxFit(float fval_a);
    void  moveFitLimit(int x);
};
EXTERN Limits limits;


class Fit 
{
  private:
    void getFit(int *lshortfall_a, int *lbadfit_a);
  public:
    void getFitXYPos(int *ixpos1_a, int *iypos1_a, int *ixpos2_a, 
                       int *iypos2_a);
    void getFitPlotFit(void);
    void getFitNoXWin(void);
};
EXTERN Fit fit;

class Noise 
{
  private:
    MESSAGE getNoise(Dsp *pdsp);
  public:
    void    computeResults(void);
    void    getNoisePlotNoise(void);
    void    getNoiseNoXWin(void);
};
EXTERN Noise noise;


class Config 
{
  private:
  public:
    struct  ConfigParams params;
    void    updateConfig(struct ConfigParams params_a);
    MESSAGE loadConfig(void);
    MESSAGE convertOldConfigFile(void);
    MESSAGE saveConfig(void);
};
EXTERN Config config;

class InitLoadSave
{
  private:
  public:
    void initData(void);
    void loadData(void);
    void saveData(void);
    void saveDataNoXWin(void);
};
EXTERN InitLoadSave initLoadSave;

class Update 
{
  private:
    int  checkdbZoTolNoXWin(float fOffset_a);
    int  checkSlopeTolNoXWin(void);
    void checkSlopeTol(float fslope_a);
  public:
    void checkdbZoTol(float foffset_a);
    void updateOtherPWOffset(void);
    void updateOK(UINT4 iselected_pulse_wid_idx_a);
    void updateOKNoXWin(void);
};
EXTERN Update update;

class Nexrad 
{
  private:
  UINT4 iButtonField;
  UINT4 findButtonField(const struct bitex_setup *pBSetup_a);
    public:
  Nexrad();  /* Constructor */
  void setButtons(void);
  void restoreButtons(void);
  void sendQbiteResults(void);
};
EXTERN Nexrad nexrad;


// noXWin
void zaAutoCalNoXWin(void);

#undef EXTERN
#endif



