      SUBROUTINE MAIN
      LOGICAL*1 ARG(40), EXT(4), EXTF(4), ARGS(256), MINUSC(4), MINUSV(4
     *), MINUSO(4), FC(3), RAT4S(5), RAT4(40), DESCR(7), SPATH(80)
      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 MINUSD(4)
      DATA MINUSD(1)/45/,MINUSD(2)/100/,MINUSD(3)/32/,MINUSD(4)/0/
      DATA RAT4S /114, 97, 116, 52, 0/
      DATA FC /102, 99, 0/
      DATA EXTF(1), EXTF(2)/102, 0/
      DATA MINUSC/45, 99, 32, 0/
      DATA MINUSV/45, 118, 32, 0/
      DATA MINUSO/45, 111, 32, 0/
      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 .OR. ARG(1) .EQ. 63))G
     *OTO 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, RAT4) .NE. 60))GOTO 23005
      CALL ERROR(30HCannot locate rat4 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) .E
     *Q. 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, 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 RCCMD(ARG)
      LOGICAL*1 ARG(40)
      COMMON / CRC / LOAD, SAVEF, RATONL, VERBOS, LIST, DEBUG
      INTEGER LOAD
      INTEGER SAVEF
      INTEGER RATONL
      INTEGER VERBOS
      INTEGER LIST
      INTEGER DEBUG
      IF(.NOT.(ARG(1) .EQ. 63 .AND. ARG(2) .EQ. 0))GOTO 23042
      CALL ERROR(62Husage:  rc [-c][-f][-r][-v][-o][-d][-l[libr]][-pproc
     *] file ...)
      GOTO 23043
23042 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. (ARG(2) .EQ. 99 .OR. ARG(2) .EQ. 67)
     *))GOTO 23044
      LOAD = 0
      GOTO 23045
23044 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. (ARG(2) .EQ. 102 .OR. ARG(2) .EQ. 70
     *)))GOTO 23046
      SAVEF = 1
      GOTO 23047
23046 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. (ARG(2) .EQ. 114 .OR. ARG(2) .EQ. 82
     *)))GOTO 23048
      RATONL = 1
      SAVEF = 1
      GOTO 23049
23048 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. (ARG(2) .EQ. 118 .OR. ARG(2) .EQ. 86
     *)))GOTO 23050
      VERBOS = 1
      GOTO 23051
23050 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. (ARG(2) .EQ. 111 .OR. ARG(2) .EQ. 79
     *)))GOTO 23052
      LIST = 1
      GOTO 23053
23052 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. (ARG(2) .EQ. 100 .OR. ARG(2) .EQ. 68
     *)))GOTO 23054
      DEBUG = 1
      GOTO 23055
23054 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. (ARG(2) .EQ. 108 .OR. ARG(2) .EQ. 76
     * .OR. ARG(2) .EQ. 112 .OR. ARG(2) .EQ. 80)))GOTO 23056
      CALL FSTACK(ARG)
      GOTO 23057
23056 CONTINUE
      CALL REMARK(25HIgnoring invalid argument)
23057 CONTINUE
23055 CONTINUE
23053 CONTINUE
23051 CONTINUE
23049 CONTINUE
23047 CONTINUE
23045 CONTINUE
23043 CONTINUE
      RETURN
      END
      SUBROUTINE GENFIL(IN, EXT, OUT)
      INTEGER I, J
      LOGICAL*1 IN(40), EXT(4), OUT(40)
      I=1
23058 IF(.NOT.(IN(I) .NE. 46 .AND. IN(I) .NE. 0))GOTO 23060
      OUT(I) = IN(I)
23059 I=I+1
      GOTO 23058
23060 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
      I=1
23061 IF(.NOT.(FILE(I) .NE. 46 .AND. FILE(I) .NE. 0))GOTO 23063
23062 I=I+1
      GOTO 23061
23063 CONTINUE
      IF(.NOT.(FILE(I) .EQ. 46))GOTO 23064
      I = I + 1
23064 CONTINUE
      J=1
23066 IF(.NOT.(FILE(I) .NE. 0 .AND. FILE(I) .NE. 59 .AND. FILE(I) .NE. 4
     *6))GOTO 23068
      EXT(J) = FILE(I)
      I = I + 1
23067 J=J+1
      GOTO 23066
23068 CONTINUE
      EXT(J) = 0
      CALL FOLD(EXT)
      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 23069
      FLEVEL = FLEVEL + 1
      I=1
23071 IF(.NOT.(I.LE.40))GOTO 23073
      FFILES(I,FLEVEL) = IARG(I)
23072 I=I+1
      GOTO 23071
23073 CONTINUE
      CALL FOLD(FFILES(1, FLEVEL))
23069 CONTINUE
      RETURN
      END
