pack_gp.c(3)
π pack_gp.c(3) β Library Functions Manual π
okay bestie, sit down, hydrate, because we're about to get into pack_gp.c(3) and it is a lot in the best way. this is a C library function manual page and it's lowkey iconic. let's go β¨
πΈ NAME πΈ
pack_gp.c β that's it, that's the name, she's simple like that π
π SYNOPSIS π
#include 'grib2_int.h'
#include <stdlib.h>
β¨ Macros β¨
#define FALSE_ (0)β false, babes. literally just false. π#define TRUE_ (1)β true!! yes!! we love a truthy moment π«Ά
π¦ Functions π¦
int pack_gp (g2int *kfildo, g2int *ic, g2int *nxy, g2int *is523, g2int *minpk, g2int *inc, g2int *missp, g2int *misss, g2int *jmin, g2int *jmax, g2int *lbit, g2int *nov, g2int *ndg, g2int *lx, g2int *ibit, g2int *jbit, g2int *kbit, g2int *novref, g2int *lbitref, g2int *ier)β she 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 thejmin( )values (ibit), the number of bits necessary to pack thelbit( )values (jbit), and the number of bits necessary to pack thenov( )values (kbit). yeah. that's the whole job. she does all of that. π
π Detailed Description π
Author
Glahn
Date
february 1994 β a legend was born, no cap π
Definition in file pack_gp.c.
π Macro Definition Documentation π
#define FALSE_ (0)
False. periodt.
Definition at line 10 of file pack_gp.c.
Referenced by pack_gp().
#define TRUE_ (1)
True. the vibes are immaculate.
Definition at line 9 of file pack_gp.c.
Referenced by pack_gp().
π Function Documentation π
int pack_gp (g2int * kfildo, g2int * ic, g2int * nxy, g2int * is523, g2int * minpk, g2int * inc, g2int * missp, g2int * misss, g2int * jmin, g2int * jmax, g2int * lbit, g2int * nov, g2int * ndg, g2int * lx, g2int * ibit, g2int * jbit, g2int * kbit, g2int * novref, g2int * lbitref, g2int * 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).
so here's the tea, bestie π the routine is designed to determine the groups such that a small number of bits is necessary to pack the data without excessive computations. efficiency queen fr fr.
- 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, because you gotta 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 g2int. every single one.
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( ), andnov( ). - 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
geandleinstead ofgtandltin 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 = 706substituted 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 intojmin( )when all values missing to agree with grib standard. - November 2001 β Glahn changed two tests on
misspandmisss eq 0to tests onis523. however,misspandmissscannot 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
9999999to2**30+1, and made it a parameter - March 2002 β Glahn added non fatal
ier = 716,717; removednendb=nxyabove 150; addediersav=0; comments
DATA SET USE
kfildoβ unit number for output (print) file. (output)
Parameters
kfildoβ unit number for output (print) file. (input)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**30to+2**30(the the value of mallow). theseg2intvalues will be retained exactly through packing and unpacking. (input)nxyβ number of values inic( ). also treated as its dimension. (input)is523β missing value management0= data contains no missing values1= data contains primary missing values2= 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 aloop," and a slightly larger value may give about as good results with slightly less computational time. ifincisle 0,1is used, and a diagnostic is output. note: it is expected thatincwill equal1. the code usesincprimarily in the loops starting at statement 180. ifincwere 1, there would not need to be loops as such. however,kinc(the local value ofinc) is setge 1when 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 valuemisspormisss.misspis the primary missing value andmisssis the secondary missing value . these must not be values that would occur with subtracting the minimum (reference) value or scaling. for example,missp = 0would not be advisable. (input)misssβ secondary missing value indicator (seemissp). (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), thenic( )will contain only positive values. (output)novβ the number of values in each group (j=1,lx). (output)ndgβ the dimension ofjmin,jmax,lbit, andnov. (input)lxβ the number of groups determined. (output)ibitβ the number of bits necessary to pack thejmin(j)values,j=1,lx. (output)jbitβ the number of bits necessary to pack thelbit(j)values,j=1,lx. (output)kbitβ the number of bits necessary to pack thenov(j)values,j=1,lx. (output)novrefβ reference value fornov( ). (output)lbitrefβ reference value forlbit( ). (output)ierβ Error code0β No error.706β value will not pack in 30 bits--fatal714β error in reduce--non-fatal715β ngp not large enough in reduce--non-fatal716β minpk inceased--non-fatal717β inc set1--non-fatal- alternate return when
ier ne 0and fatal error.
β οΈ bestie heads up:706is fatal, and the whole thing does an alternate return whenier ne 0and it's a fatal error. pay attention to yourier, i'm begging π
Returns
0 - check ier for error code.
INTERNAL VARIABLES
(part 1 ends here β more is coming, don't go anywhere π)
okay bestie, picking up right where we left off β here's the rest of the local-variable lore for pack_gp.c, no skips, no cap. π
β¨
cfeedβ contains the character representation of a printer form feed. π¨οΈifeedβ contains theg2intvalue of a printer form feed. π¨οΈkincβ a working copy ofinc. It may be modified. β¨minaβ lowkey the minimum value in group a. πΈmaxaβ highkey the maximum value in group a. πΈnendaβ the place inic( )where group a ends. πkstartβ the place inic( )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 inic( )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 inic( )processed. βnountβ number of values added to group a. βlmissβ this one is giving reserved-bits energy: it's0whenis523 = 0. When packing into a specific number of bits, saymbits, the maximum value that can be handled is2**mbits-1. Whenis523 = 1, indicating primary missing values, this maximum value is reserved to hold the primary missing value indicator andlmiss = 1. Whenis523 = 2, the value just below the maximum, i.e.2**mbits-2, is reserved to hold the secondary missing value indicator andlmiss = 2. π₯lminpkβ local value ofminpk. This will be adjusted upward wheneverndgis not large enough to hold all the groups. π«Άmallowβ the largest allowable value for packing. πmisllaβ set to1when 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.0otherwise. Note that this does not distinguish between primary and secondary missings when secondary missings are present. This means thatlbit( )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 to1when 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.0otherwise. πmisllcβ performs the same function for group c thatmisllaandmisllbdo for groups b and c, respectively. πibxx2(j)β an array that when this routine is first entered is set to2**j,j=0,30.ibxx2(30) = 2**30, which is the largest value packable, because2**31is larger than theg2intword size. βifirstβ set by data statement to0. Changed to1on first entry whenibxx2( )is filled. πminakβ keeps track of the location inic( )where the minimum value in group a is located. πmaxakβ does the same asminak, except for the maximum. πminbkβ the same asminakfor group b. πmaxbkβ the same asmaxakfor group b. πminckβ the same asminakfor group c. πmaxckβ the same asmaxakfor group c. πaddaβ keeps track whether or not an attempt to add points to group a was made. If so, thenaddakeeps from trying to put one back into b. (g2int) πibitbsβ keeps current value ofibitbso that the loop ending at166doesn't have to start atibitb = 0every time. πmisslx(j)βmallowexcept when a group is all one value (andlbit(j) = 0) and that value is missing. In that case,misslx(j)ismisspormisss. This gets inserted intojmin(j)later as the missing indicator; it can't be put in until the end, becausejmin( )is used to calculate the maximum number of bits (ibits) needed to packjmin( ). π«Ά
π Definition at line 255 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. π
and that's the whole vibe, bestie β this page is from NCEPLIBS-g2c, version 2.3.0, pack_gp.c(3). mwah πβ¨
π¦ where this page comes from
- ubuntu resolute: libg2c-dev 2.3.0-4 Β· LGPL-3.0-only
- ubuntu stonking: libg2c-dev 2.3.0-7 Β· LGPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms