Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a standard way to do data packing (which does not break existing, non-standard methods) #1547

Closed
edwardhartnett opened this issue Nov 21, 2019 · 1 comment

Comments

@edwardhartnett
Copy link
Contributor

By packing I mean taking a 32-bit or 64-bit float array, calculating a scale and offset, and storing values as short ints. In this way a 32 or 64 bit data type can be stored in 16 bits.

Of course people have been doing this for a long time, but we have no official way to do this in the netCDF library. I suggest we add one.

So lets say I can do:

/* Define a short var. */
nc_def_var(ncid, "data", NDIM3, dimid, NC_SHORT, &varid)

/* Tell library this var is a double, packed to a short, using offset and scale factor. */
nc_def_var_packing(ncid, varid, NC_DOUBLE, offset, scale_facror)

That defines a var that is a double, stored as a short. When I call nc_put_vara_double() for this var, it automatically packs the data and stores the shorts. When I call nc_get_vara_double(), it unpacks the data. (For calls to other types, it is treated as a double, not a short.)

Then we define some attribute names to store the scale and offset.

Easy-peasy, lemon squeezy, as the kids used to say. ;-)

This is part of #1545

@edwardhartnett
Copy link
Contributor Author

I think this feature is more appropriate for the CCR, so I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant