--+----------------------------------------------------------------------------+
--+                        SOHO Project -- Control File
--+                        ----------------------------
--+
--+ Name        : MDI_DIST , !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      : Alan TURK
--+----------------------------------------------------------------------------+
--+ 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/01   289     10:19  03/02/94  A.J. TURK -- Conversion from MDI language.
--+   1/02   360     14:45  21/04/94  Ed COBB       -- Rationalization.
--+   1/03   393     09:40  20/05/94  Ed COBB       -- MDI Updates.
--+   1/04   406     13:07  24/05/94  Ed COBB       -- MDI Updates
--+   1/07   443     15:22  17/06/94  Ed COBB       -- Cf Errors.
--+   1/08   489     15:59  12/10/94  Ph. IATRINO   -- 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

    Int         !GM_I0
    Int         !GM_I9

End Common
-------------------------------------------------------------------------------<
Extern
    Cfile       MDI_MODE , MDI_LLT , MDI_FD , PLM_BLOCK , MDI_LIP
    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_DIST , 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()

--    !GM_I0 = 16000   -- Put in comment for the LASER Test (Part of the SPT).
--    !GM_I9 = 15      -- Put in comment for the LASER Test (Part of the SPT).

    Select !Proc_s
    Case "mdimrot"
        @mdimrot()

    Case "mdiprot"
        @mdiprot()

    Case "mdipdist"
        @mdipdist()

    Case "m1rotser"
        @m1rotser()

    Case "m2rotser"
        @m2rotser()

    Case "protser"
        @protser()

    Case "fdprot"
        @fdprot()

    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 mdimrot ( )
--.
--.       Cycles MTM's individually for image motion
--.
Var
    Str( 3)     !ExpName   = "MDI"
    Str(10)     !Phase     = " "
    Str(49)     !Title     = " "
    Str(80)     !S         = &80s("")
    Int         !NbErr     = 0
    Str(80)     !Question  = ""
    Str(80)     !Check     = ""
    Str(80)     !resp_s    = ""

    Int         !RI        = 0
    Int         !LM_I8     = 0
    Int         !LM_I9     = 0

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

    @SendCommand ( "MBCMSUMM" , "1 , 1" )
    @SendCommand ( "MBIPLBIC" , "4 , 4" )

    If !GM_Conf = 2 Then
       
        PERFORM/NO MDI_LIP , "liptlm2" , "no"

    End If

    @WaitTime ("00h00m15s",*!S) 

    @SendCommand ( "MBCMHDR1" , "0X4040 , 0X4040 , 0 , 1 , 0" )

    !Title = "~Taking central 256x256 in HR OBS mode" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBCMBADC" , "3" )
    !Title = "~CCD amplifier B, offset: 3" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    !Title = "Exposure time (ticks) = " + &d( !GM_I0 )
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    !Title = "Wait time (seconds) = " + &d( !GM_I9 )
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    PERFORM/NO  MDI_MODE , "lobsmode" , "no"

    !LM_I9 = 15 
    !Question =  "No. of MTM cycles (0=15)?" 
    @AskInt ( !Question , ">=0 and <=99" , *!RI , *!S , *!NbErr )

    If !RI > 0 Then 
        !LM_I9 = !RI 
    End If

    !Question =  "MDI Open Decom File(Y)"
    !Check = "in Y, y"
    @AskStr ( !Question , !Check , *!Resp_s , *!S , *!NbErr )

    !Title = "~Cycling MTM 1 (10 steps per rev) started"
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    For !LM_I8 = 1 to !LM_I9
 
        @m1rotser()                            --    Series of MTM1 motion

        !Title = "End of MTM1 repetition No. " + &d( !LM_I8 )
        @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    End For

    !Title = "~Cycling MTM 2 (10 steps per rev) started"
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    For !LM_I8 = 1 to !LM_I9
 
        @m2rotser()                            --    Series of MTM2 motion

        !Title = "End of MTM2 repetition No. " + &d( !LM_I8 )
        @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    End For

    !Title = " Soft DARK" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBCMDRKR" , "0 , " + &d( !GM_I0 ) +" , " + &d( !GM_I0 ) )
    @WaitTime    ( "00h00m15s" , *!S )

    !Question =  "MDI Close Decom File(Y)"
    !Check = "in Y, y"
    @AskStr ( !Question , !Check , *!Resp_s , *!S , *!NbErr )

    !GM_NbErr = !GM_NbErr + !NbErr

    !Title = "-FINISHED PROCEDURE: mdimrot."
    @Message( "DCL" , "date" , !ExpName , !Phase , !Title , *!S )
Return
End Procedure
-------------------------------------------------------------------------------< 
Procedure mdiprot ( )
--.
--.       Cycles PAW wheel for image motion
--.
Var
    Str( 3)     !ExpName   = "MDI"
    Str(10)     !Phase     = " "
    Str(49)     !Title     = " "
    Str(80)     !S         = &80s("")
    Int         !NbErr     = 0
    Str(80)     !Question  = ""
    Str(80)     !Check     = ""

    Int         !RI        = 0
    Int         !LM_I0     = 0
    Int         !LM_I1     = 0
    Int         !LM_I8     = 0
    Int         !LM_I9     = 0
    Str(80)     !RS        = ""
    Str(80)     !LM_S0     = ""

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

    @SendCommand ( "MBCMSUMM" , "1 , 1" )
    @SendCommand ( "MBIPLBIC" , "4 , 4" )

    If !GM_Conf = 2 Then
       
        PERFORM/NO MDI_LIP , "liptlm2" , "no"

    End If

    @WaitTime ("00h00m15s",*!S)
 
    @SendCommand ( "MBCMHDR1" , "0X4040 , 0X4040 , 0 , 1 , 0" )

    !Title = "~Central 256x256 in HR OBS mode" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBCMAADC" , "3" )

    !Title = "~CCD amplifier A, offset: 3" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    !Title = "Exposure time (ticks) = " + &d( !GM_I0 )
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    !Title = "Wait time (seconds) = " + &d( !GM_I9 )
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    !LM_I9 = 15 
    !Question =  "No. of PAW cycles (0=15)?" 
    @AskInt ( !Question , ">=0 and <=99" , *!RI , *!S , *!NbErr )

    If !RI > 0 Then 
        !LM_I9 = !RI 
    End If

    PERFORM/NO  MDI_MODE , "lobsmode" , "no"

    @SendCommand ( "MBLTOPNL" , "" )

    !Question =  "MDI Open Decom File(Y)"
    !Check = "in Y, y"
    @AskStr ( !Question , !Check , *!RS , *!S , *!NbErr )

    !LM_S0 = "OPEN" 
    !Title = "~Cycling PAW 18, 54, 90, 125 " + &d( !LM_I9 ) + " times"
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    For !LM_I8 = 1 to !LM_I9
        @protser()                         --  Cycles the PAW
        !Title = "End of repetition No. " + &d( !LM_I8 ) 
        @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    End For

    !Title = "~Soft DARK" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBCMDRKR" , "0 , " + &d( !GM_I0 ) +" , " + &d( !GM_I0 ) )
    @WaitTime    ( "00h00m08s" , *!S )

    !Question =  "Repeat with ISS locked?(Y/N)"
    !Check = "in Y, N, y, n"
    @AskStr ( !Question , !Check , *!RS , *!S , *!NbErr )
    @Upper( !RS , *!RS )

    If !RS = "Y" Then
        @SendCommand ( "MBLTCLSL" , "" )
        !LM_S0 = "CLOSED" 
        @WaitTime    ( "00h00m45s" , *!S )

        PERFORM/NO  MDI_LLT , "lltprn1" , "no"

        !Title = "~Cycling PAW 18, 54, 90, 125 " + &d( !LM_I9 ) + " times"
        @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

        For !LM_I8 = 1 to !LM_I9
            @protser()                         --  Cycles the PAW
            !Title = "End of repetition No. " + &d( !LM_I8 ) 
            @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
        End For

        !Title = "~Soft DARK" 
        @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

        @SendCommand ( "MBCMDRKR" , "0 , " + &d( !GM_I0 ) +" , " + &d( !GM_I0 ) )
        @WaitTime    ( "00h00m08s" , *!S )
    End If

    !Question =  "MDI Close Decom File(Y)"
    !Check = "in Y, y"
    @AskStr ( !Question , !Check , *!RS , *!S , *!NbErr )

    !GM_NbErr = !GM_NbErr + !NbErr

    !Title = "-FINISHED PROCEDURE: mdiprot." 
    @Message( "DCL" , "date" , !ExpName , !Phase , !Title , *!S )
