      SUBROUTINE XRY(IEOF,LONG,LAT)                                     00000100
C     THIS SUBROUTINE IS USED TO READ THE XRAY AND EPHEMERIS DATA FROM  00000200
C        THE APOLLO 15 AND 16 XRAY TAPES,500 DATA POINTS AT A TIME,EACH 00000300
C        COUNTED FOR LESS THAN 64 SECONDS.  DATA CHECKED TO BE WITHIN   00000400
C        TIME AND GEOGRAPHICAL LIMITS.  COUNTS OF CHANNELS 1-8 STORED TO00000500
C        GIVE TOTAL ACCUMULATED SPECTRUM FOR EACH DETECTOR OF EACH DATUM00000600
C        G AND N VALUES ARE INTERPOLATED BY CALLING THE SUBROUTINE      00000700
C        XINTGN,WHICH CALLS CURVE-FITTING SUBROUTINE SPLINE.            00000800
C     IEOF IS A FLAG WHICH INDICATES WHY A RETURN WAS MADE TO THE       00000900
C        CALLING PROGRAM.                                               00001000
C     IEOF=-1 SIGNIFIES THAT THE SUBROUTINE HAS BEEN ENTERED FOR THE    00001100
C        FIRST TIME.                                                    00001200
C     IEOF=1 SIGNIFIES THAT 500 XRAY SPECTRA HAVE BEEN READ.            00001300
C     IEOF=2 SIGNIFIES THAT THE LONG. AND LAT. LIMITS WERE FULFILLED.   00001400
C     IEOF=3 INDICATES THAT THE UPPER TIME LIMIT HAS BEEN EXCEEDED.     00001500
C     IEOF=4 INDICATES THAT AN EOF HAS BEEN ENCOUNTERED WHILE READING   00001600
C        THE INPUT DATA TAPE.                                           00001700
C     LONG(1) IS THE EASTERN  LONGITUDE FOR THE DATA BEING READ.        00001800
C     LONG(2) IS THE WESTERN LONGITUDE LIMIT.                           00001900
C     LAT(1) IS THE NORTHERN LATITUDE LIMIT.                            00002000
C     LAT(2) IS THE SOUTHERN LATITUDE LIMIT.                            00002100
C     NOTE: LAT(1)>LAT(2) AND LONG(1)>LONG(2) MUST ALWAYS BE FULFILLED. 00002200
C     CARTESIAN COORDINATES ARE USED.                                   00002300
      COMMON/INPDAT/NFC,NCH,ACCTIM,IOUT,GETS(2)                         00002400
C     LABELLED COMMON BLOCK/INPDAT/ IS DEFINED AS FOLLOWS:              00002500
C     'NFC' AND 'NCH' ARE RESPECTIVELY THE NUMBER OF THE LOWEST AND     00002600
C        HIGHEST CHANNELS TO BE USED FOR SUMMING.                       00002700
C     'ACCTIM' IS THE TOTAL AMOUNT OF ACCUMULATION TIME AND IS          00002800
C        ALWAYS SOME INTEGER MULTIPLE OF 8 SECONDS.                     00002900
C     IOUT HAS NO MEANING IN THIS SUBROUTINE.                           00003000
C     'GETS' IS GROUND ELAPSED TIME IN SECONDS                          00003100
      COMMON/INFO/ANS(500,8),SPECT(500,4,10),NFLAG(500),NC(500),NSPEC   00003200
C     LABELLED COMMON BLOCK/INFO/ IS DEFINED AS FOLLOWS:                00003300
C     ANS(I,1) IS THE GET TIME IN SECONDS.                              00003400
C     ANS(I,2) IS THE ORBIT NUMBER.                                     00003500
C     ANS(I,3) IS THE SELENOGRAPHIC LATITUDE IN DEGREES.                00003600
C     ANS(I,4) IS THE SELENOGRAPHIC LONGITUDE IN DEGREES.               00003700
C     ANS(I,5) IS THE ALTITUDE IN KILOMETERS.                           00003800
C     ANS(I,6) TO ANS(I,8) ARE THE SPACECRAFT LOOK ANGLES IN DEGREES.   00003900
C        ANS(I,6) IS THE PITCH.                                         00004000
C        ANS(I,7) IS THE YAW.                                           00004100
C        ANS(I,8) IS THE ROLL.                                          00004200
C                                                                       00004300
C     SPECT(I,J,K) CONTAINS THE 8 SECOND XRAY SPECTRA FOR ANS(I,X).     00004400
C        J CORRESPONDS TO THE DETECTORS 1 TO 3 AND J=4 IS THE SOLAR     00004500
C        MONITOR.                                                       00004600
C        K CORRESPONDS TO THE CHANNEL NUMBERS 1 THROUGH 8 AND 9 IS THE  00004700
C        NUMBER OF PULSES REJECTED AS BEING NON XRAY EVENTS.  FOR THE   00004800
C        SOLAR MONITOR K=9 IS THE TOTAL NUMBER OF EVENTS IN CHANNELS    00004900
C        1 TO 8 FOR ALL 4 DETECTORS.  THIS NUMBER IS THEN DIVIDED BY 16 00005000
C        BEFORE BEING TRANSMITTED TO GIVE A MEASURE OF THE DATA QUALITY 00005100
C        BEFORE AND AFTER TELEMETRY TRANSMISSION.                       00005200
C        THE SUM OF ALL THE CHANNELS FROM NFC TO NCH IS STORED IN K=10. 00005300
C     NFLAG(I) INDICATES WHICH MODE THE SPECTROMETER WAS MEASURING      00005400
C        DURING A PARTICULAR ACCUMULATION TIME INTERVAL.  THE MODES ARE:00005500
C        16= NORMAL SPECTROMETER DATA FOR ALL FOUR DETECTORS.           00005600
C        96= CALIBRATION OF DETECTORS 1 TO 3.                           00005700
C        144=DETECTOR 1 ONLY IS IN THE ATTENUATE MODE.                  00005800
C        224=DETECTOR 1 IN ATTENUATE MODE AND 1 TO 3 ARE IN CALIBRATION 00005900
C        MODE.                                                          00006000
C     NC(I) CONTAINS THE NUMBER OF CONTINUOUS 8 SECOND SPECTRA FOR THE  00006100
C        SPECIFIC ACCUMULATION INTERVAL.                                00006200
C     NSPEC IS THE NUMBER OF SPECTRA THAT HAVE BEEN READ BY THE SUB-    00006300
C        ROUTINE BEFORE RETURNING CONTROL TO THE CALLING PROGRAM.       00006400
C                                                                       00006500
      COMMON/RATIO/IDUM,D(1500,8)                                       00006600
C     LABELLED COMMON BLOCK/RATIO/ IS DEFINED AS FOLLOWS:               00006700
C        'IDUM' IS A DUMMY VARIABLE FOR 'I'.                            00006800
C        'D' ARRAY IS TEMPORARY STORAGE FOR THE G AND N DATA.           00006900
      REAL LONG(2),LAT(2),ATEM(8),SAVTEM(8)                             00007000
C     ATEM IS TEMPORARY STORAGE FOR THE EPHEMERIS DATA BEING READ AND   00007100
C        CORRESPONDS TO THE VECTOR ANS.  THERE IS A ONE TO ONE          00007200
C        CORRESPONDENCE BETWEEN EACH COMPONENT OF ANS AND EACH          00007300
C        COMPONENT OF ATEM.                                             00007400
C     SAVTEM IS A STORAGE VECTOR FOR EPHEMERIS DATA WHICH IS TO BE      00007500
C        INTERPOLATED AT THE END OF THE ACCUMULATION PERIOD.            00007600
C                                                                       00007700
      INTEGER CHSM(4,10),SPECT,TSPEC(9,4)                               00007800
C     CHSM(4,10) IS THE TEMPORARY STORAGE USED FOR SUMMING SPECTRA IF   00007900
C        ACCTIM>8 SECONDS.                                              00008000
C     TSPEC(9,4) IS TEMPORARY STORAGE FOR THE SPECTRA BEING READ.       00008100
C     NOTE: ONLY 8 SPECTRA OR 64 SECONDS OF DATA ARE ALLOWED IN THIS    00008200
C        SUBROUTINE WITHOUT FURTHER MODIFICATION.                       00008300
C                                                                       00008400
      IF(ACCTIM.LE.64.0) GO TO 10                                       00008500
      WRITE(6,2000) ACCTIM                                              00008600
 2000 FORMAT(' ACCUMULATION TIME EXCEEDS 64 SECONDS, TIME= ',F6.1)      00008700
      NSPEC=0                                                           00008800
      GO TO 330                                                         00008900
C     NSCOL=NUMBER OF SPECTRA TO BE COLLECTED FOR SUMMING.              00009000
   10 NSCOL=ACCTIM/8.0                                                  00009100
C                                                                       00009200
C     NR IS THE NUMBER OF SPECTRA ALREADY READ DURING THE SPECTRA       00009300
C        SUMMING.                                                       00009400
      NR=0                                                              00009500
      KK=0                                                              00009600
      IF(IEOF.EQ.-1) GO TO 70                                           00009700
      GO TO (20,80,70,70),IEOF                                          00009800
C                                                                       00009900
C     FOLLOWING IS LOOP TO KEEP G&N DATA CONTINUOUS FOR CORRECT INTER-  00010000
C        POLATION OF G&N INFORMATION FOR ALL DATA POINTS AFTER READING  00010100
C        READING OF TAPE HALTED(STORAGE VECTORS FULL,NSPEC=500).        00010200
C     THE LAST 4 VECTORS WERE SAVED FOR CONTINUITY.                     00010300
   20 DO 60 I=1,4                                                       00010400
      NP=496+I                                                          00010500
      DO 30 J=1,8                                                       00010600
   30 D(I,J)=ANS(NP,J)                                                  00010700
   60 CONTINUE                                                          00010800
      KK=4                                                              00010900
      GO TO 80                                                          00011000
C     SINCE UPPER LIMIT EXCEEDED OR IEOF NOT EQUAL TO ZERO, START       00011100
C        AGAIN ON NEXT RECORD AS AT BEGINNING.                          00011200
   70 REWIND 9                                                          00011300
C     M IS USED TO COUNT THE NUMBER OF SPECTRA ACCUMULATED.             00011400
   80 M=0                                                               00011500
C     RESET IEOF AND BEGIN READING THE DATA TAPE                        00011600
   90 IEOF=0                                                            00011700
C     READ THE MODE FLAG(NF) AND EPHEMERIS DATA.                        00011800
  100 READ(9,END=300) NF,ATEM                                           00011900
      GET=ATEM(1)+4.0                                                   00012000
C                                                                       00012100
C     READ THE XRAY SPECTRA.                                            00012200
      READ(9,END=300) TSPEC                                             00012300
C     CHECK TO SEE IF THE 'GET' EXCEEDS THE STARTING TIME. IF NOT READ  00012400
C        THE NEXT SPECTRUM.                                             00012500
      IF(ATEM(1).LT.GETS(1)) GO TO 100                                  00012600
C                                                                       00012700
C     CHECK TO SEE IF THE 'GET' JUST READ EXCEEDS THE END TIME FROM THE 00012800
C        CALLING PROGRAM AND  IF SO THEN RETURN TO THE CALLING PROGRAM. 00012900
C        SET IEOF AT 3.                                                 00013000
      IF(ATEM(1).LE.GETS(2)) GO TO 105                                  00013100
      IEOF=3                                                            00013200
C     IF M NOT EQUAL TO 0, INTERPOLATE ACCUMULATED SPECTRA.             00013300
       IF(M.EQ.0) GO TO 320                                             00013400
      GO TO 165                                                         00013500
C     CHECK TO SEE IF THE DATA IS WITHIN THE DELTA LONG/LAT LIMITS.     00013600
  105 IF(ATEM(3).GT.LAT(1).OR.ATEM(3).LT.LAT(2)) GO TO 100              00013700
      IF(ATEM(4).GE.LONG(2).AND.ATEM(4).LE.LONG(1)) GO TO 110           00013800
C     IF NO SPECTRA ACCUMULATED, READ NEXT SPECTRUM.                    00013900
      IF(M.EQ.0) GO TO 100                                              00014000
      IEOF=2                                                            00014100
C     IF NO SPECTRA HAVE BEEN READ DURING SUMMING, OR COUNTING TIME     00014200
C        IS 8 SECONDS, RETURN TO CALLING PROGRAM.                       00014300
      IF(NR.EQ.0.OR.NSCOL.EQ.1) GO TO 320                               00014400
C     FINISH PROCESSING SUMMED DATA AND THEN RETURN TO THE CALLING      00014500
C        PROGRAM.                                                       00014600
      GO TO 165                                                         00014700
  110 KK=KK+1                                                           00014800
      DO 112 K=1,8                                                      00014900
  112 D(KK,K)=ATEM(K)                                                   00015000
      IF(NSCOL.GT.1) GO TO 130                                          00015100
C     FOR 8 SECOND ACCUMULATION TIMES THE TEMPORARY DATA IS TRANSFERRED 00015200
C        DIRECTLY TO THE THE OUTPUT VECTORS.                            00015300
      M=M+1                                                             00015400
      DO 120 J=1,4                                                      00015500
      ISUM=0                                                            00015600
      DO 115 K=1,9                                                      00015700
      IF(K.GE.NFC.AND.K.LE.NCH) ISUM=ISUM+TSPEC(K,J)                    00015800
  115 SPECT(M,J,K)=TSPEC(K,J)                                           00015900
C     STORE THE SUM OF THE CHANNELS NFC TO NCH IN SPECT(M,J,10).        00016000
      SPECT(M,J,10) =ISUM                                               00016100
  120 CONTINUE                                                          00016200
C     STORE THE NUMBER OF SPECTRA IN NC(M).                             00016300
      NC(M)=1                                                           00016400
C     STORE THE MODE CODE('NF').                                        00016500
      NFLAG(M)=NF                                                       00016600
C     STORE THE GET IN ANS(M,1).                                        00016700
      ANS(M,1)=GET                                                      00016800
C     CHECK TO SEE IF THE OUTPUT VECTORS ARE FULL.  IF NOT, CONTINUE.   00016900
      IF(M.LT.500.AND.KK.LT.1500) GO TO 100                             00017000
C     IF FULL PREPARE TO EXIT TO THE CALLING PROGRAM.                   00017100
      GO TO 310                                                         00017200
C                                                                       00017300
C     BEGIN THE ADDITION OF MULTIPLE SPECTRA.                           00017400
  130 NR=NR+1                                                           00017500
      IF(NR.GT.1) GO TO 140                                             00017600
C     DEFINE STARTING CONDITIONS OF VARIABLES FOR SUMMING.              00017700
      M=M+1                                                             00017800
      NC(M)=0                                                           00017900
      NFLAG(M)=NF                                                       00018000
      DO 135 J=1,4                                                      00018100
      DO 135 K=1,10                                                     00018200
  135 CHSM(J,K)=0                                                       00018300
      GO TO 142                                                         00018400
C     IF SPECTRA HAVE ALREADY BEEN COUNTED FOR MORE THAN 8 SECONDS      00018500
C        AND/OR MODES OF MEASUREMENT VARIABLES DO NOT AGREE, GO         00018600
C        TO STORE DATA IN TEMPORARY STORAGE FOR DATA COUNTED FOR        00018700
C        MORE THAN ONE 8 SECOND COUNT(CHSM).                            00018800
  140 IF(NR.GT.NSCOL) GO TO 160                                         00018900
      IF(NF.NE.NFLAG(M)) GO TO 160                                      00019000
      IF(GET-SAVTEM(NR-1).GE.10.1) GO TO 160                            00019100
C     STORE DATA IN LOCATION TO BE READ AT END OF ACCUMULATION          00019200
C        PERIOD(SAVTEM).                                                00019300
  142 SAVTEM(NR)=GET                                                    00019400
      DO 155 J=1,4                                                      00019500
      ISUM=0                                                            00019600
      DO 150 K=1,9                                                      00019700
      IF(K.GE.NFC.OR.K.LE.NCH) ISUM=ISUM+TSPEC(K,J)                     00019800
      CHSM(J,K)=CHSM(J,K)+TSPEC(K,J)                                    00019900
  150 CONTINUE                                                          00020000
      CHSM(J,10)=CHSM(J,10)+ISUM                                        00020100
  155 CONTINUE                                                          00020200
      NC(M)=NC(M)+1                                                     00020300
      IF(KK.LT.1500) GO TO 100                                          00020400
      IEOF=1                                                            00020500
  160 NR=NR-1                                                           00020600
C     STORE THE SUMMED SPECTRA IN CHSM.                                 00020700
  165 DO 170 J=1,4                                                      00020800
      DO 170 K=1,10                                                     00020900
  170 SPECT(M,J,K)=CHSM(J,K)                                            00021000
C     INTERPOLATE THE EPHEMERIS DATA.                                   00021100
  180 ANS(M,1)=(SAVTEM(NR)+SAVTEM(1))/2.0                               00021200
      NR=0                                                              00021300
      IF(M.EQ.500) IEOF=1                                               00021400
      IF(IEOF.NE.0) GO TO 320                                           00021500
      GO TO 130                                                         00021600
C     SET THE RETURN CODE FLAG.                                         00021700
  300 IEOF=3                                                            00021800
  310 IEOF=IEOF+1                                                       00021900
  320 NSPEC=M                                                           00022000
  330 IF(NSPEC.GT.0) CALL XINTGN(KK)                                    00022100
C     IF ANY SPECTRA HAVE BEEN ACCUMULATED, CALL THE G AND N            00022200
C        INTERPOLATION SUBROUTINE.                                      00022300
      RETURN                                                            00022400
      END                                                               00022500
