pack_gp.c(3)

πŸ“¦
version 2.3.0 Β· 2 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– 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 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). 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:

  1. February 1994 β€” Glahn tdl mos-2000
  2. June 1995 β€” Glahn modified for lmiss error.
  3. July 1996 β€” Glahn added misss
  4. February 1997 β€” Glahn removed 4 redundant tests for missp.eq.0; inserted a test to better handle a string of 9999's
  5. February 1997 β€” Glahn added loops to eliminate test for misss when misss = 0
  6. March 1997 β€” Glahn corrected for secondary missing value
  7. March 1997 β€” Glahn corrected for use of local value of minpk
  8. March 1997 β€” Glahn corrected for secondary missing value
  9. 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( ).
  10. 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.
  11. March 2000 β€” Glahn modified for grib2; changed name from packgp
  12. january 2001 β€” Glahn comments; ier = 706 substituted for stops; added return1; removed statement number 110; added ier and * return
  13. November 2001 β€” Glahn changed some diagnostic formats to allow printing larger numbers
  14. November 2001 β€” Glahn added misslx( ) to put maximum value into jmin( ) when all values missing to agree with grib standard.
  15. 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.
  16. November 2001 β€” Glahn added call to reduce; defined itest before loops to reduce computation; started large group when all same value
  17. December 2001 β€” Glahn modified and added a few comments
  18. January 2002 β€” Glahn removed loop before 150 to determine a group of all same value
  19. January 2002 β€” Glahn changed mallow from 9999999 to 2**30+1, and made it a parameter
  20. 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

  • 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**30 to +2**30 (the the value of mallow). these g2int 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 aloop," 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.
⚠️ bestie heads up: 706 is fatal, and the whole thing does an alternate return when ier ne 0 and it's a fatal error. pay attention to your ier, 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 the g2int value of a printer form feed. πŸ–¨οΈ
  • kinc β€” a working copy of inc. It may be modified. ✨
  • mina β€” lowkey the minimum value in group a. 🌸
  • maxa β€” highkey the 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 β€” this one is giving reserved-bits energy: it's 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 g2int 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. (g2int) πŸ›‘
  • ibitbs β€” keeps current value of ibitb so that the 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 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