# File: mag30.src
#
program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/eof/src/mag30.src"
descr "mag30 - load magnetogram program"
#
# DSBQUE                ; Disable Queue
tcblock mbipldin 0x0154 
#
#=======================================================
#
#
#; IP program to construct a magnetogram.
#; The program assumes that the camera frames have
#; been accumulated as shown;
#;    Sa (RCP) - Page 0     Sa (LCP) - Page 4
#;    Sc (RCP) - Page 1     Sc (LCP) - Page 6
#;
#; The mag30 observation accumulates raw camera data as 
#; shown above.
#;
#; Successive Magnetograms are saved in pages 11, 15, 17, 18 and 1
#;
#; Algorithm:
#;
#;  STEP 1:
#;     7:             Make LCP Velocity
#;     8:             Make RCP Velocity
#;
#;  STEP 2:           EXTRACT a (LCP) sub-image to provide 
#;                    integral shift w.r.t. RCP Velocity image
#;
#;  STEP 3:
#;     1: (CallBack)  Align LCP-V
#;                    Align RCP-V
#;     2: (CallBack)  SUM LCP-V and RCP-V
#;                    Add result to Accumulator
#;                    If Accumulation Completed, 
#;                        Do Setup for next MAG 
#;
#;  STEP 4:           For Hi-Res apply FD Cropping
#;
#;----------------------------------------------------------------
#;
#;
#DOMAG30:
#;
#    GOTOREG   R3016
tcblock mbipcmd 0x0091 0x0900   0x0158 0x0BC8 
#    CALLQUE   &INITMAG
tcblock mbipcmd 0x0091 0x0902   0x01F8 0x09FA 
#    SETREG    R3016  &MAGVECT
tcblock mbipcmd 0x0091 0x0904   0x0140 0x0BC8 0x0907 
#;
#MAGVECT:
#    BRANCHEQ  R3072  0x0007  &L_VEL
tcblock mbipcmd 0x0091 0x0907   0x01AE 0x0C00 0x0007 0x0910 
#    BRANCHEQ  R3072  0x0008  &R_VEL
tcblock mbipcmd 0x0091 0x090B   0x01AE 0x0C00 0x0008 0x0913 
#    END
tcblock mbipcmd 0x0091 0x090F   0x01FC 
#
#;
#;.......................................................
#;
#L_VEL:
#   _VLCTY     $IPRL_MAG_LVEL
tcblock mbipcmd 0x0091 0x0910   0x817C 0x04F5 
#    END
tcblock mbipcmd 0x0091 0x0912   0x01FC 
#;
#;.......................................................
#;
#R_VEL:
#   _VLCTY     $IPRL_MAG_RVEL
tcblock mbipcmd 0x0091 0x0913   0x817C 0x04FD 
#    HRDINIT   $IPRL_MAG_HDR
tcblock mbipcmd 0x0091 0x0915   0x019C 0x053E 
#;  
#;.......................................................
#; Align Velocities
#;
#ALIGN_VEL:
#    COPYREG    R96  $IPRL_MAG_VPIXALGN
tcblock mbipcmd 0x0091 0x0917   0x0142 0x0060 0x0505 
#    COPYREG    R97  $IPRL_MAG_VPIXALGN+1
tcblock mbipcmd 0x0091 0x091A   0x0142 0x0061 0x0506 
#    _EXTRACT    $IPRL_MAG_VPIXALGN        ; Effect integral pixel
tcblock mbipcmd 0x0091 0x091D   0x817A 0x0505 
#                                          ;_extracting L_Vel with
#;
#    COPYREG    R98  $IPRL_MAG_XALGN_RV+5
tcblock mbipcmd 0x0091 0x091F   0x0142 0x0062 0x0512 
#    COPYREG    R99  $IPRL_MAG_YALGN_RV+5
tcblock mbipcmd 0x0091 0x0922   0x0142 0x0063 0x051A 
#    REGNEG     $IPRL_MAG_XALGN_RV+5   $IPRL_MAG_XALGN_RV+5  $IPRL
tcblock mbipcmd 0x0091 0x0925   0x4146 0x0512 0x0512 0x0522 
#    REGNEG     $IPRL_MAG_YALGN_RV+5   $IPRL_MAG_XALGN_RV+5  $IPRL
tcblock mbipcmd 0x0091 0x0929   0x4146 0x051A 0x0512 0x052A 
#
#   _XALIGN     $IPRL_MAG_XALGN_RV         ; Fractional Pixel Alig
tcblock mbipcmd 0x0091 0x092D   0x81DA 0x050D 
#;
#    COPYRD2D   $IPRL_MAG_YALGN_RV     $IPRL_MAG_ALGNWRK     $#IPR
tcblock mbipcmd 0x0091 0x092F   0x0144 0x0515 0x0572 0x0008 
#    YALIGN     $IPRL_MAG_ALGNWRK
tcblock mbipcmd 0x0091 0x0933   0x01DC 0x0572 
#    YALIGN     $IPRL_MAG_ALGNWRK
tcblock mbipcmd 0x0091 0x0935   0x01DC 0x0572 
#    YALIGN     $IPRL_MAG_ALGNWRK
tcblock mbipcmd 0x0091 0x0937   0x01DC 0x0572 
#    YALIGN     $IPRL_MAG_ALGNWRK
tcblock mbipcmd 0x0091 0x0939   0x01DC 0x0572 
#;
#   _XALIGN     $IPRL_MAG_XALGN_LV
tcblock mbipcmd 0x0091 0x093B   0x81DA 0x051D 
#;
#    COPYRD2D   $IPRL_MAG_YALGN_LV     $IPRL_MAG_ALGNWRK     $#IPR
tcblock mbipcmd 0x0091 0x093D   0x0144 0x0525 0x0572 0x0008 
#    YALIGN     $IPRL_MAG_ALGNWRK
tcblock mbipcmd 0x0091 0x0941   0x01DC 0x0572 
#    YALIGN     $IPRL_MAG_ALGNWRK
tcblock mbipcmd 0x0091 0x0943   0x01DC 0x0572 
#    YALIGN     $IPRL_MAG_ALGNWRK
tcblock mbipcmd 0x0091 0x0945   0x01DC 0x0572 
#    YALIGN     $IPRL_MAG_ALGNWRK
tcblock mbipcmd 0x0091 0x0947   0x01DC 0x0572 
#;
#;
#;.......................................................
#; Accumulate Magnetogram
#;
#PROC_MAG:
#   _SCALESUM    $IPRL_MAG_GENMAG            ; newMAG = RCP_VEL - 
tcblock mbipcmd 0x0091 0x0949   0x81E0 0x052D 
#;
#    BRANCHNE    $IPRF_STR_CF  0  &MAG160KDL ; Campaign Mode
tcblock mbipcmd 0x0091 0x094B   0x01B0 0x05A9 0x0000 0x0955 
#    BRANCHIF    $IPRL_STR_VC     &ACCMAG    ; No 160K-> Accumulat
tcblock mbipcmd 0x0091 0x094F   0x015A 0x0546 0x09A9 
#    BRANCHIF    $IPRL_STR_MAGHR  &MAG5KDL   ; 160k d/l disabled -
tcblock mbipcmd 0x0091 0x0952   0x015A 0x0547 0x0978 
#;
#; High Rate Downlink
#MAG160KDL:
#    SETREGS     R512                6       18:0x00001  0x4000 0x
tcblock mbipcmd 0x0091 0x0955   0x01B2 0x0200 0x0006 0x0001 \
                                0x9000 0x4000 0x00E5 0x0000 \
                                0xFF28 
#    COPYREG     $IPRL_MAG_HDR+4     R516
tcblock mbipcmd 0x0091 0x095E   0x0142 0x0542 0x0204 
#    HRDINIT     R512
tcblock mbipcmd 0x0091 0x0961   0x019C 0x0200 
#    SETREGS     $IPRL_MAG_MVDL      6  5:0x00000  8:0x00226  0x10
tcblock mbipcmd 0x0091 0x0963   0x01B2 0x0538 0x0006 0x0000 \
                                0x2800 0x0226 0x4000 0x0000 \
                                0x0010 
#    MOVBLKI     $IPRL_MAG_MVDL
tcblock mbipcmd 0x0091 0x096C   0x0166 0x0538 
#    SETREGS     R518  2  0x100000L
tcblock mbipcmd 0x0091 0x096E   0x01B2 0x0206 0x0002 0x0000 \
                                0x0010 
#    START1HR    0x01  0x4000  R518  
tcblock mbipcmd 0x0091 0x0973   0x0174 0x0001 0x4000 0x0206 
#    END
tcblock mbipcmd 0x0091 0x0977   0x01FC 
#;
#;
#MAG5KDL:
#;
#; Accumulate Magnetogram for downlink in the 5K channel. In this 
#; magnetogram is always accumulated in page 19. The cadence must 
#; be greater than ~20 minutes. The "Dynamics" mode should not be 
#; when less than 20 minutes of 160K channel time is remaining. 
#;
#    GOTOREG     $IPRP_MAG_5KEP
tcblock mbipcmd 0x0091 0x0978   0x0158 0x057A 
#;
#CLR5KBF:
#    FILLBLK     19:0x00000         0x120000L     0
tcblock mbipcmd 0x0091 0x097A   0x016C 0x0000 0x9800 0x0000 \
                                0x0012 0x0000 
#    SETREG      $IPRP_MAG_5KEP     &DO_M5K
tcblock mbipcmd 0x0091 0x0980   0x0140 0x057A 0x0983 
#;
#DO_M5K:
#    SETREG      $IPRL_MAG_SUMMAG+5 0x9800
tcblock mbipcmd 0x0091 0x0983   0x0140 0x054D 0x9800 
#    SETREG      $IPRL_MAG_CPYMAG+1 0x9800
tcblock mbipcmd 0x0091 0x0986   0x0140 0x0554 0x9800 
#   _MOVBLKI     $IPRL_MAG_CPYMAG 
tcblock mbipcmd 0x0091 0x0989   0x8166 0x0553 
#   _SCALESUM    $IPRL_MAG_SUMMAG
tcblock mbipcmd 0x0091 0x098B   0x81E0 0x0548 
#    BRANCHGT    $IPRL_STR_COUNT    1             &MAGEXIT
tcblock mbipcmd 0x0091 0x098D   0x01BA 0x0544 0x0001 0x09F9 
#;
#    SETREGS     $IPRL_MAG_LRDPRM     9  0 0 0  300 19:0x00226 819
tcblock mbipcmd 0x0091 0x0991   0x01B2 0x0562 0x0009 0x0000 \
                                0x0000 0x0000 0x012C 0x0226 \
                                0x9800 0x2000 0x000E 0x0005 
#    SETREGS     $IPRL_MAG_LRDPRM+9   5  4000 0xBFFF 0xFFB8 0 0x00
tcblock mbipcmd 0x0091 0x099D   0x01B2 0x056B 0x0005 0x0FA0 \
                                0xBFFF 0xFFB8 0x0000 0x0010 
#    SETREG      $IPRP_MAG_5KEP       &CLR5KBF
tcblock mbipcmd 0x0091 0x09A5   0x0140 0x057A 0x097A 
#    END
tcblock mbipcmd 0x0091 0x09A8   0x01FC 
#;
#ACCMAG:
#;
#; Accumulate magnetograms for later downlink via the 160k channel
#; in VC2 mode (Delivered to GSFC). In this mode, each accumulatio
#; directed to a different page. Pages 15, 18, and 19 have been se
#; these magnetograms. 
#;
#    COPYREG     $IPRP_MAG_ACCPAG   $IPRL_MAG_SUMMAG+5
tcblock mbipcmd 0x0091 0x09A9   0x0142 0x05A1 0x054D 
#    COPYREG     $IPRP_MAG_ACCPAG   $IPRL_MAG_CPYMAG+1
tcblock mbipcmd 0x0091 0x09AC   0x0142 0x05A1 0x0554 
#;
#   _MOVBLKI     $IPRL_MAG_CPYMAG 
tcblock mbipcmd 0x0091 0x09AF   0x8166 0x0553 
#   _SCALESUM    $IPRL_MAG_SUMMAG
tcblock mbipcmd 0x0091 0x09B1   0x81E0 0x0548 
#;
#    BRANCHGT    $IPRL_STR_COUNT    1  &MAGEXIT
tcblock mbipcmd 0x0091 0x09B3   0x01BA 0x0544 0x0001 0x09F9 
#;
#; Copy the header for the completed magnetogram to the accumulati
#; The header is always created at 18:0x00000. 
#    BRANCHEQ    $IPRP_MAG_ACCPAG   0x9000   &SKIPHCP   ;If acc da
tcblock mbipcmd 0x0091 0x09B7   0x01AE 0x05A1 0x9000 0x09C0 
#    COPYREG     $IPRP_MAG_ACCPAG   $IPRL_MAG_CPYHDR+3  ;Set heade
tcblock mbipcmd 0x0091 0x09BB   0x0142 0x05A1 0x05A5 
#   _MOVBLKI     $IPRL_MAG_CPYHDR                       ;Copy Head
tcblock mbipcmd 0x0091 0x09BE   0x8166 0x05A2 
#;
#SKIPHCP:
#    GOTOREG     $IPRP_MAG_NEWPAG                       ;Jump to n
tcblock mbipcmd 0x0091 0x09C0   0x0158 0x05A0 
#;
#PAGE1:
#    COPYREG     $IPRP_MAG_ACCPAG   $IPRL_MAG_DONE1 
tcblock mbipcmd 0x0091 0x09C2   0x0142 0x05A1 0x058C 
#    SETREG      $IPRP_MAG_ACCPAG   0x6800
tcblock mbipcmd 0x0091 0x09C5   0x0140 0x05A1 0x6800 
#    SETREG      $IPRP_MAG_NEWPAG   &PAGE2
tcblock mbipcmd 0x0091 0x09C8   0x0140 0x05A0 0x09CD 
#    GOTO        &MAGEXIT
tcblock mbipcmd 0x0091 0x09CB   0x0156 0x09F9 
#;
#PAGE2:
#    COPYREG     $IPRP_MAG_ACCPAG   $IPRL_MAG_DONE1+1 
tcblock mbipcmd 0x0091 0x09CD   0x0142 0x05A1 0x058D 
#    SETREG      $IPRP_MAG_ACCPAG   0x7800
tcblock mbipcmd 0x0091 0x09D0   0x0140 0x05A1 0x7800 
#    SETREG      $IPRP_MAG_NEWPAG   &PAGE4       ; Skip P17 for no
tcblock mbipcmd 0x0091 0x09D3   0x0140 0x05A0 0x09E3 
#    GOTO        &MAGEXIT
tcblock mbipcmd 0x0091 0x09D6   0x0156 0x09F9 
#;
#PAGE3:
#    COPYREG     $IPRP_MAG_ACCPAG   $IPRL_MAG_DONE1+2 
tcblock mbipcmd 0x0091 0x09D8   0x0142 0x05A1 0x058E 
#    SETREG      $IPRP_MAG_ACCPAG   0x8800
tcblock mbipcmd 0x0091 0x09DB   0x0140 0x05A1 0x8800 
#    SETREG      $IPRP_MAG_NEWPAG   &PAGE4
tcblock mbipcmd 0x0091 0x09DE   0x0140 0x05A0 0x09E3 
#    GOTO        &MAGEXIT
tcblock mbipcmd 0x0091 0x09E1   0x0156 0x09F9 
#;
#PAGE4:
#    COPYREG     $IPRP_MAG_ACCPAG   $IPRL_MAG_DONE1+3 
tcblock mbipcmd 0x0091 0x09E3   0x0142 0x05A1 0x058F 
#    SETREG      $IPRP_MAG_ACCPAG   0x9000
tcblock mbipcmd 0x0091 0x09E6   0x0140 0x05A1 0x9000 
#    SETREG      $IPRP_MAG_NEWPAG   &PAGE5
tcblock mbipcmd 0x0091 0x09E9   0x0140 0x05A0 0x09EE 
#    GOTO        &MAGEXIT
tcblock mbipcmd 0x0091 0x09EC   0x0156 0x09F9 
#;
#PAGE5:
#    COPYREG     $IPRP_MAG_ACCPAG   $IPRL_MAG_DONE1+4 
tcblock mbipcmd 0x0091 0x09EE   0x0142 0x05A1 0x0590 
#    SETREG      $IPRP_MAG_ACCPAG   0x9800
tcblock mbipcmd 0x0091 0x09F1   0x0140 0x05A1 0x9800 
#    SETREG      $IPRP_MAG_NEWPAG   &PAGE1
tcblock mbipcmd 0x0091 0x09F4   0x0140 0x05A0 0x09C2 
#    GOTO        &MAGEXIT
tcblock mbipcmd 0x0091 0x09F7   0x0156 0x09F9 
#;
#MAGEXIT:
#    END
tcblock mbipcmd 0x0091 0x09F9   0x01FC 
#;
#;.......................................................
#; Register Lists:
#;
#INITMAG::
#;
#    SETREGS  $IPRL_MAG_LVEL  8  4:0x00514  6:0x00514  5:0x00000  
tcblock mbipcmd 0x0091 0x09FA   0x01B2 0x04F5 0x0008 0x0514 \
                                0x2000 0x0514 0x3000 0x0000 \
                                0x2800 0x0004 0x007F 
#    SETREGS  $IPRL_MAG_RVEL  8  0:0x00514  1:0x00514  6:0x00000  
tcblock mbipcmd 0x0091 0x0A05   0x01B2 0x04FD 0x0008 0x0514 \
                                0x0000 0x0514 0x0800 0x0000 \
                                0x3000 0x0004 0x007F 
#;
#    SETREGS  $IPRL_MAG_VPIXALGN 8 5:0x00000  4:0x00000  1024 1024
tcblock mbipcmd 0x0091 0x0A10   0x01B2 0x0505 0x0008 0x0000 \
                                0x2800 0x0000 0x2000 0x0400 \
                                0x0400 0x0400 0x0045 
#;
#    SETREGS  $IPRL_MAG_XALGN_RV    8  6:0x00000  5:0x00000 1024 0
tcblock mbipcmd 0x0091 0x0A1B   0x01B2 0x050D 0x0008 0x0000 \
                                0x3000 0x0000 0x2800 0x0400 \
                                0x0000 0x0400 0x0400 
#    SETREGS  $IPRL_MAG_YALGN_RV    8  5:0x00000  6:0x00000 1024 0
tcblock mbipcmd 0x0091 0x0A26   0x01B2 0x0515 0x0008 0x0000 \
                                0x2800 0x0000 0x3000 0x0400 \
                                0x0000 0x0400 0x00FF 
#    SETREGS  $IPRL_MAG_XALGN_LV    8  4:0x00000  5:0x00000 1024 0
tcblock mbipcmd 0x0091 0x0A31   0x01B2 0x051D 0x0008 0x0000 \
                                0x2000 0x0000 0x2800 0x0400 \
                                0x0000 0x0400 0x0400 
#    SETREGS  $IPRL_MAG_YALGN_LV    8  5:0x00000  4:0x00000 1024 0
tcblock mbipcmd 0x0091 0x0A3C   0x01B2 0x0525 0x0008 0x0000 \
                                0x2800 0x0000 0x2000 0x0400 \
                                0x0000 0x0400 0x00FF 
#
#; Magnetograms are created in Page 5.
#    SETREGS  $IPRL_MAG_GENMAG      6  6:0x00000  4:0x00000  5:0x0
tcblock mbipcmd 0x0091 0x0A47   0x01B2 0x052D 0x0006 0x0000 \
                                0x3000 0x0000 0x2000 0x0000 \
                                0x2800 
#    SETREGS  $IPRL_MAG_GENMAG+6    5  0x100000L  1  0xFFFF  0
tcblock mbipcmd 0x0091 0x0A50   0x01B2 0x0533 0x0005 0x0000 \
                                0x0010 0x0001 0xFFFF 0x0000 
#;
#; Magnetograms are stored at an offset of 0x00226 words; The firs
#; words are reserved for header data.
#    SETREGS  $IPRL_MAG_SUMMAG      6  5:0x00000  4:0x00000  13:0x
tcblock mbipcmd 0x0091 0x0A58   0x01B2 0x0548 0x0006 0x0000 \
                                0x2800 0x0000 0x2000 0x0226 \
                                0x6800 
#    SETREGS  $IPRL_MAG_SUMMAG+6    5  0x100000L  1    1     0
tcblock mbipcmd 0x0091 0x0A61   0x01B2 0x054E 0x0005 0x0000 \
                                0x0010 0x0001 0x0001 0x0000 
#;
#    SETREGS  $IPRL_MAG_CPYMAG      6 13:0x00226  4:0x00000  0x100
tcblock mbipcmd 0x0091 0x0A69   0x01B2 0x0553 0x0006 0x0226 \
                                0x6800 0x0000 0x2000 0x0000 \
                                0x0010 
#;
#; The Magnetogram header is saved in 18:0x00000
#    SETREGS  $IPRL_MAG_HDR         6  6:0x00001  0x9000     0xe5 
tcblock mbipcmd 0x0091 0x0A72   0x01B2 0x053E 0x0006 0x0001 \
                                0x3000 0x9000 0x00E5 0xBFFF \
                                0xFF27 
#    SETREGS  $IPRL_MAG_CPYHDR      6  18:0x0000  13:0x00000 0x002
tcblock mbipcmd 0x0091 0x0A7B   0x01B2 0x05A2 0x0006 0x0000 \
                                0x9000 0x0000 0x6800 0x0226 \
                                0x0000 
#    SETREGS  $IPRL_MAG_MVDL        6  5:0x00000  8:0x00000  0x100
tcblock mbipcmd 0x0091 0x0A84   0x01B2 0x0538 0x0006 0x0000 \
                                0x2800 0x0000 0x4000 0x0226 \
                                0x0010 
#;
#; Set 5K Accumulation entry point
#    SETREG   $IPRP_MAG_5KEP   &CLR5KBF
tcblock mbipcmd 0x0091 0x0A8D   0x0140 0x057A 0x097A 
#;
#; Set Accumulation setup address
#    SETREGS  $IPRL_MAG_DONE1       6  0  0  0  0  0  0 
tcblock mbipcmd 0x0091 0x0A90   0x01B2 0x058C 0x0006 0x0000 \
                                0x0000 0x0000 0x0000 0x0000 \
                                0x0000 
#    SETREG   $IPRP_MAG_ACCPAG   0x6800
tcblock mbipcmd 0x0091 0x0A99   0x0140 0x05A1 0x6800 
#    SETREG   $IPRP_MAG_NEWPAG   &PAGE2
tcblock mbipcmd 0x0091 0x0A9C   0x0140 0x05A0 0x09CD 
#    SETREGS  $IPRL_MAG_DL     6  0       0x6800  0       0x4000  
tcblock mbipcmd 0x0091 0x0A9F   0x01B2 0x0592 0x0006 0x0000 \
                                0x6800 0x0000 0x4000 0x0000 \
                                0x000C 
#
#;
#; Clear Accumulation pages
#    FILLBLK  15:0x00000  0x120000L  0
tcblock mbipcmd 0x0091 0x0AA8   0x016C 0x0000 0x7800 0x0000 \
                                0x0012 0x0000 
#    FILLBLK  18:0x00000  0x120000L  0
tcblock mbipcmd 0x0091 0x0AAE   0x016C 0x0000 0x9000 0x0000 \
                                0x0012 0x0000 
#    FILLBLK  19:0x00000  0x120000L  0
tcblock mbipcmd 0x0091 0x0AB4   0x016C 0x0000 0x9800 0x0000 \
                                0x0012 0x0000 
#;
#    RTNQUE
tcblock mbipcmd 0x0091 0x0ABA   0x01FA 
#;....................................................... 
#;=======================================================
#=======================================================
#
# ENBQUE                ; Enable Queue
tcblock mbipldin 0x0136
#
#
return
#
#=======================================================
