NETCDF(3)
β¨ NAME β¨
okay so bestie, this is NETCDF(3) β the manual page for netcdf, aka Unidata's Network Common Data Form (netCDF) library interface. It lives in the UNIDATA LIBRARY FUNCTIONS section of the manual, and it's giving foundational Unix lore, no cap. π
π¦ SYNOPSIS π¦
First thing: you include netcdf.inc:
include netcdf.inc
Most Systems:
f77 ... -lnetcdf
CRAY PVP Systems:
f90 -dp -i64 ... -lnetcdf
Complete documentation for the netCDF libraries can be found at the netCDF website: https://www.unidata.ucar.edu/software/netcdf/. β¨
π LIBRARY VERSION π
This document describes version 3 of the Unidata netCDF data-access interface for the FORTRAN programming language. π
character*80 nf_inq_libvers(void)
Returns a string identifying the version of the netCDF library, and when it was built, like: "3.1a of Aug 22 1996 12:57:47 $". π
The RCS ident(1) command will find a string like "$Id: @(#) netcdf library version 3.1a of Sep 6 1996 15:56:26 $" in the library. The SCCS what(1) command will find a string like "netcdf library version 3.1a of Aug 23 1996 16:07:40 $". π¦
πΈ RETURN VALUES πΈ
All netCDF functions (except nf_inq_libvers() and nf_strerror()) return an integer status. Fr fr, that's the whole vibe check. π
If this returned status value is not equal to NF_NOERR (zero), it indicates that an error occurred. The possible status values are defined in netcdf.inc. π
character*80 nf_strerror(integer status)
Returns a string textual translation of the status value, like "Attribute or variable name contains illegal characters" or "No such file or directory". π«Ά
π FILE OPERATIONS π
okay bestie, this is the main character section. File ops era. Grab your iced coffee. π
integer function nf_create(character*(*) path, integer cmode, integer ncid)
Creates a new netCDF dataset at path, returning a netCDF ID in ncid. The argument cmode may include the bitwise-or of the following flags:
NF_NOCLOBBERβ protects existing datasets. Without it, the default silently blows them away. πNF_SHAREβ for synchronous dataset updates for classic format files (default is to buffer accesses).NF_64BIT_OFFSETβ to create a file in the 64-bit offset format (as opposed to classic format, the default).
When a netCDF dataset is created, it's opened NF_WRITE. The new netCDF dataset is in define mode. β¨
integer function nf__create(character*(*) path, integer cmode, integer initialsize, integer chunksize, integer ncid)
Like nf_create() but has additional performance tuning parameters. Highkey useful if you're tuning the vibe. π
The argument initialsize sets the initial size of the file at creation time.
See nf__open() below for an explanation of the chunksize parameter. π¦
integer function nf_open(character*(*) path, integer mode, integer ncid)
(Corresponds to ncopn() in version 2)
Opens an existing netCDF dataset at path returning a netCDF ID in ncid. The type of access is described by the mode parameter, which may include the bitwise-or of the following flags:
NF_WRITEβ for read-write access (default read-only).NF_SHAREβ for synchronous dataset updates (default is to buffer accesses).NF_LOCKβ (not yet implemented).
integer function nf__open(character*(*) path, integer mode, integer chunksize, integer ncid)
Like nf_open() but has an additional performance tuning parameter. π
The argument referenced by chunksize controls a space versus time tradeoff, memory allocated in the netcdf library versus number of system calls. Because of internal requirements, the value may not be set to exactly the value requested. The actual value chosen is returned by reference. Using the value NF_SIZEHINT_DEFAULT causes the library to choose a default. How the system chooses the default depends on the system. On many systems, the "preferred I/O block size" is available from the stat() system call, struct stat member st_blksize. If this is available it is used. Lacking that, twice the system pagesize is used. Lacking a call to discover the system pagesize, we just set default chunksize to 8192. π
The chunksize is a property of a given open netcdf descriptor ncid, it is not a persistent property of the netcdf dataset. π
integer function nf_redef(integer ncid)
(Corresponds to ncredf() in version 2)
Puts an open netCDF dataset into define mode, so dimensions, variables, and attributes can be added or renamed and attributes can be deleted. Slay. π
integer function nf_enddef(integer ncid)
(Corresponds to ncendf() in version 2)
Takes an open netCDF dataset out of define mode. The changes made to the netCDF dataset while it was in define mode are checked and committed to disk if no problems occurred. Some data values may be written as well, see "VARIABLE PREFILLING" below. After a successful call, variable data can be read or written to the dataset. β¨
integer function nf__enddef(integer ncid, integer h_minfree, integer v_align, integer v_minfree, integer r_align)
Like nf_enddef() but has additional performance tuning parameters. π
β οΈ Caution: this function exposes internals of the netcdf version 1 file format. It may not be available on future netcdf implementations. No cap, be careful with this one. π
The current netcdf file format has three sections, the "header" section, the data section for fixed size variables, and the data section for variables which have an unlimited dimension (record variables). The header begins at the beginning of the file. The index (offset) of the beginning of the other two sections is contained in the header. Typically, there is no space between the sections. This causes copying overhead to accrue if one wishes to change the size of the sections, as may happen when changing names of things, text attribute values, adding attributes or adding variables. Also, for buffered i/o, there may be advantages to aligning sections in certain ways. π¦
The minfree parameters allow one to control costs of future calls to nf_redef(), nf_enddef() by requesting that minfree bytes be available at the end of the section. The h_minfree parameter sets the pad at the end of the "header" section. The v_minfree parameter sets the pad at the end of the data section for fixed size variables. πΈ
The align parameters allow one to set the alignment of the beginning of the corresponding sections. The beginning of the section is rounded up to an index which is a multiple of the align parameter. The flag value NF_ALIGN_CHUNK tells the library to use the chunksize (see above) as the align parameter. The v_align parameter controls the alignment of the beginning of the data section for fixed size variables. The r_align parameter controls the alignment of the beginning of the data section for variables which have an unlimited dimension (record variables). π
The file format requires mod 4 alignment, so the align parameters are silently rounded up to multiples of 4. The usual call, nf_enddef(ncid) is equivalent to nf__enddef(ncid, 0, 4, 0, 4). β¨
The file format does not contain a "record size" value, this is calculated from the sizes of the record variables. This unfortunate fact prevents us from providing minfree and alignment control of the "records" in a netcdf file. If you add a variable which has an unlimited dimension, the third section will always be copied with the new variable added. π
integer function nf_sync(integer ncid)
(Corresponds to ncsnc() in version 2)
Unless the NF_SHARE bit is set in nf_open() or nf_create(), accesses to the underlying netCDF dataset are buffered by the library. This function synchronizes the state of the underlying dataset and the library. This is done automatically by nf_close() and nf_enddef(). π
integer function nf_abort(integer ncid)
(Corresponds to ncabor() in version 2)
You don't need to call this function. It's called automatically by nf_close() if the netCDF was in define mode and something goes wrong with the commit. If the netCDF dataset isn't in define mode, then this function is equivalent to nf_close(). If it is called after nf_redef(), but before nf_enddef(), the new definitions are not committed and the dataset is closed. If it is called after nf_create() but before nf_enddef(), the dataset disappears. π
integer function nf_close(integer ncid)
(Corresponds to ncclos() in version 2)
Closes an open netCDF dataset. If the dataset is in define mode, nf_enddef() will be called before closing. After a dataset is closed, its ID may be reassigned to another dataset. π«Ά
integer function nf_inq(integer ncid, integer ndims, integer nvars, integer natts, integer unlimdimid)
integer function nf_inq_ndims(integer ncid, integer ndims)
integer function nf_inq_nvars(integer ncid, integer nvars)
integer function nf_inq_natts(integer ncid, integer natts)
integer function nf_inq_unlimdim(integer ncid, integer unlimdimid)
integer function nf_inq_format(integer ncid, integer formatn)
Use these functions to find out what is in a netCDF dataset. Upon successful return, ndims will contain the number of dimensions defined for this netCDF dataset, nvars will contain the number of variables, natts will contain the number of attributes, and unlimdimid will contain the dimension ID of the unlimited dimension if one exists, or 0 otherwise. formatn will contain the version number of the dataset <format>, one of NF_FORMAT_CLASSIC, NF_FORMAT_64BIT, NF_FORMAT_NETCDF4, or NF_FORMAT_NETCDF4_CLASSIC. π
integer function nf_def_dim(integer ncid, character*(*) name, integer len, integer dimid)
(Corresponds to ncddef() in version 2)
Adds a new dimension to an open netCDF dataset, which must be in define mode. name is the dimension name. dimid will contain the dimension ID of the newly created dimension. Slay, periodt. π
π« DIMENSIONS π«
integer function nf_inq_dimid(integer ncid, character*(*) name, integer dimid)
ok so you have a dimension name and you want the ID? hand it over bestie β nf_inq_dimid returns the ID of a netCDF dimension in dimid. β¨ (It corresponds to ncdid() in version 2, for anyone reading ancient code π)
integer function nf_inq_dim(integer ncid, integer dimid, character*(*) name, integer len)
integer function nf_inq_dimname(integer ncid, integer dimid, character*(*) name)
integer function nf_inq_dimlen(integer ncid, integer dimid, integer len)
Use these functions to find out about a dimension π«Ά Your name buffer should be big enough (NF_MAX_NAME) to hold the dimension name, because the name literally gets copied into your storage, no cap. The length return parameter len will contain the size of the dimension. And for the unlimited dimension? the returned length is the current maximum value used for writing into any of the variables which use the dimension β it grows as you write, iykyk π±
integer function nf_rename_dim(integer ncid, integer dimid, character*(*) name)
Renames an existing dimension in an open netCDF dataset π (corresponds to ncdren() in version 2, if you were wondering). Tiny catch: if the new name is longer than the old name, the netCDF dataset must be in define mode. And no, you cannot rename a dimension to have the same name as another dimension. that's a hard no π
π¦ VARIABLES π¦
integer function nf_def_var(integer ncid, character*(*) name, integer xtype, integer ndims, integer dimids(1), integer varid)
Adds a brand new variable to a netCDF dataset β¨ (corresponds to ncvdef() in version 2). The netCDF must be in define mode β like, non-negotiable. When it's done, varid will be set to the netCDF variable ID. slay.
integer function nf_inq_varid(integer ncid, character*(*) name, integer varid)
The name β ID pipeline π«‘ (corresponds to ncvid() in version 2). Returns the ID of a netCDF variable in varid given its name.
integer function nf_inq_var(integer ncid, integer varid, character*(*) name, integer xtype, integer ndims, integer dimids(1), integer natts)
integer function nf_inq_varname(integer ncid, integer varid, character*(*) name)
integer function nf_inq_vartype(integer ncid, integer varid, integer xtype)
integer function nf_inq_varndims(integer ncid, integer varid, integer ndims)
integer function nf_inq_vardimid(integer ncid, integer varid, integer dimids(1))
integer function nf_inq_varnatts(integer ncid, integer varid, integer natts)
Returns information about a netCDF variable, given its ID π β one function per little answer, so you can grab just the piece you need instead of ordering the whole combo meal.
integer function nf_rename_var(integer ncid, integer varid, character*(*) name)
Changes the name of a netCDF variable (corresponds to ncvren() in version 2). If the new name is longer than the old name, the netCDF must be in define mode. And you cannot rename a variable to have the name of any existing variable. periodt π
βοΈ WRITING AND READING WHOLE VARIABLES π
integer function nf_put_var_text(integer ncid, integer varid, character*(*) out)
integer function nf_put_var_int1(integer ncid, integer varid, integer*1 out(1))
integer function nf_put_var_int2(integer ncid, integer varid, integer*2 out(1))
integer function nf_put_var_int(integer ncid, integer varid, integer out(1))
integer function nf_put_var_real(integer ncid, integer varid, real out(1))
integer function nf_put_var_double(integer ncid, integer varid, doubleprecision out(1))
Writes an entire netCDF variable β like, all the values, the whole thing π. The netCDF dataset must be open and in data mode. The type of the data is specified in the function name, and it gets converted to the external type of the specified variable, if possible β otherwise an NF_ERANGE error is returned.
β οΈ real talk: rounding is not performed during the conversion. Floating point numbers are truncated when converted to integers. chopped. gone. not rounded, bestie π
integer function nf_get_var_text(integer ncid, integer varid, character*(*) in)
integer function nf_get_var_int1(integer ncid, integer varid, integer*1 in(1))
integer function nf_get_var_int2(integer ncid, integer varid, integer*2 in(1))
integer function nf_get_var_int(integer ncid, integer varid, integer in(1))
integer function nf_get_var_real(integer ncid, integer varid, real in(1))
integer function nf_get_var_double(integer ncid, integer varid, doubleprecision in(1))
Reads an entire netCDF variable (all the values, yes all of them π). The netCDF dataset must be open and in data mode. The data is converted from the external type of the specified variable, if necessary, to the type specified in the function name. If conversion is not possible, an NF_ERANGE error is returned.
π― WRITING AND READING ONE DATUM π―
integer function nf_put_var1_text(integer ncid, integer varid, integer index(1), character*1 *out)
integer function nf_put_var1_int1(integer ncid, integer varid, integer index(1), integer*1 *out)
integer function nf_put_var1_int2(integer ncid, integer varid, integer index(1), integer*2 *out)
integer function nf_put_var1_int(integer ncid, integer varid, integer index(1), integer *out)
integer function nf_put_var1_real(integer ncid, integer varid, integer index(1), real *out)
integer function nf_put_var1_double(integer ncid, integer varid, integer index(1), doubleprecision *out)
Puts a single data value into a variable at the position index, in an open netCDF dataset that's in data mode π― just one lil guy, one datum, no thoughts. The type of the data is specified in the function name, and it is converted to the external type of the specified variable, if possible, otherwise an NF_ERANGE error is returned.
integer function nf_get_var1_text(integer ncid, integer varid, integer index(1), character*1 in)
integer function nf_get_var1_int1(integer ncid, integer varid, integer index(1), integer*1 in)
integer function nf_get_var1_int2(integer ncid, integer varid, integer index(1), integer*2 in)
integer function nf_get_var1_int(integer ncid, integer varid, integer index(1), integer in)
integer function nf_get_var1_real(integer ncid, integer varid, integer index(1), real in)
integer function nf_get_var1_double(integer ncid, integer varid, integer index(1), doubleprecision in)
Gets a single data value from a variable at the position index of an open netCDF dataset that is in data mode π«Ά The data is converted from the external type of the specified variable, if necessary, to the type specified in the function name. If conversion is not possible, an NF_ERANGE error is returned.
π§ WRITING AND READING AN ARRAY π§
integer function nf_put_vara_text(integer ncid, integer varid, integer start(1), integer count(1), character*(*) out)
integer function nf_put_vara_int1(integer ncid, integer varid, integer start(1), integer count(1), integer*1 out(1))
integer function nf_put_vara_int2(integer ncid, integer varid, integer start(1), integer count(1), integer*2 out(1))
integer function nf_put_vara_int(integer ncid, integer varid, integer start(1), integer count(1), integer out(1))
integer function nf_put_vara_real(integer ncid, integer varid, integer start(1), integer count(1), real out(1))
integer function nf_put_vara_double(integer ncid, integer varid, integer start(1), integer count(1), doubleprecision out(1))
Writes an array section of values into a netCDF variable of an open netCDF dataset, which must be in data mode π The array section is specified by the start and count vectors, which give the starting index and count of values along each dimension of the specified variable. The type of the data is specified in the function name and is converted to the external type of the specified variable, if possible, otherwise an NF_ERANGE error is returned.
integer function nf_get_vara_text(integer ncid, integer varid, integer start(1), integer count(1), character*(*) in)
integer function nf_get_vara_int1(integer ncid, integer varid, integer start(1), integer count(1), integer*1 in(1))
integer function nf_get_vara_int2(integer ncid, integer varid, integer start(1), integer count(1), integer*2 in(1))
integer function nf_get_vara_int(integer ncid, integer varid, integer start(1), integer count(1), integer in(1))
integer function nf_get_vara_real(integer ncid, integer varid, integer start(1), integer count(1), real in(1))
integer function nf_get_vara_double(integer ncid, integer varid, integer start(1), integer count(1), doubleprecision in(1))
Reads an array section of values from a netCDF variable of an open netCDF dataset, which must be in data mode πΈ The array section is specified by the start and count vectors, which give the starting index and count of values along each dimension of the specified variable. The data is converted from the external type of the specified variable, if necessary, to the type specified in the function name. If conversion is not possible, an NF_ERANGE error is returned.
π¦ WRITING AND READING A SLICED ARRAY π¦
okay so these are the strided girlies π
literally array-section energy but with a lil hop between accessed values in every dimension. first up, the put squad for strided output:
integer function nf_put_vars_text(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), character*(*) out)
integer function nf_put_vars_int1(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), integer*1 out(1))
integer function nf_put_vars_int2(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), integer*2 out(1))
integer function nf_put_vars_int(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), integer out(1))
integer function nf_put_vars_real(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), real out(1))
integer function nf_put_vars_double(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), doubleprecision out(1))
These functions are used for strided output, which is like the array section output described above, except that the sampling stride (the interval between accessed values) is specified for each dimension. For an explanation of the sampling stride vector, see COMMON ARGUMENTS DESCRIPTIONS below. no cap, that stride vector is doing the main character work β¨
and now the get side for strided input, same vibe but reading instead of writing π«Ά
integer function nf_get_vars_text(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), character*(*) in)
integer function nf_get_vars_int1(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), integer*1 in(1))
integer function nf_get_vars_int2(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), integer*2 in(1))
integer function nf_get_vars_int(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), integer in(1))
integer function nf_get_vars_real(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), real in(1))
integer function nf_get_vars_double(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), doubleprecision in(1))
These functions are used for strided input, which is like the array section input described above, except that the sampling stride (the interval between accessed values) is specified for each dimension. For an explanation of the sampling stride vector, see COMMON ARGUMENTS DESCRIPTIONS below. periodt π
π WRITING AND READING A MAPPED ARRAY π
okay bestie, now we're in mapped output territory β it's giving strided output but with an extra little something: an index mapping vector that tells it how the data values are arranged in memory. iconic, honestly π
integer function nf_put_varm_text(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, character*(*) out)
integer function nf_put_varm_int1(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, integer*1 out(1))
integer function nf_put_varm_int2(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, integer*2 out(1))
integer function nf_put_varm_int(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, integer out(1))
integer function nf_put_varm_real(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, real out(1))
integer function nf_put_varm_double(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, doubleprecision out(1))
These functions are used for mapped output, which is like strided output described above, except that an additional index mapping vector is provided to specify the in-memory arrangement of the data values. For an explanation of the index mapping vector, see COMMON ARGUMENTS DESCRIPTIONS below. the imap is lowkey the blueprint of the whole fit π
and now the mapped input version β same mapped situation, but pulling values in instead of pushing them out π¦
integer function nf_get_varm_text(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, character*(*) in)
integer function nf_get_varm_int1(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, integer*1 in(1))
integer function nf_get_varm_int2(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, integer*2 in(1))
integer function nf_get_varm_int(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, integer in(1))
integer function nf_get_varm_real(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, real in(1))
integer function nf_get_varm_double(integer ncid, integer varid, integer start(1), integer count(1), integer stride(1), imap, doubleprecision in(1))
These functions are used for mapped input, which is like strided input described above, except that an additional index mapping vector is provided to specify the in-memory arrangement of the data values. For an explanation of the index mapping vector, see COMMON ARGUMENTS DESCRIPTIONS below. fr fr, that imap is carrying the whole read situation πβ¨
π ATTRIBUTES π
okay bestie, this is the moment β attributes are like the little sticky notes and vibe annotations you slap onto your variables and your whole file. They're metadata and they're lowkey iconic. Let's get into it β¨
integer function nf_put_att_text(integer ncid, integer varid, character*(*) name, integer xtype, integer len, character*(*) out)
integer function nf_put_att_int1(integer ncid, integer varid, character*(*) name, integer xtype, integer len, integer*1 out(1))
integer function nf_put_att_int2(integer ncid, integer varid, character*(*) name, integer xtype, integer len, integer*2 out(1))
integer function nf_put_att_int(integer ncid, integer varid, character*(*) name, integer xtype, integer len, integer out(1))
integer function nf_put_att_real(integer ncid, integer varid, character*(*) name, integer xtype, integer len, real out(1))
integer function nf_put_att_double(integer ncid, integer varid, character*(*) name, integer xtype, integer len, doubleprecision out(1))
integer function nf_put_att(integer ncid, integer varid, character*(*) name, integer xtype, integer len, void * ip)
integer function nf_get_att(integer ncid, integer varid, character*(*) name, void * ip)
So here's the tea π« unlike variables (which get a whole separate define-then-write situation), attributes do not have separate functions for defining vs. writing values. This whole family of functions either defines a brand-new attribute with a value or changes the value of one that already exists. Two birds, one slay. π¦
Now the mode check, because netCDF is that girl: if the attribute is new, or if the space required to store the attribute value is greater than before, the netCDF dataset must be in define mode. no exceptions, bestie. π
The parameter len is the number of values from out to transfer. It's often one β except for nf_put_att_text() where it will usually be len_trim(out). Note that down, it's giving important. π
For these functions, the type component of the function name refers to the in-memory type of the value, whereas the xtype argument refers to the external type for storing the value. Two different type worlds, don't mix them up. An NF_ERANGE error results if a conversion between these types is not possible. And when that happens? The value is represented with the appropriate fill-value for the associated external type. β¨
integer function nf_inq_attname(integer ncid, integer varid, integer attnum, character*(*) name)
Gets the name of an attribute, given its variable ID and attribute number. This one is a whole lifesaver for generic applications that need to get the names of all the attributes associated with a variable β because every other attribute function accesses attributes by name, not by number. iykyk π
Heads up though: the number of an attribute is more volatile than the name, since it can change when other attributes of the same variable are deleted. so don't go getting attached to numbers, they're not loyal π
The attributes for each variable are numbered from 1 (the first attribute) to nvatts, where nvatts is the number of attributes for the variable, as returned from a call to nf_inq_varnatts().
integer function nf_inq_att(integer ncid, integer varid, character*(*) name, integer xtype, integer len)
integer function nf_inq_attid(integer ncid, integer varid, character*(*) name, integer attnum)
integer function nf_inq_atttype(integer ncid, integer varid, character*(*) name, integer xtype)
integer function nf_inq_attlen(integer ncid, integer varid, character*(*) name, integer len)
These functions return information about a netCDF attribute, given its variable ID and name. What you get back is the external type in xtype and the number of elements in the attribute as len. literally the receipts for your attribute π
integer function nf_copy_att(integer ncid, integer varid_in, character*(*) name, integer ncid_out, integer varid_out)
Copies an attribute from one netCDF dataset to another. It can also be used to copy an attribute from one variable to another within the same netCDF. Two-for-one, we love a multitasker π«Ά
ncid_inis the netCDF ID of an input netCDF dataset from which the attribute will be copied.varid_inis the ID of the variable in the input netCDF dataset from which the attribute will be copied, orNF_GLOBALfor a global attribute.nameis the name of the attribute in the input netCDF dataset to be copied.ncid_outis the netCDF ID of the output netCDF dataset to which the attribute will be copied. It is permissible for the input and output netCDF ID's to be the same.varid_outis the ID of the variable in the output netCDF dataset to which the attribute will be copied, orNF_GLOBALto copy to a global attribute.
The output netCDF dataset should be in define mode if the attribute to be copied does not already exist for the target variable, or if it would cause an existing target attribute to grow. So yeah, check your mode first bestie π
integer function nf_rename_att(integer ncid, integer varid, character*(*) name, character*(*) newname)
Changes the name of an attribute β glow-up for your metadata π¦ If the new name is longer than the original name, the netCDF must be in define mode. And you cannot rename an attribute to have the same name as another attribute of the same variable β that's a collision and netCDF said no π
name is the original attribute name. newname is the new name to be assigned to the specified attribute. And yeah, saying it twice because it matters: if the new name is longer than the old name, the netCDF dataset must be in define mode. π
integer function nf_del_att(integer ncid, integer varid, character*(*) name)
Deletes an attribute from a netCDF dataset. The dataset must be in define mode. that's it, that's the whole function. bye bestie πβ¨
integer function nf_get_att_text(integer ncid, integer varid, character*(*) name, character*(*) in)
integer function nf_get_att_int1(integer ncid, integer varid, character*(*) name, integer*1 in(1))
integer function nf_get_att_int2(integer ncid, integer varid, character*(*) name, integer*2 in(1))
integer function nf_get_att_int(integer ncid, integer varid, character*(*) name, integer in(1))
integer function nf_get_att_real(integer ncid, integer varid, character*(*) name, real in(1))
integer function nf_get_att_double(integer ncid, integer varid, character*(*) name, doubleprecision in(1))
Gets the value(s) of a netCDF attribute, given its variable ID and name. It converts from the external type to the type specified in the function name, if possible β otherwise it returns an NF_ERANGE error. π₯
All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. Every single one, no partial reads here, she gives you everything π And if you don't know how much space to reserve? Call nf_inq_attlen() first to find out the length of the attribute. that's your pre-check, bestie, always do the pre-check π
π COMMON ARGUMENT DESCRIPTIONS π
okay so this is the shared-argument glossary, bestie β the stuff that shows up all over the FUNCTION DESCRIPTIONS section. Same facts, no skips, letβs go β¨
integer ncidβ the netCDF ID that came back from a previous, successful call tonf_open()ornf_create(). Itβs literally the little handle you keep passing around π«Άcharacter*(*) nameβ the name of a dimension, variable, or attribute. These names can be arbitrary sequences of alphanumeric characters, plus underscore'_', period'.', and hyphen'-', and they start with a letter or an underscore. But heads up: names that start with underscore are reserved for system use. Case is significant in netCDF names, and a zero-length name is not allowed. The maximum allowable number of characters isNF_MAX_NAME. πinteger xtypeβ says what the external data type is for a netCDF variable or attribute. Itβs one of these:NF_BYTE,NF_CHAR,NF_SHORT,NF_INT,NF_FLOAT, orNF_DOUBLE. These mean 8-bit integers, characters, 16-bit integers, 32-bit integers, 32-bit IEEE floating point numbers, and 64-bit IEEE floating-point numbers, respectively. Slay, type system πinteger dimids(1)β a vector of dimension IDβs that defines the shape of a netCDF variable. The vectorβs size shall be greater than or equal to the rank (i.e. the number of dimensions) of the variable (ndims). The vector shall be ordered by how fast each dimension varies:dimids(1)is the dimension ID of the most rapidly varying dimension, anddimids(ndims)is the dimension ID of the most slowly varying dimension. The maximum possible number of dimensions for a variable is the symbolic constantNF_MAX_VAR_DIMS. π₯integer dimidβ the ID of a netCDF dimension. netCDF dimension IDβs are allocated sequentially from the positive integers beginning with1. No zero-index jumpscare here πinteger ndimsβ either the total number of dimensions in a netCDF dataset, or the rank (i.e. the number of dimensions) of a netCDF variable. The value shall not be negative or greater than the symbolic constantNF_MAX_VAR_DIMS. βinteger varidβ the ID of a netCDF variable, or β for the attribute-access functions β the symbolic constantNF_GLOBAL, which is used to reference global attributes. netCDF variable IDβs are allocated sequentially from the positive integers beginning with1. πinteger nattsβ the number of global attributes in a netCDF dataset for thenf_inquire()function, or the number of attributes associated with a netCDF variable for thenf_varinq()function. Counting era π§integer index(1)β specifies the indicial coordinates of the netCDF data value to be accessed. The indices start at1; so, for example, the first data value of a two-dimensional variable is(1,1). The vectorβs size shall be at least the rank of the associated netCDF variable, and its elements shall correspond, in order, to the variableβs dimensions. π¦integer start(1)β specifies the starting point for accessing a netCDF variableβs data values in terms of the indicial coordinates of the corner of the array section. The indices start at1; so the first data value of a variable is(1, 1, ..., 1). The vectorβs size shall be at least the rank of the associated netCDF variable, and its elements shall correspond, in order, to the variableβs dimensions. πΈinteger count(1)β specifies the number of indices selected along each dimension of the array section. So to access a single value, for example, you specifycountas(1, 1, ..., 1). Important vibe check: for strided I/O, this argument must be adjusted to be compatible with thestrideandstartarguments, so that the interaction of the three does not attempt to access an invalid data co-ordinate. The elements of thecountvector correspond, in order, to the variableβs dimensions. πinteger stride(1)β specifies the sampling interval along each dimension of the netCDF variable. The elements of thestridevector correspond, in order, to the netCDF variableβs dimensions (stride(1)gives the sampling interval along the most rapidly varying dimension of the netCDF variable). Sampling intervals are specified in type-independent units of elements: a value of1selects consecutive elements of the netCDF variable along the corresponding dimension, a value of2selects every other element, etc. πimapβ specifies the mapping between the dimensions of a netCDF variable and the in-memory structure of the internal data array. The elements of the index mapping vector correspond, in order, to the netCDF variableβs dimensions (imap(1)gives the distance between elements of the internal array corresponding to the most rapidly varying dimension of the netCDF variable). Distances between elements are specified in type-independent units of elements β the distance between internal elements that occupy adjacent memory locations is1, and not the elementβs byte-length as in netCDF 2. iykyk π
β¨ VARIABLE PREFILLING β¨
By default, the netCDF interface sets the values of all newly-defined variables of finite length β i.e. those that do not have an unlimited dimension β to the type-dependent fill-value associated with each variable. This happens when nf_enddef() is called. The fill-value for a variable may be changed from the default value by defining the attribute _FillValue for the variable. This attribute must have the same type as the variable and be of length one. π
Variables with an unlimited dimension are also prefilled, but on an as needed basis. Example: if the first write of such a variable is to position 5, then positions 1 through 4 (and no others) would be set to the fill-value at the same time. π
This default prefilling of data values may be disabled by orβing the NF_NOFILL flag into the mode parameter of nf_open() or nf_create(), or by calling the function nf_set_fill() with the argument NF_NOFILL. For variables that do not use the unlimited dimension, this call must be made before nf_enddef(). For variables that use the unlimited dimension, this call may be made at any time. π₯
One can obtain increased performance of the netCDF interface by using this feature, but only at the expense of requiring the application to set every single data value. The performance enhancing behavior of this function is dependent on the particulars of the implementation and dataset format. The flag value controlled by nf_set_fill() is per netCDF ID, not per variable or per write. Allowing this to change affects the degree to which a program can be effectively parallelized. Given all of this, we state that the use of this feature may not be available (or even needed) in future releases. Programmers are cautioned against heavy reliance upon this feature. π
integer function nf_setfill(integer ncid, integer fillmode, integer old_fillemode)
Determines whether or not variable prefilling will be done (see above). The netCDF dataset shall be writable. fillmode is either NF_FILL to enable prefilling (the default) or NF_NOFILL to disable prefilling. This function returns the previous setting in old_fillmode. π
π MPP FUNCTION DESCRIPTIONS π
Additional functions for use on SGI/Cray MPP machines (_CRAYMPP). These are used to set and inquire which PE is the base for MPP for a particular netCDF. These are only relevant when using the SGI/Cray global Flexible File I/O layer and desire to have only a subset of PEs to open the specific netCDF file. For technical reasons, these functions are available on all platforms. On a platform other than SGI/Cray MPP, it is as if only processor available were processor 0. π«Ά
To use this feature, you need to specify a communicator group and call glio_group_mpi() or glio_group_shmem() prior to the netCDF nf_open() and nf_create() calls. π§
integer function nf__create_mp(character*(*) path, integer cmode, integer initialsize, integer pe, integer chunksize, integer ncid)
Like nf__create() but allows the base PE to be set. The argument pe sets the base PE at creation time. In the MPP environment, nf__create() and nf_create() set the base PE to processor zero by default. β
integer function nf__open_mp(character*(*) path, integer mode, integer pe, integer chunksize, integer ncid)
Like nf__open() but allows the base PE to be set. The argument pe sets the base PE at creation time. In the MPP environment, nf__open() and nf_open() set the base PE to processor zero by default. πΈ
integer function nf_inq_base_pe(integer ncid, integer pe)
Inquires of the netCDF dataset which PE is being used as the base for MPP use. This is safe to use at any time. π
integer function nf_set_base_pe(integer ncid, integer pe)
Resets the base PE for the netCDF dataset. Only perform this operation when the affected communicator group synchronizes before and after the call. This operation is very risky and should only be contemplated under only the most extreme cases. π
π ENVIRONMENT VARIABLES π
NETCDF_FFIOSPEC
Specifies the Flexible File I/O buffers for netCDF I/O when executing under the UNICOS operating system (the variable is ignored on other operating systems). An appropriate specification can greatly increase the efficiency of netCDF I/O β to the extent that it can actually surpass FORTRAN binary I/O. This environment variable has been made a little more generalized, such that other FFIO option specifications can now be added. The default specification is bufa:336:2, unless a current FFIO specification is in operation, which will be honored. See UNICOS Flexible File I/O for more information. π¦
π MAILING-LISTS π
Okay bestie, so there's literally a whole community behind netCDF and you can absolutely be part of it π«Ά. Both a mailing list and a digest are available β the list is for discussion of the netCDF interface, and both are where announcements about netCDF bugs, fixes, and enhancements live. So like... the gossip, but make it technical β¨.
To begin or change your subscription to either the mailing-list or the digest, you send one of the following in the body (β οΈ not the subject line) of an email message to majordomo@unidata.ucar.edu. And use your own email address in place of jdoe@host.inst.domain β that's just the placeholder bestie, don't actually send that one π.
πΈ To subscribe to the netCDF mailing list
subscribe netcdfgroup jdoe@host.inst.domain
π¦ To unsubscribe from the netCDF mailing list
unsubscribe netcdfgroup jdoe@host.inst.domain
π To subscribe to the netCDF digest
subscribe netcdfdigest jdoe@host.inst.domain
π To unsubscribe from the netCDF digest
unsubscribe netcdfdigest jdoe@host.inst.domain
β To retrieve the general introductory information for the mailing list
info netcdfgroup
π To get a synopsis of other majordomo commands
help
Reminder bestie: body of the message, not the subject line. The subject line is giving main character energy but majordomo is NOT reading it π.
π SEE ALSO π
Also, the netCDF User's Guide, published by the Unidata Program Center, University Corporation for Atmospheric Research, located in Boulder, Colorado ποΈ (yes that's the whole location, we love a full address).
And the NetCDF home page at http:/www.unidata.ucar.edu/netcdf β typed exactly like that, one slash and all π, no I will not be "fixing" it, it's iconic.
And that's the whole page bestie, we did it πβ¨ Go forth and netCDF responsibly. This was NETCDF(3), printed 2026-11-03, with the page itself dated 1997-04-18 β a vintage icon serving looks since the 90s π
π
π¦ where this page comes from
- arch rolling: netcdf-fortran 4.6.4-1 Β· custom
- arch rolling: netcdf-fortran-openmpi 4.6.4-1 Β· custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms