
#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 UINT4 iPulseWidIdx_c; 
EXTERN int   lautocalMode_c;
EXTERN float finter_c;
EXTERN float flin_i0_c, fzcal_c;
EXTERN SINT4 siggenlimits_c[2];
EXTERN UINT2 bZCalMode;

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 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;
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;


struct Cal
{
  FLT4  fAutoStepSigGen;
  FLT4  fAutoLimitsSigGen[2];
  FLT4  fFitLimitsSigGen[2];
  FLT4  fSlopeTol;
  FLT4  fDBZoTol;
};

struct Range
{
  FLT4  fAutoStepSigGen;
  FLT4  fAutoLimitsLowSigGen[2];
  FLT4  fAutoLimitsHighSigGen[2];
  FLT4  fFitLimitsSigGen[2];
  FLT4  fDBmTol;
};

struct ConfigParams
{
  char  sVersion[8] ;        // IRIS version when saved
  UINT4 iPulseWidIdx; 
  UINT2 bUpdateOtherPW;
  UINT2 bPolarIsHoriz; 
  FLT4  fPlotLimitsSigGen[2];
  FLT4  fPlotLimitsIFPower[2];
  struct Cal cal;
  struct Range rng;
};


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:
    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(void);
    int  checkSlopeTolNoXWin(void);
    void checkSlopeTol(float fslope_a);
  public:
    void checkdbZoTol(float foffset_a);
    void updateSlope(void);
    void updateOtherPWOffset(void);
    void updateOK(UINT4 iselected_pulse_wid_idx_a);
    void updateOKNoXWin(void);
};
EXTERN Update update;


// noXWin
void zaAutoCalNoXWin(void);

#undef EXTERN
#endif



