      SUBROUTINE FORDF (XFIL,PVVA,PIFN,PXFN,PVFN,MAXVQD,VQD,
     1                  QC,FC,FCOFS,OFS,IERR)
      INTEGER XFIL
      INTEGER PVVA,PIFN,PXFN,PVFN
      INTEGER MAXVQD
      INTEGER VQD(MAXVQD,5)
      INTEGER QC,FC,FCOFS,OFS
      INTEGER IERR
C
      INTEGER ADD,SUB,MULT,DIV,POWER
      INTEGER INUM,RNUM,SUM,PROD
      INTEGER STDRD,EXTERN,REAL,INT
      INTEGER CONINT,LININT,SPLINE,VAR,FUNC
      INTEGER UMINUS,INDVAR,ENDSUM,ENDPRD,VECTOR,ACTIVE
      PARAMETER (ADD=43,SUB=45,MULT=42,DIV=47,POWER=94)
      PARAMETER (INUM=262,RNUM=263)
      PARAMETER (SUM=265,PROD=266)
      PARAMETER (STDRD=272,EXTERN=273)
      PARAMETER (REAL=277,INT=278,CONINT=280)
      PARAMETER (LININT=281,SPLINE=282,VAR=283,FUNC=285)
      PARAMETER (UMINUS=290)
      PARAMETER (INDVAR=291,ENDSUM=292,ENDPRD=293)
      PARAMETER (VECTOR=297,ACTIVE=298)
C
      INTEGER MAXEXT
      PARAMETER (MAXEXT=1)
C
      INTEGER EXTTYP(MAXEXT)
C
      CHARACTER*30 S1,S2,S3,S4,S5,S6,S7,S8
      INTEGER SLEN1,SLEN2,SLEN3,SLEN4,SLEN5,SLEN6,SLEN7,SLEN8
C
      INTEGER EXT,X,Y
C
      DATA EXTTYP /0/
C
      X=VQD(QC,1)
      IF (X .EQ. VAR) THEN
        IF (FC .LT. 0) THEN
          CALL MAKEP(FCOFS,-FC,S1,SLEN1)
        ELSE
          CALL ITOA(FC,S1,SLEN1)
        ENDIF
        CALL ITOA(VQD(QC,4),S2,SLEN2)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,FC,VQD(QC,5),FCOFS,S3,SLEN3)
        IF (OFS .GT. 0) CALL STRCT(S2,SLEN2,'+IOFS',5)
        IF (FC .LE. PVFN-(PIFN-PXFN)) THEN
          WRITE(XFIL,'(6X,A)') 'DF('//S1(1:SLEN1)//',IAUX('//
     1              S2(1:SLEN2)//'))=DF('//S1(1:SLEN1)//',IAUX('//
     2              S2(1:SLEN2)//'))+'//S3(1:SLEN3)
        ELSE
          WRITE(XFIL,'(6X,A)') 'VGRAD('//S1(1:SLEN1)//',IAUX('//
     1              S2(1:SLEN2)//'))=VGRAD('//S1(1:SLEN1)//',IAUX('//
     1              S2(1:SLEN2)//'))+'//S3(1:SLEN3)
        ENDIF
        RETURN
C 
      ELSE IF (X .EQ. ADD) THEN
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S2,SLEN2)
        WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='
     1            //S1(1:SLEN1)//'+'//S2(1:SLEN2)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,4),FCOFS,S1,SLEN1)
        WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='
     1            //S1(1:SLEN1)//'+'//S2(1:SLEN2)
        RETURN  
C
      ELSE IF (X .EQ. SUB) THEN
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S2,SLEN2)
        WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='
     1            //S1(1:SLEN1)//'+'//S2(1:SLEN2)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,4),FCOFS,S1,SLEN1)
        WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='
     1            //S1(1:SLEN1)//'-'//S2(1:SLEN2)
        RETURN  
C
      ELSE IF (X .EQ. MULT) THEN
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
        CALL MAKEX(PVVA,OFS,VQD(QC,4),S2,SLEN2)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
        WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S2(1:SLEN2)//'*'//S3(1:SLEN3)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,4),FCOFS,S1,SLEN1)
        CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
        WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S2(1:SLEN2)//'*'//S3(1:SLEN3)
        RETURN  
C
      ELSE IF (X .EQ. DIV) THEN
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S2,SLEN2)
        CALL MAKEX(PVVA,OFS,VQD(QC,4),S3,SLEN3)
        WRITE(XFIL,'(6X,A)') 'IF ('//S3(1:SLEN3)//' .EQ. 0.0D0) THEN'
        WRITE(XFIL,'(6X,A)') 'IERR=9'
        WRITE(XFIL,'(6X,A)') 'RETURN'
        WRITE(XFIL,'(6X,A)') 'ENDIF'
        WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S2(1:SLEN2)//'/'//S3(1:SLEN3)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,4),FCOFS,S1,SLEN1)
        CALL MAKEX(PVVA,OFS,VQD(QC,3),S3,SLEN3)
        CALL MAKEX(PVVA,OFS,VQD(QC,4),S4,SLEN4)
        CALL FOLD(XFIL,S1(1:SLEN1)//'='//S1(1:SLEN1)//'-'
     1            //S2(1:SLEN2)//'*'//S3(1:SLEN3)
     2            //'/'//S4(1:SLEN4)//'**2',
     3            2*SLEN1+SLEN2+SLEN3+SLEN4+7,IERR)
        RETURN