Return
End Procedure
-------------------------------------------------------------------------------< 
Procedure mdipdist ( )
--.
--.       Cycles the PAW wheel for distortion analysis
--.
Var
    Str( 3)     !ExpName   = "MDI"
    Str(10)     !Phase     = " "
    Str(49)     !Title     = " "
    Str(80)     !S         = &80s("")
    Int         !NbErr     = 0
    Str(80)     !Question  = ""
    Str(80)     !Check     = ""
    Str(80)     !Resp_s     = ""

    Int         !RI        = 0
    Int         !LM_I8     = 0
    Int         !LM_I9     = 0

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

    @SendCommand ( "MBCMSUMM" , "1 , 1" )
    @SendCommand ( "MBIPLBIC" , "3 , 3" )

    If !GM_Conf = 2 Then
       
        PERFORM/NO MDI_LIP , "liptlm2" , "no"

    End If

    @WaitTime ("00h00m15s",*!S) 

    @SendCommand ( "MBCMHDR1" , "0X4040 , 0X4040 , 0 , 1 , 0" )

    !Title = "~Full 1024x1024 in FD OBS Mode" 
    @Message( "DCL" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBCMAADC" , "3" )

    !Title = "~CCD amplifier A, offset: 3" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    !GM_I9 = 150

    !Title = "Exposure time (ticks) = " + &d( !GM_I0 )
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    !Title = "Wait time (seconds) = " + &d( !GM_I9 )
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    !LM_I9 = 5 
    !Question =  "No. of PAW cycle (0=5)" 
    @AskInt ( !Question , ">=0 and <=99" , *!RI , *!S , *!NbErr )

    If !RI > 0 Then
        !LM_I9 = !RI 
    End If

    PERFORM/NO  MDI_MODE , "lobsmode" , "no"

    !Question =  "MDI Open Decom File(Y)"
    !Check = "in Y, y"
    @AskStr ( !Question , !Check , *!Resp_s , *!S , *!NbErr )

    !Title = "~Cycling PAW 18, 54, 90, 125 " + &d( !LM_I9 ) + " times"
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBLTOPNL" , "" )

    !Title = "ISS OPEN loop" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    !Title = "Cycling PAW " 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    For !LM_I8 = 1 to !LM_I9
 
        @fdprot()

        !Title = "End of repetition No. " + &d( !LM_I8 ) 
        @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    End For

    !Title = "~Soft DARK" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )

    @SendCommand ( "MBCMDRKR" , "0 , " + &d( !GM_I0 ) + " , " + &d( !GM_I0 ))
    @WaitTime    ( "00h02m00s" , *!S )

    !Question =  "MDI Close Decom File(Y)"
    !Check = "in Y, y"
    @AskStr ( !Question , !Check , *!Resp_s , *!S , *!NbErr )

    !GM_NbErr = !GM_NbErr + !NbErr

    !Title =  "-FINISHED PROCEDURE: mdipdist." 
    @Message( "DCL" , "date" , !ExpName , !Phase , !Title , *!S )
