netCDFPerl(1)

πŸ“¦ version 1.2.4, in fedora 43, fedora 44

πŸ’– netCDFPerl πŸ’–

okay so bestie, welcome to netCDFPerl β€” a perl extension for netCDF dataset access, straight out of the UNIDATA UTILITIES manual. no cap, this one is niche but it slays. πŸ¦‹


✨ NAME ✨

netCDFPerl β€” a perl extension for netCDF dataset access. yes that's it, that's the whole name section, she's concise. πŸ’…


🌸 SYNOPSIS 🌸

use netCDF;

NetCDF::create("foo.nc", NetCDF::CLOBBER);
...

literally just use netCDF; and you're in, babes. that ... is doing a lot of heavy lifting and honestly, same. πŸŽ€


🫢 DESCRIPTION 🫢

netCDFPerl is a Perl 5 extension-module interface to the services provided by the netCDF version 2 API, netcdf2(3). it's giving "let me call C from Perl and make it cute." πŸ‘‘

So here's the vibe: every function in the netCDF version 2 library can be reached from a Perl 5 script by swapping the nc prefix of the regular netCDF version 2 C function names with NetCDF::. for example, the C function nccreate() shows up to a perl script as NetCDF::create. iconic behavior fr fr. ✨

Each perl function matches its C counterpart as closely as possible and necessary:

  • the number, order, and semantics of the arguments are identical. one lil note tho β€” you do not have to specify the number of elements in an array, because perl arrays carry that information themselves. she's self-aware, we love that. πŸ’–
  • the behavior is the same in terms of the netCDF dataset.
  • a value of -1 is returned to indicate an error. yes bestie, -1, that's your red flag. 🚩

Scalar argument types are mapped in an obvious way:

The individual elements of an array argument are similarly mapped.

Array arguments themselves are passed by reference for both input and output. for example, this Perl 5 code will write and then read a hyperslab of values:

@start = (0, 0, 0);
@count = (1, 2, 3);
@out = (1, 2, 3, 4, 5, 6);
NetCDF::varput($ncid, $varid, @start, @count, @out);
NetCDF::varget($ncid, $varid, @start, @count, @in);

(the above assumes that $ncid and $varid have been appropriately set, so like… set them, bestie.) after this code runs, the array @in will have the same values as the array @out. 🌈

⚠️ heads up: the previous contents, if any, of an array used for input are destroyed (e.g. @in in the above example). she's gone. πŸ’€

To define a scalar variable with NetCDF::vardef(), use an empty dimension-ID array, like this:

NetCDF::vardef($ncid, "scalar_variable", NetCDF::FLOAT, \());

The interface doesn't support null arguments. you cannot use a void pointer to indicate that no value is requested for a particular argument β€” all arguments must be present. no skipping, no ghosting, everyone shows up to the function call. πŸ™ˆ

For technical reasons, output variables must be initialized, i.e. any variable argument that is to have its value set by a function must already have a value. for example, if the first occurrence of the variable $attval is in the following:

NetCDF::attget($ncid, NetCDF::GLOBAL, "history", \$attval);

then a core dump will probably result. 😭 the solution is to initialize the variable before using it:

$attval="";
NetCDF::attget($ncid, NetCDF::GLOBAL, "history", \$attval);

Two additional functions are provided for error handling:

  • NetCDF::opts(i) determines the handling of errors by setting the ncopts variable to i. it returns the previous value. πŸŽ€
  • NetCDF::err() returns the value of the error code variable, ncerr.

In addition to the above functions, most C macro constants that are defined in the netCDF header file netcdf.h are also available to a perl script by dropping any NC_ substring and using the NetCDF:: prefix, e.g. NetCDF::LONG. the way they just chopped the prefix off and said "you're welcome"? obsessed. πŸ’…


🌟 SEE ALSO 🌟


and that's the whole page, babe. πŸ’œ

Printed: 126-10-12 β€” $Date: 1999/07/21 16:38:27 $ β€” from the netCDFPerl(1) era, which is lowkey giving vintage but she still ate. 🌸 periodt. πŸ’–

πŸ“¦ where this page comes from