--+------------------------------------------------------------------------+
--+                        SOHO Project -- Control File
--+                        ----------------------------
--+
--+ Name        : MDI_LCAL , !Proc_s , !Print
--+ Purpose     : (See Procedure headers)
--+                    
--+ Sub_system  : PLM
--+ Drawing No  : 3137-ZA042-SCB  Issue : A/00
--+ Project No  : SH-MAR-SW-70224
--+ Origin      : UK 
--+ Author      : Jon B. CARTER
--+------------------------------------------------------------------------+
--+ Principle   :
--+ ---------
--+   Holding CF for a group of related Procedures, originally written in
--+   MDI's own Control File language.
--+
--+ Passed parameters :
--+ -----------------
--+   !Proc_s   : Name of required Procedure.
--+   !Print    : CF Log print indicator ( "yes" (default) | "no" ).
--+
--+ Prerequisites :
--+ -------------
--+ Control File MDI_ON must have been successfully performed.
--+
--+ History :
--+ -------
--+   Issue SIC Note Time   Date      Name/Updates
--+   +---+ +------+ +---+  +------+ +-------------------------------------+
--+   1/00   211     17:18  07/01/94 A.J. TURK -- Conversion from MDI language. 
--+   1/01   289     19:29  07/02/94 A.J. TURK -- Debug phase. 
--+   1/02   360     17:39  21/04/94 Ed COBB   -- Rationalization
--+   1/07   443     15:45  17/06/94 Ed COBB   -- CF Errors.
--+
--+------------------------------------------------------------------------+
Common
Var
    Bool        !GZ_Window              -- Open window flag (on CF start)
    Bool        !GZ_Spool               -- Automatic Spool (at End of CF exec)
    Bool        !GZ_Halt                -- Check Error flag (to halt if error)
    Bool        !GZ_Test                -- Execution test flag (to not send TC)
    Int         !GZ_Trace               -- Level of Trace (TBD)

    Int         !GM_Conf                -- MDI Configuration
    Int         !GM_NbErr               -- MDI Global Error Count

    Str(80)     !GM_S0
    Str(80)     !GM_S6

End Common
-------------------------------------------------------------------------------<
Extern
    Cfile       MDI_LMCH
    Group       MWTM , PWP12TM

    Procedure   AskReal , AskStr , AskInt
    Procedure   CheckAna , CheckDig , CheckReg
    Procedure   CheckArgReal , CheckArgStr , CheckArgInt
    Procedure   DispMess
    Procedure   ExConnect , ExDisconnect
    Procedure   ExitCF
    Procedure   Message
    Procedure   OpenWindow
    Procedure   PrintAna , PrintDig , PrintReg , PrintParam
    Procedure   SendCommand 
    Procedure   Lower , Upper
    Procedure   WaitAna , WaitDig , WaitReg , WaitTime

End Extern
-------------------------------------------------------------------------------<
Program MDI_LCAL , Unique

Defarg
    Str(80)     !Proc_s
    Str(3)      !Print            = "yes"
End Defarg

Var
    Str( 3)     !ExpName   = "MDI"
    Int         !NbErr     = 0
    Str(49)     !Title     = " "
    str(80)     !S         = &80s(" ")

Main
    @OpenWindow()

    Select !Proc_s
    Case "lcal1com"
        @lcal1com()

    Case "lcal2com"
        @lcal2com()

    Default
        !Title = "*ERROR: UNKNOWN PROCEDURE: "+!Proc_s
        @Message("DCL" , "date" , !ExpName , " " , !Title , *!S)
--      Beep
        Halt
        !Title = "*Operator CONTinue"
        @Message("DC" , "date" , !ExpName , " " , !Title , *!S)
        Return !Rstat

    End Select

    @ExitCF (!NbErr)
    @PrintCF ( !ExpName , !Print )
Return !Rstat
End Program
----------------------------------------------------------------------------------<
Procedure lcal1com ( )
--.
--.  This procedure file performs the commissioning for the 
--.  Calibration/Focus Motor 1 (CAL1)
--.
Var
    Str( 3)     !ExpName   = "MDI"
    Str(10)     !Phase     = " "
    Str(49)     !Title     = " "
    Str(80)     !S         = &80s(" ")
    Int         !NbErr     = 0
    Int         !Get_int   = 0