C
      ELSE IF (X .EQ. POWER) THEN
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
        CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
        CALL MAKEX(PVVA,OFS,VQD(QC,4),S3,SLEN3)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S4,SLEN4)
        WRITE(XFIL,'(6X,A)') 'IF ('//S2(1:SLEN2)
     1                         //' .LE. 0.0D0) THEN'
        WRITE(XFIL,'(6X,A)') 'IERR=9'
        WRITE(XFIL,'(6X,A)') 'RETURN'
        WRITE(XFIL,'(6X,A)') 'ENDIF'
        CALL FOLD(XFIL,S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'//S3(1:SLEN3)
     1         //'*'//S2(1:SLEN2)//'**('//S3(1:SLEN3)//'-1.0D0)*'
     2          //S4(1:SLEN4),2*SLEN1+SLEN2+2*SLEN3+SLEN4+14,IERR) 
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,4),FCOFS,S1,SLEN1)
        CALL FOLD(XFIL,S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'//S2(1:SLEN2)
     1          //'**'//S3(1:SLEN3)//'*'//'DLOG('//S2(1:SLEN2)
     2          //')*'//S4(1:SLEN4),2*SLEN1+2*SLEN2+SLEN3+SLEN4+12,IERR)
        RETURN
C
      ELSE IF (X .EQ. POWER+128) THEN
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
        CALL ITOA(VQD(QC,2),S2,SLEN2)
        CALL MAKEX(PVVA,OFS,VQD(QC,3),S3,SLEN3)
        CALL ITOA(VQD(QC,2)-1,S4,SLEN4)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S5,SLEN5)
        IF (VQD(QC,2) .GT. 1) THEN
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S2(1:SLEN2)//'*'//S3(1:SLEN3)//'**'
     2            //S4(1:SLEN4)//'*'//S5(1:SLEN5)
        ELSE IF (VQD(QC,2) .EQ. 1) THEN
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1              //S2(1:SLEN2)//'*'//S5(1:SLEN5)
        ELSE
          WRITE(XFIL,'(6X,A)') 'IF ('//S3(1:SLEN3)
     1                         //' .EQ. 0.0D0) THEN'
          WRITE(XFIL,'(6X,A)') 'IERR=9'
          WRITE(XFIL,'(6X,A)') 'RETURN'
          WRITE(XFIL,'(6X,A)') 'ENDIF'
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1               //'('//S2(1:SLEN2)//')'//'*'//S3(1:SLEN3)//'**'
     2               //'('//S4(1:SLEN4)//')'//'*'//S5(1:SLEN5)
        ENDIF
        RETURN
C
      ELSE IF (X .EQ. UMINUS) THEN
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S2,SLEN2)
        WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'-'
     1            //S2(1:SLEN2)
        RETURN
C
      ELSE IF ((X .EQ. RNUM) .OR. (X .EQ. REAL)) THEN
        RETURN
C
      ELSE IF ((X .EQ. INUM) .OR. (X .EQ. INT)) THEN
        RETURN
C
      ELSE IF (X .EQ. INDVAR) THEN
        RETURN
C
      ELSE IF (X .EQ. INUM+128) THEN
        RETURN
C
      ELSE IF (X .EQ. ADD+128) THEN
        RETURN
C
      ELSE IF (X .EQ. SUB+128) THEN
        RETURN
C
      ELSE IF (X .EQ. MULT+128) THEN
        RETURN
C
      ELSE IF (X .EQ. DIV+128) THEN
        RETURN
C
      ELSE IF (X .EQ. UMINUS+128) THEN
        RETURN
C
      ELSE IF (X .EQ. FUNC+128) THEN
        RETURN
C
      ELSE IF (X .EQ. INDVAR+128) THEN
        RETURN
C
      ELSE IF (X .EQ. FUNC) THEN
        CALL ITOA(QC,S1,SLEN1)
        CALL ITOA(PVVA,S2,SLEN2)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,FC,1,FCOFS,S3,SLEN3)
        S3=S3(1:SLEN3-3)//',I)'
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,FC,VQD(QC,5),FCOFS,S5,SLEN5)
        IF (VQD(QC,3) .GT. 0) THEN
          CALL MAKEI(OFS,VQD(QC,4),S4,SLEN4)
