      SUBROUTINE DMFIX(XP,YP,ZP,/NP/,XS,YS,ZS,/NS/,XPREF,YPREF,ZPREF,   00000100
     1                 XSREF,YSREF,ZSREF,GMT,IMODE)                     00000110
      INTEGER*2 GMT(6),NP,NS,N                                          00000120
      INTEGER XP(1),YP(1),ZP(1),XS(1),YS(1),ZS(1)                       00000130
     1       ,XPREF(1),YPREF(1),ZPREF(1),XSREF(1),YSREF(1),ZSREF(1)     00000140
     2       ,XPDX(6),YPDX(5),ZPDX(5),XSDX(6),YSDX(5),ZSDX(5)           00000150
     3       ,XPLAST/2048/,XSLAST/2048/,YPDIFF/0/,YSDIFF/0/,ZPDIFF/0/   00000160
     4       ,ZSDIFF/0/,DELP(3),DELS(3),PREF(3),SREF(3),KELP(3),KELS(3) 00000170
      COMMON /HEADER/ LFM(6)                                            00000180
C                                                                       00000190
C            CORRECT FOR DRIFT IN DELTA MODULATION STRING   =W82JS.DMFIX00000200
C                                                                       00000210
C     0         1         2         3                                   00000220
C     0         0         0         0                                   00000230
C      DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD    STRING OF DM OUTPUT SAMPLES    00000240
C     X         Y         Z         X                                   00000250
C     R         R         R         R    FULL WORD REFERENCE LOCATIONS  00000260
C                                                                       00000270
C        CR-6 PRIME MAG HAS 30 DM SAMPLES PER SEQUENCE                  00000280
C        CR-6 SECONDARY MAG HAS 15 DM SAMPLES PER SEQUENCE              00000290
C                                                                       00000300
      CALL LOOK(LFM,DELP,DELS,PREF,SREF,IMODE)                          00000310
      CALL DXSAVE(XP(29),XPDX(2),NP,30)                                 00000320
      CALL DXSAVE(XS(14),XSDX(2),NS,15)                                 00000330
C                                                                       00000340
      CALL DXSAVE(YP(9),YPDX,NP,30)                                     00000350
      CALL DXSAVE(YS(4),YSDX,NS,15)                                     00000360
C                                                                       00000370
      CALL DXSAVE(ZP(19),ZPDX,NP,30)                                    00000380
      CALL DXSAVE(ZS(9),ZSDX,NS,15)                                     00000390
C                                                                       00000400
C               REMOVE DC LEVEL TO LINE UP WITH LEFT FULL WORD          00000410
C                                                                       00000420
      CALL XSHIFT(XP,XPREF,XPLAST,NP,PREF(1))                           00000430
      CALL XSHIFT(XS,XSREF,XSLAST,NS,SREF(1))                           00000440
      KELP(1) = XP(NP-1) - XPDX(6)                                      00000450
      KELS(1) = XS(NS-1) - XSDX(6)                                      00000460
      IF(XPDX(6) .EQ. 99999) KELP(1) = 99999                            00000464
      IF(XSDX(6) .EQ. 99999) KELS(1) = 99999                            00000468
C                                                                       00000470
      CALL YZSHIF(YP,YPREF,YPDIFF,NP,20)                                00000480
      CALL YZSHIF(YS,YSREF,YSDIFF,NS,10)                                00000490
      KELP(2) = DELP(2) + YPDIFF                                        00000500
      KELS(2) = DELS(2) + YSDIFF                                        00000510
      IF(DELP(2) .LE. 0) KELP(2) = 99999                                00000514
      IF(DELS(2) .LE. 0) KELS(2) = 99999                                00000518
C                                                                       00000520
      CALL YZSHIF(ZP,ZPREF,ZPDIFF,NP,10)                                00000530
      CALL YZSHIF(ZS,ZSREF,ZSDIFF,NS,5)                                 00000540
      KELP(3) = DELP(3) + ZPDIFF                                        00000550
      KELS(3) = DELS(3) + ZSDIFF                                        00000560
      IF(DELP(3) .LE. 0) KELP(3) = 99999                                00000564
      IF(DELS(3) .LE. 0) KELS(3) = 99999                                00000568
C                                                                       00000570
C         ROTATE DM STRING ABOUT LEFT FULL WORD TO MATCH                00000580
C         LEVEL OF FULL WORD ON RIGHT                                   00000590
C                                                                       00000600
      CALL PIVOT(XP,XPREF,XPDX,30,30,PREF(1),KELP(1),NP,5)              00000610
      CALL PIVOT(XS,XSREF,XSDX,15,15,SREF(1),KELS(1),NS,5)              00000620
      IF(PREF(1) .NE. 0) XP(NP) = PREF(1)                               00000630
      IF(SREF(1) .NE. 0) XS(NS) = SREF(1)                               00000640
C                                                                       00000650
      CALL PIVOT(YP,YPREF,YPDX,30,10,PREF(2),KELP(2),NP,5)              00000660
      CALL PIVOT(YS,YSREF,YSDX,15,5,SREF(2),KELS(2),NS,5)               00000670
C                                                                       00000680
      CALL PIVOT(ZP,ZPREF,ZPDX,30,20,PREF(3),KELP(3),NP,5)              00000690
      CALL PIVOT(ZS,ZSREF,ZSDX,15,10,SREF(3),KELS(3),NS,5)              00000700
C                                                                       00000710
      RETURN                                                            00000720
      END                                                               00000730
      SUBROUTINE DMFIX5(XP,YP,ZP,/NP/,XS,YS,ZS,/NS/,XPREF,YPREF,ZPREF,  00000010
     1                 XSREF,YSREF,ZSREF,GMT,IMODE)                     00000020
      INTEGER*2 GMT(6),NP,NS                                            00000030
      INTEGER XP(1),YP(1),ZP(1),XS(1),YS(1),ZS(1)                       00000040
     1       ,XPREF(1),YPREF(1),ZPREF(1),XSREF(1),YSREF(1),ZSREF(1)     00000050
     2       ,XPDX(11),YPDX(11),ZPDX(11)                                00000060
     X       ,XSDX(6),YSDX(6),ZSDX(6)                                   00000070
     3       ,XPLAST/2048/,XSLAST/2048/                                 00000080
     4                 ,DELP(3),DELS(3),PREF(3),SREF(3),KELP(3),KELS(3) 00000090
      INTEGER YPLAST/2048/,YSLAST/2048/,ZPLAST/2048/,ZSLAST/2048/       00000100
      COMMON /HEADER/ LFM(6)                                            00000110
C                                                                       00000120
C            CORRECT FOR DRIFT IN DELTA MODULATION STRING               00000130
C                                                                       00000140
      CALL LOOK(LFM,DELP,DELS,PREF,SREF,IMODE)                          00000150
C                                                                       00000160
C        CR-5 PRIME MAG HAS 20 DM SAMPLES PER SEQUENCE                  00000170
C        CR-5 SECONDARY MAG HAS 10 DM SAMPLES PER SEQUENCE              00000180
C                                                                       00000190
      CALL DXSAVE(XP(19),XPDX(2),NP,20)                                 00000200
      CALL DXSAVE(XS(09),XSDX(2),NS,10)                                 00000210
C                                                                       00000220
      CALL DXSAVE(YP(19),YPDX(2),NP,20)                                 00000230
      CALL DXSAVE(YS(09),YSDX(2),NS,10)                                 00000240
C                                                                       00000250
      CALL DXSAVE(ZP(19),ZPDX(2),NP,20)                                 00000260
      CALL DXSAVE(ZS(09),ZSDX(2),NS,10)                                 00000270
C                                                                       00000280
C               REMOVE DC LEVEL TO LINE UP WITH LEFT FULL WORD          00000290
C                                                                       00000300
      CALL DMSHF5(XP,XPREF,XPLAST,NP,PREF(1),10)                        00000310
      CALL DMSHF5(XS,XSREF,XSLAST,NS,SREF(1),5)                         00000320
      KELP(1) = XP(NP-1) - XPDX(11)                                     00000330
      KELS(1) = XS(NS-1) - XSDX(6)                                      00000340
      IF(XPDX(11).EQ. 99999) KELP(1) = 99999                            00000350
      IF(XSDX(6) .EQ. 99999) KELS(1) = 99999                            00000360
C                                                                       00000370
      CALL DMSHF5(YP,YPREF,YPLAST,NP,PREF(2),10)                        00000380
      CALL DMSHF5(YS,YSREF,YSLAST,NS,SREF(2),5)                         00000390
      KELP(2) = YP(NP-1) - YPDX(11)                                     00000400
      KELS(2) = YS(NS-1) - YSDX(6)                                      00000410
      IF(YPDX(11).EQ. 99999) KELP(2) = 99999                            00000420
      IF(YSDX(6) .EQ. 99999) KELS(2) = 99999                            00000430
C                                                                       00000440
      CALL DMSHF5(ZP,ZPREF,ZPLAST,NP,PREF(3),10)                        00000450
      CALL DMSHF5(ZS,ZSREF,ZSLAST,NS,SREF(3),5)                         00000460
      KELP(3) = ZP(NP-1) - ZPDX(11)                                     00000470
      KELS(3) = ZS(NS-1) - ZSDX(6)                                      00000480
      IF(ZPDX(11).EQ. 99999) KELP(3) = 99999                            00000490
      IF(ZSDX(6) .EQ. 99999) KELS(3) = 99999                            00000500
C                                                                       00000510
C         ROTATE DM STRING ABOUT LEFT FULL WORD TO MATCH                00000520
C         LEVEL OF FULL WORD ON RIGHT                                   00000530
C                                                                       00000540
      CALL PIVOT(XP,XPREF,XPDX,20,20,PREF(1),KELP(1),NP,10)             00000550
      CALL PIVOT(XS,XSREF,XSDX,10,10,SREF(1),KELS(1),NS,5)              00000560
      CALL PIVOT(YP,YPREF,YPDX,20,20,PREF(2),KELP(2),NP,10)             00000570
      CALL PIVOT(ZP,ZPREF,ZPDX,20,20,PREF(3),KELP(3),NP,10)             00000580
      CALL PIVOT(ZS,ZSREF,ZSDX,10,10,SREF(3),KELS(3),NS,5)              00000590
      CALL PIVOT(YS,YSREF,YSDX,10,10,SREF(2),KELS(2),NS,5)              00000600
C                                                                       00000610
      IF(XP(NP-1).LE.0)RETURN                                           00000620
C                                                                       00000630
      IF(PREF(1) .NE. 0) XP(NP) = PREF(1)                               00000640
      IF(SREF(1) .NE. 0) XS(NS) = SREF(1)                               00000650
C                                                                       00000660
      IF(PREF(2) .NE. 0) YP(NP) = PREF(2)                               00000670
      IF(SREF(2) .NE. 0) YS(NS) = SREF(2)                               00000680
C                                                                       00000690
      IF(PREF(3) .NE. 0) ZP(NP) = PREF(3)                               00000700
      IF(SREF(3) .NE. 0) ZS(NS) = SREF(3)                               00000710
C                                                                       00000720
      RETURN                                                            00000730
      END                                                               00000740
C                                                                       00001000
C      THIS CODE WAS REWRITTEN FROM HARDCOPY DUE TO LOSS 3/28/91        00002000
C      T. MCCLANAHAN ST SYSTEMS, GSFC CODE694                           00003000
C                                                                       00004000
C                                                                       00005000
       SUBROUTINE DMSHF5(X,XREF,XLAST,N,NEXT,LOOP)                      00010000
       INTEGER*2 N                                                      00020000
       INTEGER XLAST,X(1),XDIFF,XREF(1),YZDIFF,YZ(1),YZREF(1),NEXT      00030000
C                                                                       00040000
C      GIVEN DELTA MODULATOR OUTPUT STRING OF DATA, TIE IT              00050000
C      DOWN TO THE LEVEL OF REFERENCE WORDS.                            00060000
C                                                                       00070000
         NL = N/LOOP                                                    00080000
         NL1 = NL - 1                                                   00090000
         XDIFF = XREF(1) - XLAST                                        00100000
         IF (X(1) .LE. 0) XREF(1) = 0                                   00110000
         IF (XLAST .LE. 0) XDIFF = XREF(1) - X(1)                       00120000
         IF (XREF(1) .EQ. 0) CALL NOFULL(XDIFF,X,NL1,&5)                00130000
        CALL DRIFT(X(1),XDIFF,NL1)                                      00140000
  5     K = NL                                                          00150001
       DO 10 I = 2, LOOP                                                00160000
            XDIFF = XREF(I) - X(K)                                      00170000
            IF (X(K) .LE. 0) XDIFF = XREF(I) - X(K+1)                   00180000
            IF (X(K+1) .LE. 0) XREF(I) = 0                              00190000
            IF (XREF(I) .EQ. 0) CALL NOFULL(XDIFF,X(K),NL,&10)          00200000
           CALL DRIFT(X(K),XDIFF,NL)                                    00210000
  10      K = K + NL                                                    00220000
                                                                        00221000
          IF (XDIFF .NE. -999999) GO TO 20                              00230000
          X(N) = -1                                                     00240000
          RETURN                                                        00250000
  20    XLAST = X(N)                                                    00260000
        X(N) = NEXT                                                     00270000
        IF (NEXT .EQ. 0) X(N) = XLAST + XDIFF                           00280000
       RETURN                                                           00290000
       END                                                              00300000
      SUBROUTINE DMSHIF                                                 00000100
      INTEGER*2 N                                                       00000110
      INTEGER XLAST,X(1),XDIFF,XREF(1),YZDIFF,YZ(1),YZREF(1),NEXT       00000120
C                                                                       00000130
C                                                          =W82JS.DMSHIF00000140
C      GIVEN DELTA MODULATOR OUTPUT STRING OF DATA,  TIE IT             00000150
C      DOWN TO THE LEVEL OF REFERENCE WORDS                             00000160
C                                                                       00000170
      ENTRY XSHIFT(X,XREF,XLAST,N,NEXT)                                 00000180
      NL = N/5                                                          00000190
      NL1 = NL - 1                                                      00000200
      XDIFF = XREF(1) - XLAST                                           00000210
      IF(XLAST .LE. 0) XDIFF = XREF(1) - X(1)                           00000215
      IF(XREF(1) .EQ. 0) CALL NOFULL(XDIFF,X,NL1,&5)                    00000220
      CALL DRIFT(X(1),XDIFF,NL1)                                        00000230
   5  K = NL                                                            00000240
      DO 10 I=2,5                                                       00000250
      XDIFF = XREF(I) - X(K)                                            00000260
      IF(X(K) .LE. 0) XDIFF = XREF(I) - X(K+1)                          00000265
      IF(XREF(I) .EQ. 0) CALL NOFULL(XDIFF,X(K),NL,&10)                 00000270
      CALL DRIFT(X(K),XDIFF,NL)                                         00000280
  10  K = K + NL                                                        00000290
      XLAST = X(N)                                                      00000300
      X(N) = NEXT                                                       00000310
      IF(NEXT .EQ. 0) X(N) = XLAST + XDIFF                              00000320
      RETURN                                                            00000330
C                                                                       00000340
      ENTRY YZSHIF(YZ,YZREF,YZDIFF,N,L)                                 00000350
      NL = N/5                                                          00000360
      NLP = NL - L                                                      00000370
      NL1 = NLP - 1                                                     00000380
      IF(YZDIFF .EQ. -999999) CALL NOFULL(YZDIFF,YZ(1),NL1,&15)         00000390
      CALL DRIFT(YZ(1),YZDIFF,NL1)                                      00000400
  15  K = NLP                                                           00000410
      DO 20 I=1,4                                                       00000420
      YZDIFF = YZREF(I) - YZ(K)                                         00000430
      IF(YZ(K) .LE. 0) YZDIFF = YZREF(I) - YZ(K+1)                      00000435
      IF(YZREF(I) .EQ. 0) CALL NOFULL(YZDIFF,YZ(K),NL,&20)              00000440
      CALL DRIFT(YZ(K),YZDIFF,NL)                                       00000450
  20  K = K + NL                                                        00000460
      YZDIFF = YZREF(5) - YZ(K)                                         00000470
      IF(YZ(K) .LE. 0) YZDIFF = YZREF(5) -YZ(K+1)                       00000475
      IF(YZREF(5) .EQ. 0) CALL NOFULL(YZDIFF,YZ(K),L+1,&30)             00000480
      CALL DRIFT(YZ(K),YZDIFF,L+1)                                      00000490
  30  RETURN                                                            00000500
      END                                                               00000510
