CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C
C  NAME : READUMP_WINDII_L3TP_DATA.F
C
C  USAGE : THIS PROGRAM READS UARS LEVEL 3TP WINDII DATA FILES DISTRIBUTED 
C          FROM THE GSFC DAAC.  TO RUN THIS PROGRAM, TYPE IN THE PROGRAM 
C          NAME. THE PROGRAM WILL PROMPT YOU FOR THE METADATA FILE NAME
C          (*MERA EXTENSION).
C          EXAMPLE: READUMP_WINDII_L3TP_DATA 
C                   PLEASE ENTER MATA DATA FILE NAME BELLOW :
C                   WINDII_L3TP_SPARAM_L3TP_D0030.V0001_C01_META
C
C  DESCRIPTION : THIS PROGRAM FIRST OPENS THE METADATA FILE (*.*META) 
C                TO GET THE DATA FILE NAME (*.*PROD), AND ITS PHYSICAL 
C                RECORD SIZE.  THE DATA FILE IS THEN OPENED, AND ITS
C                CONTENTS ARE READ AND DUMPED TO THE SCREEN.
C
C  AUTHOR : KE - JUN SUN   HUGHES_STX
C
C  DATE : FEBRUARY 2, 1994
C
C  LIMITATIONS : THIS PROGRAM AND THE DATA IT READS ARE DESIGNED FOR 
C              MACHINES RUNNING A UNIX OPERATING SYSTEM, AND HAVING  
C              32-BIT ARCHITECTURE. IEEE FLOATING POINT AND/OR INTEGER  
C              VALUES WILL NOT TRANSLATE CORRECTLY ON OTHER MACHINES!
C
C  NOTES : SINCE THIS PROGRAM USES THE METADATA FILE (*.*META) TO GET 
C          THE DATA FILE NAME (*.*PROD) AND RECORD SIZE, BOTH THE DATA 
C          FILE AND ITS CORRESPONDING METADATA FILE MUST BE IN THE SAME 
C          DIRECTORY.
C          NAGWare (nag_decs and nag_pfort) AND ftnchek WERE USED
C          ON THIS PROGRAM TO ENHANCE NETWORK PORTABILITY.
C
C  ALGORITHM INFORMATION : NO CALCULATION IS PERFORMED IN THIS PROGRAM.
C
C  VERSION : 0
C
C
C  TO COMPILE THIS PROGAM :
C         f77 -o READUMP_WINDII_L3TP_DATA READUMP_WINDII_L3TP_DATA.F
C       or for SUN machines
C         f77 -DSUNF -o READUMP_WINDII_L3TP_DATA READUMP_WINDII_L3TP_DATA.F
C     EXECUTABLE CODE WILL BE NAMED READUMP_WINDII_L3TP_DATA
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

C     .. Parameters ..
      INTEGER MAXDAT
      PARAMETER (MAXDAT=17)
C     ..
C     .. Local Scalars ..
      CHARACTER HDR*28,DATAFN*170,METAFN*170,LINE*255,NREC*8
      CHARACTER JOBVSN*8,CDBVSN*8,SPARE*8
      INTEGER ACTUAL,I,IOSTT,IREC,IROW,K,NUMBPR,RECSIZ,RLEN,START,TOTAL
      INTEGER PHYREC, NUMREC
      INTEGER*2 TWOBYT1,TWOBYT2,SWP
      REAL LAT,LON
C     ..
C     .. Local Arrays ..
      CHARACTER BLANK(60),BUFFER(232)
      INTEGER TIME(2)

      DO 661 I = 1,170
       DATAFN(I:I) = ' '
 661  CONTINUE

C
C     ** REMOVE THE C-COMMENT BELOW IF USING PROGRAM OUT OF SCRIPT
C     PRINT *,' PLEASE ENTER META DATA FILE NAME BELOW: '
      READ (5,FMT='(A)') METAFN

      OPEN (UNIT=20,FILE=METAFN,STATUS='OLD',ERR=991)

C   SKIP 9 LINES IN META FILE

      DO 111 IROW = 1,9
          READ (20,FMT=50) LINE
  111 CONTINUE

C   GET FILE NAME FROM 10TH LINE OR FROM META DATA FILE NAME

      READ (20,FMT=50) LINE
C      DO 112 I = 1,70
C          DATAFN(I:I) = LINE(14+I:14+I)
C  112 CONTINUE

      I = 1
      DO 777 WHILE (METAFN(I:I).NE.' ')
       I = I + 1
 777  CONTINUE
      I = I - 4
      DO 888 K = 1,I
        DATAFN(K:K) = METAFN(K:K)
 888  CONTINUE
      DATAFN(I:I+4) = 'PROD'

C   SKIP ONE LINE

      READ (20,FMT=50) LINE

C   GET RECORD SIZE

      READ (20,FMT=50) LINE
   50 FORMAT (A80)

      READ (LINE(17:19),FMT=333) RECSIZ
  333 FORMAT (I3)