C
          IF (FC .GT. 0) THEN
            CALL ITOA(FC,S6,SLEN6)
          ELSE
            CALL MAKEP(FCOFS,-FC,S6,SLEN6)
          ENDIF
          S7='DF('//S4(1:SLEN4)//',I)'
          SLEN7=3+SLEN4+3
          IF (S3 .EQ. S7) THEN
            WRITE(XFIL,'(6X,A)') 'DO '//S1(1:SLEN1)//' I=1,'//
     1                            S2(1:SLEN2)
            WRITE(XFIL,'(6X,A)') S3(1:SLEN3)//'='//S3(1:SLEN3)//'+'
     1                //'DFHELP(I)*'//S5(1:SLEN5)
            WRITE(XFIL,'(I5,1X,A)') QC,'CONTINUE'
          ELSE
            IF ((FCOFS .EQ. VQD(QC,2)) .AND. (VQD(QC,4) .NE. 0)) THEN
              WRITE(XFIL,'(6X,A)') 'DO '//S1(1:SLEN1)//' I=1,'//
     1                              S2(1:SLEN2)
              WRITE(XFIL,'(6X,A)') 'IF ('//S6(1:SLEN6)//' .NE. '//
     1                              S4(1:SLEN4)//') THEN'
              WRITE(XFIL,'(6X,A)') 'DFHELP(I)=DF('//S4(1:SLEN4)//',I)'
              WRITE(XFIL,'(6X,A)') 'ENDIF'
              WRITE(XFIL,'(6X,A)') S3(1:SLEN3)//'='//S3(1:SLEN3)//'+'
     1                  //'DFHELP(I)*'//S5(1:SLEN5)
              WRITE(XFIL,'(I5,1X,A)') QC,'CONTINUE'
            ELSE
              WRITE(XFIL,'(6X,A)') 'DO '//S1(1:SLEN1)//' I=1,'//
     1                              S2(1:SLEN2)
              WRITE(XFIL,'(6X,A)') S3(1:SLEN3)//'='//S3(1:SLEN3)//'+'
     1                  //'DF('//S4(1:SLEN4)//',I)*'//S5(1:SLEN5)
              WRITE(XFIL,'(I5,1X,A)') QC,'CONTINUE'
            ENDIF
          ENDIF
C
          RETURN
        ELSE IF (VQD(QC,3) .EQ. 0) THEN
          CALL ITOA(VQD(QC,2),S4,SLEN4)
C
          IF (FC .GT. 0) THEN
            CALL ITOA(FC,S6,SLEN6)
          ELSE
            CALL MAKEP(FCOFS,-FC,S6,SLEN6)
          ENDIF
C
          S7='DF('//S4(1:SLEN4)//',I)'
          SLEN7=3+SLEN4+3
          IF (S3 .EQ. S7) THEN
            WRITE(XFIL,'(6X,A)') 'DO '//S1(1:SLEN1)//' I=1,'//
     1                            S2(1:SLEN2)
            WRITE(XFIL,'(6X,A)') S3(1:SLEN3)//'='//S3(1:SLEN3)//'+'
     1                //'DFHELP(I)*'//S5(1:SLEN5)
            WRITE(XFIL,'(I5,1X,A)') QC,'CONTINUE'
          ELSE
            WRITE(XFIL,'(6X,A)') 'DO '//S1(1:SLEN1)//' I=1,'//
     1                            S2(1:SLEN2)
            WRITE(XFIL,'(6X,A)') S3(1:SLEN3)//'='//S3(1:SLEN3)//'+'
     1                //'DF('//S4(1:SLEN4)//',I)*'//S5(1:SLEN5)
            WRITE(XFIL,'(I5,1X,A)') QC,'CONTINUE'
          ENDIF
          RETURN 
        ELSE IF (VQD(QC,3) .EQ. -1) THEN
          CALL ITOA(VQD(QC,2),S4,SLEN4)
C
          IF (FC .GT. 0) THEN
            CALL ITOA(FC,S6,SLEN6)
          ELSE
            CALL MAKEP(FCOFS,-FC,S6,SLEN6)
          ENDIF
          S7='VGRAD('//S4(1:SLEN4)//',I)'
          SLEN7=6+SLEN4+3
          IF (S3 .EQ. S7) THEN
            WRITE(XFIL,'(6X,A)') 'DO '//S1(1:SLEN1)//' I=1,'//
     1                           S2(1:SLEN2)
            WRITE(XFIL,'(6X,A)') S3(1:SLEN3)//'='//S3(1:SLEN3)//'+'
     1                //'DFHELP(I)*'//S5(1:SLEN5)
            WRITE(XFIL,'(I5,1X,A)') QC,'CONTINUE'
          ELSE
            WRITE(XFIL,'(6X,A)') 'DO '//S1(1:SLEN1)//' I=1,'//
     1                           S2(1:SLEN2)
            WRITE(XFIL,'(6X,A)') S3(1:SLEN3)//'='//S3(1:SLEN3)//'+'
     1                //'VGRAD('//S4(1:SLEN4)//',I)*'//S5(1:SLEN5)
            WRITE(XFIL,'(I5,1X,A)') QC,'CONTINUE'
          ENDIF
          RETURN
        ELSE
          RETURN
        ENDIF
C-----------------------------------------------------------------
      ELSE IF ((X .EQ. SUM+128) .OR. (X .EQ. PROD+128)) THEN
        RETURN
C
      ELSE IF ((X .EQ. SUM) .OR. (X .EQ. PROD)) THEN
        OFS=OFS-1
        WRITE(XFIL,'(I5,1X,A)') QC,'CONTINUE' 
        RETURN
C
      ELSE IF ((X .EQ. ENDSUM) .OR. (X .EQ. ENDPRD)) THEN
        OFS=OFS+1
        CALL ITOA(VQD(QC,2)*VQD(VQD(QC,5),3),S1,SLEN1)
        CALL ITOA(VQD(VQD(QC,5),2)-1,S2,SLEN2)
        CALL ITOA(VQD(VQD(QC,5),3)-1,S3,SLEN3)
        CALL ITOA(VQD(VQD(QC,5),4),S4,SLEN4)
        CALL ITOA(VQD(QC,5),S5,SLEN5)
        CALL ITOA(VQD(QC,2),S6,SLEN6)
        WRITE(XFIL,'(6X,A)') 'OFS=OFS+'//S1(1:SLEN1)
C
        CALL ITOA(VQD(QC,3)*VQD(VQD(QC,5),3),S7,SLEN7)
        CALL ITOA(VQD(QC,3),S8,SLEN8)
        WRITE(XFIL,'(6X,A)') 'IOFS=IOFS+'//S7(1:SLEN7)
C
        WRITE(XFIL,'(6X,A)') 'DO '//S5(1:SLEN5)//' I'//S2(1:SLEN2)//
     1                     '='//S3(1:SLEN3)//',0,-1'
        WRITE(XFIL,'(6X,A)') 'IX'//S2(1:SLEN2)//'=VINDEX('//
     1                     S4(1:SLEN4)//'+I'//S2(1:SLEN2)//')'
        WRITE(XFIL,'(6X,A)') 'OFS=OFS-'//S6(1:SLEN6)
C
        WRITE(XFIL,'(6X,A)') 'IOFS=IOFS-'//S8(1:SLEN8)
C
        RETURN
