end ! ----------------------------------------------------------------------------------------------- DOES_DIR_EXIST: ! Uses dir$, sets dirExists% ! Uses local vars _n%, fn$, cmd$, _ret% dirExists% = 0 ! Try to create a temp file named "_" in dir$ _n% = len(dir$) ! If dir$ does not end with backslash char, if dir$[_n%] <> "\\" then fn$ = dir$ & "\\" & "_" else fn$ = dir$ & "_" endif on error goto DOES_DIR_EXIST_ERROR assign @_fp to fn$ "w" off error assign @_fp to "" ! Delete the temp file gosub DELETE_FILE ! Uses fn$ dirExists% = 1 return DOES_DIR_EXIST_ERROR: off error dirExists% = 0 return ! ----------------------------------------------------------------------------------------------- CREATE_DIR: ! Create directory specified by var dir$ cmd$ = "cmd /c mkdir " & dir$ _ret% = execute(cmd$) if _ret% <> 0 then msg$ = " Cannot create directory " & dir$ & " " gosub SHOW_ERROR_DIALOG stop endif return ! ----------------------------------------------------------------------------------------------- DOES_FILE_EXIST: ! Uses fn$, sets fileExists% fileExists% = 0 on error goto DOES_FILE_EXIST_ERROR assign @_fp to fn$ "r" off error assign @_fp to "" fileExists% = 1 return DOES_FILE_EXIST_ERROR: off error fileExists% = 0 return ! ----------------------------------------------------------------------------------------------- CHECK_OK_TO_OVERWRITE_FILE: ! Uses var fn$, sets var ok% ok% = 1 gosub DOES_FILE_EXIST ! Uses var fn$, sets var fileExists% if fileExists% <> 0 then msg$ = " Overwrite file " & fn$ & " ? " on error goto DIALOG_ESCAPED ok% = dialog(msg$, 6) off error endif return ! ----------------------------------------------------------------------------------------------- CREATE_LOG_FILE: ! Creates file LogFile$ to receive messages assign @_fp to LogFile$ "w" assign @_fp to "" msg$ = "Create log file" gosub LOG_DATE_TIME_MSG return ! ----------------------------------------------------------------------------------------------- LOG_MSG: ! Append msg$ to the log file assign @_fp to LogFile$ "a" output @_fp; msg$ assign @_fp to "" return ! ----------------------------------------------------------------------------------------------- LOG_DATE_TIME_MSG: _t = timedate if msg$ <> "" then msg$ = date$(_t) & " " & time$(_t) & ": " & msg$ else msg$ = date$(_t) & " " & time$(_t) endif gosub LOG_MSG return ! ----------------------------------------------------------------------------------------------- SET_AGC_ON: ! Sets AGC control On setnum(getid("Controls / Acquisition / AGC"), 1, "") return ! ----------------------------------------------------------------------------------------------- SET_AGC_OFF: ! Sets AGC control Off setnum(getid("Controls / Acquisition / AGC"), 0, "") return ! ----------------------------------------------------------------------------------------------- SET_TARGET_RANGE: ! Sets value of Target Range control using var TargetRange setnum(getid("Controls / Acquisition / Target Range"), TargetRange, "") return ! ----------------------------------------------------------------------------------------------- SET_MIN_AREA_SIZE: ! Sets value of Min Area Size control using var MinAreaSize setnum(getid("Controls / Phase Processing / Min Area Size"), MinAreaSize, "") return ! ----------------------------------------------------------------------------------------------- SET_LIGHT_LEVEL_PCT: ! Sets value of Light Level Pct control using var LightLevelPct setnum(getid("Controls / Acquisition / Light Level Pct"), LightLevelPct, "") return ! ----------------------------------------------------------------------------------------------- GET_LIGHT_LEVEL_PCT: ! Gets value of Light Level Pct control into var LightLevelPct LightLevelPct = getval(getid("Controls / Acquisition / Light Level Pct"), "") return ! ----------------------------------------------------------------------------------------------- SET_MIN_MOD_PCT: ! Sets value of Min Mod (%) control using var MinModPct setnum(getid("Controls / Acquisition / Min Mod (%)"), MinModPct, "") return ! ----------------------------------------------------------------------------------------------- SET_LOWER_PROG_LIMIT: ! Set value of Lower Prog Limit custom control using var LowerProgLimit setnum(getid("Controls / Custom / Numeric 1"), int(LowerProgLimit + 0.5), "") return ! ----------------------------------------------------------------------------------------------- GET_LOWER_PROG_LIMIT: ! Get value of Lower Prog Limit custom control into var LowerProgLimit LowerProgLimit = int(getval(getid("Controls / Custom / Numeric 1"), "") + 0.5) return ! ----------------------------------------------------------------------------------------------- SET_UPPER_PROG_LIMIT: ! Set value of Upper Prog Limit custom control using var UpperProgLimit setnum(getid("Controls / Custom / Numeric 2"), int(UpperProgLimit + 0.5), "") return ! ----------------------------------------------------------------------------------------------- GET_UPPER_PROG_LIMIT: ! Get value of Upper Prog Limit custom control into var UpperProgLimit UpperProgLimit = int(getval(getid("Controls / Custom / Numeric 2"), "") + 0.5) return ! ----------------------------------------------------------------------------------------------- GET_ARTIF_TEST_NUM_ITERATIONS: ! Get value of Artif Test Num Iterations custom control into var TestIterations% TestIterations% = getval(getid("Controls / Custom / Numeric 3"), "") return ! ----------------------------------------------------------------------------------------------- SET_1X_POS: ! Set value of 1X Pos custom control using var OneXPos setnum(getid("Controls / Custom / Numeric 4"), OneXPos, "") return ! ----------------------------------------------------------------------------------------------- GET_1X_POS: ! Get value of 1X Pos custom control into var OneXPos OneXPos = getval(getid("Controls / Custom / Numeric 4"), "") return ! ----------------------------------------------------------------------------------------------- GET_BACKLASH_COMP: ! Get value of Backlash Comp custom control into var BacklashComp BacklashComp = getval(getid("Controls / Custom / Numeric 5"), "") return ! ----------------------------------------------------------------------------------------------- SET_BACKLASH_COMP: ! Set value of Backlash Comp custom control using var BacklashComp setnum(getid("Controls / Custom / Numeric 5"), BacklashComp, "") return ! ----------------------------------------------------------------------------------------------- SET_BACKLASH_COMP_CALINFO: ! Sets the MetroPro internal backlash compensation value. ! (This is a value that can be written to or read from the cal file.) ! Uses var BacklashComp ofmti("%.0f") line$ = "GpiEncZoomBacklash " & val$(BacklashComp) setcalinfo(line$) return ! ----------------------------------------------------------------------------------------------- SET_CONFIG_CALINFO: ! Sets the MetroPro internal encoded zoom config flag. ! (This is a value that can be written to or read from the cal file.) line$ = "GpiEncZoomConfig 1" setcalinfo(line$) return ! ----------------------------------------------------------------------------------------------- SET_PROG_LIMITS_CALINFO: ! Sets the MetroPro internal prog limit values. ! (These are values that can be written to or read from the cal file.) ! Uses vars LowerProgLimit and UpperProgLimit ofmti("%.0f") line$ = "GpiEncZoomProgLim " & val$(LowerProgLimit) & " " & val$(UpperProgLimit) setcalinfo(line$) return ! ----------------------------------------------------------------------------------------------- CLEAR_PROG_LIMITS_CALINFO: ! Disables the MetroPro internal prog limit values. ! (These are values that can be written to or read from the cal file.) ofmti("%.0f") line$ = "GpiEncZoomProgLim 0 0" setcalinfo(line$) return ! ----------------------------------------------------------------------------------------------- SET_WAND_LIMITS_CALINFO: ! Sets the MetroPro internal wand limit values. ! (These are values that can be written to or read from the cal file.) ! Uses vars LowerWandLimit and UpperWandLimit ofmti("%.0f") line$ = "GpiEncZoomWandLim " & val$(LowerWandLimit) & " " & val$(UpperWandLimit) setcalinfo(line$) return ! ----------------------------------------------------------------------------------------------- SET_STD_MAGS_CALINFO: ! Sets the MetroPro standard magnification values. ! (These are values that can be written to or read from the cal file.) line$ = "GpiEncZoomStdMags 1.00 1.25 1.50 1.75 2.00 2.50 3.00 4.00 5.00" setcalinfo(line$) return ! ----------------------------------------------------------------------------------------------- GET_SCRIPT_STATUS: ! Get value of Script Status custom control into var ScriptStatus% ScriptStatus% = getval(getid("Controls / Custom / Numeric 6"), "") return ! ----------------------------------------------------------------------------------------------- SET_SCRIPT_STATUS: ! Set value of Script Status custom control using var ScriptStatus% setnum(getid("Controls / Custom / Numeric 6"), ScriptStatus%, "") return ! ----------------------------------------------------------------------------------------------- GET_1X_FILL_PCT: ! Get value of 1X Fill Pct custom control into var OneXFillPct OneXFillPct = getval(getid("Controls / Custom / Numeric 7"), "") return ! ----------------------------------------------------------------------------------------------- SET_1X_FILL_PCT: ! Set value of 1X Fill Pct custom control using var OneXFillPct setnum(getid("Controls / Custom / Numeric 7"), OneXFillPct, "") return ! ----------------------------------------------------------------------------------------------- GET_TARG_POS: ! Get value of Targ Pos custom control into var TargPos TargPos = getval(getid("Controls / Custom / Numeric 8"), "") return ! ----------------------------------------------------------------------------------------------- SET_TARG_POS: ! Set value of Targ Pos custom control using var TargPos setnum(getid("Controls / Custom / Numeric 8"), TargPos, "") return ! ----------------------------------------------------------------------------------------------- GET_APERT_DIAM: ! Get value of Apert Diam custom control into var ApertDiam in millimeters ApertDiam = getval(getid("Controls / Custom / Linear 9"), "mm") return ! ----------------------------------------------------------------------------------------------- GET_PROG_MOVE_TEST_ITERATIONS: ! Get value of Prog Move Test Iterations custom control into var TestIterations% TestIterations% = getval(getid("Controls / Custom / Numeric 10"), "") return ! ----------------------------------------------------------------------------------------------- GET_WAND_MOVE_TEST_ITERATIONS: ! Get value of Wand Move Test Iterations custom control into var TestIterations% TestIterations% = getval(getid("Controls / Custom / Numeric 12"), "") return ! ----------------------------------------------------------------------------------------------- SET_LOWER_WAND_LIMIT: ! Set value of Lower Wand Limit custom control using var LowerWandLimit setnum(getid("Controls / Custom / Numeric 13"), int(LowerWandLimit + 0.5), "") return ! ----------------------------------------------------------------------------------------------- GET_LOWER_WAND_LIMIT: ! Get value of Lower Wand Limit custom control into var LowerWandLimit LowerWandLimit = int(getval(getid("Controls / Custom / Numeric 13"), "") + 0.5) return ! ----------------------------------------------------------------------------------------------- SET_UPPER_WAND_LIMIT: ! Set value of Upper Wand Limit custom control using var UpperWandLimit setnum(getid("Controls / Custom / Numeric 14"), int(UpperWandLimit + 0.5), "") return ! ----------------------------------------------------------------------------------------------- GET_UPPER_WAND_LIMIT: ! Get value of Upper Wand Limit custom control into var UpperWandLimit UpperWandLimit = int(getval(getid("Controls / Custom / Numeric 14"), "") + 0.5) return ! ----------------------------------------------------------------------------------------------- SET_ARTIF_ZONE: ! Set value of Artifact Zone custom control using var ArtifZone% setnum(getid("Controls / Custom / Numeric 15"), ArtifZone%, "") return ! ----------------------------------------------------------------------------------------------- GET_ARTIF_ZONE: ! Get value of Artifact Zone custom control into var ArtifZone% ArtifZone% = getval(getid("Controls / Custom / Numeric 15"), "") return ! ----------------------------------------------------------------------------------------------- SET_SCRIPT_STATUS_PASS: ScriptStatus% = 1 gosub SET_SCRIPT_STATUS return ! ----------------------------------------------------------------------------------------------- SET_SCRIPT_STATUS_FAIL: ScriptStatus% = 0 gosub SET_SCRIPT_STATUS return ! ----------------------------------------------------------------------------------------------- VERIFY_SCRIPT_STATUS_PASS: gosub GET_SCRIPT_STATUS ! Gets control value into var ScriptStatus% if ScriptStatus% = 0 then stop endif return ! ----------------------------------------------------------------------------------------------- GET_CAM_SIZE_X: ! Get camera size in X dimension into var CamSizeX CamSizeX = getcamsizx("pix") return ! ----------------------------------------------------------------------------------------------- GET_CAM_SIZE_Y: ! Get camera size in Y dimension into var CamSizeY CamSizeY = getcamsizy("pix") return ! ----------------------------------------------------------------------------------------------- GET_CAM_RES: ! Get camera resolution into var CamRes CamRes = getcamres("mm") return ! ----------------------------------------------------------------------------------------------- SET_GEN_CAM_SIZE_X: ! Set Generate Camera Size X control using var CamSizeX setnum(getid("Controls / Generate / Camera Size X"), CamSizeX, "") return ! ----------------------------------------------------------------------------------------------- SET_GEN_CAM_SIZE_Y: ! Set Generate Camera Size Y control using var CamSizeY setnum(getid("Controls / Generate / Camera Size Y"), CamSizeY, "") return ! ----------------------------------------------------------------------------------------------- SET_GEN_CAM_RES: ! Set Generate Camera Res control using var GenCamRes (in mm) setnum(getid("Controls / Generate / Camera Res"), GenCamRes, "mm") return ! ----------------------------------------------------------------------------------------------- GET_DATA_ZOOM_MAG: ! Get zoom mag attribute associated with current data into var DataZoomMag DataZoomMag = getval(getid("Attributes / Interferometer / GPI Encoded Zoom / GPI Encoded Zoom Data Mag"), "") return ! ----------------------------------------------------------------------------------------------- GET_DATA_POINTS: ! Get value of Points result into var DataPoints (no unit) DataPoints = getval(getid("Surface Wavefront Map / Results / Points"), "") return ! ----------------------------------------------------------------------------------------------- GET_DATA_SIZE_X: ! Get value of Size X result into var DataSizeX (in pixels) DataSizeX = getval(getid("Surface Wavefront Map / Results / Size / Size X"), "pix") return ! ----------------------------------------------------------------------------------------------- GET_DATA_SIZE_Y: ! Get value of Size Y result into var DataSizeY (in pixels) DataSizeY = getval(getid("Surface Wavefront Map / Results / Size / Size Y"), "pix") return ! ----------------------------------------------------------------------------------------------- GET_DATA_CENTROID_X: ! Get value of Centroid X result into var DataCentroidX (in pixels) DataCentroidX = getval(getid("Surface Wavefront Map / Results / Centroid / Centroid X"), "pix") return ! ----------------------------------------------------------------------------------------------- GET_DATA_CENTROID_Y: ! Get value of Centroid Y result into var DataCentroidY (in pixels) DataCentroidY = getval(getid("Surface Wavefront Map / Results / Centroid / Centroid Y"), "pix") return ! ----------------------------------------------------------------------------------------------- GET_DATA_OUTER_DIAM: ! Get value of Outer Diam result into var DataOuterDiam (in pixels) DataOuterDiam = getval(getid("Surface Wavefront Map / Results / Diam / Outer Diam"), "pix") return ! ----------------------------------------------------------------------------------------------- GET_DATA_PV: ! Get value of PV result into var DataPv in fringes DataPv = getval(getid("Surface Wavefront Map / Results / Peak Valley / PV"), "fr") return ! ----------------------------------------------------------------------------------------------- GET_DATA_PV_TR: ! Get value of PV result from Test+Ref Map into var DataPv in fringes DataPv = getval(getid("Surface Wavefront Map (T+R) / Results / Peak Valley (All) / PV (All)"), "fr") return ! ----------------------------------------------------------------------------------------------- GET_DATA_TILT_MAG_TR: ! Get value of TltMag result from Test+Ref Map into var DataTiltMag in microradians DataTiltMag = getval(getid("Surface Wavefront Map (T+R) / Results / Tilt (All) / TltMag"), "urad") return ! ----------------------------------------------------------------------------------------------- GET_LATERAL_RESULTS: gosub GET_DATA_SIZE_X ! Gets result value into var DataSizeX gosub GET_DATA_SIZE_Y ! Gets result value into var DataSizeY gosub GET_DATA_OUTER_DIAM ! Gets result value into var DataOuterDiam gosub GET_DATA_CENTROID_X ! Gets result value into var DataCentroidX gosub GET_DATA_CENTROID_Y ! Gets result value into var DataCentroidY return ! ----------------------------------------------------------------------------------------------- MEASURE_WITH_RETRY: RetryCount% = 0 MaxRetryCount% = 10 MEASURE_WITH_RETRY_LOOP: on error goto MEASURE_WITH_RETRY_ERROR measure off error return MEASURE_WITH_RETRY_ERROR: off error msg$ = errm$ gosub LOG_DATE_TIME_MSG if pos(errm$, "Processing aborted") > 0 then msg$ = " Processing aborted " gosub SHOW_ERROR_DIALOG stop endif if pos(errm$, "Test Calibration Marker is required") > 0 then msg$ = " Test Calibration Marker is required " gosub SHOW_ERROR_DIALOG stop endif RetryCount% = RetryCount% + 1 if RetryCount% > MaxRetryCount% then msg$ = " Measure failed: " & trim$(errm$) & " " gosub SHOW_ERROR_DIALOG msg$ = trim$(msg$) gosub SET_STATUS_MSG_2 stop else msg$ = "Measure failed: " & trim$(errm$) & " Retrying" gosub SET_STATUS_MSG_2 msg$ = "Retrying" gosub LOG_DATE_TIME_MSG goto MEASURE_WITH_RETRY_LOOP endif return ! ----------------------------------------------------------------------------------------------- SET_AUTO_APERTURE: ! Uses var AutoApert% _id% = getid("Surface Wavefront Map / Controls / Auto Aperture / Auto Aperture") setnum(_id%, AutoApert%, "") return ! ----------------------------------------------------------------------------------------------- ENABLE_AUTO_APERTURE: AutoApert% = 1 gosub SET_AUTO_APERTURE return ! ----------------------------------------------------------------------------------------------- DISABLE_AUTO_APERTURE: AutoApert% = 0 gosub SET_AUTO_APERTURE return ! ----------------------------------------------------------------------------------------------- APPEND_FILE_TO_LOG: ! Appends text file specified by fn$ to the log file specified by LogFile$. assign @_fp1 to LogFile$ "a" output @_fp1; fn$ on error goto APPEND_FILE_TO_LOG_2 assign @_fp2 to fn$ "r" ! Read lines from @_fp2 and write to @_fp1 until EOF error APPEND_FILE_TO_LOG_LOOP: enterline @_fp2; line$ output @_fp1; line$ goto APPEND_FILE_TO_LOG_LOOP APPEND_FILE_TO_LOG_2: off error assign @_fp1 to "" assign @_fp2 to "" return ! ----------------------------------------------------------------------------------------------- PAD_STATUS_MSG: ! Pads the global msg$ value to StatusMsgLen% _L% = len(msg$) if _L% < StatusMsgLen% then msg$ = msg$ & blanks$[1, StatusMsgLen%-_L%] endif return ! ----------------------------------------------------------------------------------------------- SET_STATUS_MSG_1: gosub PAD_STATUS_MSG setstr (getannotid(getwinid("Encoded Zoom Calibration and Test"), "Status 1"), msg$) return ! ----------------------------------------------------------------------------------------------- SET_STATUS_MSG_2: gosub PAD_STATUS_MSG setstr (getannotid(getwinid("Encoded Zoom Calibration and Test"), "Status 2"), msg$) return ! ----------------------------------------------------------------------------------------------- CLR_STATUS_MSG_1: msg$ = "" gosub SET_STATUS_MSG_1 return ! ----------------------------------------------------------------------------------------------- CLR_STATUS_MSG_2: msg$ = "" gosub SET_STATUS_MSG_2 return ! ----------------------------------------------------------------------------------------------- CLR_STATUS_MSG_ALL: gosub CLR_STATUS_MSG_1 gosub CLR_STATUS_MSG_2 return ! ----------------------------------------------------------------------------------------------- GET_CUR_POS: ! Get current position of zoom (in motor counts). ! Sets var CurPos CurPos = getgpizoom(0) return ! ----------------------------------------------------------------------------------------------- GET_CUR_POS_AVG: ! Get current average position of zoom (in motor counts). ! Sets var CurPos _sum = 0 for _i% = 1 to PosAvgCount% _pos = getgpizoom(0) _sum = _sum + _pos next _i% CurPos = _sum / PosAvgCount% return ! ----------------------------------------------------------------------------------------------- MOVE_AWAY_FROM_LIMIT_SWITCH: ! Make incremental moves to get away from a limit switch. ! Size and direction of move is controlled by var LimitStep. ! Sets var CurPos. MOVE_AWAY_FROM_LIMIT_SWITCH_LOOP: gosub GET_CUR_POS_AVG ! Sets var CurPos TargPos = CurPos + LimitStep gosub SET_ZOOM_POS_AND_DETECT_ERRORS ! Uses var TargPos, sets var ErrorBits% if bitand(ErrorBits%, 1) <> 0 then goto MOVE_AWAY_FROM_LIMIT_SWITCH_LOOP endif if bitand(ErrorBits%, 2) <> 0 then msg$ = "Following error" gosub LOG_DATE_TIME_MSG msg$ = " Following error " gosub SHOW_ERROR_DIALOG stop endif if bitand(ErrorBits%, 4) <> 0 then msg$ = "Not-in-position error" gosub LOG_DATE_TIME_MSG msg$ = " Not-in-position error " gosub SHOW_ERROR_DIALOG stop endif gosub GET_CUR_POS_AVG ! Sets var CurPos return ! ----------------------------------------------------------------------------------------------- SET_ZOOM_POS_AND_DETECT_ERRORS: ! Set zoom position and detect errors. ! Don't stop if one of the expected errors is detected, ! but stop if an unexpected error occurs. ! Target position is specified by var TargPos. ! Sets var ErrorBits% ErrorBits% = 0 on error goto SET_ZOOM_POS_AND_DETECT_ERRORS_2 setgpizoom(TargPos, 0) off error ! No errors return SET_ZOOM_POS_AND_DETECT_ERRORS_2: off error ! Got an error ofmtr("%g") msg$ = "setgpizoom(" & val$(TargPos) & ",0) failed: " & errm$ gosub LOG_DATE_TIME_MSG ! If it was a limit error, if pos(errm$, "limit") <> 0 then ErrorBits% = 1 return endif ! If it was a following error, if pos(errm$, "following") <> 0 then ErrorBits% = 2 return endif ! If it was a not-in-position error, if pos(errm$, "not in position") <> 0 then ErrorBits% = 4 return endif ! Any other error: report it and stop. msg$ = " Move error: " msg$ = msg$ & " " & errm$ & " " gosub SHOW_ERROR_DIALOG stop ! ----------------------------------------------------------------------------------------------- SET_ZOOM_POS_AND_IGNORE_ERRORS: ! Make a move and ignore errors. ! Target position is specified by var TargPos on error goto SET_ZOOM_POS_AND_IGNORE_ERRORS_2 setgpizoom(TargPos, 0) off error return SET_ZOOM_POS_AND_IGNORE_ERRORS_2: off error return ! ----------------------------------------------------------------------------------------------- MOVE_AND_STOP_ON_ERROR: ! Make a move; if any error detected, report it and stop. ! Target position is specified by var TargPos gosub SET_ZOOM_POS_AND_DETECT_ERRORS ! Uses var TargPos, sets var ErrorBits% if bitand(ErrorBits%, 1) <> 0 then msg$ = "Limit error" gosub LOG_DATE_TIME_MSG msg$ = " Limit error " gosub SHOW_ERROR_DIALOG stop endif if bitand(ErrorBits%, 2) <> 0 then msg$ = "Following error" gosub LOG_DATE_TIME_MSG msg$ = " Following error " gosub SHOW_ERROR_DIALOG stop endif if bitand(ErrorBits%, 4) <> 0 then msg$ = "Not-in-position error" gosub LOG_DATE_TIME_MSG msg$ = " Not-in-position error " gosub SHOW_ERROR_DIALOG stop endif return ! ----------------------------------------------------------------------------------------------- MOVE_AND_CHECK_POS_ERROR: ! Make a move and check for position error. ! Target position is specified by var TargPos. ! Position error tolerance is specified by var PosErrorTol. ! Sets vars CurPos and PosError. gosub SET_ZOOM_POS_AND_IGNORE_ERRORS ! Uses var TargPos gosub GET_CUR_POS_AVG ! Sets var CurPos PosError = CurPos - TargPos ! Round PosError to an integer if PosError > 0 then PosError = int(PosError + 0.5) endif if PosError < 0 then PosError = int(PosError - 0.5) endif gosub CHECK_POS_ERROR ! Uses vars PosError and PosErrorTol return ! ----------------------------------------------------------------------------------------------- CHECK_POS_ERROR: ! Uses vars PosError and PosErrorTol if abs(PosError) > PosErrorTol then ofmtr("%.0f") msg$ = "Position error = " & val$(PosError) & " is out-of-tolerance " & val$(PosErrorTol) gosub LOG_DATE_TIME_MSG msg$ = " " & msg$ & " " gosub SHOW_ERROR_DIALOG stop endif return ! ----------------------------------------------------------------------------------------------- SET_ZOOM_MAG_WITH_RETRY: ! Uses var TargMag RetryCount% = 0 MaxRetryCount% = 10 SET_ZOOM_MAG_WITH_RETRY_LOOP: on error goto SET_ZOOM_MAG_WITH_RETRY_ERROR setgpizoom(TargMag, 1) off error return SET_ZOOM_MAG_WITH_RETRY_ERROR: off error msg$ = errm$ gosub LOG_DATE_TIME_MSG if pos(errm$, "Processing aborted") > 0 then msg$ = " Processing aborted " gosub SHOW_ERROR_DIALOG stop endif ofmtr("%g") msg$ = "setgpizoom(" & val$(TargMag) & ", 1) failed: " & trim$(errm$) RetryCount% = RetryCount% + 1 if RetryCount% > MaxRetryCount% then msg$ = msg$ & " Giving up" gosub LOG_DATE_TIME_MSG msg$ = " " & msg$ & " " gosub SHOW_ERROR_DIALOG stop else msg$ = msg$ & " Retrying" gosub LOG_DATE_TIME_MSG gosub SET_STATUS_MSG_2 goto MEASURE_WITH_RETRY_LOOP endif return ! ----------------------------------------------------------------------------------------------- SHOW_DIALOG: ! Uses vars msg$ and msgtype%, sets var ok% on error goto DIALOG_ESCAPED ok% = dialog(msg$, msgtype%) off error return ! ----------------------------------------------------------------------------------------------- SHOW_MESSAGE_DIALOG: ! Show msg$ in a message dialog. msgtype% = 1 gosub SHOW_DIALOG ! Uses vars msg$ and msgtype%, sets var ok% return ! ----------------------------------------------------------------------------------------------- SHOW_ERROR_DIALOG: ! Show msg$ in an error dialog. msgtype% = 2 gosub SHOW_DIALOG ! Uses vars msg$ and msgtype%, sets var ok% return ! ----------------------------------------------------------------------------------------------- SHOW_WARNING_DIALOG: ! Show msg$ in a warning dialog. msgtype% = 3 gosub SHOW_DIALOG ! Uses vars msg$ and msgtype%, sets var ok% return ! ----------------------------------------------------------------------------------------------- PROMPT_FOR_NUMBER: ! Prompt operator to enter a number. ! Uses vars prompt$ and str$ ! Sets var number ! If operator does not enter a valid number string, then number is set to maxreal on error goto DIALOG_ESCAPED _s$ = promptstr$(prompt$, str$, 10) off error _s$ = trim$(_s$) if len(_s$) = 0 then number = maxreal else number = val(_s$) endif return ! ----------------------------------------------------------------------------------------------- DIALOG_ESCAPED: ! Handle error generated by Esc key during dialog. ! Try to leave joysticks enabled. on error goto DIALOG_ESCAPED_2 joyon DIALOG_ESCAPED_2: off error stop ! ----------------------------------------------------------------------------------------------- ! ----------------------------------------------------------------------------------------------- MOVE_SRC_TO_DST: ! Copy file src$ to dst$, then delete src$ gosub COPY_SRC_TO_DST cmd$ = "cmd /c del " & src$ _ret% = execute(cmd$) return ! ----------------------------------------------------------------------------------------------- COPY_SRC_TO_DST: ! Copy file src$ to dst$ gosub COPY_SRC_TO_DST_0 if _ret% <> 0 then msg$ = "Error copying " & src$ & " to " & dst$ gosub LOG_DATE_TIME_MSG msg$ = " " & msg$ & " " gosub SHOW_ERROR_DIALOG stop endif return ! ----------------------------------------------------------------------------------------------- ! Copy file src$ to dst$, ignore any error COPY_SRC_TO_DST_0: cmd$ = "cmd /c copy " & src$ & " " & dst$ & " /Y" _ret% = execute(cmd$) return ! ----------------------------------------------------------------------------------------------- DELETE_FILE: ! Uses fn$ cmd$ = "cmd /c del " & fn$ & " /Q" _ret% = execute(cmd$) return ! ----------------------------------------------------------------------------------------------- SAVE_RAW_CAL_DATA: ! Saves raw cal data to a file. ! Uses vars RawCalDataFile$, NumCalPos%, TargPosAry(), ActualPosAry(), PosErrorAry(), ! MeasPvAry() and GenPvAry() fn$ = RawCalDataFile$ assign @fp to RawCalDataFile$ "w" ! Heading line line$ = "TargetPos, ActualPos, PosError, MeasPv, GenPv" output @fp; line$ ! Output in order of increasing position values if TargPosAry(1) < TargPosAry(2) then _i1% = 1 _i2% = NumCalPos% _istep% = 1 else _i1% = NumCalPos% _i2% = 1 _istep% = -1 endif for _i% = _i1% to _i2% step _istep% TargPos = TargPosAry(_i%) ActualPos = ActualPosAry(_i%) PosError = PosErrorAry(_i%) MeasPv = MeasPvAry(_i%) GenPv = GenPvAry(_i%) ofmtr("%14.1f") line$ = val$(TargPos) & "," & val$(ActualPos) & "," & val$(PosError) ofmtr("%14.6f") line$ = line$ & "," & val$(MeasPv) & "," & val$(GenPv) output @fp; line$ next _i% assign @fp to "" return ! ----------------------------------------------------------------------------------------------- LOAD_RAW_CAL_DATA: ! Loads raw cal data from file. ! Uses var RawCalDataFile$ fn$ = RawCalDataFile$ on error goto LOAD_RAW_CAL_DATA_CANT_OPEN_FILE assign @fp to RawCalDataFile$ "r" off error ! Count number of lines in the file num_lines% = 0 on error goto LOAD_RAW_CAL_DATA_EOF LOAD_RAW_CAL_DATA_COUNT_LINES: enterline @fp; line$ num_lines% = num_lines% + 1 goto LOAD_RAW_CAL_DATA_COUNT_LINES LOAD_RAW_CAL_DATA_EOF: off error if num_lines% = 0 then msg$ = "File " & fn$ & " is empty" gosub LOG_DATE_TIME_MSG msg$ = " " & msg$ & " " gosub SHOW_ERROR_DIALOG stop endif ! Re-open the file assign @fp to "" assign @fp to fn$ "r" ! Set dimensions of arrays NumCalPos% = num_lines% - 1 dim TargPosAry(NumCalPos%) dim ActualPosAry(NumCalPos%) dim PosErrorAry(NumCalPos%) dim MeasPvAry(NumCalPos%) dim GenPvAry(NumCalPos%) ! Read and discard first line enterline @fp; line$ ! Read remaining lines and fill in arrays for _i% = 1 to NumCalPos% enter @fp; TargPos, ActualPos, PosError, MeasPv, GenPv TargPosAry(_i%) = TargPos ActualPosAry(_i%) = ActualPos PosErrorAry(_i%) = PosError MeasPvAry(_i%) = MeasPv GenPvAry(_i%) = GenPv next _i% assign @fp to "" return LOAD_RAW_CAL_DATA_CANT_OPEN_FILE: off error msg$ = "Cannot read file " & fn$ gosub LOG_DATE_TIME_MSG msg$ = " " & msg$ & " " gosub SHOW_ERROR_DIALOG stop ! ----------------------------------------------------------------------------------------------- READ_TILT_MAG_ERROR_FROM_FILE: ! Reads TiltMagError value from text file. ! Uses var fn$, sets var TiltMagError on error goto READ_TILT_MAG_ERROR_CANT_OPEN_FILE assign @fp to fn$ "r" off error READ_TILT_MAG_ERROR_LOOP: on error goto READ_TILT_MAG_ERROR_EOF enterline @fp; line$ off error if pos(line$, "TiltMagError") = 0 then goto READ_TILT_MAG_ERROR_LOOP endif assign @fp to "" i% = pos(line$, "=") + 1 j% = pos(line$, "%") - 1 str$ = trim$(line$[i%,j%]) TiltMagError = val(str$) return READ_TILT_MAG_ERROR_EOF: off error assign @fp to "" msg$ = " Error reading TiltMagError from file " & fn$ & " " gosub SHOW_ERROR_DIALOG stop READ_TILT_MAG_ERROR_CANT_OPEN_FILE: off error msg$ = "Cannot read file " & fn$ gosub LOG_DATE_TIME_MSG msg$ = " " & msg$ & " " gosub SHOW_ERROR_DIALOG stop ! ----------------------------------------------------------------------------------------------- CALCULATE_1X_PV: ! Look up OneXPos value in ActualPosAry. ! Interpolate GenPvAry values to get the expected OneXPv. ! Uses vars OneXPos, ActualPosAry(), NumCalPos%. ! Sets var OneXPv OneXPv = 0 for _i% = 1 to (NumCalPos% - 1) Pos1 = ActualPosAry(_i%) Pos2 = ActualPosAry(_i% + 1) if (Pos1 <= OneXPos) and (OneXPos <= Pos2) then Pv1 = GenPvAry(_i%) Pv2 = GenPvAry(_i% + 1) OneXPv = Pv1 + ((OneXPos - Pos1) * (Pv2 - Pv1) / (Pos2 - Pos1)) return endif next _i% msg$ = "Cannot find the 1X position value in the raw cal data" gosub LOG_DATE_TIME_MSG msg$ = " " & msg$ & " " gosub SHOW_ERROR_DIALOG stop return ! ----------------------------------------------------------------------------------------------- CALCULATE_MAG_DATA: ! Uses vars OneXPv, GenPvAry(), NumCalPos%. ! Sets vars MagAry() dim MagAry(NumCalPos%) for _i% = 1 to NumCalPos% Pv = GenPvAry(_i%) Mag = OneXPv / Pv MagAry(_i%) = Mag next _i% return ! ----------------------------------------------------------------------------------------------- SAVE_ZOOM_CAL_DATA: ! Uses vars ZoomCalDataFile$, NumCalPos%, ActualPosAry(), and MagAry() assign @fp to ZoomCalDataFile$ "w" ! Column separator string, can use comma or blank ColumnSeparator$ = " " t = timedate line$ = date$(t) & " " & time$(t) output @fp; line$ for _i% = 1 to NumCalPos% ActualPos = ActualPosAry(_i%) Mag = MagAry(_i%) ofmtr("%14.6f") line$ = val$(ActualPos) & ColumnSeparator$ & val$(Mag) output @fp; line$ next _i% assign @fp to "" return ! ----------------------------------------------------------------------------------------------- SET_ZERNIKE_PLANE_CONTROLS: ! Set controls to support fitting a zernike plane to current data, then generating that plane ! Uses var GenCamRes ! Set fit controls id% = getid("Surface Wavefront Map / Controls / Zernike Terms") setstr(id%, "3") ! Set generate controls gosub SET_GEN_CAM_RES ! Uses var GenCamRes gosub GET_CAM_SIZE_X ! Sets var CamSizeX gosub GET_CAM_SIZE_Y ! Sets var CamSizeY gosub SET_GEN_CAM_SIZE_X ! Uses var CamSizeX gosub SET_GEN_CAM_SIZE_Y ! Uses var CamSizeY id% = getid("Controls / Generate / Surface Type") setstr(id%, "Zernike") id% = getid("Controls / Generate / Zernike / Zernike Terms") setstr(id%, "3") return ! ----------------------------------------------------------------------------------------------- SET_REMOVE_CONTROL_ON: id% = getid("Surface Wavefront Map / Controls / Remove") setnum(id%, 3, "") return ! ----------------------------------------------------------------------------------------------- SET_REMOVE_CONTROL_OFF: id% = getid("Surface Wavefront Map / Controls / Remove") setnum(id%, 0, "") return ! ----------------------------------------------------------------------------------------------- SET_LOW_CLIP_CONTROL: ! Sets Low Clip control to LowClip in zygos id% = getid("Surface Wavefront Map / Controls / Clip / Low Clip") setnum(id%, LowClip, "zygos") return ! ----------------------------------------------------------------------------------------------- GENERATE_ZERNIKE_PLANE: getzernikes generate return ! ----------------------------------------------------------------------------------------------- DOES_MASK_EXIST: ! Sets var maskExists% maskExists% = 1 on error goto DOES_MASK_EXIST_ERROR id% = getmaskid(0, 0, "pix") off error return DOES_MASK_EXIST_ERROR: off error maskExists% = 0 return ! ----------------------------------------------------------------------------------------------- SET_MASK_AND_ZOOM_FOR_ARTIF_ZONE: ! Set up to measure an artifact region. ! Uses var ArtifZone% gosub SET_ARTIF_ZONE ! Sets control using var ArtifZone% _MaskFile$ = ArtifZoneMaskFile$(ArtifZone%) loadmasks(_MaskFile$) _ZoomMag = ArtifZoneZoomMag(ArtifZone%) setgpizoom(_ZoomMag, 1) ofmti("%d") ofmtr("%.3f") msg$ = "Artifact zone " & val$(ArtifZone%) & ", zoom mag = " & val$(_ZoomMag) & ", mask file = " & _MaskFile$ gosub SET_STATUS_MSG_2 return ! ----------------------------------------------------------------------------------------------- MEASURE_ARTIF_ZONE: ! Measures an artifact zone. gosub OPEN_MODULATION_MAP_WINDOW gosub MEASURE_WITH_RETRY ! Save unprocessed height data savedata(0, "Height.dat") ! Save modulation data fn$ = "Mod1.dat" gosub SAVE_MODULATION_MAP_DATA gosub SET_REMOVE_CONTROL_OFF ! Load modulation data back in for clipping loaddata("Mod1.dat") ! Get value of Peak (All) result from Test+Ref Map in zygos ModPeak = getval(getid("Surface Wavefront Map (T+R) / Results / Peak Valley (All) / Peak (All)"), "zygos") ! Set Low Clip control LowClip = 0.6 * ModPeak gosub SET_LOW_CLIP_CONTROL ! Sets control using var LowClip in zygos ! Re-analyze to apply the clipping analyze ! Save processed modulation data fn$ = "Mod2.dat" gosub SAVE_SURFACE_MAP_DATA ! Clear the Low Clip control LowClip = maxreal gosub SET_LOW_CLIP_CONTROL ! Sets control using var LowClip in zygos ! Restore the Remove control gosub SET_REMOVE_CONTROL_ON return ! Load clipped modulation data back in for scaling loaddata("Mod2.dat") ! Scale it to zero so we can use add it as a mask scaledata(0) ! Save root data to same file savedata(0, "Mod3.dat") ! Load height data back in loaddata("Height.dat") ! Add the mask adddata("Mod3.dat") return ! ----------------------------------------------------------------------------------------------- GET_MODULATION_MAP_WINDOW_ID: ! Gets the ID of Modulation Map data window ! Sets var winid% winid% = getwinid("Modulation Map") return ! ----------------------------------------------------------------------------------------------- GET_MODULATION_MAP_DATA_ID: ! Gets the ID of Modulation Map data ! Sets var dataid% dataid% = getid("Modulation Map") return ! ----------------------------------------------------------------------------------------------- OPEN_MODULATION_MAP_WINDOW: ! Opens the Modulation Map data window gosub GET_MODULATION_MAP_WINDOW_ID ! Sets var winid% openwin(winid%) return ! ----------------------------------------------------------------------------------------------- CLOSE_MODULATION_MAP_WINDOW: ! Closes the Modulation Map data window gosub GET_MODULATION_MAP_WINDOW_ID ! Sets var winid% closewin(winid%) return ! ----------------------------------------------------------------------------------------------- SAVE_MODULATION_MAP_DATA: ! Saves data from Modulation Map data window. ! Uses var fn$ gosub GET_MODULATION_MAP_DATA_ID ! Sets var dataid% savedata(dataid%, fn$) return ! ----------------------------------------------------------------------------------------------- GET_SURFACE_MAP_DATA_ID: ! Gets the ID of Surface/Wavefront Map data ! Sets var dataid% dataid% = getid("Surface Wavefront Map") return ! ----------------------------------------------------------------------------------------------- SAVE_SURFACE_MAP_DATA: ! Saves data from Surface/Wavefront Map data window. ! Uses var fn$ gosub GET_SURFACE_MAP_DATA_ID ! Sets var dataid% savedata(dataid%, fn$) return ! ----------------------------------------------------------------------------------------------- SET_QUIET_FLAG: ! Creates a file that tells a sub-script to be non-interactive ! Write current time in secs to the file. assign @fp to QuietTimeFile$ "w" t1 = timedate ofmtr("%.2f") output @fp; t1 assign @fp to "" return ! ----------------------------------------------------------------------------------------------- GET_QUIET_FLAG: ! Tries to read a file used like a semaphore that tells a sub-script to be non-interactive. ! Sets var quietFlag% quietFlag% = 0 fn$ = QuietTimeFile$ gosub DOES_FILE_EXIST ! Uses var fn$, sets var fileExists% if fileExists% <> 0 then ! Read time value in secs from file assign @fp to QuietTimeFile$ "r" enterline @fp; line$ assign @fp to "" t1 = val(line$) ! Get current time in secs t2 = timedate epsilon = 3 ! If t2 is not very long after the time read from file, if t2 <= (t1 + epsilon) then ! Set the quiet flag quietFlag% = 1 endif endif return ! ----------------------------------------------------------------------------------------------- DELETE_MASKS_AND_MAKE_CAL_MARKER_FOR_MST: ! Delete any mask (so we acquire and analyze maximum region of data). ! For an MST app, this will delete any cal markers, so we have to make one. resetmasks gosub MAKE_CAL_MARKER_FOR_MST return ! ----------------------------------------------------------------------------------------------- MAKE_CAL_MARKER_FOR_MST: ! Make a cal marker if this is an MST app gosub GET_CAM_SIZE_X ! Get camera size in X dimension into var CamSizeX gosub GET_CAM_SIZE_Y ! Get camera size in Y dimension into var CamSizeY on error goto MAKE_CAL_MARKER_FOR_MST_ERROR makemstcalmark(0,0,(CamSizeX/2),(CamSizeY/2),"pix") off error return MAKE_CAL_MARKER_FOR_MST_ERROR: off error ! If not an MST app, ignore this expected error if pos(errm$, "Feature is not implemented") > 0 then return endif ! Report any other error msg$ = errm$ gosub SHOW_ERROR_DIALOG stop ! ----------------------------------------------------------------------------------------------- VERIFY_MST_2S_CAV_LEN_SCAN_OFF: ! If using an MST app, verify that the 2S Cav Length Scan ! control is off. on error goto VERIFY_MST_2S_CAV_LEN_SCAN_OFF_NO_CTRL id% = getid("Controls / Acquisition / 2S Cav Len Scan / 2S Cav Length Scan") off error if getnum(id%,"") > 0 then msg$ = " The 2S Cav Length Scan control must be Off. " gosub SHOW_ERROR_DIALOG stop endif VERIFY_MST_2S_CAV_LEN_SCAN_OFF_NO_CTRL: off error return ! ----------------------------------------------------------------------------------------------- SET_MST_2S_CAV_LEN_SCAN_OFF: ! If using an MST app, set the 2S Cav Length Scan control off. on error goto SET_MST_2S_CAV_LEN_SCAN_OFF_NO_CTRL id% = getid("Controls / FTPSI / 2S Cav Length Scan") off error setnum(id%,0,"") endif SET_MST_2S_CAV_LEN_SCAN_OFF_NO_CTRL: off error return