Return
End Procedure
-------------------------------------------------------------------------------< 
Procedure m1rotser ( )
--.
--.       This procedure takes series of MTM1 motion
--.
Var
    Str( 3)     !ExpName   = "MDI"
    Str(10)     !Phase     = " "
    Str(49)     !Title     = " "
    Str(80)     !S         = &80s("")
    Str(10)     !Time      = " "
    Int         !NbErr     = 0

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

    @varcmd      ( "MBDPCONF" , "163 , 53" )
    @WaitTime    ( "00h00m01s" , *!S )
    @SendCommand ( "MBCMTP3R" , "163 , 53 , " + &d( !GM_I0 ) )
    @Time_To_Text( !GM_I9 , *!Time )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "1" )
    @SendCommand ( "MBCMTP3R" , "1 , 53 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "19" )
    @SendCommand ( "MBCMTP3R" , "19 , 53 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "37" )
    @SendCommand ( "MBCMTP3R" , "37 , 53 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "55" )
    @SendCommand ( "MBCMTP3R" , "55 , 53 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "73" )
    @SendCommand ( "MBCMTP3R" , "73 , 53 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "91" )
    @SendCommand ( "MBCMTP3R" , "91 , 53 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "109" )
    @SendCommand ( "MBCMTP3R" , "109 , 53 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "127" )
    @SendCommand ( "MBCMTP3R" , "127 , 53 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "145" )
    @SendCommand ( "MBCMTP3R" , "145 , 53 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    !GM_NbErr = !GM_NbErr + !NbErr

    !Title = "-FINISHED PROCEDURE:  m1rotser."
    @Message( "DCL" , "date" , !ExpName , !Phase , !Title , *!S )
Return
End Procedure
-------------------------------------------------------------------------------< 
Procedure m2rotser ( )
--.
--.       This procedure takes series of MTM2 motion
--.
Var
    Str( 3)     !ExpName   = "MDI"
    Str(10)     !Phase     = " "
    Str(49)     !Title     = " "
    Str(80)     !S         = &80s("")
    Str(10)     !Time      = " "
    Int         !NbErr     = 0

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

    @varcmd      ( "MBDPCONF" , "163 , 53" )
    @WaitTime    ( "00h00m01s" , *!S )
    @SendCommand ( "MBCMTP3R" , "163 , 53 , " + &d( !GM_I0 ) )
    @Time_To_Text( !GM_I9 , *!Time )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "0xFFFF , 71" )
    @SendCommand ( "MBCMTP3R" , "163 , 71 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "0xFFFF , 89" )
    @SendCommand ( "MBCMTP3R" , "163 , 89 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "0xFFFF , 107" )
    @SendCommand ( "MBCMTP3R" , "163 , 107 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "0xFFFF , 125" )
    @SendCommand ( "MBCMTP3R" , "163 , 125 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "0xFFFF , 143" )
    @SendCommand ( "MBCMTP3R" , "163 , 143 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "0xFFFF , 161" )
    @SendCommand ( "MBCMTP3R" , "163 , 161 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "0xFFFF , 179" )
    @SendCommand ( "MBCMTP3R" , "163 , 179 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "0xFFFF , 17" )
    @SendCommand ( "MBCMTP3R" , "163 , 17 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    @varcmd      ( "MBDPCONF" , "0xFFFF , 35" )
    @SendCommand ( "MBCMTP3R" , "163 , 35 , " + &d( !GM_I0 ) )
    @WaitTime    ( !Time , *!S )

    !GM_NbErr = !GM_NbErr + !NbErr

    !Title = "-FINISHED PROCEDURE:  m2rotser."
    @Message( "DCL" , "date" , !ExpName , !Phase , !Title , *!S )
Return
End Procedure
-------------------------------------------------------------------------------< 
Procedure protser ( )
--.
--.     Cycles the PAW
--.
Var
    Str( 3)     !ExpName   = "MDI"
    Str(10)     !Phase     = " "
    Str(49)     !Title     = " "
    Str(80)     !S         = &80s("")
    Str(10)     !Time      = " "
    Int         !NbErr     = 0
    Str(10)     !Question  = " "

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

    !Title = "Paw to 17 (LCP)"
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    @varcmd      ( "MBDPCONF" , "0XFFFF , 0XFFFF , 17" )
    @SendCommand ( "MBCMTP3R" , "0 , 17 ," +&d(!GM_I0))
    @Time_To_Text( !GM_I9 , *!Time )
    @WaitTime    ( !Time , *!S )

    !Title = "Paw to 53 (RCP)"
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    @varcmd      ( "MBDPCONF" , "0XFFFF , 0XFFFF , 53" )
    @SendCommand ( "MBCMTP3R" , "0 , 53 ," +&d(!GM_I0))
    @WaitTime    ( !Time , *!S )

    !Title = "Paw to 89 (s-wave)"
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    @varcmd      ( "MBDPCONF" , "0XFFFF , 0XFFFF , 89" )
    @SendCommand ( "MBCMTP3R" , "0 , 89 ," +&d(!GM_I0))
    @WaitTime    ( !Time , *!S )

    !Title = "Paw to 125 (p-wave)"
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    @varcmd      ( "MBDPCONF" , "0XFFFF , 0XFFFF , 125" )
    @SendCommand ( "MBCMTP3R" , "0 , 125 ," +&d(!GM_I0))
    @WaitTime    ( !Time , *!S )

    !GM_NbErr = !GM_NbErr + !NbErr

    !Title = "-FINISHED PROCEDURE:  protser."
    @Message( "DCL" , "date" , !ExpName , !Phase , !Title , *!S )
Return
End Procedure
-------------------------------------------------------------------------------< 
Procedure fdprot ( )
--.
--.	Cycles the PAW & takes FD pictures
--.
Var
    Str( 3)     !ExpName   = "MDI"
    Str(10)     !Phase     = " "
    Str(49)     !Title     = " "
    Str(80)     !S         = &80s("")
    Int         !NbErr     = 0
    Str(10)     !Time      = " "

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

    !Title = "~PAW to 17 (LCP)" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    @varcmd      ( "MBDPCONF" , "0XFFFF , 0XFFFF , 17" )
    @SendCommand ( "MBCMTP1R" , "0 , 17 , " + &d(!GM_I0) )
    @Time_To_Text( !GM_I9 , *!Time )
    @WaitTime    ( !Time , *!S )

    !Title = "~PAW to 53 (RCP)" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    @varcmd      ( "MBDPCONF" , "0XFFFF , 0XFFFF , 53" )
    @SendCommand ( "MBCMTP1R" , "0 , 53 , " + &d(!GM_I0) )
    @WaitTime    ( !Time , *!S )

    !Title = "~PAW to 89 (s-wave)" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    @varcmd      ( "MBDPCONF" , "0XFFFF , 0XFFFF , 89" )
    @SendCommand ( "MBCMTP1R" , "0 , 89 , " + &d(!GM_I0) )
    @WaitTime    ( !Time , *!S )

    !Title = "~PAW to 125 (p-wave)" 
    @Message( "DC" , "time" , !ExpName , !Phase , !Title , *!S )
    @varcmd      ( "MBDPCONF" , "0XFFFF , 0XFFFF , 125" )
    @SendCommand ( "MBCMTP1R" , "0 , 125 , " + &d(!GM_I0) )
    @WaitTime    ( !Time , *!S )

    !GM_NbErr = !GM_NbErr + !NbErr

    !Title = "-FINISHED PROCEDURE: fdprot."
    @Message( "DCL" , "date" , !ExpName , !Phase , !Title , *!S )
Return
End Procedure
-------------------------------------------------------------------------------< 
Procedure varcmd( Str(10) !Cmd_name , Str(80) !Cmd_data )
Var
    Str(1)    !Expt_s
    Int       !Code_i
    Int       !Cmd_data_i(30)
    Int       !No_of_cmds_i
    Int       !Data_len_i
    Str(10)   !Data_item_s
    Int       !Commas_i
    Int       !Count
    Int       !Char_pos 
    Str(1)    !Char
    Str(49)   !Title     = " "
    Str(80)   !Cmd_data_s
    Str(80)   !S = &80s("")
Main
    !Expt_s = Extract( !Cmd_name , 1 , 1 )
    If !Expt_s <> "M" Then
        !Title = "*ERROR: Non-MDI Command " + !Cmd_name
        @Message( "DC", "time", "MDI", " ", !Title , *!S)
--        Beep
        Halt
        !Title = "+Operator CONTinue "
        @Message( "DC", "time", "MDI", " ", !Title , *!S)
        Return
    End If

    Select !Cmd_name
    Case "MBIPCMD"
        !Code_i = 0x0E
        !No_of_cmds_i = 0

    Case "MBIPLDIN"
        !Code_i = 0x12
        !No_of_cmds_i = 1
        !Cmd_data_i(0) = 4

    Case "MBDPML"
        !Code_i = 0x0A
        !No_of_cmds_i = 0

    Case "MBDPCONF"
        !Code_i = 0x1D
        !No_of_cmds_i = 0

    Default
        !Title = "*ERROR: Unrecognised Command " + !Cmd_name
        @Message( "DC", "time", "MDI", " ", !Title , *!S)
--        Beep
        Halt
        !Title = "+Operator CONTinue "
        @Message( "DC", "time", "MDI", " ", !Title , *!S)
        Return
    End Select

    !Cmd_data_s = !Cmd_data + ","
    !Data_len_i = Len( !Cmd_data_s )
    !Commas_i = 0

    For !Char_pos = 1 to !Data_len_i
        !Char = Extract( !Cmd_data_s , !Char_pos , 1 )
        If !Char = "," Then
            !Commas_i = !Commas_i + 1
        End If
    End For

    For !Count = 1 To !Commas_i
        !Data_item_s = Splitstr( !Cmd_data_s , "," , !Count )
        !Cmd_data_i( !No_of_cmds_i ) = Int( Val( !Data_item_s ) )
        !No_of_cmds_i = !No_of_cmds_i + 1
    End For

    PERFORM/NO  PLM_BLOCK , "MDI" , !Code_i , !Cmd_data_i() , !No_of_cmds_i

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
-----------------------------------------------------------------------
Procedure Time_To_Text (Int !Stime, Str(10) *!Text)
--. Convert a time passed in seconds to a string as "hh:mn:ss".
--. The number of hours is limited to 999 with no error reported.
  Var
     Int         !hour   = 0
     Int         !minute = 0
     Int         !second = 0
 
  Main 
    CALL Hh_mn_ss(!Stime, *!hour, *!minute, *!second)
    !Text = &02d(!hour) + "h" + &02d(!minute)+ "m"+ &02d(!second) +"s"
  Return
End Procedure
-------------------------------------------------------------------------------------
Procedure Hh_mn_ss(Int !STime, Int *!hour, Int *!minute, Int *!second)
--. Compute and return the number of hour, minute and second from an interger number
--. of seconds.
  Var
     Int     !Tmp

  Main
     !Tmp    = !STime
     !hour   = !Tmp / 3600
     !Tmp    = !Tmp Mod 3600
     !minute = !Tmp / 60
     !second = !Tmp Mod 60
  Return
End Procedure
-------------------------------------------------------------------------------------