NCEPLIBS-g2  3.5.0
pack_gp.f File Reference

This subroutine determines groups of variable size. More...

Go to the source code of this file.

Functions/Subroutines

subroutine pack_gp (IC, NXY, IS523, MINPK, INC, MISSP, MISSS, JMIN, JMAX, LBIT, NOV, NDG, LX, IBIT, JBIT, KBIT, NOVREF, LBITREF, IER)
 This subroutine determines groups of variable size, but at least of size minpk, the associated max(JMAX) and min(JMIN), the number of bits necessary to hold the values in each group LBIT, the number of values in each group NOV, the number of bits necessary to pack the JMIN values IBIT, the number of bits necessary to pack the LBIT values JBIT, and the number of bits necessary to pack the NOV values KBIT. More...
 

Detailed Description

This subroutine determines groups of variable size.

Author
Harry Glahn
Date
1994-02-01

Definition in file pack_gp.f.

Function/Subroutine Documentation

◆ pack_gp()

subroutine pack_gp ( dimension(nxy)  IC,
  NXY,
  IS523,
  MINPK,
  INC,
  MISSP,
  MISSS,
dimension(ndg)  JMIN,
dimension(ndg)  JMAX,
dimension(ndg)  LBIT,
dimension(ndg)  NOV,
  NDG,
  LX,
  IBIT,
  JBIT,
  KBIT,
  NOVREF,
  LBITREF,
  IER 
)

This subroutine determines groups of variable size, but at least of size minpk, the associated max(JMAX) and min(JMIN), the number of bits necessary to hold the values in each group LBIT, the number of values in each group NOV, the number of bits necessary to pack the JMIN values IBIT, the number of bits necessary to pack the LBIT values JBIT, and the number of bits necessary to pack the NOV values KBIT.

The routine is designed to determine the groups such that a small number of bits is necessary to pack the data without excessive computations. If all values in the group are zero, the number of bits to use in packing is defined as zero when there can be no missing values; when there can be missing values, the number of bits must be at least 1 to have the capability to recognize the missing value. However, if all values in a group are missing, the number of bits needed is 0, and the unpacker recognizes this.

All variables are integer, even though the groups are initially of size minpk or larger, an adjustment between two groups (the lookback procedure) may make a group smaller than minpk. The control on group size is that the sum of the sizes of the two consecutive groups, each of size minpk or larger, is not decreased.

When determining the number of bits necessary for packing, the largest value that can be accommodated in, say mbits is 2**mbits-1 this largest value (and the next smallest value) is reserved for the missing value indicator (only) when is 523 ne 0.

If the dimension NDG is not large enough to hold all the groups, the local value of minpk is increased by 50 percent. this is repeated until ndg will suffice. A diagnostic is printed whenever this happens, which should be very rarely. If it happens often, NDG in subroutine pack should be increased and a corresponding increase in subroutine unpack made.

Considerable code is provided so that no more checking for missing values within loops is done than necessary; the added efficiency of this is relatively minor, but does no harm.

For grib2, the reference value for the length of groups in nov and for the number of bits necessary to pack group values are determined, and subtracted before jbit and kbit are determined. When 1 or more groups are large compared to the others, the width of all groups must be as large as the largest. A subroutine reduce breaks up large groups into 2 or more to reduce total bits required. If reduce() should abort, pack_gp() will be executed again without the call to reduce.

Parameters
[in]ICarray to hold data for packing. The values do not have to be positive at this point, but must be in the range -2**30 to +2**30 (the value of mallow). These integer values will be retained exactly through packing and unpacking.
[in]NXYnumber of values in IC. also treated as its dimension.
[in]IS523missing value management 0=data contains no missing values: 1 data contains primary missing values; 2=data contains primary and secondary missing values.
[in]MINPKthe minimum size of each group, except possibly the last one.
[in]INCthe number of values to add to an already existing group in determining whether or not to start a new group. Ideally, this would be 1, but each time inc values are attempted, the max and min of the next minpk values must be found. This is "a loop within a loop," and a slightly larger value may give about as good results with slightly less computational time. If inc is le 0, 1 is used, and a diagnostic is output. note: it is expected that INC will equal 1. The code uses inc primarily in the loops starting at statement 180. If INC were 1, there would not need to be loops as such. However, kinc (the local value of INC) is set ge 1 when near the end of the data to forestall a very small group at the end.
[in]MISSPwhen missing points can be present in the data, they will have the value missp or misss. missp is the primary missing value and misss is the secondary missing value. These must not be values that would occur with subtracting the minimum (reference) value or scaling. for example, missp = 0 would not be advisable.
[in]MISSSsecondary missing value indicator (see missp).
[out]JMINthe minimum of each group (j=1,lx).
[out]JMAXthe maximum of each group (j=1,lx). This is not really needed, but since the max of each group must be found, saving it here is cheap in case the user wants it.
[out]LBITthe number of bits necessary to pack each group (j=1,lx). It is assumed the minimum of each group will be removed before packing, and the values to pack will, therefore, all be positive. However, IC does not necessarily contain all positive values. If the overall minimum has been removed (the usual case), then IC will contain only positive values.
[out]NOVthe number of values in each group (j=1,lx).
[in]NDGthe dimension of JMIN, JMAX, LBIT, and NOV.
[out]LXthe number of groups determined.
[out]IBITthe number of bits necessary to pack the JMIN(j) values, j=1,LX.
[out]JBITthe number of bits necessary to pack the LBIT(j) values, j=1,LX.
[out]KBITthe number of bits necessary to pack the NOV(j) values, j=1,LX.
[out]NOVREFreference value for NOV.
[out]LBITREFreference value for LBIT.
[out]IERerror return.
  • 706 value will not pack in 30 bits–fatal
  • 714 error in reduce–non-fatal
  • 715 ngp not large enough in reduce–non-fatal
  • 716 minpk inceased–non-fatal
  • 717 inc set = 1–non-fatal
Author
Harry Glahn
Date
1994-02-01

Definition at line 113 of file pack_gp.f.

References reduce().

Referenced by compack(), and misspack().