PnetCDF(3)
π PnetCDF(3) β LIBRARY FUNCTIONS π
okay bestie, gather round, because this is the manual page for PnetCDF β the Parallel library for accessing files in Network Common Data Form (CDF, CDF-2 and CDF-5 formats). yes she's a whole legend, yes she's doing the most, and yes you're gonna understand her. periodt. π
β¨ SYNOPSIS β¨
#include <pnetcdf.h>
mpicc ... -lpnetcdf
Complete documentation for the PnetCDF libraries can be found at the PnetCDF website: http://cucis.ece.northwestern.edu/projects/PnetCDF/.
like, the whole lore is on the website, bestie. go look. π
πΈ LIBRARY VERSION πΈ
This document describes PnetCDF APIs for the C programming language.
const char* ncmpi_inq_libvers()
(Corresponds to nc_inq_libvers() in netCDF)
Returns a string identifying the version of the PnetCDF library, and when it was built, like: "1.15.0 of 2026-07-01". it's giving β¨birth certificateβ¨ but for a library.
The RCS ident(1) command will find a string like "$Id: @(#) PnetCDF library version 1.15.0 of 2026-07-01 $" in the library. The SCCS what(1) command will find a string like "PnetCDF library version 1.15.0 of 2026-07-01". not one but two tools can dig up her version string, she's so iconic for that. π
π RETURN VALUES π
All PnetCDF functions (except ncmpi_inq_libvers() and ncmpi_strerror()) return an integer status.
If this returned status value is not equal to NC_NOERR (zero), it indicates that an error occurred. The possible status values are defined in system include file <errno.h> and in "pnetcdf.h".
π¨ no cap: zero is good, anything that isn't zero means something went wrong. check your status, bestie, every single time.
const char* ncmpi_strerror(int status)
(Corresponds to nc_strerror() in netCDF)
Returns a string textual translation of the status value, like "Attribute or variable name contains illegal characters" or "No such file or directory". she translates error-code gibberish into human feelings so you don't have to suffer in silence. π«Ά
π¦ FILE OPERATIONS π¦
int ncmpi_create(MPI_Comm comm, const char path[], int cmode, MPI_Info info, int* ncid)
(Corresponds to nc_create() in netCDF)
Creates a new netCDF dataset at path collectively by a group of MPI processes specified by comm, returning a netCDF ID in ncid. The argument cmode may include the bitwise-or of the following flags: NC_NOCLOBBER to protect existing datasets (default is NC_CLOBBER, silently blows them away πͺοΈ), NC_64BIT_OFFSET to create a file in the 64-bit offset format (CDF-2), as opposed to classic format, the default, or NC_64BIT_DATA to create a file in the 64-bit data format (CDF-5). Use either NC_64BIT_OFFSET or NC_64BIT_DATA. The 64-bit offset format allows the creation of very large files with far fewer restrictions than netCDF classic format, but can only be read by the netCDF library version 3.6 or greater. Users are cautioned that files that use the 64-bit offset format will not be recognized by netCDF applications linked to an earlier version of the netCDF library than 3.6. Applications linked to version 3.6 or later will be able to transparently access either the classic format or 64-bit offset format. The 64-bit data format allows the creation of very large array variables. CDF-5 files currently will not be recognized by netCDF 3 or 4 library.
The argument cmode must be consistent among all MPI processes that collectively create the file. The argument info is an MPI info object. Users can use it to supply the file access hints further performance improvement. The hints include existing MPI-IO hints as well as hints defined and used in PnetCDF.
When a netCDF dataset is created, it is opened in NC_WRITE mode. When this function returns, the new netCDF dataset is in define mode.
β οΈ default isNC_CLOBBER, meaning she will silently blow away existing datasets. no warning, no text, no nothing. if you care about that file, sayNC_NOCLOBBER. π
int ncmpi_open(MPI_Comm comm, const char path[], int mode, MPI_Info info, int* ncid)
(Corresponds to nc_open() in netCDF)
Opens an existing netCDF dataset at path collectively by a group of MPI processes specified by comm, 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: NC_WRITE for read-write access (default read-only).
The argument mode must be consistent among all MPI processes that collectively open the file. The argument info is an MPI info object. Users can use it to supply the file access hints further performance improvement. The hints include existing MPI-IO hints as well as hints defined and used in PnetCDF.
int ncmpi_redef(int ncid)
(Corresponds to nc_redef() in netCDF)
Puts an open netCDF dataset into define mode, so dimensions, variables, and attributes can be added or renamed and attributes can be deleted. it's the "wait wait wait, I wanna change something" era. βοΈ
int ncmpi_enddef(int ncid)
(Corresponds to nc_enddef() in netCDF)
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. After a successful call, variable data can be read or written to the dataset. she locks it in and ships it. π₯
int ncmpi_sync(int ncid)
(Corresponds to nc_sync() in netCDF)
Data written by PnetCDF APIs may be cached by local file system on each compute node. This API flushes cached data by calling MPI_File_sync. flush her out, bestie, let the disk see the truth. π§
int ncmpi_abort(int ncid)
(Corresponds to nc_abort() in netCDF)
You don't need to call this function. This function is called automatically by ncmpi_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 ncmpi_close(). If it is called after ncmpi_redef(), but before ncmpi_enddef(), the new definitions are not committed and the dataset is closed. If it is called after ncmpi_create() but before ncmpi_enddef(), the dataset disappears.
π the dataset disappears. she said what she said. it's the nuclear option, and it handles itself anyway β you don't need to call her.
int ncmpi_close(int ncid)
(Corresponds to nc_close() in netCDF)
Closes an open netCDF dataset. If the dataset is in define mode, ncmpi_enddef() will be called before closing. After a dataset is closed, its ID may be reassigned to another dataset. so don't go holding onto that ncid like it's your emotional support number β she might belong to somebody else now. π
π inq era (finding out what's inside) π
int ncmpi_inq(int ncid, int* ndims, int* nvars, int* natts, int* unlimdimid)
(Corresponds to nc_inq() in netCDF)
int ncmpi_inq_ndims(int ncid, int* ndims)
(Corresponds to nc_inq_ndims() in netCDF)
int ncmpi_inq_nvars(int ncid, int* nvars)
(Corresponds to nc_inq_nvars() in netCDF)
int ncmpi_inq_natts(int ncid, int* natts)
(Corresponds to nc_inq_natts() in netCDF)
int ncmpi_inq_unlimdim(int ncid, int* unlimdimid)
(Corresponds to nc_inq_unlimdim() in netCDF)
int ncmpi_inq_format(int ncid, int* formatn)
(Corresponds to nc_inq_format() in netCDF)
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 -1 otherwise. formatn will contain the version number of the dataset <format>, one of NC_FORMAT_CLASSIC, NC_FORMAT_64BIT, or NC_FORMAT_64BIT_DATA. If any of the return parameters is a NULL pointer, then the corresponding information will not be returned; hence, no space need be allocated for it.
π‘ pass NULL for anything you don't care about. she will simply not tell you. no wasted space, no drama. that's the vibe check.
π define mode girlies π
int ncmpi_def_dim(int ncid, const char name[], MPI_Offset len, int* dimid)
(Corresponds to nc_def_dim() in netCDF)
Adds a new dimension to an open netCDF dataset, which must be in define mode. name is the dimension name. If dimid is not a NULL pointer then upon successful completion dimid will contain the dimension ID of the newly created dimension.
π§ DIMENSIONS π§
int ncmpi_inq_dimid(int ncid, const char name[], int* dimid)
(Corresponds to nc_inq_dimid() in netCDF)
Given a dimension name, returns the ID of a netCDF dimension in dimid. name in, ID out. the trade of the century. π
int ncmpi_inq_dim(int ncid, int dimid, char name[], MPI_Offset* len)
(Corresponds to nc_inq_dim() in netCDF)
int ncmpi_inq_dimname(int ncid, int dimid, char name[])
(Corresponds to nc_inq_dimname() in netCDF)
int ncmpi_inq_dimlen(int ncid, int dimid, MPI_Offset* len)
(Corresponds to nc_inq_dimlen() in netCDF)
Use these functions to find out about a dimension. If either the name argument or len argument is a NULL pointer, then the associated information will not be returned. Otherwise, name should be big enough (NC_MAX_NAME) to hold the dimension name as the name will be copied into your storage. The length return parameter, len will contain the size of the dimension. For the unlimited dimension, the returned length is the current maximum value used for writing into any of the variables which use the dimension.
π size yournamebuffer toNC_MAX_NAME, fr fr. she copies in and she is not checking whether your little buffer can hold her. cute but dangerous.
int ncmpi_rename_dim(int ncid, int dimid, const char name[])
(Corresponds to nc_rename_dim() in netCDF)
Renames an existing dimension in an open netCDF dataset. If the new name is longer than the old name, the netCDF dataset must be in define mode. You cannot rename a dimension to have the same name as another dimension. glow-up era β¨, but she's booked and busy in define mode if the new name is longer.
β¨ VARIABLES β¨
okay bestie, this is the part where we actually make β¨variablesβ¨ β the whole point of the file, lowkey. buckle up π
π§ Making a variable
int ncmpi_def_var(int ncid, const char name[], nc_type xtype, int ndims,
const int dimids[], int* varid)
(Corresponds to nc_def_var() in netCDF)
Adds a new variable to a netCDF dataset. the netCDF must be in define mode, no cap β try it in data mode and it's not gonna slay. π
varidβ if it's notNULL, this gets set to the netCDF variable ID. free real estate πndimsβ the number of dimensions for the variable.nameβ the name of the netCDF variable.xtypeβ the external, netCDF type of the variable, and it should be one ofNC_BYTENC_CHAR,NC_SHORT,NC_INT,NC_FLOAT, orNC_DOUBLE, for CDF-1 and CDF-2 file formats. CDF-5 says sike and defines extra external types:NC_UBYTE,NC_USHORT,NC_UINT,NC_INT64, andNC_UINT64. iconic. πdimidsβ a vector ofndimsdimension IDs corresponding to the variable dimensions.
π Asking about variables
int ncmpi_inq_varid(int ncid, const char name[], int* varid)
(Corresponds to nc_inq_varid() in netCDF)
Returns the ID of a netCDF variable in varid given its name. you give me the name, i give you the number, that's the deal π«Ά
int ncmpi_inq_var(int ncid, int varid, char name[], nc_type* xtype, int*
ndims, int dimids[], int* natts)
(Corresponds to nc_inq_var() in netCDF)
int ncmpi_inq_varname(int ncid, int varid, char name[])
(Corresponds to nc_inq_varname() in netCDF)
int ncmpi_inq_vartype(int ncid, int varid, nc_type* xtype)
(Corresponds to nc_inq_vartype() in netCDF)
int ncmpi_inq_varndims(int ncid, int varid, int* ndims)
(Corresponds to nc_inq_varndims() in netCDF)
int ncmpi_inq_vardimid(int ncid, int varid, int dimids[])
(Corresponds to nc_inq_vardimid() in netCDF)
int ncmpi_inq_varnatts(int ncid, int varid, int* natts)
(Corresponds to nc_inq_varnatts() in netCDF)
Returns information about a netCDF variable, given its ID. π΅οΈββοΈ and here's the juicy part: if any of the return parameters (name, xtype, ndims, dimids, or natts) is a NULL pointer, then that piece of info just will not be returned β so you don't even need to allocate space for it. not me passing NULL for everything i don't care about π efficient fr fr.
π Renaming a variable
int ncmpi_rename_var(int ncid, int varid, const char name[])
(Corresponds to nc_rename_var() in netCDF)
Changes the name of a netCDF variable. glow-up time β¨ but listen: 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 β that's a name collision and the universe will simply not allow it. periodt. π ββοΈ
π WRITING AND READING WHOLE VARIABLES π
the moment you've all been waiting for β moving ALL the data at once. main character energy only πΈ
π Putting the whole thing
int ncmpi_put_var_text(int ncid, int varid, const char out[])
(Corresponds to nc_put_var_text() in netCDF)
int ncmpi_put_var_uchar(int ncid, int varid, const unsigned char out[])
(Corresponds to nc_put_var_uchar() in netCDF)
int ncmpi_put_var_schar(int ncid, int varid, const signed char out[])
(Corresponds to nc_put_var_schar() in netCDF)
int ncmpi_put_var_short(int ncid, int varid, const short out[])
(Corresponds to nc_put_var_short() in netCDF)
int ncmpi_put_var_int(int ncid, int varid, const int out[])
(Corresponds to nc_put_var_int() in netCDF)
int ncmpi_put_var_long(int ncid, int varid, const long out[])
(Corresponds to nc_put_var_long() in netCDF)
int ncmpi_put_var_float(int ncid, int varid, const float out[])
(Corresponds to nc_put_var_float() in netCDF)
int ncmpi_put_var_double(int ncid, int varid, const double out[])
(Corresponds to nc_put_var_double() in netCDF)
Writes an entire netCDF variable (i.e. all the values). 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 NC_ERANGE error comes back at you. π
bestie heads up: rounding is not performed during the conversion. floating point numbers are truncated when converted to integers. so3.9does not become4, it becomes3. she's a lil brutal like that. π
π Getting the whole thing
int ncmpi_get_var_text(int ncid, int varid, char in[])
(Corresponds to nc_get_var_text() in netCDF)
int ncmpi_get_var_uchar(int ncid, int varid, unsigned char in[])
(Corresponds to nc_get_var_uchar() in netCDF)
int ncmpi_get_var_schar(int ncid, int varid, signed char in[])
(Corresponds to nc_get_var_schar() in netCDF)
int ncmpi_get_var_short(int ncid, int varid, short in[])
(Corresponds to nc_get_var_short() in netCDF)
int ncmpi_get_var_int(int ncid, int varid, int in[])
(Corresponds to nc_get_var_int() in netCDF)
int ncmpi_get_var_long(int ncid, int varid, long in[])
(Corresponds to nc_get_var_long() in netCDF)
int ncmpi_get_var_float(int ncid, int varid, float in[])
(Corresponds to nc_get_var_float() in netCDF)
int ncmpi_get_var_double(int ncid, int varid, double in[])
(Corresponds to nc_get_var_double() in netCDF)
Reads an entire netCDF variable (i.e. all the values, the whole grid, every last one π¦). 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. and if conversion is not possible? NC_ERANGE. that's the vibe check. π¨
π WRITING AND READING ONE DATUM π
one single value. the smallest unit of slay. π
βοΈ Putting one value
int ncmpi_put_var1_text(int ncid, int varid, const MPI_Offset index[],
char *out)
(Corresponds to nc_put_var1_text() in netCDF)
int ncmpi_put_var1_uchar(int ncid, int varid, const MPI_Offset index[],
unsigned char *out)
(Corresponds to nc_put_var1_uchar() in netCDF)
int ncmpi_put_var1_schar(int ncid, int varid, const MPI_Offset index[],
signed char *out)
(Corresponds to nc_put_var1_schar() in netCDF)
int ncmpi_put_var1_short(int ncid, int varid, const MPI_Offset index[],
short *out)
(Corresponds to nc_put_var1_short() in netCDF)
int ncmpi_put_var1_int(int ncid, int varid, const MPI_Offset index[],
int *out)
(Corresponds to nc_put_var1_int() in netCDF)
int ncmpi_put_var1_long(int ncid, int varid, const MPI_Offset index[],
long *out)
(Corresponds to nc_put_var1_long() in netCDF)
int ncmpi_put_var1_float(int ncid, int varid, const MPI_Offset index[],
float *out)
(Corresponds to nc_put_var1_float() in netCDF)
int ncmpi_put_var1_double(int ncid, int varid, const MPI_Offset index[],
double *out)
(Corresponds to nc_put_var1_double() in netCDF)
Puts a single data value into a variable at the position index of an open netCDF dataset that is in data mode. the type of the data is specified in the function name, and it's converted to the external type of the specified variable if possible β otherwise, you guessed it, NC_ERANGE. π€
π«Ά Getting one value
int ncmpi_get_var1_text(int ncid, int varid, const MPI_Offset index[],
char* in)
(Corresponds to nc_get_var1_text() in netCDF)
int ncmpi_get_var1_uchar(int ncid, int varid, const MPI_Offset index[],
unsigned char* in)
(Corresponds to nc_get_var1_uchar() in netCDF)
int ncmpi_get_var1_schar(int ncid, int varid, const MPI_Offset index[],
signed char* in)
(Corresponds to nc_get_var1_schar() in netCDF)
int ncmpi_get_var1_short(int ncid, int varid, const MPI_Offset index[],
short* in)
(Corresponds to nc_get_var1_short() in netCDF)
int ncmpi_get_var1_int(int ncid, int varid, const MPI_Offset index[],
int* in)
(Corresponds to nc_get_var1_int() in netCDF)
int ncmpi_get_var1_long(int ncid, int varid, const MPI_Offset index[],
long* in)
(Corresponds to nc_get_var1_long() in netCDF)
int ncmpi_get_var1_float(int ncid, int varid, const MPI_Offset index[],
float* in)
(Corresponds to nc_get_var1_float() in netCDF)
int ncmpi_get_var1_double(int ncid, int varid, const MPI_Offset index[],
double* in)
(Corresponds to nc_get_var1_double() in netCDF)
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, NC_ERANGE comes knocking. ngl that error is everywhere in this page, it's giving main character of its own story. πβ
π WRITING AND READING AN ARRAY π
okay bestie, this is the classic "give me a whole rectangular chunk of the variable" move. here are all the writers π«Ά
int ncmpi_put_vara_text(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const char out[])
(Corresponds to nc_put_vara_text() in netCDF)
int ncmpi_put_vara_uchar(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const unsigned char out[])
(Corresponds to nc_put_vara_uchar() in netCDF)
int ncmpi_put_vara_schar(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const signed char out[])
(Corresponds to nc_put_vara_schar() in netCDF)
int ncmpi_put_vara_short(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const short out[])
(Corresponds to nc_put_vara_short() in netCDF)
int ncmpi_put_vara_int(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const int out[])
(Corresponds to nc_put_vara_int() in netCDF)
int ncmpi_put_vara_long(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const long out[])
(Corresponds to nc_put_vara_long() in netCDF)
int ncmpi_put_vara_float(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const float out[])
(Corresponds to nc_put_vara_float() in netCDF)
int ncmpi_put_vara_double(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const double out[])
(Corresponds to nc_put_vara_double() in netCDF)
so what do these actually do?? they write an array section of values into a netCDF variable of an open netCDF dataset, and the dataset must be in data mode (define mode girls, you're not invited rn π
). 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 it's converted to the external type of the specified variable if possible β otherwise you get an NC_ERANGE error back. no cap. π
and now the readers, aka the girls who show up and actually hand you the data πΈ
int ncmpi_get_vara_text(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], char in[])
(Corresponds to nc_get_vara_text() in netCDF)
int ncmpi_get_vara_uchar(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], unsigned char in[])
(Corresponds to nc_get_vara_uchar() in netCDF)
int ncmpi_get_vara_schar(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], signed char in[])
(Corresponds to nc_get_vara_schar() in netCDF)
int ncmpi_get_vara_short(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], short in[])
(Corresponds to nc_get_vara_short() in netCDF)
int ncmpi_get_vara_int(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], int in[])
(Corresponds to nc_get_vara_int() in netCDF)
int ncmpi_get_vara_long(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], long in[])
(Corresponds to nc_get_vara_long() in netCDF)
int ncmpi_get_vara_float(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], float in[])
(Corresponds to nc_get_vara_float() in netCDF)
int ncmpi_get_vara_double(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], double in[])
(Corresponds to nc_get_vara_double() in netCDF)
these ones read an array section of values from a netCDF variable of an open netCDF dataset, which β yes bestie, same energy β must be in data mode. the array section is again 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. and if that conversion is not possible?? NC_ERANGE error. returned. periodt. π
π¦ WRITING AND READING A SLICED ARRAY π¦
the strided girls have entered the chat. same rectangles, but now we're sampling π
int ncmpi_put_vars_text(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], const char out[])
(Corresponds to nc_put_vars_text() in netCDF)
int ncmpi_put_vars_uchar(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], const unsigned char out[])
(Corresponds to nc_put_vars_uchar() in netCDF)
int ncmpi_put_vars_schar(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], const signed char out[])
(Corresponds to nc_put_vars_schar() in netCDF)
int ncmpi_put_vars_short(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], const short out[])
(Corresponds to nc_put_vars_short() in netCDF)
int ncmpi_put_vars_int(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], const int out[])
(Corresponds to nc_put_vars_int() in netCDF)
int ncmpi_put_vars_long(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], const long out[])
(Corresponds to nc_put_vars_long() in netCDF)
int ncmpi_put_vars_float(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], const float out[])
(Corresponds to nc_put_vars_float() in netCDF)
int ncmpi_put_vars_double(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], const double out[])
(Corresponds to nc_put_vars_double() in netCDF)
soooo 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. iykyk π§
int ncmpi_get_vars_text(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], char in[])
(Corresponds to nc_get_vars_text() in netCDF)
int ncmpi_get_vars_uchar(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], unsigned char in[])
(Corresponds to nc_get_vars_uchar() in netCDF)
int ncmpi_get_vars_schar(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], signed char in[])
(Corresponds to nc_get_vars_schar() in netCDF)
int ncmpi_get_vars_short(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], short in[])
(Corresponds to nc_get_vars_short() in netCDF)
int ncmpi_get_vars_int(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], int in[])
(Corresponds to nc_get_vars_int() in netCDF)
int ncmpi_get_vars_long(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], long in[])
(Corresponds to nc_get_vars_long() in netCDF)
int ncmpi_get_vars_float(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], float in[])
(Corresponds to nc_get_vars_float() in netCDF)
int ncmpi_get_vars_double(int ncid, int varid, const MPI_Offset start[], const MPI_Offset count[], const MPI_Offset stride[], double in[])
(Corresponds to nc_get_vars_double() in netCDF)
and these cuties are 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. π
β¨ WRITING AND READING A MAPPED ARRAY β¨
Okay bestie, this is the β¨fancyβ¨ version of strided I/O. Same energy as the strided stuff, except now you ALSO get to hand over an index mapping vector that tells PnetCDF how your data is laid out in memory. It's giving fully custom layout. π
π The put_varm girlies (mapped output)
ncmpi_put_varm_text
int ncmpi_put_varm_text(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], const char out[])
(Corresponds to nc_put_varm_text() in netCDF)
ncmpi_put_varm_uchar
int ncmpi_put_varm_uchar(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], const unsigned char out[])
(Corresponds to nc_put_varm_uchar() in netCDF)
ncmpi_put_varm_schar
int ncmpi_put_varm_schar(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], const signed char out[])
(Corresponds to nc_put_varm_schar() in netCDF)
ncmpi_put_varm_short
int ncmpi_put_varm_short(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], const short out[])
(Corresponds to nc_put_varm_short() in netCDF)
ncmpi_put_varm_int
int ncmpi_put_varm_int(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], const int out[])
(Corresponds to nc_put_varm_int() in netCDF)
ncmpi_put_varm_long
int ncmpi_put_varm_long(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], const long out[])
(Corresponds to nc_put_varm_long() in netCDF)
ncmpi_put_varm_float
int ncmpi_put_varm_float(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], const float out[])
(Corresponds to nc_put_varm_float() in netCDF)
ncmpi_put_varm_double
int ncmpi_put_varm_double(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], const double out[])
(Corresponds to nc_put_varm_double() in netCDF)
So these ones are for mapped output, which is basically strided output from earlierβ¦ except there's an extra index mapping vector in the mix that specifies how your data values are arranged in memory. π§ β¨ Wanna know what that index mapping vector is actually doing? The explanation lives down in COMMON ARGUMENTS DESCRIPTIONS below. π
πΈ The get_varm girlies (mapped input)
ncmpi_get_varm_text
int ncmpi_get_varm_text(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], char in[])
(Corresponds to nc_get_varm_text() in netCDF)
ncmpi_get_varm_uchar
int ncmpi_get_varm_uchar(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], unsigned char in[])
(Corresponds to nc_get_varm_uchar() in netCDF)
ncmpi_get_varm_schar
int ncmpi_get_varm_schar(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], signed char in[])
(Corresponds to nc_get_varm_schar() in netCDF)
ncmpi_get_varm_short
int ncmpi_get_varm_short(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], short in[])
(Corresponds to nc_get_varm_short() in netCDF)
ncmpi_get_varm_int
int ncmpi_get_varm_int(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], int in[])
(Corresponds to nc_get_varm_int() in netCDF)
ncmpi_get_varm_long
int ncmpi_get_varm_long(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], long in[])
(Corresponds to nc_get_varm_long() in netCDF)
ncmpi_get_varm_float
int ncmpi_get_varm_float(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], float in[])
(Corresponds to nc_get_varm_float() in netCDF)
ncmpi_get_varm_double
int ncmpi_get_varm_double(int ncid, int varid, const MPI_Offset start[],
const MPI_Offset count[], const MPI_Offset stride[], const
MPI_Offset imap[], double in[])
(Corresponds to nc_get_varm_double() in netCDF)
And these cuties are for mapped input, aka strided input from above but again with that extra index mapping vector that tells it how your values are laid out in memory. π Samesies β the index mapping vector explanation is waiting for you in COMMON ARGUMENTS DESCRIPTIONS below. π«Ά
ATTRIBUTES π
Okay bestie, this is where it gets real fun. Attributes are like the little sticky notes you slap on your variables (or on the whole dataset, global vibes only β¨). And PnetCDF has a whole squad of functions for putting them, getting them, inquiring about them, copying them, renaming them, and straight-up deleting them. Let's go π
Putting attributes π
int ncmpi_put_att_text(int ncid, int varid, const char name[], nc_type xtype, MPI_Offset len, const char out[])
int ncmpi_put_att_uchar(int ncid, int varid, const char name[], nc_type xtype, MPI_Offset len, const unsigned char out[])
int ncmpi_put_att_schar(int ncid, int varid, const char name[], nc_type xtype, MPI_Offset len, const signed char out[])
int ncmpi_put_att_short(int ncid, int varid, const char name[], nc_type xtype, MPI_Offset len, const short out[])
int ncmpi_put_att_int(int ncid, int varid, const char name[], nc_type xtype, MPI_Offset len, const int out[])
int ncmpi_put_att_long(int ncid, int varid, const char name[], nc_type xtype, MPI_Offset len, const long out[])
int ncmpi_put_att_float(int ncid, int varid, const char name[], nc_type xtype, MPI_Offset len, const float out[])
int ncmpi_put_att_double(int ncid, int varid, const char name[], nc_type xtype, MPI_Offset len, const double out[])
int ncmpi_put_att(int ncid, int varid, const char name[], nc_type xtype, MPI_Offset len, void * ip)
int ncmpi_get_att(int ncid, int varid, const char name[], void ** ip)
Each one of those ncmpi_put_att_* bad boys corresponds to a nc_put_att_* function in netCDF, and ncmpi_get_att() corresponds to nc_get_att() in netCDF. Same energy, different prefix π«
Not me about to drop the most important tea: unlike variables, attributes do NOT have separate functions for defining and writing values. This whole family of functions either defines a new attribute with a value, or changes the value of an existing one. That's it. One function, two jobs. Multitasking queen π
Now for the details, gorgeous:
- If the attribute is brand new, or if the space needed to store the attribute value is greater than before, the netCDF dataset must be in define mode. No exceptions, bestie. Put it in define mode first.
- The parameter _len_ is the number of values from _out_ that get transferred. It's usually one, except for
ncmpi_put_att_text()where it'll usually bestrlen(out). Makes sense β strings need their whole length, periodt. - For these functions, the type component of the function name refers to the in-memory type of the value, while the _xtype_ argument refers to the external type used for storing the value.
- If a conversion between those two types is not possible, you get an
NC_ERANGEerror. And in that case, the value gets represented with the appropriate fill-value for the associated external type. So it's not a crash, it's a fill-value situation, but still β be aware π«Ά
Inquiring about attributes πΈ
int ncmpi_inq_attname(int ncid, int varid, int attnum, char name[])
int ncmpi_inq_att(int ncid, int varid, const char name[], nc_type* xtype, MPI_Offset* len)
int ncmpi_inq_attid(int ncid, int varid, const char name[], int* attnum)
int ncmpi_inq_atttype(int ncid, int varid, const char name[], nc_type* xtype)
int ncmpi_inq_attlen(int ncid, int varid, const char name[], MPI_Offset* len)
All of these correspond to their nc_inq_att* cousins in netCDF, obviously, because we do things the netCDF way around here but with PnetCDF flair β¨
About ncmpi_inq_attname():
Gets the name of an attribute, given its variable ID and attribute number. This one is a lifesaver in generic applications that need to grab the names of all the attributes attached to a variable, because β plot twist β in every other attribute function, attributes are accessed by name, not by number. The name is the moment, the number is just a number π
And here's the thing: the number of an attribute is more volatile than the name. Why? Because it can change when other attributes of the same variable get deleted. So don't get too attached to the number, it's giving toxic ex energy π
The attributes for each variable are numbered from 0 (the first attribute) to nvatts-1, where nvatts is the number of attributes for the variable, as returned from a call to ncmpi_inq_varnatts().
Also super cute detail: if the _name_ parameter is a NULL pointer, no name will be returned and no space needs to be allocated. Convenient, right? π
About ncmpi_inq_att(), ncmpi_inq_attid(), ncmpi_inq_atttype(), and ncmpi_inq_attlen():
These functions return information about a netCDF attribute, given its variable ID and name. The info you get back is:
- the external type in _xtype_
- the number of elements in the attribute as _len_
And bestie, if any of the return arguments is a NULL pointer, that specified information just won't be returned. No drama, no errors, it just skips it π
Copying, renaming, and deleting attributes π¦
int ncmpi_copy_att(int ncid, int varid_in, const char name[], int ncid_out, int varid_out)
int ncmpi_rename_att(int ncid, int varid, const char name[], const char newname[])
int ncmpi_del_att(int ncid, int varid, const char name[])
ncmpi_copy_att() β Corresponds to nc_copy_att() in netCDF.
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. Look at the versatility, we love to see it π
Let's break down the players:
- _ncid_in_ is the netCDF ID of an input netCDF dataset from which the attribute will be copied.
- _varid_in_ is the ID of the variable in the input netCDF dataset from which the attribute will be copied, or
NC_GLOBALfor a global attribute. - _name_ is the name of the attribute in the input netCDF dataset to be copied.
- _ncid_out_ is the netCDF ID of the output netCDF dataset to which the attribute will be copied. It is permissible for the input and output netCDF IDs to be the same.
- 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.
- _varid_out_ is the ID of the variable in the output netCDF dataset to which the attribute will be copied, or
NC_GLOBALto copy to a global attribute.
ncmpi_rename_att() β Corresponds to nc_rename_att() in netCDF.
Changes the name of an attribute. Some rules, bestie, listen up:
- If the new name is longer than the original name, the netCDF must be in define mode.
- You cannot rename an attribute to have the same name as another attribute of the same variable. No duplicates allowed, we're not doing that π ββοΈ
- _name_ is the original attribute name.
- _newname_ is the new name to be assigned to the specified attribute.
- Again for the people in the back: if the new name is longer than the old name, the netCDF dataset must be in define mode.
ncmpi_del_att() β Corresponds to nc_del_att() in netCDF.
Deletes an attribute from a netCDF dataset. And you already know β the dataset must be in define mode. Say it with me: define mode, define mode, define mode π£
Getting attributes π§
int ncmpi_get_att_text(int ncid, int varid, const char name[], char in[])
int ncmpi_get_att_uchar(int ncid, int varid, const char name[], unsigned char in[])
int ncmpi_get_att_schar(int ncid, int varid, const char name[], signed char in[])
int ncmpi_get_att_short(int ncid, int varid, const char name[], short in[])
int ncmpi_get_att_int(int ncid, int varid, const char name[], int in[])
int ncmpi_get_att_long(int ncid, int varid, const char name[], long in[])
int ncmpi_get_att_float(int ncid, int varid, const char name[], float in[])
int ncmpi_get_att_double(int ncid, int varid, const char name[], double in[])
Each one corresponds to its nc_get_att_* equivalent in netCDF. You know the drill β¨
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 NC_ERANGE error. So if the conversion can't happen, you're getting that error, fr fr.
All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. And if you don't know how much space to reserve? No worries, bestie β just call ncmpi_inq_attlen() first to find out the length of the attribute. That's your move. Inquire first, allocate second, get your values third. Slay π
β¨ COMMON ARGUMENT DESCRIPTIONS β¨
okay bestie, this is the lil glossary part π these are all the arguments that keep showing up over and over in the FUNCTION DESCRIPTIONS section, so we're defining them once here instead of forty-seven times. you're welcome, you're gonna see them everywhere.
int ncidβ the netCDF ID that a previous, successful call toncmpi_open()orncmpi_create()handed back to you. if you don't have one of these yet, we can't do anything, so go get one π«Άchar name[]β the name of a dimension, variable, or attribute. Names of dimensions, variables and attributes are made of arbitrary sequences of alphanumeric characters (plus underscore'_', period'.'and hyphen'-'), and they have to start with a letter or an underscore. (heads up though: names that begin with an underscore are reserved for system use, so likeβ¦ don't π). Case is significant in netCDF names βTempandtempare two different girls. A zero-length name is NOT allowed, periodt. As an input argument, it shall be a pointer to a0-terminated string; as an output argument, it shall be the address of a buffer in which to hold such a string. The maximum allowable number of characters (not counting the terminating0) isNC_MAX_NAME.nc_type xtypeβ the external data type of a netCDF variable or attribute, and it's one of these cuties:NC_BYTE,NC_CHAR,NC_SHORT,NC_INT,NC_FLOAT, orNC_DOUBLEfor the CDF-1 and CDF-2 file formats π They specify 8-bit integers, characters, 16-bit integers, 32-bit integers, 32-bit IEEE floating point numbers, and 64-bit IEEE floating-point numbers, respectively, in that exact order. (NC_LONGin netCDF version 2 is now obsolete and set toNC_INTβ she's retired, let her rest π). CDF-5 defines extra external types:NC_UBYTE,NC_USHORT,NC_UINT,NC_INT64, andNC_UINT64. iconic behavior honestly.int dimids[]β a vector of dimension ID's that defines the shape of a netCDF variable. The size of the vector 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 the speed with which a dimension varies:dimids[ndims-1]shall be the dimension ID of the most rapidly varying dimension anddimids[0]shall be the dimension ID of the most slowly varying dimension. The maximum possible number of dimensions for a variable is given by the symbolic constantNC_MAX_VAR_DIMS.int dimidβ the ID of a netCDF dimension. netCDF dimension ID's are allocated sequentially from the non-negative integers beginning with0. yes queen, we count from zero here π’int 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 and shall not be greater than the symbolic constantNC_MAX_VAR_DIMS.int varidβ the ID of a netCDF variable, or (for the attribute-access functions) the symbolic constantNC_GLOBAL, which is what you use to reference global attributes π netCDF variable ID's are allocated sequentially from the non-negative integers beginning with0.int* nattsβ the number of global attributes in a netCDF dataset for thencmpi_inquire()function, or the number of attributes associated with a netCDF variable for thencmpi_varinq()function. one little pointer, two whole moods β¨const MPI_Offset index[]β specifies the coordinates of the netCDF data value to be accessed. The indices start at0; so for example, the first data value of a two-dimensional variable is(0,0). The size of the vector shall be at least the rank of the associated netCDF variable, and its elements shall correspond, in order, to the variable's dimensions.const MPI_Offset start[]β 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 at0; so the first data value of a variable is(0, 0, ..., 0). The size of the vector shall be at least the rank of the associated netCDF variable, and its elements shall correspond, in order, to the variable's dimensions.const MPI_Offset count[]β 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). π Note that, 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.const MPI_Offset stride[]β 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[0]gives the sampling interval along the most slowly 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. ANULLstride argument is treated as(1, 1, ... , 1).const MPI_Offset 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[0]gives the distance between elements of the internal array corresponding to the most slowly 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. ANULLpointer means the memory-resident values have the same structure as the associated netCDF variable. it's giving "just let me lay it all out flat" energy π
π VARIABLE PREFILLING π
lowkey a whole saga, sit down bestie π
Prior to version 1.6.1, PnetCDF does not support data filling. The default fill mode in PnetCDF is NC_NOFILL. This is contrary to the netCDF library, whose default is NC_FILL. When fill mode is enabled, PnetCDF 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 is done when ncmpi_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 not prefilled in PnetCDF. This is also contrary to netCDF, which does prefill record variables. In PnetCDF, filling a record variable must be done by calling ncmpi_fill_var_rec(). Note this fills only one record of a variable. so like, one record at a time, no shortcuts π
The fill mode for the entire file can be set by ncmpi_set_fill(). Per-variable fill mode setting is also available through ncmpi_def_var_fill(). In PnetCDF, changing fill mode must be done in define mode. In netCDF, it is true only for fixed-size variables. For record variables, changing fill mode can be made at any time in NetCDF. (again: netCDF said "any time", PnetCDF said "define mode only", and I'm just the messenger π« )
π ENVIRONMENT VARIABLES π
PNETCDF_SAFE_MODEβ set it to1to enable the metadata consistency check β¨ Warning messages will be printed tostdoutif any inconsistency is detected. it's the friend who double-checks the group chat before anyone hits send π«Ά
π MAILING-LISTS π
A mailing list is available for discussion of the PnetCDF interface and announcements about PnetCDF bugs, fixes, and enhancements. To subscribe or unsubscribe to the PnetCDF mailing list, visit https://lists.mcs.anl.gov/mailman/listinfo/parallel-netcdf. come hang out, it's a whole vibe π
π SEE ALSO π
ncmpidump(1), ncmpigen(1), ncmpidiff(1), ncvalidator(1), pnetcdf(3).
go read those too bestie, they're all bangers, iykyk β
π DATE π
July 1, 2026
PnetCDF User's Guide, published by Northwestern University and Argonne National Laboratory. This document is adopted from the netCDF User's Guide, developed at the Unidata Program Center, University Corporation for Atmospheric Research, located in Boulder, Colorado. ποΈ
PnetCDF home page at https://parallel-netcdf.github.io π
and that's a wrap on the whole page, babe π you just read PnetCDF(3) from PnetCDF 1.15.0, printed on 2026-11-02 β go forth and write some parallel netCDF files, you absolute icon π
β¨
π¦ where this page comes from
- ubuntu stonking: libpnetcdf-dev 1.15.0-3build1 Β· Northwestern
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms