      SUBROUTINE MAIN
      LOGICAL*1 ARG(40), EXT(4), ARGS(256), RAT4(40), DESCR(7), SPATH(12
     *0)
      INTEGER ERRCNT, I, K, STATUS, SSPAWN, GETARG, LOCCOM
      COMMON /FLIST/ FLEVEL, FFILES(40, 25)
      INTEGER FLEVEL
      LOGICAL*1 FFILES
      COMMON / CRC / LOAD, SAVEF, RATONL, VERBOS, LIST, DEBUG
      INTEGER LOAD
      INTEGER SAVEF
      INTEGER RATONL
      INTEGER VERBOS
      INTEGER LIST
      INTEGER DEBUG
      LOGICAL*1 SUFFIX(7)
      LOGICAL*1 MINUSD(4)
      LOGICAL*1 RAT4S(7)
      LOGICAL*1 FC(3)
      LOGICAL*1 EXTF(4)
      LOGICAL*1 MINUSC(4)
      LOGICAL*1 MINUSV(4)
      LOGICAL*1 MINUSO(4)
      DATA SUFFIX(1)/46/,SUFFIX(2)/116/,SUFFIX(3)/115/,SUFFIX(4)/107/,SU
     *FFIX(5)/0/,SUFFIX(6)/10/,SUFFIX(7)/0/
      DATA MINUSD(1)/45/,MINUSD(2)/100/,MINUSD(3)/32/,MINUSD(4)/0/
      DATA RAT4S(1)/114/,RAT4S(2)/97/,RAT4S(3)/116/,RAT4S(4)/102/,RAT4S(
     *5)/111/,RAT4S(6)/114/,RAT4S(7)/0/
      DATA FC(1)/102/,FC(2)/99/,FC(3)/0/
      DATA EXTF(1)/102/,EXTF(2)/0/
      DATA MINUSC(1)/45/,MINUSC(2)/99/,MINUSC(3)/32/,MINUSC(4)/0/
      DATA MINUSV(1)/45/,MINUSV(2)/118/,MINUSV(3)/32/,MINUSV(4)/0/
      DATA MINUSO(1)/45/,MINUSO(2)/111/,MINUSO(3)/32/,MINUSO(4)/0/
      CALL QUERY(49Husage:  rc [-cdforv] [-l[libr]] [-pproc] file ...)
      LOAD = 1
      SAVEF = 0
      RATONL = 0
      VERBOS = 0
      LIST = 0
      DEBUG = 0
      ERRCNT = 0
      I=1
23000 IF (.NOT.(GETARG(I, ARG, 40) .NE. -1))GOTO 23002
      IF (.NOT.(ARG(1) .EQ. 45 .OR. ARG(1) .EQ. 43))GOTO 23003
      CALL RCCMD(ARG)
      GOTO 23004
23003 CONTINUE
      CALL FSTACK(ARG)
23004 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
      CALL IMPATH(SPATH)
      IF (.NOT.(LOCCOM(RAT4S, SPATH, SUFFIX, RAT4) .NE. 60))GOTO 23005
      CALL ERROR(32HCannot locate ratfor image file.)
23005 CONTINUE
      I=1
23007 IF (.NOT.(I .LE. FLEVEL))GOTO 23009
      CALL GETEXT(FFILES(1,I), EXT)
      IF (.NOT.(FFILES(1,I) .NE. 45 .AND. EXT(1) .EQ. 114 .AND. EXT(2) .
     *EQ. 0))GOTO 23010
      CALL GENFIL(FFILES(1,I), EXTF, ARG)
      K = 1
      CALL STCOPY(RAT4S, 1, ARGS, K)
      CALL CHCOPY(32, ARGS, K)
      CALL STCOPY(FFILES(1,I), 1, ARGS, K)
      CALL CHCOPY(32, ARGS, K)
      CALL CHCOPY(62, ARGS, K)
      CALL SCOPY(ARG, 1, ARGS, K)
      IF (.NOT.(VERBOS .EQ. 1))GOTO 23012
      CALL REMARK(ARGS)
