PROGRAM LGFOR
********************************************
****** 12-31-90
********************************************
      IMPLICIT REAL*8(A-G,O-R,T-Z)
      IMPLICIT INTEGER(H-N)
      INTEGER X(100),IORDER(100)
      CHARACTER IFMT(1)*127,TITLE(1)*127,IFT(1)*127,OUTFMT(1)*127,
     &          ITMNAM(100)*8,KEYWRD*10,YESNO*10,NOYES*10,SSFILE*20
      REAL*8 N
      WRITE(*,'(A/A/A,A\)')' What is the input specification file?',
     &'  INPUT                          = 1',
     &'  or Specify different file name = 2',
     &'                            '
      READ(*,*)INKEY
      IF (INKEY .EQ. 1)THEN
         SSFILE='INPUT'
      ELSE
      WRITE(*,'(A/A\)')' Input specification file is:  ',
     &'  ===> '
      READ(*,'(A)')SSFILE
      ENDIF
      WRITE (*,'(A\)') ' File "'
      WRITE (*,'(A\)')SSFILE
      WRITE (*,'(A)') ' " will be used as the input specification file.'
      OPEN (1,FILE=SSFILE,STATUS='OLD')
      OPEN (2,FILE='LG.OUT',STATUS='NEW')
      WRITE(*,'(A/A)')'   ',
     &'  '
      WRITE(*,'(A/A/A,A\)')' What is the raw data input file?',
     &'  RAW                            = 1',
     &'  or Specify different file name = 2',
     &'                            '
      READ(*,*)INKEY
      IF (INKEY .EQ. 1)THEN
         SSFILE='RAW'
      ELSE
      WRITE(*,'(A/A\)')' Raw data input file is:  ',
     &'  ===> '
      READ(*,'(A)')SSFILE
      ENDIF
      WRITE (*,'(A\)') ' ..... File "'
      WRITE (*,'(A\)')SSFILE
      WRITE (*,'(A)') ' " is being input as the raw data file.'
      OPEN (4,FILE=SSFILE,STATUS='OLD')
   50 READ (1,'(A10)',END=65)KEYWRD
   65 IF  (KEYWRD .EQ. 'TITLE')  THEN
      READ (1,'(A127)')TITLE
      WRITE(2,'(A127)')TITLE
      GOTO 50
       ELSE IF  (KEYWRD .EQ. 'NCASES')  THEN
        READ (1,'(I4)')NCASES
        GOTO 50
       ELSE IF (KEYWRD .EQ. 'WAVES')THEN
        READ (1,'(I4)')NWAVES
        GOTO 50
       ELSE IF (KEYWRD .EQ. 'SELECT')THEN
        IYES=1
        READ (1,'(I1)')IFNUM
        GOTO 50
   70  ELSE IF (KEYWRD .EQ. 'HOWREAD') THEN
        READ (1,'(A127)',END=100)IFMT(1)
        IF (IYES .EQ. 0) IFMT(2)=IFMT(1)
        GOTO 50
  100  ELSE IF (KEYWRD .EQ. 'ITEMS')THEN
        READ (1,'(I4)')NVARS
  110   DO 120 I=1,NVARS
        READ (1,*,END=175)ITMNAM(I),IORDER(I)
  120   ICOUNT=ICOUNT+1
        DO 150 I=1,ICOUNT
        IF (ITMNAM(I) .EQ. ' ')GO TO 175
  150   CONTINUE
  175   II=I-1
        GOTO 50
       ELSE IF (KEYWRD .EQ. 'LCSMAX') THEN
        READ (1,'(A10)')YESNO
        GOTO 50
       ELSE IF (KEYWRD .EQ. 'FREQUENCY') THEN
        READ (1,'(A10)')NOYES
        GOTO 50
       ELSE IF (KEYWRD .EQ. 'END') THEN
        GOTO 185
      ENDIF
 185    IF (YESNO .EQ. 'YES') ION=1
        IF (YESNO .EQ. 'yes') ION=1
        IF (YESNO .EQ. 'Yes') ION=1
        IF (NOYES .EQ. 'YES') IION=1
        IF (NOYES .EQ. 'yes') IION=1
        IF (NOYES .EQ. 'Yes') IION=1
        WRITE(2,'(I1)')ION
        WRITE(2,'(I1)')IION
        WRITE(2,'(I4)')NVARS/NWAVES
      CLOSE(1)
  186 IF (IYES .EQ. 1)GOTO 200
  188  READ (4,IFMT(1))(X(I),I=1,NVARS)
      III=III+1
       WRITE (*,'(A)')
     & '     NREAL      NCASES      III '
       WRITE (*,'(I8,3X,I8,3X,I8)')
     & NREAL,NCASES,III
  189 DO 190 I=1,NVARS
  190  IF (X(I) .NE. 0 .AND. X(I) .NE. 1)GOTO 198
  191 DO 192 I=1,NVARS
  192 WRITE(2,'(I1\)') X(IORDER(I))
       WRITE(2,'(A)')
     & ' '
      NREAL=NREAL+1
  198  IF (X(I) .EQ. 0 .OR. X(I) .EQ. 1)GOTO 199
       WRITE (*,'(A)')
     & '     X(I)       NCASES      III '
       WRITE (*,'(I8,3X,I8,3X,I8)')
     & X(I),NCASES,III
  199 IF (III.LT.NCASES)GOTO 188
      GOTO 500
  200  READ (4,IFMT(1))(X(I),I=1,NVARS+1)
      III=III+1
       IF (X(1) .EQ. IFNUM)GOTO 220
  210 IF (III.LT.NCASES)GOTO 200
      GOTO 500
  220 DO 222 I=2,NVARS+1
  222  IF (X(I) .NE. 0 .AND. X(I) .NE. 1)GOTO 210
  290 DO 292 I=1,NVARS
  292 WRITE(2,'(I1\)') X(IORDER(I)+1)
       WRITE(2,'(A)')
     & ' '
      NREAL=NREAL+1
      IF (III.LT.NCASES)GOTO 200
  500  WRITE(2,'(A)')
     & '-'
  510  DO 520 I=1,NVARS
      WRITE(2,*) ITMNAM(IORDER(I))
  520  CONTINUE
  600 END