NCEPLIBS-w3emc  2.11.0
gtbits.f
Go to the documentation of this file.
1 C> @file
2 C> @brief The number of bits required to pack a given field.
3 C> @author Mark Iredell @date 1992-10-31
4 
5 C> The number of bits required to pack a given field
6 c> at a particular decimal scaling is computed using the field range.
7 C> The field is rounded off to the decimal scaling for packing.
8 C> The minimum and maximum rounded field values are also returned.
9 C> Grib bitmap masking for valid data is optionally used.
10 C>
11 C> Program history log:
12 C> - Mark Iredell 1992-10-31
13 C>
14 C> @param[in] ibm integer bitmap flag (=0 for no bitmap).
15 c> @param[in] ids integer decimal scaling
16 c> (e.g. ids=3 to round field to nearest milli-value).
17 c> @param[in] len integer length of the field and bitmap.
18 c> @param[in] mg integer (len) bitmap if ibm=1 (0 to skip, 1 to keep).
19 c> @param[in] g real (len) field.
20 c> @param[out] ground real (len) field rounded to decimal scaling
21 c> (set to zero where bitmap is 0 if ibm=1).
22 c> @param[out] gmin real minimum valid rounded field value.
23 c> @param[out] gmax real maximum valid rounded field value.
24 c> @param[out] nbit integer number of bits to pack.
25 C>
26 C> @author Mark Iredell @date 1992-10-31
27  SUBROUTINE gtbits(IBM,IDS,LEN,MG,G,GROUND,GMIN,GMAX,NBIT)
28  dimension mg(len),g(len),ground(len)
29 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30 C ROUND FIELD AND DETERMINE EXTREMES WHERE BITMAP IS ON
31  ds=10.**ids
32  IF(ibm.EQ.0) THEN
33  ground(1)=nint(g(1)*ds)/ds
34  gmax=ground(1)
35  gmin=ground(1)
36  DO i=2,len
37  ground(i)=nint(g(i)*ds)/ds
38  gmax=max(gmax,ground(i))
39  gmin=min(gmin,ground(i))
40  ENDDO
41  ELSE
42  i1=isrchne(len,mg,1,0)
43  IF(i1.GT.0.AND.i1.LE.len) THEN
44  DO i=1,i1-1
45  ground(i)=0.
46  ENDDO
47  ground(i1)=nint(g(i1)*ds)/ds
48  gmax=ground(i1)
49  gmin=ground(i1)
50  DO i=i1+1,len
51  IF(mg(i).NE.0) THEN
52  ground(i)=nint(g(i)*ds)/ds
53  gmax=max(gmax,ground(i))
54  gmin=min(gmin,ground(i))
55  ELSE
56  ground(i)=0.
57  ENDIF
58  ENDDO
59  ELSE
60  DO i=1,len
61  ground(i)=0.
62  ENDDO
63  gmax=0.
64  gmin=0.
65  ENDIF
66  ENDIF
67 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 C COMPUTE NUMBER OF BITS
69  nbit=log((gmax-gmin)*ds+0.9)/log(2.)+1.
70 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
71  RETURN
72  END
subroutine gtbits(IBM, IDS, LEN, MG, G, GROUND, GMIN, GMAX, NBIT)
The number of bits required to pack a given field at a particular decimal scaling is computed using t...
Definition: gtbits.f:28
function isrchne(N, X, INCX, TARGET)
Program history log:
Definition: isrchne.f:21