      program rmon  
c
c     read levitus monthly data files - Using Unix ASCII files
c
      PARAMETER (IMAX=360,JMAX=180,KMAX=19)
      PARAMETER (K1=01,K2=11,K3=12,K4=19,K5=23,K6=24)
C
      DIMENSION KDATA(KMAX),XSEC(JMAX,KMAX),IEND(20)
      DIMENSION TITLE1(20),TITLE2(20)
C
      open(10,file='/huron/u2/ftp/download/ios/jan')
C
C  PROGRAM IS SET UP TO READ IN THE FORMATTED CARD-IMAGE FILE ON UNIT 10 AS
C  ONE DEGREE SQUARE COLUMNS ( 3 CARD IMAGES PER COLUMN ) AND WRITES OUT THE
C  UNPACKED DATA IN UNFORMATTED FORM TO UNIT 20 AS MERIDIONAL CROSS SECTIONS
C  DIMENSIONED (180,33) OF WHICH THERE ARE 360.THE FIRST DIMENSION OF THIS
C  ARRAY REPRESENTS LATITUDE "J" AND HAS A RANGE OF 1 TO 180 AS DESCRIBED ON THE
C  ATTACHED (360,180) COORDINATE  DESCRIPTION SHEET.   THE SECOND DIMENSION
C  REPRESENTS STANDARD LEVEL NUMBER  "K"  . SEE FOLLOWING STATEMENTS AND
C  ATTACHED VERTICAL COORDINATE DESCRIPTION SHEET.
C
C
C
C  I REPRESENTS LONGITUDE AND J REPRESENTS LATITUDE FOR THE ONE-DEGREE SQUARE
C  JUST READ AS DEFINED ON THE ACCOMPANYING DESCRIPTION OF THE (360,180) GRID.
C
C
C
C  THE FIRST CROSS-SECTION WRITTEN OUT IS FOR LONGITUDE ,I=1, WHICH IS AT 0.5 E
C  AND THE LAST CROSS SECTION WRITTEN IS FOR LONGITUDE I=360 WHICH IS AT 0.5W .
C
C
C
C  K REPRESENTS THE STANDARD LEVEL.     THE DEPTH OF EACH STANDARD LEVEL CAN BE
C  FOUND IN TABLE 1 OF "CLIMATOLOGICAL ATLAS OF THE WORLD OCEAN". NOTE THAT
C  THERE ARE "STANDARD" LEVELS AT 3500 METERS , 4500 METERS AND 5500 METERS THAT
C  ARE NOT NODC STANDARD LEVELS.
C
C
C
C  AMISS IS USED TO DENOTE LAND GRIDPOINTS AND SUB-OCEAN FLOOR GRIDPOINTS.
      AMISS=-1.E10
C
C  NREAD IS THE NUMBER OF ONE DEGREE-SQUARE COLUMNS OF OCEAN.
C
      NREAD=42164
C
C
C  NSEC IS A COUNTER OF THE NUMBER OF CROSS-SECTIONS WRITTEN TO UNIT 20 AND
C  SHOULD =360 WHEN PRINTED OUT.
C
      NSEC=0
C
C  READ AND PRINT TITLE INFORMATION.
C
      write(6,215)
215   format(' -------- beginning output from rmon ---------'/,
     *       ' missing values (subterranean) are printed as *****'/)
      READ(10,1)TITLE1
      READ(10,1)TITLE2
    1 FORMAT(20A4)
      PRINT 2,TITLE1
      PRINT 2,TITLE2
    2 FORMAT(1H0,20A4)
C
C
C READ AND PRINT SCALE AND DIVISION FACTORS.
C
      READ(10,3)CON,RDIV
    3 FORMAT(2F5.0)
      PRINT 4,CON,RDIV
    4 FORMAT(1H0,'CON=',F5.0,4X,'RDIV =',F5.0)
C
C
C INITIALIZE FIRST MERIDIONAL CROSS-SECTION TO =AMISS.
C
      DO 5 J=1,JMAX
      DO 5 K=1,KMAX
      XSEC(J,K)=AMISS
    5 CONTINUE
C
C
C  READ ONE-DEGREE SQUARE COLUMNS , THREE CARD IMAGES PER COLUMN.
C
C
C  NOTE THAT ONE-DEGREE SQUARE COLUMNS THAT ARE TOTALLY LAND POINTS HAVE NOT
C  BEEN WRITTEN  TO TAPE. EACH GRIDPOINT VALUE IN THESE COLUMNS IS  SET EQUAL
C  TO  -1.E10  BY THE INITIALIZATION PERFORMED WITHIN THIS PROGRAM.
C
      DO 6 N=1,NREAD
C
      READ(10,27)(KDATA(K),K=K1,K2),KL1,I,J
      READ(10,27)(KDATA(K),K=K3,K4),KL2,I,J
   27 FORMAT(14I5)
C
C
C  KL1,KL2,KL3 REPRESENT THE CARD IMAGE NUMBER AND SHLOULD ALWAYS EQUAL 1,2,3
C  RESPECTIVELY. THESE PARAMETERS HOWEVER HAVE NOT BEEN USED IN THIS PROGRAM.
C
C
      IF ( N .EQ. 1 ) IOLD=I
C
C  IF NEW LONGITUDE IS ENCOUNTERED, BRANCH TO WRITE OUT COMPLETED CROSS-SECTION.
C
      IF ( I .NE. IOLD) GO TO 10
    9 CONTINUE
C
      DO 7 K=1,KMAX
C
C  NOTE THAT KDATA(K)=0 MEANS THAT THIS LEVEL IS BENEATH THE OCEAN FLOOR AND
C  SO THE VALUE IN XSEC WILL RETAIN ITS VALUE = TO -1.E10 WHICH DENOTES LAND AND
C  SUB-OCEAN FLOOR GRIDPOINTS.
C
      IF ( KDATA(K) .EQ. 0 ) GO TO 7
      XSEC(J,K)=(FLOAT(KDATA(K))/RDIV)-CON
    7 CONTINUE
C
      GO TO 6
   10 CONTINUE
C
C  HAVE ENCOUNTERED A NEW LONGITUDE SO WRITE OUT PREVIOUS CROSS-SECTION TO TAPE.
C
C
C  FOR EACH MERIDIONAL SECTION THE RECORD CONTAINS THE LONGITUDE , IOLD , WHICH
C  HAS A VALUE  OF 1 TO 360 AND THE ARRAY XSEC WHICH IS THE CROSS SECTION OF
C  VALUES WITH LAND AND SUB-OCEAN FLOOR GRIDPOINTS SET EQUAL TO -1.E10 .
C
c**   WRITE(20)IOLD,XSEC
      NSEC=NSEC+1
C
C
C  PRINT CHECK VALUES
C
      JJ=60
      IF ( IOLD .EQ. 001) PRINT 37,IOLD,JJ,XSEC(JJ,5)
      JJ=145
      IF ( IOLD .EQ. 180) PRINT 37,IOLD,JJ,XSEC(JJ,26)
      JJ=95
      IF ( IOLD .EQ. 330) PRINT 37,IOLD,JJ,XSEC(JJ,19)
C
   37 FORMAT(1H0,'I= ',I3,2X,'J= ',I3,2X,'VALUE= ',F7.3)
C
C
C
      IOLD=I
C
C  INITIALIZE NEW CROSS-SECTION
C
      DO 11 jJ=1,JMAX
      DO 11 K=1,KMAX
      XSEC(Jj,K)=AMISS
   11 CONTINUE
C
C  CONTINUE PROCESSING OF NEW SECTION
C
      GO TO 9
C
    6 CONTINUE
C
C  WRITE OUT LAST CROSS-SECTION.
C
c**   WRITE(20)I,XSEC
      NSEC=NSEC+1
C
      PRINT 19,NSEC
   19 FORMAT(1H0,'NSEC= ',I4)
C
C
C  READ "END" CARD , LAST CARD IN FILE.
C
      READ(10,12)IEND
   12 FORMAT(20I4)
C
C  CHECK THAT LAST CARD-IMAGE IS THE 'END FILE' CARD.
      DO 13 N=1,20
      IF ( IEND(N) .NE. 9999)GO TO 14
   13 CONTINUE
C
      PRINT 15
   15 FORMAT(1H0,'HAVE READ LAST CARD IMAGE ON THE FILE ,CORRECT MATCH')
      GO TO 17
   14 PRINT 16
   16 FORMAT(1H0,'HAVE NOT READ FILE SUCCESSFULLY')
   17 CONTINUE
C
C
      STOP
      END
