      SUBROUTINE G1CLS7(IFUNCO,LENGTH,IDATA,RDATA)
C
C          ------------------------------------------------
C          ROUTINE NO. (1018)   VERSION (A8.8)    14:JUL:97
C          ------------------------------------------------
C
C          THIS DECODES MAPPING AND PICTURE-TRANSFORMATION FUNCTIONS.
C
C
C          THE ARGUMENTS ARE AS FOLLOWS:
C
C          <IFUNCO> GIVES THE FUNCTION CODE:
C                   =  1, DEFINE LIN.-LIN. MAP       (X1,X2,Y1,Y2),
C                   =  2, DEFINE LIN.-LOG. MAP       (X1,X2,Y1,Y2),
C                   =  3, DEFINE LOG.-LIN. MAP       (X1,X2,Y1,Y2),
C                   =  4, DEFINE LOG.-LOG. MAP       (X1,X2,Y1,Y2),
C                   =  5, DEFINE VECTOR WINDOW       (X1,X2,Y1,Y2),
C                   =  6, DEFINE NEW MASK AREA       (X1,X2,Y1,Y2),
C                   =  7, SET MASK LEVEL             (N),
C                   =  8, SET PICTURE X-SCALE        (FACTOR),
C                   =  9, SET PICTURE Y-SCALE        (FACTOR),
C                   = 10, -NO LONGER USED-
C                   = 11, -NO LONGER USED-
C                   = 12, SET PICTURE ROTATE         (ANGLE),
C                   = 13, SET DEVICE REFERENCE POINT (X,Y),
C                   = 14, DO A TRANSFORM INDENT,
C                   = 15, DO A TRANSFORM UNDENT      (C1,....C7),
C                   = 16, SET CLIP TRANSFORM MODE    (N),
C                   = 17, SET TRANSFORM RANGE        (N).
C          <LENGTH> GIVES THE DATA LENGTH (IN BYTES),
C          [IDATA]  IS THE INTEGER DATA ARRAY, AND
C          [RDATA]  IS THE ALTERNATIVE REAL DATA ARRAY.
C
C
      REAL    RDATA(*)
      INTEGER IDATA(*)
      LOGICAL SHIFT1,CURTRA,ERRON
C
      COMMON /T1CFON/ KFONT1
      COMMON /T1CPOS/ XCHAR,YCHAR
      COMMON /T1MAPP/ X1MAP1,X2MAP1,Y1MAP1,Y2MAP1
      COMMON /T1MAPS/ ORIMX1,ORIMY1,SCAMX1,SCAMY1
      COMMON /T1MAPT/ MAPNO1
      COMMON /T1MASK/ X1MSK1(10),X2MSK1(10),Y1MSK1(10),Y2MSK1(10),MSKLV1
      COMMON /T1PPBT/ XPLOTB,YPLOTB
      COMMON /T1PPOS/ XPLOT1,YPLOT1
      COMMON /T1TCOB/ XCBX,XCBY,YCBX,YCBY,RPICXB,RPICYB,RDEVXB,RDEVYB
      COMMON /T1TCOC/ XCCX,XCCY,YCCX,YCCY,RPICXC,RPICYC,RDEVXC,RDEVYC,
     &                CURTRA
      COMMON /T1TCOR/ XRVX,XRVY,YRVX,YRVY,RPICXR,RPICYR,RDEVXR,RDEVYR
      COMMON /T1TRNC/ SCALXC,SCALYC,ROTATC
C     COMMON /T1TRNB/ SCALXB,SCALYB,ROTATB
      COMMON /T1TRNS/ SCALXS,SCALYS,ROTATS,RDEVXS,RDEVYS
      COMMON /T1TRST/ SHIFT1,MTRAN1,KLIPM1,INDLVL
      COMMON /T1WNDO/ X1WND1,X2WND1,Y1WND1,Y2WND1
      COMMON /T3ERRS/ ERRON,NUMERR
      COMMON /T3LIMS/ IMAXI,RMAXI,RMINI
C
C
      IF (IFUNCO.LT.1.OR.IFUNCO.GT.17)  RETURN
      IF (IFUNCO.EQ.10.OR.IFUNCO.EQ.11) RETURN
      IF (IFUNCO.GT.4) GO TO 4
C
C          THE FIRST 4 FUNCTIONS SET THE MAPPING.
C
      MAPNO1= IFUNCO
      X1MAP1= RDATA(1)
      X2MAP1= RDATA(2)
      Y1MAP1= RDATA(3)
      Y2MAP1= RDATA(4)
C
C          THE CURRENT POSITIONS ARE RESET FOR A NEW MAP.
C
      XPLOT1= X1MAP1
      YPLOT1= Y1MAP1
      CALL G1LINE(0.0,0.0,.FALSE.)
      XCHAR= XPLOTB
      YCHAR= YPLOTB
C
C          THE NEW X AND Y MAPPING FACTORS ARE CALCULATED.
C
      IF (MAPNO1.EQ.3.OR.MAPNO1.EQ.4) GO TO 1
C
      ORIMX1= X1MAP1
      SCAMX1= 0.0
      IF (ABS(X2MAP1-X1MAP1).LT.RMINI) GO TO 2
C
      SCAMX1= 1.0/(X2MAP1-X1MAP1)
      GO TO 2
C
    1 IF (ABS(SIGN(1.0,X2MAP1)-SIGN(1.0,X1MAP1)).GE.RMINI) GO TO 901
C
      AB1MAP= ABS(X1MAP1)
      AB2MAP= ABS(X2MAP1)
      IF (AB1MAP.LT.RMINI.OR.AB2MAP.LT.RMINI) GO TO 901
C
      ORIMX1= ALOG(AB1MAP)
      DEXP= ALOG(AB2MAP)-ORIMX1
      IF (ABS(DEXP).LT.RMINI) GO TO 901
C
      SCAMX1= 1.0/DEXP
    2 IF (MAPNO1.EQ.2.OR.MAPNO1.EQ.4) GO TO 3
C
      ORIMY1= Y1MAP1
      SCAMY1= 0.0
      IF (ABS(Y2MAP1-Y1MAP1).LT.RMINI) RETURN
C
      SCAMY1= 1.0/(Y2MAP1-Y1MAP1)
      RETURN
C
    3 IF (ABS(SIGN(1.0,Y2MAP1)-SIGN(1.0,Y1MAP1)).GE.RMINI) GO TO 901
C
      AB1MAP= ABS(Y1MAP1)
      AB2MAP= ABS(Y2MAP1)
      IF (AB1MAP.LT.RMINI.OR.AB2MAP.LT.RMINI) GO TO 901
C
      ORIMY1= ALOG(AB1MAP)
      DEXP= ALOG(AB2MAP)-ORIMY1
      IF (ABS(DEXP).LT.RMINI) GO TO 901
C
      SCAMY1= 1.0/DEXP
      RETURN
C
    4 IFUNC= IFUNCO-4
      GO TO (7,8,9,10,11,10,11,12,13,16,17,18,19), IFUNC
C
C          THIS PART SETS THE WINDOW AREA.
C
    7 CALL G1MAPP(RDATA(1),RDATA(3),XVAL1,YVAL1,0)
      CALL G1MAPP(RDATA(2),RDATA(4),XVAL2,YVAL2,0)
      X1WND1= AMIN1(XVAL1,XVAL2)-0.00001
      X2WND1= AMAX1(XVAL1,XVAL2)+0.00001
      Y1WND1= AMIN1(YVAL1,YVAL2)-0.00001
      Y2WND1= AMAX1(YVAL1,YVAL2)+0.00001
      RETURN
C
C          THIS PART SETS THE NEXT MASKING AREA,
C          PROVIDED THE LEVEL DOES NOT EXCEED 10.
C
    8 IF (MSKLV1.GE.10) RETURN
      MSKLV1= MSKLV1+1
      CALL G1MAPP(RDATA(1),RDATA(3),XVAL1,YVAL1,0)
      CALL G1MAPP(RDATA(2),RDATA(4),XVAL2,YVAL2,0)
      X1MSK1(MSKLV1)= AMIN1(XVAL1,XVAL2)
      X2MSK1(MSKLV1)= AMAX1(XVAL1,XVAL2)
      Y1MSK1(MSKLV1)= AMIN1(YVAL1,YVAL2)
      Y2MSK1(MSKLV1)= AMAX1(YVAL1,YVAL2)
      RETURN
C
C          THIS SECTION SETS A NEW MASKING LEVEL,
C          PROVIDED IT IS IN THE RANGE [0 TO 10].
C
    9 IF (IDATA(1).LT.0.OR.IDATA(1).GT.10) RETURN
C
      MSKLV1= IDATA(1)
      RETURN
C
C          THIS SETS X AND Y SCALING FACTORS.
C
   10 IF (ABS(RDATA(1)).GE.RMINI) SCALXC= RDATA(1)
      IF (KFONT1.GE.101) THEN
        CALL G1HRDW(3)
        CALL G1HRDW(7)
      ENDIF
C
      GO TO 14
C
   11 IF (ABS(RDATA(1)).GE.RMINI) SCALYC= RDATA(1)
      IF (KFONT1.GE.101) THEN
        CALL G1HRDW(3)
        CALL G1HRDW(7)
      ENDIF
C
      GO TO 14
C
C          THIS SETS THE ROTATION FACTOR (RADIANS).
C
   12 ROTATC= RDATA(1)
      IF (KFONT1.GE.101) CALL G1HRDW(2)
      GO TO 14
C
C          THIS SETS THE DEVICE-REFERENCE-POINT. (WHEN
C          NO DATA IS GIVEN, IT FOLLOWS THE PICTURE ONE).
C
   13 SHIFT1= .FALSE.
      IF (LENGTH.EQ.0) GO TO 14
C
      RDEVXC= RDATA(1)
      RDEVYC= RDATA(2)
      SHIFT1= .TRUE.
C
C          THIS SECTION RECALCULATES CURRENT TRANS. COEFFICIENTS.
C          THE PICTURE-REFERENCE-POINT IS AT THE CURRENT POSITION.
C
   14 RPICXC= XPLOTB
      RPICYC= YPLOTB
      IF (SHIFT1) GO TO 15
      RDEVXC= RPICXC
      RDEVYC= RPICYC
   15 COSROC= COS(ROTATC)
      SINROC= SIN(ROTATC)
      XCCX=  SCALXC*COSROC
      XCCY= -SCALYC*SINROC
      YCCX=  SCALXC*SINROC
      YCCY=  SCALYC*COSROC
C
C          THE CURRENT POSITION IS RESET TO ENSURE CORRECT PLACING.
C
      CALL G1LINE(XPLOTB,YPLOTB,.FALSE.)
C
C          THIS PART CALCULATES A NEW CURRENT REVERSE TRANSFORM
C          WHENEVER THE PROGRAM-LEVEL CURRENT TRANSFORM IS CHANGED.
C
      IF (INDLVL.NE.0) RETURN
C
      TEMPX= XCCX*XCCX+YCCX*YCCX
      TEMPY= XCCY*XCCY+YCCY*YCCY
      XRVX=  XCCX/TEMPX
      XRVY= -XCCY/TEMPY
      YRVX= -YCCX/TEMPX
      YRVY=  YCCY/TEMPY
      RPICXR= RPICXC
      RPICYR= RPICYC
      RDEVXR= RDEVXC
      RDEVYR= RDEVYC
      RETURN
C
C          THIS SECTION PERFORMS A TRANSFORMATION INDENT.
C
   16 INDLVL= INDLVL+1
      TEMPX= RDEVXC-RPICXB
      TEMPY= RDEVYC-RPICYB
      RDEVXB= RDEVXB+(XCBX*TEMPX+XCBY*TEMPY)
      RDEVYB= RDEVYB+(YCBX*TEMPX+YCBY*TEMPY)
      RPICXB= RPICXC
      RPICYB= RPICYC
      XTEMPX= XCBX*XCCX+XCBY*YCCX
      XTEMPY= XCBX*XCCY+XCBY*YCCY
      YTEMPX= YCBX*XCCX+YCBY*YCCX
      YTEMPY= YCBX*XCCY+YCBY*YCCY
      XCBX= XTEMPX
      XCBY= XTEMPY
      YCBX= YTEMPX
      YCBY= YTEMPY
      SCALXS= SCALXC
      SCALYS= SCALYC
      ROTATS= ROTATC
      RDEVXS= RDEVXC
      RDEVYS= RDEVYC
      RDEVXC= 0.0
      RDEVYC= 0.0
      RPICXC= 0.0
      RPICYC= 0.0
      XCCX= 1.0
      XCCY= 0.0
      YCCX= 0.0
      YCCY= 1.0
      SCALXC= 1.0
      SCALYC= 1.0
      ROTATC= 0.0
      IF (KFONT1.GE.101) THEN
        CALL G1HRDW(3)
        CALL G1HRDW(7)
        CALL G1HRDW(2)
      ENDIF

      SHIFT1= .FALSE.
      RETURN
C
C          THIS SECTION PERFORMS A TRANSFORMATION UNDENT.
C
   17 INDLVL= INDLVL-1
      SCALXC= SCALXS
      SCALYC= SCALYS
      ROTATC= ROTATS
      IF (KFONT1.GE.101) THEN
        CALL G1HRDW(3)
        CALL G1HRDW(7)
        CALL G1HRDW(2)
      ENDIF

      COSROC= COS(ROTATC)
      SINROC= SIN(ROTATC)
      XCCX=  SCALXC*COSROC
      XCCY= -SCALYC*SINROC
      YCCX=  SCALXC*SINROC
      YCCY=  SCALYC*COSROC
      RPICXC= RPICXB
      RPICYC= RPICYB
      RDEVXC= RDEVXS
      RDEVYC= RDEVYS
      XTEMPX= XCBX*COSROC/SCALXC-XCBY*SINROC/SCALYC
      XTEMPY= XCBY*COSROC/SCALYC+XCBX*SINROC/SCALXC
      YTEMPX= YCBX*COSROC/SCALXC-YCBY*SINROC/SCALYC
      YTEMPY= YCBY*COSROC/SCALYC+YCBX*SINROC/SCALXC
      XCBX= XTEMPX
      XCBY= XTEMPY
      YCBX= YTEMPX
      YCBY= YTEMPY
C
C          THE NEW SAVED VALUES ARE TAKEN FROM THE INPUT DATA.
C
      SCALXS= RDATA(1)
      SCALYS= RDATA(2)
      ROTATS= RDATA(3)
      RDEVXS= RDATA(4)
      RDEVYS= RDATA(5)
C
C          THE NEW BASE REFERENCE-POINTS ARE FOUND. (THE DEVICE
C          ONE IS A KNOWN POSITION WHEN GOING TO PICTURE-LEVEL 0).
C
      RPICXB= RDATA(6)
      RPICYB= RDATA(7)
      TEMPX= RDEVXC-RPICXB
      TEMPY= RDEVYC-RPICYB
      RDEVXB= RDEVXB-(XCBX*TEMPX+XCBY*TEMPY)
      RDEVYB= RDEVYB-(YCBX*TEMPX+YCBY*TEMPY)
      IF (INDLVL.GT.0) RETURN
C
      RDEVXB= 0.0
      RDEVYB= 0.0
      RETURN
C
C          THIS SETS THE CLIPPING-AREA TRANSFORMATION MODE.
C
   18 KLIPM1= IDATA(1)
      RETURN
C
C          THIS SETS THE TRANSFORMATION RANGE. THE CURRENT
C          TRANSFORMATION STATE IS SET ACCORDINGLY. THE
C          POSITION IS REAFFIRMED TO ENSURE CORRECT PLACING.
C
   19 MTRAN1= IDATA(1)
      CURTRA= .TRUE.
      IF (MTRAN1.EQ.0.OR.MTRAN1.EQ.2) CURTRA= .FALSE.
C
      CALL G1LINE(XPLOTB,YPLOTB,.FALSE.)
      RETURN
C
C          THIS SECTION IS FOR LOG.-MAPPING ERRORS.
C
  901 SCAMX1= 0.0
      SCAMY1= 0.0
      VALIM= 1.0
      IF (ABS(X2MAP1).GE.RMINI) VALIM= SIGN(VALIM,X2MAP1)
      IF (ABS(X1MAP1).GT.RMINI) VALIM= SIGN(VALIM,X1MAP1)
C
      X1MAP1= VALIM
      ORIMX1= VALIM
      VALIM= 1.0
      IF (ABS(Y2MAP1).GE.RMINI) VALIM= SIGN(VALIM,Y2MAP1)
      IF (ABS(Y1MAP1).GE.RMINI) VALIM= SIGN(VALIM,Y1MAP1)
C
      Y1MAP1= VALIM
      ORIMY1= VALIM
      NUMERR= 1001
      IF (.NOT.ERRON) RETURN
C
      CALL G1FILB(0,0,-84,0)
      CALL G1ERMS
C
      RETURN
      END
