C******************** START FILE UCHUNS.FOR ; GROUP UFNTER *************
C--------------------------------------------------------------
C  UCHUNS
C  PERFORM UNITS TRANSFORMATION UNDER USER CONTROL
C
      SUBROUTINE UCHUNS(AID,UNITS,IFLAG,OLDUNS,ARR,NARR,
     >                    ZCONA,ZCONB,IX)
C
      REAL ARR(NARR)
      CHARACTER*10 UNITS,OLDUNS,zunits
      character*(*) AID
C
C  AID-- 1 LETTER ID OF VARIABLE TO UNDERGO UNITS TRANSFORM
C  UNITS-- 10 CHAR UNITS ARRAY FOR VARIABLE
C  IFLAG-- RETURNED =1 IF UNITS TRANSFORM PERFORMED, 0 O.W.
C           =2 IF *EXPONENTIAL* TRANSFORMATION IS PERFORMED
C  OLDUNS- OLD UNITS LABEL PUT HERE IF TRANSFORM PERFORMED
C  ARR(NARR)  ARRAY CONTAINING VARIABLE TO BE
C    TRANSFORMED (MULTIPLIED BY UNITS CONVERSION FACTOR)
C  ZCONA,ZCONB  (OUTPUT) CONVERSION FACTORS USED
C    X(NEW)=ZCONA*X(OLD)+ZCONB
C  IX: INPUT:  =1: ARRAY IS INDEPENDANT COORDINATE; DO NOT ALLOW
C      ORDER REVERSAL VIA ZCONA.LT.0.0
C              =2: DEPENDENT COORD, ZCONA.LT.0.0 IS ALLOWED
C
C  USER ENTERS CONVERSION FACTOR AND NEW UNITS LABEL
C
C
C *LISMAK* 12-APR-88  GENERATED LOGICAL DECLARATIONS
      LOGICAL LCHAR,lxout
C *LISMAK* END OF GENERATED LOGICAL DECLARATIONS
C
      luntrm=lnout(0)
C
 5    CONTINUE
C
C  DEFAULT:
C
      ZCONA=1.0
      ZCONB=0.0
C
      CALL NEUPAG
      IFLAG=0
      OLDUNS=UNITS
 10   CONTINUE
      IF(LXOUT(0)) WRITE(LUNTRM,2001) AID(1:1),OLDUNS
 2001 FORMAT(/' "',A1,'" ARRAY OLD UNITS:  "',A10,'"'//
     >  ' ENTER NEW UNITS TO TRANSFORM QUANTITY VIA'/
     >  ' X(NEW) = A*X(OLD) + B  **OR**  X(NEW)= B*|X(OLD)|**A;'/
     >  ' A AND B FACTORS SPECIFIED BELOW.'//
     >  ' enter "1" for blank units label'/)
      ZCON=1.0
      CALL UREAD(
     >'UCHUNS:  ENTER NEW UNITS (10 CHAR LABEL) OR "0" NOT TO CHANGE:$')
      call cdcod(zunits)
      if(zunits(1:2).eq.'Q ') return
      if(zunits(1:2).eq.'0 ') return
      if(zunits(1:2).eq.'1 ') zunits=' '
      units=zunits
      IFLAG=1
      CALL UCLEAR
      IF(LXOUT(0).AND.(IX.EQ.1)) WRITE(LUNTRM,2002)
 2002 FORMAT(' % POSITIVE CONVERSION FACTOR REQUIRED')
      IF(LXOUT(0)) WRITE(LUNTRM,2003)
 2003 FORMAT(
     >'   FOR EXPONENTIAL TRANSFORM SPECIFY "E" FOLLOWED BY NUMBER'/
     >'   %WARNING - EXPONENTIATION APPLIED TO ABS. VALUE OF DATA')
 11   CALL UREAD(
     >'UCHUNS:  ENTER CONVERSION FACTOR A: (NEW UNITS PER OLD UNIT)$')
      if(lchar('Q')) GO TO 5
      IF(LCHAR('E')) THEN
        IFLAG=2
        GO TO 11
      ENDIF
      ZCONA=FDCOD(IERT)
      IF(IERT.NE.0) GO TO 100
      IF(ZCONA.EQ.0.0) GO TO 100
      IF((ZCONA.LT.0.0).AND.(IX.EQ.1)) GO TO 100
C
      CALL UREAD(
     >'UCHUNS:  ENTER OFFSET B (QUANTITY TO ADD OR FACTOR INTO DATA):$')
      if(lchar('Q')) GO TO 5
      ZCONB=FDCOD(IERT)
      IF(IERT.NE.0) GO TO 100
      IF(IFLAG.EQ.2) THEN
C  IF B IS MULTIPLICATIVE...
        IF(ZCONB.EQ.0.0) GO TO 100
      ENDIF
C
      DO 20 I=1,NARR
       IF(IFLAG.EQ.1) THEN
        ARR(I)=ZCONA*ARR(I)+ZCONB
       ELSE
        ARR(I)=ZCONB*(ABS(ARR(I)))**ZCONA
       ENDIF
 20   CONTINUE
      RETURN
C
 100  CONTINUE
C
      UNITS=OLDUNS
      IFLAG=0
      CALL UERMSG('% ILLEGAL CONVERSION FACTOR',' ',0)
      GO TO 10
      	END
C******************** END FILE UCHUNS.FOR ; GROUP UFNTER ***************