C-----------------------------------------------------------------
      ELSE IF (X .EQ. STDRD) THEN
        Y=VQD(QC,2)
        IF (Y .EQ. 1) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //'DSIGN(1.0D0,'//S2(1:SLEN2)//')*'//S3(1:SLEN3) 
          RETURN
        ELSE IF (Y .EQ. 2) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') 'IF ('//S2(1:SLEN2)
     1                         //' .LT. 0.0D0) THEN'
          WRITE(XFIL,'(6X,A)') 'IERR=53'
          WRITE(XFIL,'(6X,A)') 'RETURN'
          WRITE(XFIL,'(6X,A)') 'ELSE IF ('//S2(1:SLEN2)
     1                         //' .EQ. 0.0D0) THEN'
          WRITE(XFIL,'(6X,A)') 'IERR=9'
          WRITE(XFIL,'(6X,A)') 'RETURN'
          WRITE(XFIL,'(6X,A)') 'ENDIF'
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //'0.5D0/DSQRT('//S2(1:SLEN2)//')*'//S3(1:SLEN3) 
          RETURN
        ELSE IF (Y .EQ. 3) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //'DEXP('//S2(1:SLEN2)//')*'//S3(1:SLEN3) 
          RETURN
        ELSE IF (Y .EQ. 4) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') 'IF ('//S2(1:SLEN2)
     1                         //' .LE. 0.0D0) THEN'
          WRITE(XFIL,'(6X,A)') 'IERR=52'
          WRITE(XFIL,'(6X,A)') 'RETURN'
          WRITE(XFIL,'(6X,A)') 'ENDIF'
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S3(1:SLEN3)//'/'//S2(1:SLEN2) 
          RETURN
        ELSE IF (Y .EQ. 5) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') 'IF ('//S2(1:SLEN2)
     1                         //' .LE. 0.0D0) THEN'
          WRITE(XFIL,'(6X,A)') 'IERR=52'
          WRITE(XFIL,'(6X,A)') 'RETURN'
          WRITE(XFIL,'(6X,A)') 'ENDIF'
          CALL FOLD(XFIL,S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'//S3(1:SLEN3)
     1          //'/('//S2(1:SLEN2)//'*DLOG(10.0D0))',2*SLEN1+SLEN2
     2          +SLEN3+18,IERR)
          RETURN
        ELSE IF (Y .EQ. 6) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //'DCOS('//S2(1:SLEN2)//')*'//S3(1:SLEN3) 
          RETURN
        ELSE IF (Y .EQ. 7) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'-'
     1            //'DSIN('//S2(1:SLEN2)//')*'//S3(1:SLEN3) 
          RETURN
        ELSE IF (Y .EQ. 8) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S3(1:SLEN3)//'/DCOS('//S2(1:SLEN2)//')**2'
          RETURN
        ELSE IF (Y .EQ. 9) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') 'IF (DABS('//S2(1:SLEN2)//
     1                            ') .GE. 1.0D0) THEN'
          WRITE(XFIL,'(6X,A)') 'IERR = 54'
          WRITE(XFIL,'(6X,A)') 'RETURN'
          WRITE(XFIL,'(6X,A)') 'ENDIF'
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S3(1:SLEN3)//'/DSQRT(1.0D0-'//S2(1:SLEN2)//'**2)'
          RETURN
        ELSE IF (Y .EQ. 10) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') 'IF (DABS('//S2(1:SLEN2)//
     1                            ') .GE. 1.0D0) THEN'
          WRITE(XFIL,'(6X,A)') 'IERR = 55'
          WRITE(XFIL,'(6X,A)') 'RETURN'
          WRITE(XFIL,'(6X,A)') 'ENDIF'
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'-'
     1            //S3(1:SLEN3)//'/DSQRT(1.0D0-'//S2(1:SLEN2)//'**2)'
          RETURN
        ELSE IF (Y .EQ. 11) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S3(1:SLEN3)//'/(1.0D0+'//S2(1:SLEN2)//'**2)'
          RETURN
        ELSE IF (Y .EQ. 12) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //'DCOSH('//S2(1:SLEN2)//')*'//S3(1:SLEN3)
          RETURN
        ELSE IF (Y .EQ. 13) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //'DSINH('//S2(1:SLEN2)//')*'//S3(1:SLEN3)
          RETURN
        ELSE IF (Y .EQ. 14) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S3(1:SLEN3)//'/DCOSH('//S2(1:SLEN2)//')**2'
          RETURN
        ELSE IF (Y .EQ. 15) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S3(1:SLEN3)//'/DSQRT(1.0D0+'//S2(1:SLEN2)//'**2)'
          RETURN
        ELSE IF (Y .EQ. 16) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') 'IF ('//S2(1:SLEN2)//
     1                            ' .LE. 1.0D0) THEN'
          WRITE(XFIL,'(6X,A)') 'IERR = 56'
          WRITE(XFIL,'(6X,A)') 'RETURN'
          WRITE(XFIL,'(6X,A)') 'ENDIF'
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S3(1:SLEN3)//'/DSQRT('//S2(1:SLEN2)//'**2-1.0D0)'
          RETURN
        ELSE IF (Y .EQ. 17) THEN
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,3),FCOFS,S1,SLEN1)
          CALL MAKEX(PVVA,OFS,VQD(QC,3),S2,SLEN2)
          CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1           FC,VQD(QC,5),FCOFS,S3,SLEN3)
          WRITE(XFIL,'(6X,A)') 'IF (DABS('//S2(1:SLEN2)//
     1                            ') .GE. 1.0D0) THEN'
          WRITE(XFIL,'(6X,A)') 'IERR = 51'
          WRITE(XFIL,'(6X,A)') 'RETURN'
          WRITE(XFIL,'(6X,A)') 'ENDIF'
          WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1            //S3(1:SLEN3)//'/(1.0D0-'//S2(1:SLEN2)//'**2)'
          RETURN
        ELSE
          IERR=26
          WRITE(*,*) ' FORDF (5504) : unknown standard function ',Y
          RETURN
        ENDIF
C
      ELSE IF (X .EQ. EXTERN) THEN
        EXT=VQD(QC,2)
        IF (EXTTYP(EXT) .EQ. 1) THEN
          CALL MAKEI(OFS,VQD(QC,3),S1,SLEN1)
          WRITE(XFIL,'(6X,A)') 'EXTPAR(1)='//S1(1:SLEN1)
        ELSE IF (EXTTYP(EXT) .EQ. 2) THEN
          CALL MAKEI(OFS,VQD(QC,3),S1,SLEN1)
          CALL MAKEI(OFS,VQD(QC,4),S2,SLEN2)
          WRITE(XFIL,'(6X,A)') 'EXTPAR(1)='//S1(1:SLEN1)
          WRITE(XFIL,'(6X,A)') 'EXTPAR(2)='//S2(1:SLEN2)
        ENDIF
        CALL ITOA(EXT,S1,SLEN1)
        WRITE(XFIL,'(6X,A)') 'CALL EXTGRA('//S1(1:SLEN1)//
     1         ',X,N,Z,EXTPAR)'
C
        CALL ITOA(QC,S1,SLEN1)
        CALL ITOA(PVVA,S2,SLEN2)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1         FC,1,FCOFS,S3,SLEN3)
        S3=S3(1:SLEN3-3)//',I)'
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1         FC,VQD(QC,5),FCOFS,S4,SLEN4)
        WRITE(XFIL,'(6X,A)') 'DO '//S1(1:SLEN1)//' I=1,'//S2(1:SLEN2)
        WRITE(XFIL,'(6X,A)') S3(1:SLEN3)//'='//S3(1:SLEN3)//'+Z(I)*'
     1          //S4(1:SLEN4)
        WRITE(XFIL,'(I5,1X,A)') QC,'CONTINUE'
        RETURN    
C
      ELSE IF (X .EQ. CONINT) THEN
          RETURN
C
      ELSE IF (X .EQ. CONINT+128) THEN
          RETURN
C
      ELSE IF (X .EQ. LININT) THEN
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1         FC,VQD(QC+1,5),FCOFS,S1,SLEN1)
        CALL ITOA(VQD(QC,4),S2,SLEN2)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1         FC,VQD(QC,5),FCOFS,S3,SLEN3)
        WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1          //'IR'//S2(1:SLEN2)//'*'//S3(1:SLEN3) 
        RETURN
C
      ELSE IF (X .EQ. LININT+128) THEN
          RETURN
C
      ELSE IF (X .EQ. SPLINE) THEN
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1         FC,VQD(QC+1,5),FCOFS,S1,SLEN1)
        CALL ITOA(VQD(QC,4),S2,SLEN2)
        CALL MAKEY(PIFN,PXFN,PVFN,PVVA,OFS,
     1         FC,VQD(QC,5),FCOFS,S3,SLEN3)
        WRITE(XFIL,'(6X,A)') S1(1:SLEN1)//'='//S1(1:SLEN1)//'+'
     1          //'IR'//S2(1:SLEN2)//'*'//S3(1:SLEN3) 
        RETURN