23012 CONTINUE
      IF (.NOT.(SSPAWN(RAT4, ARGS, DESCR, 119) .EQ. -3))GOTO 23014
      ERRCNT = ERRCNT + 1
23014 CONTINUE
      K = 1
      IF (.NOT.(SAVEF .EQ. 0))GOTO 23016
      FFILES(1,I) = 62
      K = 2
23016 CONTINUE
      CALL SCOPY(ARG, 1, FFILES(1,I), K)
23010 CONTINUE
23008 I=I+1
      GOTO 23007
23009 CONTINUE
      IF (.NOT.(RATONL .EQ. 0 .AND. ERRCNT .EQ. 0))GOTO 23018
      K = 1
      CALL STCOPY(FC, 1, ARGS, K)
      CALL CHCOPY(32, ARGS, K)
      IF (.NOT.(LOAD .EQ. 0))GOTO 23020
      CALL STCOPY(MINUSC, 1, ARGS, K)
23020 CONTINUE
      IF (.NOT.(VERBOS .EQ. 1))GOTO 23022
      CALL STCOPY(MINUSV, 1, ARGS, K)
23022 CONTINUE
      IF (.NOT.(LIST .EQ. 1))GOTO 23024
      CALL STCOPY(MINUSO, 1, ARGS, K)
23024 CONTINUE
      IF (.NOT.(DEBUG .EQ. 1))GOTO 23026
      CALL STCOPY(MINUSD, 1, ARGS, K)
23026 CONTINUE
      I=1
23028 IF (.NOT.(I .LE. FLEVEL))GOTO 23030
      IF (.NOT.(FFILES(1,I) .EQ. 62))GOTO 23031
      CALL STCOPY(FFILES(1,I), 2, ARGS, K)
      GOTO 23032
23031 CONTINUE
      CALL STCOPY(FFILES(1,I), 1, ARGS, K)
23032 CONTINUE
      CALL CHCOPY(32, ARGS, K)
23029 I=I+1
      GOTO 23028
23030 CONTINUE
      ARGS(K-1) = 0
      IF (.NOT.(VERBOS .EQ. 1))GOTO 23033
      CALL REMARK(ARGS)
23033 CONTINUE
      IF (.NOT.(LOCCOM(FC, SPATH, SUFFIX, ARG) .NE. 60))GOTO 23035
      CALL ERROR(28HCannot locate fc image file.)
23035 CONTINUE
      STATUS = SSPAWN(ARG, ARGS, DESCR, 119)
      I=1
23037 IF (.NOT.(I .LE. FLEVEL))GOTO 23039
      IF (.NOT.(FFILES(1,I) .EQ. 62))GOTO 23040
      CALL REMOVE(FFILES(2,I))
23040 CONTINUE
23038 I=I+1
      GOTO 23037
23039 CONTINUE
23018 CONTINUE
      RETURN
      END
      SUBROUTINE FSTACK (IARG)
      INTEGER I
      LOGICAL*1 IARG(40)
      COMMON /FLIST/ FLEVEL, FFILES(40, 25)
      INTEGER FLEVEL
      LOGICAL*1 FFILES
      IF (.NOT.(FLEVEL .LT. 25))GOTO 23042
      FLEVEL = FLEVEL + 1
      I=1
23044 IF (.NOT.(I.LE.40))GOTO 23046
      FFILES(I,FLEVEL) = IARG(I)
23045 I=I+1
      GOTO 23044
23046 CONTINUE
      CALL FOLD(FFILES(1, FLEVEL))
23042 CONTINUE
      RETURN
      END
      SUBROUTINE GENFIL(IN, EXT, OUT)
      INTEGER I, J
      INTEGER LENGTH
      LOGICAL*1 IN(40), EXT(4), OUT(40)
      LOGICAL*1 TRMCHR(3)
      DATA TRMCHR(1)/47/,TRMCHR(2)/93/,TRMCHR(3)/0/
      I=LENGTH(IN)
