NCEPLIBS-g2  3.4.5
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 (KFILDO, 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 (   KFILDO,
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 is523 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.

PROGRAM HISTORY LOG:

  • 1994-02-01 Harry Glahn tdl mos-2000.
  • 1995-06-01 Harry Glahn modified for lmiss error.
  • 1996-07-01 Harry Glahn added misss.
  • 1997-02-01 Harry Glahn removed 4 redundant tests for missp.eq.0; inserted a test to better handle a string of 9999's.
  • 1997-02-01 Harry Glahn added loops to eliminate test for misss when misss = 0.
  • 1997-03-01 Harry Glahn corrected for secondary missing value.
  • 1997-03-01 Harry Glahn corrected for use of local value of minpk.
  • 1997-03-01 Harry Glahn corrected for secondary missing value.
  • 1997-03-01 Harry Glahn changed calculating number of bits through exponents to an array (improved overall packing performance by about 35 percent). Allowed 0 bit for packing JMIN, LBIT, and NOV.
  • 1997-05-01 Harry Glahn a number of changes for efficiency. mod functions eliminated and one ifthen added. Jount removed. Recomputation of bits not made unless necessary after moving points from one group to another. Nendb adjusted to eliminate possibility of very small group at the end. About 8 percent improvement in overall packing. ISKIPA removed; There is always a group b that can become group A. Control on size of group b (statement below 150) added. Added adda, and use of ge and le instead of gt and lt in loop between 150 and 160. IBITBS added to shorten trip through loop.
  • 2000-03-01 Harry Glahn modified for grib2; changed name from packgp.
  • 2001-01-01 Harry Glahn Add comments; ier = 706 substituted for stops; added return; removed statement number 110; added ier.
  • 2001-11-01 Harry Glahn changed some diagnostic formats to allow printing larger numbers
  • 2001-11-01 Harry Glahn added misslx to put maximum value into JMIN when all values missing to agree with grib standard.
  • 2001-11-01 Harry Glahn changed two tests on missp and misss eq 0 to tests on is523. However, missp and misss cannot in general be 0.
  • 2001-11-01 Harry Glahn added call to reduce; defined itest before loops to reduce computation; started large group when all same value.
  • 2001-12-01 Harry Glahn modified and added a few comments.
  • 2002-01-01 Harry Glahn removed loop before 150 to determine a group of all same value.
  • 2002-01-01 Harry Glahn changed mallow from 9999999 to 2**30+1, and made it a parameter.
  • 2002-03-01 Harry Glahn added non fatal ier = 716, 717; removed nendb=nxy above 150; added iersav=0.
Parameters
[in]KFILDOunit number for output/print file.
[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 155 of file pack_gp.f.