C
      ELSE IF (X .EQ. SPLINE+128) THEN
          RETURN
C
      ELSE IF ((X .EQ. VECTOR) .OR. (X .EQ. ACTIVE)) THEN
          RETURN
C
      ENDIF
      IERR=26
      WRITE(*,*) ' FORDF (5535) : unknown opcode ',X
      RETURN
      END
C
C
C
      SUBROUTINE MAKEF (PIFN,PXFN,PVFN,I,J,STRING,STRLEN)
      INTEGER PIFN,PXFN,PVFN,I,J
      CHARACTER*(*) STRING
      INTEGER STRLEN
C
      CHARACTER*10 S
      INTEGER SLEN
C
      IF (I .GE. 0) THEN
        CALL ITOA(I,S,SLEN)
      ELSE
        CALL MAKEP(J,-I,S,SLEN)
      ENDIF
      IF (I .LE. PVFN-(PIFN-PXFN)) THEN
        STRING='F('//S(1:SLEN)//')'
        STRLEN=2+SLEN+1
      ELSE
        STRING='VFUNC('//S(1:SLEN)//')'
        STRLEN=6+SLEN+1
      ENDIF
      RETURN
      END
C
C
C 
      SUBROUTINE MAKEL (I,STRING,STRLEN)
      INTEGER I
      CHARACTER*(*) STRING
      INTEGER STRLEN
C
      CHARACTER*10 S
      INTEGER SLEN
C
      CALL ITOA(I,S,SLEN)
      STRING='LAUX('//S(1:SLEN)//')'
      STRLEN=5+SLEN+1
      RETURN
      END
C
C
C 
      SUBROUTINE MAKEI (OFS,I,STRING,STRLEN)
      INTEGER OFS,I
      CHARACTER*(*) STRING
      INTEGER STRLEN
C
      CHARACTER*20 S
      INTEGER SLEN
C
      IF (I .GE. 0) THEN
        CALL ITOA(I,S,SLEN)
        IF (OFS .GT. 0) THEN
          S=S(1:SLEN)//'+IOFS'
          SLEN=SLEN+5
        ENDIF
        STRING='IAUX('//S(1:SLEN)//')'
        STRLEN=5+SLEN+1
        RETURN
      ELSE
        RETURN
      ENDIF
      END
C
C
C 
      SUBROUTINE MAKEX (PVVA,OFS,I,STRING,STRLEN)
      INTEGER PVVA,I,OFS
      CHARACTER*(*) STRING
      INTEGER STRLEN
C
      CHARACTER*20 S
      INTEGER SLEN
C
      IF (I .GE. 0) THEN
        CALL ITOA(I,S,SLEN)
      ENDIF
      IF (I .LE. PVVA) THEN
        STRING='X('//S(1:SLEN)//')'
        STRLEN=2+SLEN+1
      ELSE
        IF (OFS .GT. 0) THEN
          S=S(1:SLEN)//'+OFS'
          SLEN=SLEN+4
        ENDIF
        STRING='XAUX('//S(1:SLEN)//')'
        STRLEN=5+SLEN+1
      ENDIF
      RETURN
      END
C
C
C 
      SUBROUTINE MAKEY (PIFN,PXFN,PVFN,PVVA,OFS,I,J,K,STRING,STRLEN)
      INTEGER PIFN,PXFN,PVFN,PVVA,OFS,I,J
      CHARACTER*(*) STRING
      INTEGER STRLEN
C
      CHARACTER*20 S1,S2
      INTEGER SLEN1,SLEN2
      INTEGER K
C
      IF (I .GE. 0) THEN
        CALL ITOA(I,S1,SLEN1)
      ELSE
        CALL MAKEP(K,-I,S1,SLEN1)
      ENDIF
      IF (J .GE. 0) THEN
        CALL ITOA(J,S2,SLEN2)
      ENDIF
      IF (J .GT. PVVA) THEN
        IF (OFS .GT. 0) THEN
          S2=S2(1:SLEN2)//'+OFS'
          SLEN2=SLEN2+4
        ENDIF
        STRING='YAUX('//S2(1:SLEN2)//')'
        STRLEN=5+SLEN2+1
      ELSE IF (I .LE. PVFN-(PIFN-PXFN)) THEN
        STRING='DF('//S1(1:SLEN1)//','//S2(1:SLEN2)//')'
        STRLEN=3+SLEN1+1+SLEN2+1
      ELSE
        STRING='VGRAD('//S1(1:SLEN1)//','//S2(1:SLEN2)//')'
        STRLEN=6+SLEN1+1+SLEN2+1
      ENDIF
      RETURN
      END
C
C
C     
      SUBROUTINE FTOA (X,S,SLEN)
      DOUBLE PRECISION X
      CHARACTER*24 S
      INTEGER SLEN
C
      CHARACTER*24 DUMMY
      INTEGER I
C
      WRITE(S,'(D24.17)',ERR=11) X
      DO 10 I=1,24
        IF (S(I:I) .NE. ' ') THEN
C         S=S(I:24)
          DUMMY=S(I:24)
          S=DUMMY
          SLEN=24-I+1
          RETURN
        ENDIF
 10   CONTINUE
 11   CONTINUE
      SLEN=24
      RETURN
      END
C
C
C     
      SUBROUTINE ITOA (N,S,SLEN)
      INTEGER N
      CHARACTER*10 S
      INTEGER SLEN
C
      CHARACTER*10 DUMMY
      INTEGER I
C
      WRITE(S,'(I10)',ERR=11) N
      DO 10 I=1,10 
        IF (S(I:I) .NE. ' ') THEN
C         S=S(I:10)
          DUMMY=S(I:10)
          S=DUMMY
          SLEN=10-I+1
          RETURN
        ENDIF
 10   CONTINUE
 11   CONTINUE
      SLEN=10
      RETURN
      END
C
C
C     
      SUBROUTINE MAKEP (I,J,STRING,STRLEN)
      INTEGER I,J
      CHARACTER*(*) STRING
      INTEGER STRLEN
C
      CHARACTER*10 S1,S2
      INTEGER SLEN1,SLEN2
C
      IF (I .EQ. 0) THEN
        CALL ITOA(J-1,S1,SLEN1)
        STRING='IX'//S1(1:SLEN1)
        STRLEN=2+SLEN1
        RETURN
      ELSE
        CALL ITOA(I,S1,SLEN1)
        CALL ITOA(J-1,S2,SLEN2)
        STRING=S1(1:SLEN1)//'+IX'//S2(1:SLEN2)
        STRLEN=SLEN1+3+SLEN2
        RETURN
      ENDIF 
      END
C
C
C
      SUBROUTINE STRCT (S1,SLEN1,S2,SLEN2)
      CHARACTER*(*) S1,S2
      INTEGER SLEN1,SLEN2
C
      IF (SLEN1 .EQ. 0) THEN
        S1=S2(1:SLEN2)
        SLEN1=SLEN2
      ELSE
        S1=S1(1:SLEN1)//S2(1:SLEN2)
        SLEN1=SLEN1+SLEN2
      ENDIF
      RETURN
      END
C
C
C
      SUBROUTINE IDATA (XFIL,V,N,ID)
      INTEGER XFIL,N
      INTEGER V(N)
      CHARACTER*6 ID
C
      INTEGER FIRST,LAST,COUNT,ROW,COL
      CHARACTER*80 STRING,S1,S2
      INTEGER STRLEN,SLEN1,SLEN2
C
      CHARACTER CONT(10)
      DATA CONT /'1','2','3','4','5','6','7','8','9','O'/
C
      FIRST=1
 10   IF (N .LT. FIRST+49) THEN
        LAST=N
      ELSE
        LAST=FIRST+49
      ENDIF
      CALL ITOA(FIRST,S1(1:10),SLEN1)
      CALL ITOA(LAST,S2(1:10),SLEN2)
      WRITE(XFIL,'(6X,A)') 'DATA ('//ID//'(I), I='//S1(1:SLEN1)//
     1                     ','//S2(1:SLEN2)//')'
      COUNT=FIRST
      ROW=1
      COL=1
      STRING='/'
      STRLEN=1
 20   CALL ITOA(V(COUNT),S1(1:10),SLEN1)
      CALL STRCT(STRING,STRLEN,S1,SLEN1)
      IF (COUNT .EQ. LAST) THEN
        CALL STRCT(STRING,STRLEN,'/',1)
      ELSE
        CALL STRCT(STRING,STRLEN,',',1)
      ENDIF
      IF ((COUNT .EQ. LAST) .OR. (COL .EQ. 5)) THEN
        WRITE(XFIL,'(5X,A,5X,A)') CONT(ROW),STRING(1:STRLEN)
        STRING=' '
        STRLEN=1
        ROW=ROW+1
        COL=1
      ELSE
        COL=COL+1
      ENDIF
      COUNT=COUNT+1
      IF (COUNT .LE. LAST) GO TO 20
      IF (LAST .LT. N) THEN
        FIRST=LAST+1
        GO TO 10 
      ENDIF
      RETURN
      END