C   CLOSE META FILE

      CLOSE (20)

C----------------------------------------------------------
C  NOTE: SGI AND HP READ 4 BYTE WORDS, SUN READS 1 BYTE.
C        ADDED BY JAMES JOHNSON 09/27/94.                  
C----------------------------------------------------------
#ifndef SUNF
      RLEN=RECSIZ/4
#endif
#ifdef SUNF
      RLEN=RECSIZ
#endif

      OPEN (UNIT=10,FILE=DATAFN,STATUS='OLD',ERR=992,FORM='UNFORMATTED',
     +     ACCESS='DIRECT',RECL=RLEN)

      PRINT *,'********************************************'
      PRINT *,' READING   ',DATAFN
      PRINT *,'********************************************'
      READ (10,REC=1,IOSTAT=IOSTT,ERR=993) (BUFFER(K),K=1,RECSIZ)
      WRITE (6,FMT=*) '  DESCRIPTOR RECORD'
      WRITE (6,FMT=*) '-------------------------------'
      WRITE (6,FMT=*) ' SFDU T(Z) AND L(Z) '
      WRITE (6,FMT=*) '-------------------------------'
      WRITE (6,FMT=*) ' CONTROL ID : ', (BUFFER(K),K=1,4)
      WRITE (6,FMT=*) ' VERSION ID : ',BUFFER(5)
      WRITE (6,FMT=*) ' CLASS ID   : ',BUFFER(6)
      WRITE (6,FMT=*) ' DATA DESCRIPTIVE RECORDRD ID : ',
     +  (BUFFER(K),K=9,12)
      WRITE (6,FMT=*) ' LENGTH : ', (BUFFER(K),K=13,20)
      WRITE (6,FMT=*) '-------------------------------'
      WRITE (6,FMT=*) ' SFDU T(I) AND L(I) '
      WRITE (6,FMT=*) '-------------------------------'
      WRITE (6,FMT=*) ' CONTROL ID : ', (BUFFER(K),K=21,24)
      WRITE (6,FMT=*) ' VERSION ID : ',BUFFER(25)
      WRITE (6,FMT=*) ' CLASS ID   : ',BUFFER(26)
      WRITE (6,FMT=*) ' DATA DESCRIPTIVE RECORDRD ID : ',
     +  (BUFFER(K),K=29,32)
      WRITE (6,FMT=*) ' LENGTH : ', (BUFFER(K),K=33,40)
      READ (10,REC=2,IOSTAT=IOSTT,ERR=994) (BUFFER(K),K=1,RECSIZ)
      WRITE (6,FMT=*) '-------------------------------'
      WRITE (6,FMT=*) ' REC NUMBER 2  LABEL RECORD'
      WRITE (6,FMT=*) '-------------------------------'
      WRITE (6,FMT=*) ' SATELLITE ID : ', (BUFFER(K),K=1,4)
      WRITE (6,FMT=*) ' RECORD TYPE  : ', (BUFFER(K),K=5,6)
      WRITE (6,FMT=*) ' INSTRUMENT ID : ', (BUFFER(K),K=7,18)
      WRITE (6,FMT=*) ' DATA SUBTYPE OR SPECIES : ', (BUFFER(K),K=19,30)
      WRITE (6,FMT=*) ' FORMAT VERSION NUMBER   : ', (BUFFER(K),K=31,34)
      WRITE (6,FMT=*) ' PHYSICAL RECORDRD COUNT   : ',
     +  (BUFFER(K),K=35,42)
      WRITE (6,FMT=*)
     +  ' NUMBER OF CONTINUATION RECORDRDS FOR FILE LABEL : ',
     +  (BUFFER(K),K=43,46)
      DO 112 I = 1,8
        NREC(I:I) = BUFFER(I+46)
 112  CONTINUE
      READ(NREC(1:8),FMT=321)NUMREC
 321  FORMAT(I8)
      WRITE (6,FMT=*) ' NUMBER OF PHYSICAL RECORDRDS IN FILE : ',NUMREC
      WRITE (6,FMT=*) ' FILE CREATION TIME : ', (BUFFER(K),K=55,77)
      WRITE (6,FMT=*) ' YEAR FOR 1ST DATA RECORD       : ',
     +  (BUFFER(K),K=78,80)
      WRITE (6,FMT=*) ' DAY OF YEAR OF 1ST DATA RECORD : ',
     +  (BUFFER(K),K=81,83)
      WRITE (6,FMT=*) ' MS OF DAY FOR 1ST DATA RECORD : ',
     +  (BUFFER(K),K=84,91)
      WRITE (6,FMT=*) ' YEAR FOR LAST DATA RECORD       : ',
     +  (BUFFER(K),K=92,94)
      WRITE (6,FMT=*) ' DAY OF YEAR OF LAST DATA RECORD : ',
     +  (BUFFER(K),K=95,97)
      WRITE (6,FMT=*) ' MS OF DAY FOR LAST DATA RECORD : ',
     +  (BUFFER(K),K=98,105)
      WRITE (6,FMT=*) ' DATA LEVEL      : ', (BUFFER(K),K=106,108)
      WRITE (6,FMT=*) ' UARS DAY NUMBER : ', (BUFFER(K),K=109,112)
      WRITE (6,FMT=*) ' NUMBER OF 32-BIT WORDS : ',
     +  (BUFFER(K),K=113,116)
C      WRITE(6,*)' BASE INDEX OF DATA POINT VALUE : ',
C     &(BUFFER(K),K=117,120)
      WRITE (6,FMT=*) ' RECORD LENGTH IN BYTES : ',
     +  (BUFFER(K),K=121,125)
      WRITE (6,FMT=*) ' CCB VERSION NUMBER     : ',
     +  (BUFFER(K),K=126,134)
      WRITE (6,FMT=*) ' FILE CYCLE NUMBER      : ',
     +  (BUFFER(K),K=135,139)
      WRITE (6,FMT=*) ' VITUAL FILE FLAG       : ',BUFFER(140)
      WRITE (6,FMT=*) ' TOTAL NUMBER OF TIME/VERSION ENTRIES IN FILE : '
     +  , (BUFFER(K),K=141,144)
      WRITE (6,FMT=*) ' NUMBER OF TIME/VERSION ENTRIES IN RECORD : ',
     +  (BUFFER(K),K=145,148)

      IREC = 2
      DO 456  PHYREC = 1, (NUMREC - 1)

C----------------------------------------------------------
C  NOTE: SGI AND HP USE ERR OPTION, SUN USES END INSTEAD
C        ADDED BY JAMES JOHNSON 09/27/94.                 
C----------------------------------------------------------
#ifdef SUNF
      READ (10,REC=IREC+1,IOSTAT=IOSTT,END=900) HDR,TOTAL,ACTUAL,START,
     +  TIME,LAT,LON,SPARE,NUMBPR,JOBVSN,CDBVSN,TWOBYT1,TWOBYT2,BLANK
#endif
#ifndef SUNF
      READ (10,REC=IREC+1,IOSTAT=IOSTT,ERR=900) HDR,TOTAL,ACTUAL,START,
     +  TIME,LAT,LON,SPARE,NUMBPR,JOBVSN,CDBVSN,TWOBYT1,TWOBYT2,BLANK
#endif

      WRITE (6,FMT=*) '---------------------------------------------'
      WRITE (6,FMT=*) ' RECORD NUMBER ',IREC,'   DATA RECORD'
      WRITE (6,FMT=*) '---------------------------------------------'
      WRITE (6,FMT=*) ' SATELLITE ID  : ',HDR(1:4)
      WRITE (6,FMT=*) ' RECOORD TYPE  : ',HDR(5:6)
      WRITE (6,FMT=*) ' INSTRUMENT ID : ',HDR(7:18)
      WRITE (6,FMT=*) ' PHYSICAL RECORD COUNT : ',HDR(19:26)
      WRITE (6,FMT=*) ' MAXIMUM NUMBER 32-BIT WORDS IN RECORD   : ',
     +  TOTAL
      WRITE (6,FMT=222) TIME(1),TIME(2)
  222 FORMAT ('  RECORD TIME IN UDTF FORMAT: ',I10,I10,
     +       ' (YEAR DAY, MILLISECONDS)')
      WRITE (6,FMT=*) ' LATITUDE  : ',LAT
      WRITE (6,FMT=*) ' LONGITUDE : ',LON
      WRITE (6,FMT=*) ' NUMB. OF 32-BIT PARAMETER WORDS : ',NUMBPR

      WRITE (6,FMT=*) ' JOB VERSION :',JOBVSN
      WRITE (6,FMT=*) ' CDB VERSION :',CDBVSN

      SWP = TWOBYT1/2**8
      WRITE (6,FMT=*) ' FLAG QUANTITY :',SWP

      SWP = TWOBYT1 * 2**8
      SWP = SWP / 2**8
      WRITE (6,FMT=*) ' FILTER NUMBER :',SWP

      SWP = TWOBYT2/2**8
      WRITE (6,FMT=*) ' QUALITY       :',SWP

      IREC = IREC + 1

  456 CONTINUE

  900 WRITE (6,FMT=*) ' END OF DATA'
      GO TO 999
  991 WRITE (6,FMT=*) ' CAN NOT OPEN META DATA FILE. '
      GO TO 999
  992 WRITE (6,FMT=*) ' CAN NOT OPEN DATA PRODUCT FILE. '
      GO TO 999
  993 WRITE (6,FMT=*) ' ERROR IN READING 1ST RECORDRD. ERROR CODE : ',
     +  IOSTT
      GO TO 999
  994 WRITE (6,FMT=*) ' ERROR IN READING 2ND RECORDRD. ERROR CODE : ',
     +  IOSTT
      GO TO 999

  999 CLOSE (10)
      CONTINUE
      STOP
      END
