
#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 

EXTERN UINT2 zautoWasTyped; 
EXTERN int  dspUsed, debugMode, noXWin;

EXTERN int   lautocalMode_c;
EXTERN SINT4 siggen_adjust_limits_c[2];
EXTERN float flimits_c[2], fitlimits_c[2], finter_c;
EXTERN float flimitsIFPower_c[2];
EXTERN int   istep_c;
EXTERN float flin_i0_c, fzcal_c;
EXTERN SINT4 siggenlimits_c[2];

EXTERN int lgoodnoise_c, lgoodfit_c;
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 ldspused_c;
EXTERN int otherPW_c, slopeTol_c, dbZoTol_c;
EXTERN int isetting_c;
EXTERN FLT4 factual_setting_c;
EXTERN short int iwidindex_c;
EXTERN short iwidindexAC_c;  /* AC = Auto Cal */
EXTERN UINT2 lPolarIsHoriz_c;
EXTERN UINT2 lPolarIsHorizAC_c; /* AC = Auto Cal */
EXTERN Dsp *pdsp_c;
EXTERN SINT4 iXLen;
EXTERN SINT4 iYLen;

/*
EXTERN struct dsp_gain_cal      gaincal_c;
EXTERN struct dsp_agc_cal       dspagcal_c;
*/
EXTERN struct dsp_manual_setup  dspsetup1_c;
EXTERN struct dsp_refl_cal      zcal_c;
EXTERN struct dsp_cal           zcaledit_c;
EXTERN struct dsp_cal           zcalnew_c;
EXTERN struct dsp_cal           zcalstore_c;
EXTERN struct dsp_siggen_cal    siggencal_c;

class Point 
{
   private:
      long getPointDSP(Dsp *pdsp, int isetting_a, FLT4 factual_setting_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    getIoZcal(void);
      void    getNoisePlotNoise(void);
      void    getNoiseNoXWin(void);
};
EXTERN Noise noise;


class Config 
{
   private:
   public:
      void    updateConfig(int iwidindexac_a, int otherpw_a, int istep_a,
                       SINT4 siggen_adjust_limits[2], float flimits_a[2],
                       float flimits_if_power_a[2], float fitlimits_a[2],
                        int slopetol_a, int dbzotol_a,
                       int lpolar_is_horiz_ac_a);
      MESSAGE loadConfig(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(void);
      int  checkSlopeTolNoXWin(void);
      void checkSlopeTol(float fslope_a);
   public:
      void checkdbZoTol(float foffset_a);
      void updateSlope(void);
      void updateOtherPWOffset(void);
      void updateOK(int selectedPW);
      void updateOKNoXWin(void);
};
EXTERN Update update;


// noXWin
void zaAutoCalNoXWin(void);

#undef EXTERN
#endif