C
C
C
      SUBROUTINE FDATA (XFIL,V,N,ID)
      INTEGER XFIL,N
      DOUBLE PRECISION V(N)
      CHARACTER*6 ID
C
      INTEGER FIRST,LAST,COUNT,ROW,COL
      CHARACTER*80 STRING,S1,S2
      INTEGER STRLEN,SLEN1,SLEN2
C
      CHARACTER CONT(10)
      DATA CONT /'1','2','3','4','5','6','7','8','9','O'/
C
      FIRST=1
 10   IF (N .LT. FIRST+19) THEN
        LAST=N
      ELSE
        LAST=FIRST+19
      ENDIF
      CALL ITOA(FIRST,S1(1:10),SLEN1)
      CALL ITOA(LAST,S2(1:10),SLEN2)
      WRITE(XFIL,'(6X,A)') 'DATA ('//ID//'(I), I='//S1(1:SLEN1)//
     1                     ','//S2(1:SLEN2)//')'
      COUNT=FIRST
      ROW=1
      COL=1
      STRING='/'
      STRLEN=1
 20   CALL FTOA(V(COUNT),S1(1:24),SLEN1)
      CALL STRCT(STRING,STRLEN,S1,SLEN1)
      IF (COUNT .EQ. LAST) THEN
        CALL STRCT(STRING,STRLEN,'/',1)
      ELSE
        CALL STRCT(STRING,STRLEN,',',1)
      ENDIF
      IF ((COUNT .EQ. LAST) .OR. (COL .EQ. 2)) THEN
        WRITE(XFIL,'(5X,A,5X,A)') CONT(ROW),STRING(1:STRLEN)
        STRING=' '
        STRLEN=1
        ROW=ROW+1
        COL=1
      ELSE 
        COL=COL+1
      ENDIF
      COUNT=COUNT+1
      IF (COUNT .LE. LAST) GO TO 20
      IF (LAST .LT. N) THEN
        FIRST=LAST+1
        GO TO 10 
      ENDIF
      RETURN
      END
C
C
C
      SUBROUTINE FOLD (XFIL,STRING,STRLEN,IERR)
      CHARACTER*(*) STRING
      INTEGER XFIL,STRLEN,IERR
C
      INTEGER BRACE,BREAK,CLEN,WIDTH
      CHARACTER CONT*4,X,STR*80
      LOGICAL SEP
      INTEGER I
C
      CHARACTER*255 BUFFER,DUMMY
      INTEGER BUFLEN
C
      SEP(X)=((X .EQ. '+') .OR. (X .EQ. '-') .OR. (X .EQ. '*') .OR.
     1        (X .EQ. '/') .OR. (X .EQ. '='))
C
      IF (STRLEN .GT. 255) THEN
        STOP 'FOLD: STRING LENGTH EXCEEDS 255 CHARACTERS.'
      ELSE
        BUFFER=STRING
        BUFLEN=STRLEN
      ENDIF
      WIDTH=56
      CONT=' '
      CLEN=1
 1    IF (BUFLEN .LE. WIDTH) THEN
        STR(1:BUFLEN)=BUFFER(1:BUFLEN)
        WRITE(XFIL,'(5X,A)') CONT(1:CLEN)//STR(1:BUFLEN)
      ELSE
        BRACE=0
        BREAK=0
        DO 10 I=1,WIDTH
          IF (BUFFER(I:I) .EQ. '(') BRACE=BRACE+1
          IF (BUFFER(I:I) .EQ. ')') BRACE=BRACE-1
          IF (SEP(BUFFER(I:I)) .AND. (BRACE .EQ. 0)) BREAK=I
 10     CONTINUE
        IF (BREAK .EQ. 0) THEN
          IERR=46
          RETURN
        ENDIF
        STR(1:BREAK)=BUFFER(1:BREAK)
        WRITE(XFIL,'(5X,A)') CONT(1:CLEN)//STR(1:BREAK)
        WIDTH=53
        CONT='/   '
        CLEN=4
C       BUFFER=BUFFER(BREAK+1:BUFLEN)
        DUMMY=BUFFER(BREAK+1:BUFLEN)
        BUFFER=DUMMY
        BUFLEN=BUFLEN-BREAK
        IF (BUFLEN .GT. 0) GO TO 1
      ENDIF
      RETURN
      END