Main
    !Title = "-EXECUTING PROCEDURE: lcal1com."
    @Message( "DCL" , "date" , !ExpName , !Phase , !Title , *!S )

    !Title = "~Set CAL1 to position 55; CW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC1SP" , "55" )
    @SendCommand ( "MBC1CW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC1POS" , ">= 54 and <= 55" , *!NbErr )

    !Title = "~Set CAL1 to position 91; CW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC1SP" , "91" )
    @SendCommand ( "MBC1CW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC1POS" , ">= 90 and <= 91" , *!NbErr )

    !Title = "~Set CAL1 to position 127; CW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC1SP" , "127" )
    @SendCommand ( "MBC1CW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC1POS" , ">= 126 and <= 127" , *!NbErr )

    !Title = "~Set CAL1 to position 19; CW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC1SP" , "19" )
    @SendCommand ( "MBC1CW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC1POS" , ">= 18 and <= 19" , *!NbErr )

    !Title = "~Set CAL1 to position 127; CCW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC1SP" , "127" )
    @SendCommand ( "MBC1CCW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC1POS" , ">= 126 and <= 127" , *!NbErr )

    !Title = "~Set CAL1 to position 91; CCW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC1SP" , "91" )
    @SendCommand ( "MBC1CCW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC1POS" , ">= 90 and <= 91" , *!NbErr )

    !Title = "~Set CAL1 to position 55; CCW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC1SP" , "55" )
    @SendCommand ( "MBC1CCW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC1POS" , ">= 54 and <= 55" , *!NbErr )

    !Title = "~Set CAL1 to position 19; CCW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC1SP" , "19" )
    @SendCommand ( "MBC1CCW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC1POS" , ">= 18 and <= 19" , *!NbErr )

    !GM_NbErr = !GM_NbErr + !NbErr

    !Title = "-FINISHED PROCEDURE: lcal1com."
    @Message( "DCL" , "date" , !ExpName , !Phase , !Title , *!S )
Return
End Procedure
-------------------------------------------------------------------------------< 
Procedure lcal2com ( )
--.
--.  This procedure file performs the commissioning for the 
--.  Calibration/Focus Motor 2 (CAL2)
--.
Var
    Str( 3)     !ExpName   = "MDI"
    Str(10)     !Phase     = " "
    Str(49)     !Title     = " "
    Str(80)     !S         = &80s("")
    Int         !NbErr     = 0
    Int         !Get_int   = 0

Main
    !Title = "-EXECUTING PROCEDURE: lcal2com."
    @Message( "DCL" , "date" , !ExpName , !Phase , !Title , *!S )

    !Title = "~Set CAL2 to position 53; CW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC2SP" , "53" )
    @SendCommand ( "MBC2CW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC2POS" , ">= 52 and <= 53" , *!NbErr )

    !Title = "~Set CAL2 to position 89; CW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC2SP" , "89" )
    @SendCommand ( "MBC2CW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC2POS" , ">= 88 and <= 89" , *!NbErr )

    !Title = "~Set CAL2 to position 125; CW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC2SP" , "125" )
    @SendCommand ( "MBC2CW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC2POS" , ">= 124 and <= 127" , *!NbErr )

    !Title = "~Set CAL2 to position 17; CW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC2SP" , "17" )
    @SendCommand ( "MBC2CW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC2POS" , ">= 16 and <= 18" , *!NbErr )

    !Title = "~Set CAL2 to position 125; CCW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC2SP" , "125" )
    @SendCommand ( "MBC2CCW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC2POS" , ">= 124 and <= 125" , *!NbErr )

    !Title = "~Set CAL2 to position 89; CCW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC2SP" , "89" )
    @SendCommand ( "MBC2CCW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC2POS" , ">= 88 and <= 89" , *!NbErr )

    !Title = "~Set CAL2 to position 53; CCW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC2SP" , "53" )
    @SendCommand ( "MBC2CCW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC2POS" , ">= 52 and <= 53" , *!NbErr )

    !Title = "~Set CAL2 to position 17; CCW move." 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBC2SP" , "17" )
    @SendCommand ( "MBC2CCW" , "" )
    @WaitTime    ( "00h00m45s" , *!S )

    @CheckReg( "MKC2POS" , ">= 16 and <= 17" , *!NbErr )

    !GM_NbErr = !GM_NbErr + !NbErr

    !Title = "-FINISHED PROCEDURE: lcal2com."
    @Message( "DCL" , "date" , !ExpName , !Phase , !Title , *!S )
Return
End Procedure
-------------------------------------------------------------------------------< 
Procedure PrintCF( str(3) !ExpName, str(8) !Print)
--. Print the control file log file if required by !Print ;
--.  - using the 'Spool' statement if the variable !GZ_Spool is TRUE,
--.  - using the dialog box window if the variable !GZ_Spool is FALSE.
--. 
  Var
    str(80) !S = &80s("")

  Main
    If !Print = "yes" Then
     If !GZ_Spool = TRUE  Then
        Spool CF
     Else   
        Cflog
        @Message( "DC", "date", !ExpName, " ", \
                  "++++Print the CFLog, then type CONT+++", *!S)
        Halt
        @Message( "DC", "date", !ExpName, " ", \
                  "+Operator continue.", *!S)
     End If
    End If
  Return
End Procedure
-----------------------------------------------------------------------