23047 IF (.NOT.(I .GT. 0))GOTO 23049
      IF (.NOT.(INDEX(TRMCHR, IN(I)) .GT. 0))GOTO 23050
      GOTO 23049
23050 CONTINUE
23048 I=I-1
      GOTO 23047
23049 CONTINUE
      J=I+1
23052 IF (.NOT.(IN(J) .NE. 0))GOTO 23054
      IF (.NOT.(IN(J) .EQ. 46))GOTO 23055
      GOTO 23054
23055 CONTINUE
23053 J=J+1
      GOTO 23052
23054 CONTINUE
      I=1
23057 IF (.NOT.(I .LT. J))GOTO 23059
      OUT(I) = IN(I)
23058 I=I+1
      GOTO 23057
23059 CONTINUE
      CALL CHCOPY(46, OUT, I)
      CALL SCOPY(EXT, 1, OUT, I)
      RETURN
      END
      SUBROUTINE GETEXT(FILE, EXT)
      LOGICAL*1 FILE(40), EXT(4)
      INTEGER I, J
      INTEGER LENGTH, INDEX
      LOGICAL*1 TRMCHR(3)
      DATA TRMCHR(1)/47/,TRMCHR(2)/93/,TRMCHR(3)/0/
      I=LENGTH(FILE)
23060 IF (.NOT.(I .GT. 0))GOTO 23062
      IF (.NOT.(INDEX(TRMCHR, FILE(I)) .GT. 0))GOTO 23063
      GOTO 23062
23063 CONTINUE
23061 I=I-1
      GOTO 23060
23062 CONTINUE
      J=I+1
23065 IF (.NOT.(FILE(J) .NE. 0))GOTO 23067
      IF (.NOT.(FILE(J) .EQ. 46))GOTO 23068
      J = J + 1
      GOTO 23067
23068 CONTINUE
23066 J=J+1
      GOTO 23065
23067 CONTINUE
      I=1
23070 IF (.NOT.(FILE(J) .NE. 0 .AND. FILE(J) .NE. 59 .AND. FILE(J) .NE. 
     *46))GOTO 23072
      EXT(I) = FILE(J)
      J = J + 1
23071 I=I+1
      GOTO 23070
23072 CONTINUE
      EXT(I) = 0
      CALL FOLD(EXT)
      RETURN
      END
      SUBROUTINE RCCMD(ARG)
      LOGICAL*1 ARG(40)
      INTEGER INDEX
      COMMON / CRC / LOAD, SAVEF, RATONL, VERBOS, LIST, DEBUG
      INTEGER LOAD
      INTEGER SAVEF
      INTEGER RATONL
      INTEGER VERBOS
      INTEGER LIST
      INTEGER DEBUG
      CALL FOLD(ARG)
      IF (.NOT.(ARG(1) .EQ. 45))GOTO 23073
      IF (.NOT.(ARG(2) .EQ. 108 .OR. ARG(2) .EQ. 112))GOTO 23075
      CALL FSTACK(ARG)
      GOTO 23076
23075 CONTINUE
      IF (.NOT.(INDEX(ARG, 99) .GT. 0))GOTO 23077
      LOAD = 0
23077 CONTINUE
      IF (.NOT.(INDEX(ARG, 100) .GT. 0))GOTO 23079
      DEBUG = 1
23079 CONTINUE
      IF (.NOT.(INDEX(ARG, 102) .GT. 0))GOTO 23081
      SAVEF = 1
23081 CONTINUE
      IF (.NOT.(INDEX(ARG, 111) .GT. 0))GOTO 23083
      LIST = 1
23083 CONTINUE
      IF (.NOT.(INDEX(ARG, 114) .GT. 0))GOTO 23085
      RATONL = 1
      SAVEF = 1
23085 CONTINUE
      IF (.NOT.(INDEX(ARG, 118) .GT. 0))GOTO 23087
      VERBOS = 1
23087 CONTINUE
23076 CONTINUE
      GOTO 23074
23073 CONTINUE
      CALL BADARG(ARG)
23074 CONTINUE
      RETURN
      END
