Debian Codegraph @

packages/seacas/libraries/suplib/engstr.f

raw
1 C Copyright(C) 1999-2020 National Technology & Engineering Solutions
2 C of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 C NTESS, the U.S. Government retains certain rights in this software.
4 C
5 C See packages/seacas/LICENSE for details
6
7 C=======================================================================
8 SUBROUTINE ENGSTR (NNUM, NSIG, RNUM, RSTR, LSTR)
9 C=======================================================================
10
11 C --*** ENGSTR *** (STRLIB) Convert real numbers to strings
12 C -- Written by Amy Gilkey - revised 02/14/86
13 C --
14 C --ENGSTR converts a set of real numbers into engineering notation
15 C --strings. The real numbers are not compared in any way to get a
16 C --consistent set of exponents, etc.
17 C --
18 C --Parameters:
19 C -- NNUM - IN - the number of numbers in the array set
20 C -- NSIG - IN - the maximum number of significant digits, max of 8
21 C -- RNUM - IN - the array of real numbers to be converted
22 C -- RSTR - OUT - the set of real number strings
23 C -- LSTR - OUT - the maximum length of the number strings
24
25 C --Routines Called:
26 C -- IENGRX - (included) Get engineering notation exponent
27
28 INTEGER NNUM
29 INTEGER NSIG
30 REAL RNUM(*)
31 CHARACTER*(*) RSTR(*)
32 INTEGER LSTR
33
34 CHARACTER*10 SCRFMT
35 CHARACTER*20 SCRSTR
36 CHARACTER*15 FFMT
37
38 C --Do not try to use a common exponent, but use engineering notation
39
40 WRITE (SCRFMT, 10, IOSTAT=IDUM) NSIG+7, NSIG
41 10 FORMAT ('(0PE', I2.2, '.', I2.2, ')')
42
43 LSTR = 0
44 DO 40 I = 1, NNUM
45 WRITE (SCRSTR(1:NSIG+7), SCRFMT, IOSTAT=IDUM) RNUM(I)
46 READ (SCRSTR(NSIG+5:NSIG+7), '(I3)', IOSTAT=IDUM) IE
47 ISIGN = 0
48 IF (RNUM(I) .LT. 0.0) ISIGN = 1
49
50 NEWEXP = IENGRX (IE, IE)
51
52 EXPDIV = 10.0 ** NEWEXP
53
54 NWHOLE = MAX (0, IE - NEWEXP)
55 NFRAC = MAX (0, MIN (NEWEXP - IE + NSIG,
56 & NSIG - (IE - NEWEXP)))
57 NTOTAL = ISIGN + NWHOLE + 1 + NFRAC
58
59 WRITE (FFMT, 20, IOSTAT=IDUM) NTOTAL, NFRAC
60 20 FORMAT ('(F', I2.2, '.', I2.2, ')')
61 WRITE (FFMT(8:15), 30, IOSTAT=IDUM) NEWEXP
62 30 FORMAT (',''E', SP, I3.2, ''')')
63 LSTR = MAX (LSTR, NTOTAL+4)
64
65 WRITE (RSTR(I), FFMT, IOSTAT=IDUM) RNUM(I)/EXPDIV
66 40 CONTINUE
67
68 RETURN
69 END