pack_gp.c(3) | NCEPLIBS-g2c | pack_gp.c(3) |
NAME¶
pack_gp.c
SYNOPSIS¶
#include <stdlib.h>
#include 'grib2.h'
Macros¶
#define FALSE_ (0)
False. #define TRUE_ (1)
True.
Typedefs¶
typedef g2int integer
Integer type. typedef g2int logical
Logical type.
Functions¶
int pack_gp (integer *kfildo, integer *ic,
integer *nxy, integer *is523, integer *minpk,
integer *inc, integer *missp, integer *misss,
integer *jmin, integer *jmax, integer *lbit,
integer *nov, integer *ndg, integer *lx, integer
*ibit, integer *jbit, integer *kbit, integer *novref,
integer *lbitref, integer *ier)
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).
Detailed Description¶
Author
Date
Definition in file pack_gp.c.
Macro Definition Documentation¶
#define FALSE_ (0)¶
False.
Definition at line 11 of file pack_gp.c.
#define TRUE_ (1)¶
True.
Definition at line 10 of file pack_gp.c.
Typedef Documentation¶
typedef g2int integer¶
Integer type.
Definition at line 8 of file pack_gp.c.
typedef g2int logical¶
Logical type.
Definition at line 9 of file pack_gp.c.
Function Documentation¶
int pack_gp (integer * kfildo, integer * ic, integer * nxy, integer * is523, integer * minpk, integer * inc, integer * missp, integer * misss, integer * jmin, integer * jmax, integer * lbit, integer * nov, integer * ndg, integer * lx, integer * ibit, integer * jbit, integer * kbit, integer * novref, integer * lbitref, integer * ier)¶
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:
- February 1994 Glahn tdl mos-2000
- June 1995 Glahn modified for lmiss error.
- July 1996 Glahn added misss
- February 1997 Glahn removed 4 redundant tests for missp.eq.0; inserted a test to better handle a string of 9999's
- February 1997 Glahn added loops to eliminate test for misss when misss = 0
- March 1997 Glahn corrected for secondary missing value
- March 1997 Glahn corrected for use of local value of minpk
- March 1997 Glahn corrected for secondary missing value
- March 1997 Glahn changed calculating number of bits through exponents to an array (improved overall packing performance by about 35 percent!). allowed 0 bits for packing jmin( ), lbit( ), and nov( ).
- May 1997 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 loops between 150 and 160. ibitbs added to shorten trips through loop.
- March 2000 Glahn modified for grib2; changed name from packgp
- january 2001 Glahn comments; ier = 706 substituted for stops; added return1; removed statement number 110; added ier and * return
- November 2001 Glahn changed some diagnostic formats to allow printing larger numbers
- November 2001 Glahn added misslx( ) to put maximum value into jmin( ) when all values missing to agree with grib standard.
- November 2001 Glahn changed two tests on missp and misss eq 0 to tests on is523. however, missp and misss cannot in general be = 0.
- November 2001 Glahn added call to reduce; defined itest before loops to reduce computation; started large group when all same value
- December 2001 Glahn modified and added a few comments
- January 2002 Glahn removed loop before 150 to determine a group of all same value
- January 2002 Glahn changed mallow from 9999999 to 2**30+1, and made it a parameter
- March 2002 Glahn added non fatal ier = 716, 717; removed nendb=nxy above 150; added iersav=0; comments
DATA SET USE
- •
- kfildo - unit number for output (print) file. (output)
Parameters
ic array 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 the value of mallow). these integer values will be retained exactly through packing and unpacking. (input)
nxy number of values in ic( ). also treated as its dimension. (input)
is523 missing value management 0=data contains no missing values 1=data contains primary missing values 2=data contains primary and secondary missing values (input)
minpk the minimum size of each group, except possibly the last one. (input)
inc the 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. (input)
missp when 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. (input)
misss secondary missing value indicator (see missp). (input)
jmin the minimum of each group (j=1,lx). (output)
jmax the 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. (output)
lbit the 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. (output)
nov the number of values in each group (j=1,lx). (output)
ndg the dimension of jmin, jmax, lbit, and nov. (input)
lx the number of groups determined. (output)
ibit the number of bits necessary to pack the jmin(j) values, j=1,lx. (output)
jbit the number of bits necessary to pack the lbit(j) values, j=1,lx. (output)
kbit the number of bits necessary to pack the nov(j) values, j=1,lx. (output)
novref reference value for nov( ). (output)
lbitref reference value for lbit( ). (output)
ier Error code
- 0 No error.
- 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
- alternate return when ier ne 0 and fatal error.
Returns
INTERNAL VARIABLES
cfeed = contains the character representation
of a printer form feed.
ifeed = contains the integer value of a printer
form feed.
kinc = working copy of inc. may be modified.
mina = minimum value in group a.
maxa = maximum value in group a.
nenda = the place in ic( ) where group a ends.
kstart = the place in ic( ) where group a starts.
ibita = number of bits needed to hold values in group a.
minb = minimum value in group b.
maxb = maximum value in group b.
nendb = the place in ic( ) where group b ends.
ibitb = number of bits needed to hold values in group b.
minc = minimum value in group c.
maxc = maximum value in group c.
ktotal = count of number of values in ic( ) processed.
nount = number of values added to group a.
lmiss = 0 when is523 = 0. when packing into a
specific number of bits, say mbits,
the maximum value that can be handled is
2**mbits-1. when is523 = 1, indicating
primary missing values, this maximum value
is reserved to hold the primary missing value
indicator and lmiss = 1. when is523 = 2,
the value just below the maximum (i.e.,
2**mbits-2) is reserved to hold the secondary
missing value indicator and lmiss = 2.
lminpk = local value of minpk. this will be adjusted
upward whenever ndg is not large enough to hold
all the groups.
mallow = the largest allowable value for packing.
mislla = set to 1 when all values in group a are missing.
this is used to distinguish between a real
minimum when all values are not missing
and a minimum that has been set to zero when
all values are missing. 0 otherwise.
note that this does not distinguish between
primary and secondary missings when secondary
missings are present. this means that
lbit( ) will not be zero with the resulting
compression efficiency when secondary missings
are present. also note that a check has been
made earlier to determine that secondary
missings are really there.
misllb = set to 1 when all values in group b are missing.
this is used to distinguish between a real
minimum when all values are not missing
and a minimum that has been set to zero when
all values are missing. 0 otherwise.
misllc = performs the same function for group c that
mislla and misllb do for groups b and c,
respectively.
ibxx2(j) = an array that when this routine is first entered
is set to 2**j, j=0,30. ibxx2(30) = 2**30, which
is the largest value packable, because 2**31
is larger than the integer word size.
ifirst = set by data statement to 0. changed to 1 on
first
entry when ibxx2( ) is filled.
minak = keeps track of the location in ic( ) where the
minimum value in group a is located.
maxak = does the same as minak, except for the maximum.
minbk = the same as minak for group b.
maxbk = the same as maxak for group b.
minck = the same as minak for group c.
maxck = the same as maxak for group c.
adda = keeps track whether or not an attempt to add
points to group a was made. if so, then adda
keeps from trying to put one back into b.
(logical)
ibitbs = keeps current value if ibitb so that loop
ending at 166 doesn't have to start at
ibitb = 0 every time.
misslx(j) = mallow except when a group is all one value (and
lbit(j) = 0) and that value is missing. in
that case, misslx(j) is missp or misss. this
gets inserted into jmin(j) later as the
missing indicator; it can't be put in until
the end, because jmin( ) is used to calculate
the maximum number of bits (ibits) needed to
pack jmin( ).
Definition at line 256 of file pack_gp.c.
References FALSE_, reduce(), and TRUE_.
Referenced by compack(), and misspack().
Author¶
Generated automatically by Doxygen for NCEPLIBS-g2c from the source code.
Tue May 3 2022 | Version 1.6.4 |