
#ifndef ZACOMMON_H
#define ZACOMMON_H

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

#define IPOINTMAX_P       150
#define FLIMITS_MIN       -200.0
#define FLIMITS_MAX       100.0

#define ZA_DRAW           1
#define ZA_ERASE          2

EXTERN int  dspUsed, debugMode, noXWin;

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

EXTERN int lgoodnoise_c, lgoodfit_c;
EXTERN int lnewlines_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, iwidindexAC_c;
EXTERN Dsp *pdsp_c;
EXTERN int drawAWidth, drawAHeight;


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;


/* update menu */
void createUpdateMenu(Widget parent_wgt_a);
void popupUpdateMenu(void);
void popdownUpdateMenu(void);

/* config menu */
void createConfigMenu(Widget parent_wgt_a);
void popupConfigMenu(void);
void popdownConfigMenu(void);

/* view cal menu */
void createViewCalMenu(Widget parent_wgt_a);
void popupViewCalMenu(void);
void popdownViewCalMenu(void);





void setup_gc(void);
void initValues(void);
void zaAutoCalNoXWin(void);

long    zaGetPointDSP(Dsp *pdsp, int isetting_a, FLT4 factual_setting_a);
void    zaCheckPoints(void);
void    zaGetFitLimXPos(int *ixfitlim1_a, int *ixfitlim2_a);
void    zaGetPointXYPos(int ipoint_a, int *ixpos_a, int *iypos_a);
void    zaGetFitXYPos(int *ixpos1_a, int *iypos1_a, int *ixpos2_a, 
                      int *iypos2_a);
void    zaGetFitPlotFit(void);
void    zaGetPointPlotPoint(void);
void    zaGetNoisePlotNoise(void);
void    zaCheckdbZoTol(float foffset_a);
void    zaUpdateConfig(int iwidindexac_a, int otherpw_a, int istep_a,
                       float flimits_a[2], float fitlimits_a[2],
                       int slopetol_a, int dbzotol_a);

MESSAGE zaNoise(Dsp *pdsp);
void    zaFit(int *lshortfall_a, int *lbadfit_a);
MESSAGE zaLoadConfig(void);
MESSAGE zaSaveConfig(void);
void    zaInitData(void);
void    zaLoadData(void);
void    zaSaveData(void);
float   zaChkMinLim(float fval_a);
float   zaChkMaxLim(float fval_a);
float   zaChkMinFit(float fval_a);
float   zaChkMaxFit(float fval_a);
void    zaUpdateOK(int selectedPW);
void    zaUpdateOffset(void);
void    zaUpdateSlope(void);
void    zaMoveFitLimit(int x, int y);
void    zaUpdateOtherPWOffset(void);

void    zaGetPointNoXWin(void);
void    zaGetFitNoXWin(void);
void    zaGetNoiseNoXWin(void);
void    zaUpdateOKNoXWin(void);
void    zaSaveDataNoXWin(void);

void    redrawAll(void);
void    updateSiggenPlotScale(void);
void    plotPoints(void);
void    writeResults(void);
void    writeCalParams(void);
void    plotFitLine(void);
void    plotNoiseLine(void);
void    plotFitLimitLines(int draw_line);
void    changePulWidth(void);


void    config_UpdateAutoCal(int iwidindexac_a, int otherpw_a, int istep_a,
                           float flimits_a[2], float fitlimits_a[2],
                           int slopetol_a, int dbzotol_a);

void    config_UpdateLFitLim( float lfitlimits_a);
void    config_UpdateRFitLim( float rfitlimits_a);


void    config_InitAutoCal(SINT2 iwidcnt_a, SINT2 ipwidths_a[4]);


void    view_Summary(UINT4 cur_pw_a);

void    update_UpdateMess(int iwididx);
void    update_InitMess(SINT2 ipwidths[4], int iwidcnt);


#undef EXTERN
#endif



