loadsub 'StitchDeclares.scr' !ZipStitch.scr ! 4/19/96 mdc New version, enter in start and end point all meas are in inches ! found couldn't fit 25 filenames into filelist metroscript only ! allows 200 chars in a string modified to put filenames and ! coordinates in filecoors.crd ! 4/19/96 mdc added fix to get exact dim meas (add extra meas) ! 4/22/96 mdc fixed bug, added tmp directory, added overlap adj ! 4/24/96 mdc added chk for exceeding max dimensions added on error goto 0 ! 4/29/96 mdc allow continuation on meas error ! 5/1/96 mdc reset masks, add metro controls ! 6/2/96 mdc use Overlap % as a min ! 7/3/96 mdc do everything in inches, let metroscript do everything ! 6/18/97 mdc major mods ! 8/26/97 mdc Added the ability to not load the stitched surfaces, and did cleanup ! 10/21/98 mdc modified path$ to be absolute, not relative ! 07/17/2002 PAL Added code so there is always an error handler ! 09/26/2002 PAL Removed "loadsub" of non-existing file from top of file ! 02/18/2003 PAL Changed all calls to dialog() to use new DO_DIALOG sub-routine. ! Made CENTRAL_ERROR_HANDLER the default error handler. ! Load 'GenStitch.scr' instead of 'StitchSubs.scr' ! Run the stitch part as a seperate script because of error handler changes. ! +-----------------------------------------------------------------------------------------+ ! ! | Sub STARTZIP() | ! ! | Main routine for Zip Stitching. Handles everything relating to Zip and farms out | ! ! | the stitching portion to routines in GenStitch.scr | ! ! | | ! ! | In Parameters: | ! ! | g_bUNIX | ! ! | g_ZipDistance | ! ! | PhaseRes | ! ! | g_idPhaseResCntl | ! ! | g_bDiagnostic | ! ! | ZRemIntens | ! ! | g_idStchOvrlpPerCntl | ! ! | g_idStchXSizeCntl | ! ! | g_idStchYSizeCntl | ! ! | g_idZipLSeqFileCntl | ! ! | g_idZipUSeqFileCntl | ! ! | ZLgtLvlOff | ! ! | g_idLgtLvlCntl | ! ! | g_StitchFile$ | ! ! | ret_ChkDims | ! ! | ZipShowStch | ! ! | | ! ! | Out Parameters: | ! ! | g_MPBinDir$ | ! ! | g_TempDir$ | ! ! | g_NumZips | ! ! | g_DoingZip | ! ! | g_CoordFile$ | ! ! | g_ZipXStart() | ! ! | g_ZipYStart() | ! ! | g_ZipZStart() | ! ! | g_Error | ! ! | | ! ! | Local Variables: | ! ! | l_nTemp | ! ! | l_sTemp$ | ! ! | l_msg$ | ! ! | ret_Dialog | ! ! | #CoorFile_Zip | ! ! | l_nZipLoop | ! ! | l_ZipMessage$ | ! ! | l_OldLightLevel | ! ! | tmpStchTilt | ! ! | ret_MotorZ | ! ! | | ! ! | Procedures Called: | ! ! | GET_OS | ! ! | CREATE_TMP_DIR | ! ! | GET_ZIP_CNTRLS | ! ! | HAVE_MOTORIZED_Z | ! ! | GET_Z | ! ! | MOVE_XY | ! ! | DO_ZIP_SEQ | ! ! | DO_ZIP_XY_DIM | ! ! | CLEAN_TMP_DIR | ! ! | | ! ! | Algorithm: | ! ! +-----------------------------------------------------------------------------------------+ ! STARTZIP: ! Set the error handler on error goto CENTRAL_ERROR_HANDLER ! Mark that ZIP_EXIT routine exists g_ExitZipStitchExists = 1 ! Mark that the EXIT_STITCH routine exists g_ExitStitchExists = 1 ! Clear the user abort gosub CLEAR_USER_ABORT ! Get the initial position gosub GET_XY g_ZipXStart(1) = tmp_x_pos g_ZipYStart(1) = tmp_y_pos gosub GET_Z g_ZipZStart(1) = tmp_z_pos gosub GET_OS ! determine operating system gosub STCH_INIT g_LogFile$ = "zip.log" gosub GET_ZIP_CNTRLS g_MPBinDir$ = getbindir$ & g_PathSep$ ! place to where executable lives g_TempDir$ = getwrkdir$ & g_PathSep$ & "zip_tmp" gosub CREATE_TMP_DIR g_NumZips = 2 g_DoingZip = 1 ! flag indicating we are doing Zip Stitch if ((g_bUNIX = 1)) then l_nTemp = execute("rm -f " & ZipFn$) else l_nTemp = execute("erase /f /q " & ZipFn$) endif ! do we have and need a motorized stage if ((g_ZipDistance <> 0)) then gosub HAVE_MOTORIZED_Z if ((ret_MotorZ = 0)) then goto NOZSTAGE endif ! Determine the max Phase Res allowed for the zip distance ! The rough estimate is we want to keep the data to 40% of the ! MAXDATA value = 0x3FFFFFF ! Default to Super and work our way down from there maxPhaseRes = 3 if (g_ZipDistance > 0.0025) then maxPhaseRes = 2 if (g_ZipDistance > 0.01) then maxPhaseRes = 1 ! Check to see if Phase Res is set higher than our calculated value ! if so change Phase Res to avoid data overflow if (PhaseRes > maxPhaseRes) then g_dlgStyle = DlgWarning_OK g_dlgMessage$ = " Phase Res will be changed to " if (maxPhaseRes = 1) then g_dlgMessage$ = g_dlgMessage$ & "Normal" if (maxPhaseRes = 2) then g_dlgMessage$ = g_dlgMessage$ & "High" if (maxPhaseRes = 3) then g_dlgMessage$ = g_dlgMessage$ & "Super" g_dlgMessage$ = g_dlgMessage$ & " \n to avoid data overflow " gosub DO_DIALOG setnum(g_idPhaseResCntl, maxPhaseRes, "") endif !x_tot = x_siz + x_dim g_CoordFile$ = g_TempDir$ & g_PathSep$ & "coords.crd" g_ZipCoordFile$ = g_TempDir$ & g_PathSep$ & "zipcoors.crd" !assign @CoorFile_Zip to g_ZipCoordFile$ "w" !output @CoorFile_Zip; "* Zygo Zipping Coord File Version 3" !output @CoorFile_Zip; val$(g_NumZips) & " # number of input files " !output @CoorFile_Zip; val$(g_bDiagnostic) & " # diagnostic option " !output @CoorFile_Zip; val$(ZRemIntens) & " # remove intensity flag " !gosub GET_XY !g_ZipXStart(1) = tmp_x_pos !g_ZipYStart(1) = tmp_y_pos ! !gosub GET_Z !g_ZipZStart(1) = tmp_z_pos ! !g_dlgStyle = DlgNormal_YesNo !g_dlgMessage$ = " Position at Upper Right of Lower Area \n Yes to Begin, No to Exit " !gosub DO_DIALOG !if (ret_Dialog = DlgNo) then goto ZIP_EXIT ! remove backlash if ((g_ZipDistance > 0)) then gosub GET_Z l_nTemp = tmp_z_pos - 0.01 tmp_z_pos = l_nTemp gosub MOVE_Z l_nTemp = l_nTemp + 0.01 tmp_z_pos = l_nTemp gosub MOVE_Z endif gosub GET_XY g_ZipXStart(1) = tmp_x_pos g_ZipYStart(1) = tmp_y_pos gosub GET_Z g_ZipZStart(1) = tmp_z_pos ! We now have a position to return to g_ReturnWhenDone = 1 g_ZipXStart(2) = g_ZipXStart(1) + zipXOffset g_ZipYStart(2) = g_ZipYStart(1) + zipYOffset g_ZipZStart(2) = g_ZipZStart(1) + g_ZipDistance g_CollectingZipData = 1 l_nZipLoop = 1 g_RealNumZips = 0 ZIP_STITCH_LOOP: ! Reset the stitch flags g_DoStitch = 0 g_HaveData = 0 ! Assume an error g_Error = 1 tmp_x_pos = g_ZipXStart(l_nZipLoop) tmp_y_pos = g_ZipYStart(l_nZipLoop) gosub MOVE_XY if ( g_CollectingZipData = 0 ) then goto ZIP_STITCH_LOOP_EXIT tmp_z_pos = g_ZipZStart(l_nZipLoop) gosub MOVE_Z if ( g_CollectingZipData = 0 ) then goto ZIP_STITCH_LOOP_EXIT !zpxpos(1) = g_ZipXStart(l_nZipLoop) !zpypos(1) = g_ZipYStart(l_nZipLoop) !zpx_siz = ZXSize(l_nZipLoop) !zpy_siz = ZYSize(l_nZipLoop) !x_start = g_ZipXStart(l_nZipLoop) !y_start = g_ZipYStart(l_nZipLoop) if ((l_nZipLoop = 1)) then ! get seq filenames l_ZipMessage$ = getval$(g_idZipLSeqFileCntl) else l_ZipMessage$ = getval$(g_idZipUSeqFileCntl) endif ! set the Stitch controls based on the Zip Controls setnum(g_idStchOvrlpPerCntl, ZOvrlp(l_nZipLoop), "") setnum(g_idStchXSizeCntl, ZXSize(l_nZipLoop), "in") setnum(g_idStchYSizeCntl, ZYSize(l_nZipLoop), "in") setstr(g_idStchSeqFileCntl, l_ZipMessage$) ! set the starting location for the stitch subs g_XStart = g_ZipXStart(l_nZipLoop) g_YStart = g_ZipYStart(l_nZipLoop) g_XSize = ZXSize(l_nZipLoop) g_YSize = ZYSize(l_nZipLoop) g_Overlap = ZOvrlp(l_nZipLoop) if ((ZLgtLvlOff(l_nZipLoop) <> 0)) then ! set light level l_OldLightLevel = getval(g_idLgtLvlCntl, "") setnum(g_idLgtLvlCntl, l_OldLightLevel + ZLgtLvlOff(l_nZipLoop), "") endif if ((g_bUNIX = 1)) then l_nTemp = execute("rm -f " & g_StitchFile$) else l_nTemp = execute("erase /f /q " & g_StitchFile$) endif ! for zipping we can allow Auto Tilt on the first surface, but not on any others ! if we did we would lose the tilt relationship between the surfaces if (((l_nZipLoop <> 1) and (tmpStchTilt = 2))) then ! tmpStchTilt is set by Stitch script setnum(g_idStchTiltCntl, 1, "") endif if ((UseSeqFile(l_nZipLoop) = 1)) then gosub DO_ZIP_SEQ else gosub DO_ZIP_XY_DIM endif if ( g_CollectingZipData = 0 ) then goto ZIP_STITCH_LOOP_EXIT ZIP_STITCH_LOOP_CONT: gosub CHK_USER_ABORT if ( g_CollectingZipData = 0 ) then goto ZIP_STITCH_LOOP_EXIT if ( g_bUserAbort = 1 ) then goto ZIP_EXIT endif if (((g_Error = 1) or (ret_ChkDims = 1))) then goto ZIP_EXIT if ((ZipShowStch = 1)) then loaddata(g_StitchFile$) endif !if ((ZipPrData = 1)) then ! do not disp if no show ! savedata(SavePrDataID,g_StitchFile$) !endif ! Save the stitch file if ((g_bUNIX = 1)) then l_sTemp$ = g_TempDir$ & "/zipx" & val$(l_nZipLoop) & ".dat" l_nTemp = execute("mv " & g_StitchFile$ & " " & l_sTemp$) else l_sTemp$ = g_TempDir$ & "\\zipx" & val$(l_nZipLoop) & ".dat" l_nTemp = execute("copy " & g_StitchFile$ & " " & l_sTemp$) endif !output @CoorFile_Zip; l_sTemp$ !output @CoorFile_Zip; val$(g_ZipXStart(l_nZipLoop)) & " " & val$(g_ZipYStart(l_nZipLoop)) & " # x and y position in inches " !output @CoorFile_Zip; val$(g_ZPos(1)) & " # z position in inches " ! Save the first Z position from the stitch if (USE_Z_ENCODER% = 0) then g_ZipZPos(l_nZipLoop) = g_ZMeasPos(1) else gosub GET_Z_ENCODER g_ZipZPos(l_nZipLoop) = tmp_ze_pos endif if ((ZLgtLvlOff(l_nZipLoop) <> 0)) then ! restore light level setnum(g_idLgtLvlCntl, l_OldLightLevel, "") endif ! Increment loop counter and check for done l_nZipLoop = l_nZipLoop + 1 g_RealNumZips = g_RealNumZips + 1 if ( l_nZipLoop > g_NumZips ) then goto ZIP_STITCH_LOOP_EXIT endif ! Not done, continue the loop goto ZIP_STITCH_LOOP ZIP_STITCH_LOOP_EXIT: g_CollectingZipData = 0 !ZipFileID = getid("Controls/ZipStitch/ZipFile") !zfn$ = getVal(ZipFileID) DO_ZIP_DATA: g_CollectingZipData = 0 ! Mark that we tried to do the zip g_DidZipData = 1 !output @CoorFile_Zip; ZipFn$ !assign @CoorFile_Zip to "" if ( g_RealNumZips = 1 ) then if ((g_bUNIX = 1)) then l_sTemp$ = g_TempDir$ & "/zipx1.dat" l_nTemp = execute("mv " & l_sTemp$ & " " & ZipFn$) else l_sTemp$ = g_TempDir$ & "\\zipx1.dat" l_nTemp = execute("copy " & l_sTemp$ & " " & ZipFn$) endif endif if ( g_RealNumZips > 1 ) then gosub CREATE_ZIP_COORDF l_nTemp = execute(g_MPBinDir$ & "zip " & g_ZipCoordFile$) if (l_nTemp <> 0) then goto BADZIP endif g_Error = 0 goto ZIP_EXIT BADZIP: g_dlgStyle = DlgError_OK if ( l_nTemp = 1000 ) then g_dlgMessage$ = " Maximum zip offset exceeded " else g_dlgMessage$ = " Error in Zip algorithm, program halted " endif gosub DO_DIALOG goto ZIP_EXIT NOZSTAGE: g_dlgStyle = DlgError_OK g_dlgMessage$ = " No motorized Z stage detected \n Stage is required for Zip Distance > 0 " gosub DO_DIALOG ZIP_EXIT: ! Check for user abort. Save for later. gosub CHK_USER_ABORT bUserAbort = g_bUserAbort ! Move the stages back to the initial position if ( g_ReturnWhenDone = 1 ) then tmp_x_pos = g_ZipXStart(1) tmp_y_pos = g_ZipYStart(1) gosub MOVE_XY_NO_ERROR tmp_z_pos = g_ZipZStart(1) gosub MOVE_Z_NO_ERROR endif ! Check for unzipped data if ( (g_DidZipData = 0) and (g_RealNumZips > 0) ) then g_dlgStyle = DlgNormal_YesNo g_dlgMessage$ = " Data has not been Zipped. \n Zip data now? " gosub DO_DIALOG if (ret_Dialog = DlgOK_Yes) then goto DO_ZIP_DATA endif endif ! Display an abort message if needed if ( bUserAbort <> 0 ) then g_dlgMessage$ = " Zip-Stitch Aborted " g_dlgStyle = DlgError_OK gosub DO_DIALOG endif ! Reset Stitch auto tilt control if ((tmpStchTilt = 2)) then setnum(g_idStchTiltCntl, 2, "") endif ! Delete old files g_TempDir$ = "zip_tmp" gosub CLEAN_TMP_DIR end ! +-----------------------------------------------------------------------------------------+ ! ! | Sub DO_ZIP_SEQ() | ! ! | Sets up for and calls the Run Sequence Stitching routine. | ! ! | | ! ! | In Parameters: | ! ! | g_idStchTypeCntl | ! ! | g_idStchSeqFileCntl | ! ! | | ! ! | Out Parameters: | ! ! | | ! ! | Local Variables: | ! ! | | ! ! | Procedures Called: | ! ! | | ! ! | Algorithm: | ! ! +-----------------------------------------------------------------------------------------+ ! DO_ZIP_SEQ: ! set controls for Run Sequence Stitching setnum(g_idStchTypeCntl, 5, "") setstr(g_idStchSeqFileCntl, l_ZipMessage$) ! Run Sequence Stitching routine gosub RUN_SEQ_STCH DO_ZIP_SEQ_EXIT: return ! +-----------------------------------------------------------------------------------------+ ! ! | Sub DO_ZIP_XY_DIM() | ! ! | Sets up for and calls the X & Y Stitching routine. | ! ! | | ! ! | In Parameters: | ! ! | g_idStchTypeCntl | ! ! | | ! ! | Out Parameters: | ! ! | | ! ! | Local Variables: | ! ! | | ! ! | Procedures Called: | ! ! | | ! ! | Algorithm: | ! ! +-----------------------------------------------------------------------------------------+ ! DO_ZIP_XY_DIM: ! set controls for X & Y Stitching setnum(g_idStchTypeCntl, 3, "") ! X & Y Stitching routine gosub XY_STCH DO_ZIP_XY_EXIT: return ! +-----------------------------------------------------------------------------------------+ ! ! | Sub CREATE_ZIP_COORDF() | ! ! | Writes coordinates and file names to the Zip Coordinate File. | ! ! +-----------------------------------------------------------------------------------------+ ! CREATE_ZIP_COORDF: assign @CoorFile_Zip to g_ZipCoordFile$ "w" output @CoorFile_Zip; "* Zygo Zipping Coord File Version 3" output @CoorFile_Zip; val$(g_RealNumZips) & " # number of input files " output @CoorFile_Zip; val$(g_bDiagnostic) & " # diagnostic option " output @CoorFile_Zip; val$(ZRemIntens) & " # remove intensity flag " for l_nTemp = 1 to g_RealNumZips if ((g_bUNIX = 1)) then l_sTemp$ = g_TempDir$ & "/zipx" & val$(l_nTemp) & ".dat" else l_sTemp$ = g_TempDir$ & "\\zipx" & val$(l_nTemp) & ".dat" endif output @CoorFile_Zip; l_sTemp$ output @CoorFile_Zip; val$(g_ZipXStart(l_nTemp)) & " " & val$(g_ZipYStart(l_nTemp)) & " # x and y position in inches " output @CoorFile_Zip; val$(g_ZipZPos(l_nTemp)) & " # z position in inches " next l_nTemp output @CoorFile_Zip; ZipFn$ assign @CoorFile_Zip to "" CREATE_ZIP_COORDF_EXIT: return loadsub 'GenStitch.scr'