.TH "pack_gp.c" 3 "Tue May 3 2022" "Version 1.6.4" "NCEPLIBS-g2c" \" -*- nroff -*- .ad l .nh .SH NAME pack_gp.c .SH SYNOPSIS .br .PP \fC#include \fP .br \fC#include 'grib2\&.h'\fP .br .SS "Macros" .in +1c .ti -1c .RI "#define \fBFALSE_\fP (0)" .br .RI "False\&. " .ti -1c .RI "#define \fBTRUE_\fP (1)" .br .RI "True\&. " .in -1c .SS "Typedefs" .in +1c .ti -1c .RI "typedef \fBg2int\fP \fBinteger\fP" .br .RI "Integer type\&. " .ti -1c .RI "typedef \fBg2int\fP \fBlogical\fP" .br .RI "Logical type\&. " .in -1c .SS "Functions" .in +1c .ti -1c .RI "int \fBpack_gp\fP (\fBinteger\fP *kfildo, \fBinteger\fP *ic, \fBinteger\fP *nxy, \fBinteger\fP *is523, \fBinteger\fP *minpk, \fBinteger\fP *inc, \fBinteger\fP *missp, \fBinteger\fP *misss, \fBinteger\fP *jmin, \fBinteger\fP *jmax, \fBinteger\fP *lbit, \fBinteger\fP *nov, \fBinteger\fP *ndg, \fBinteger\fP *lx, \fBinteger\fP *ibit, \fBinteger\fP *jbit, \fBinteger\fP *kbit, \fBinteger\fP *novref, \fBinteger\fP *lbitref, \fBinteger\fP *ier)" .br .RI "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)\&. " .in -1c .SH "Detailed Description" .PP .PP \fBAuthor\fP .RS 4 Glahn .RE .PP \fBDate\fP .RS 4 february 1994 .RE .PP .PP Definition in file \fBpack_gp\&.c\fP\&. .SH "Macro Definition Documentation" .PP .SS "#define FALSE_ (0)" .PP False\&. .PP Definition at line 11 of file pack_gp\&.c\&. .SS "#define TRUE_ (1)" .PP True\&. .PP Definition at line 10 of file pack_gp\&.c\&. .SH "Typedef Documentation" .PP .SS "typedef \fBg2int\fP \fBinteger\fP" .PP Integer type\&. .PP Definition at line 8 of file pack_gp\&.c\&. .SS "typedef \fBg2int\fP \fBlogical\fP" .PP Logical type\&. .PP Definition at line 9 of file pack_gp\&.c\&. .SH "Function Documentation" .PP .SS "int pack_gp (\fBinteger\fP * kfildo, \fBinteger\fP * ic, \fBinteger\fP * nxy, \fBinteger\fP * is523, \fBinteger\fP * minpk, \fBinteger\fP * inc, \fBinteger\fP * missp, \fBinteger\fP * misss, \fBinteger\fP * jmin, \fBinteger\fP * jmax, \fBinteger\fP * lbit, \fBinteger\fP * nov, \fBinteger\fP * ndg, \fBinteger\fP * lx, \fBinteger\fP * ibit, \fBinteger\fP * jbit, \fBinteger\fP * kbit, \fBinteger\fP * novref, \fBinteger\fP * lbitref, \fBinteger\fP * ier)" .PP 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\&. .PP 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\&. .PP PROGRAM HISTORY LOG: .IP "\(bu" 2 February 1994 Glahn tdl mos-2000 .IP "\(bu" 2 June 1995 Glahn modified for lmiss error\&. .IP "\(bu" 2 July 1996 Glahn added misss .IP "\(bu" 2 February 1997 Glahn removed 4 redundant tests for missp\&.eq\&.0; inserted a test to better handle a string of 9999's .IP "\(bu" 2 February 1997 Glahn added loops to eliminate test for misss when misss = 0 .IP "\(bu" 2 March 1997 Glahn corrected for secondary missing value .IP "\(bu" 2 March 1997 Glahn corrected for use of local value of minpk .IP "\(bu" 2 March 1997 Glahn corrected for secondary missing value .IP "\(bu" 2 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( )\&. .IP "\(bu" 2 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\&. .IP "\(bu" 2 March 2000 Glahn modified for grib2; changed name from packgp .IP "\(bu" 2 january 2001 Glahn comments; ier = 706 substituted for stops; added return1; removed statement number 110; added ier and * return .IP "\(bu" 2 November 2001 Glahn changed some diagnostic formats to allow printing larger numbers .IP "\(bu" 2 November 2001 Glahn added misslx( ) to put maximum value into jmin( ) when all values missing to agree with grib standard\&. .IP "\(bu" 2 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\&. .IP "\(bu" 2 November 2001 Glahn added call to reduce; defined itest before loops to reduce computation; started large group when all same value .IP "\(bu" 2 December 2001 Glahn modified and added a few comments .IP "\(bu" 2 January 2002 Glahn removed loop before 150 to determine a group of all same value .IP "\(bu" 2 January 2002 Glahn changed mallow from 9999999 to 2**30+1, and made it a parameter .IP "\(bu" 2 March 2002 Glahn added non fatal ier = 716, 717; removed nendb=nxy above 150; added iersav=0; comments .PP .PP DATA SET USE .IP "\(bu" 2 kfildo - unit number for output (print) file\&. (output) .PP .PP \fBParameters\fP .RS 4 \fIkfildo\fP unit number for output (print) file\&. (input) .br \fIic\fP 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) .br \fInxy\fP number of values in ic( )\&. also treated as its dimension\&. (input) .br \fIis523\fP missing value management 0=data contains no missing values 1=data contains primary missing values 2=data contains primary and secondary missing values (input) .br \fIminpk\fP the minimum size of each group, except possibly the last one\&. (input) .br \fIinc\fP 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) .br \fImissp\fP 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) .br \fImisss\fP secondary missing value indicator (see missp)\&. (input) .br \fIjmin\fP the minimum of each group (j=1,lx)\&. (output) .br \fIjmax\fP 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) .br \fIlbit\fP 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) .br \fInov\fP the number of values in each group (j=1,lx)\&. (output) .br \fIndg\fP the dimension of jmin, jmax, lbit, and nov\&. (input) .br \fIlx\fP the number of groups determined\&. (output) .br \fIibit\fP the number of bits necessary to pack the jmin(j) values, j=1,lx\&. (output) .br \fIjbit\fP the number of bits necessary to pack the lbit(j) values, j=1,lx\&. (output) .br \fIkbit\fP the number of bits necessary to pack the nov(j) values, j=1,lx\&. (output) .br \fInovref\fP reference value for nov( )\&. (output) .br \fIlbitref\fP reference value for lbit( )\&. (output) .br \fIier\fP Error code .IP "\(bu" 2 0 No error\&. .IP "\(bu" 2 706 value will not pack in 30 bits--fatal .IP "\(bu" 2 714 error in reduce--non-fatal .IP "\(bu" 2 715 ngp not large enough in reduce--non-fatal .IP "\(bu" 2 716 minpk inceased--non-fatal .IP "\(bu" 2 717 inc set .IP "\(bu" 2 1--non-fatal .IP "\(bu" 2 alternate return when ier ne 0 and fatal error\&. .PP .RE .PP \fBReturns\fP .RS 4 0 - check ier for error code\&. .PP .nf INTERNAL VARIABLES .fi .PP .PP .nf 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( )\&. .fi .PP .RE .PP .PP Definition at line 256 of file pack_gp\&.c\&. .PP References FALSE_, reduce(), and TRUE_\&. .PP Referenced by compack(), and misspack()\&. .SH "Author" .PP Generated automatically by Doxygen for NCEPLIBS-g2c from the source code\&.