NetCDF  4.8.1
dcopy.c File Reference
#include "config.h"
#include "ncdispatch.h"
#include "nc_logging.h"
#include "nclist.h"

Go to the source code of this file.

Functions

static int NC_compare_nc_types (int ncid1, int typeid1, int ncid2, int typeid2, int *equalp)
 
static int NC_copy_att (int ncid_in, int varid_in, const char *name, int ncid_out, int varid_out)
 Copy an attribute from one open file to another. More...
 
int nc_copy_att (int ncid_in, int varid_in, const char *name, int ncid_out, int varid_out)
 Copy an attribute from one open file to another. More...
 
int nc_copy_var (int ncid_in, int varid_in, int ncid_out)
 This will copy a variable that is an array of primitive type and its attributes from one file to another, assuming dimensions in the output file are already defined and have same dimension IDs and length. More...
 
static int NC_find_equal_type (int ncid1, nc_type xtype1, int ncid2, nc_type *xtype2)
 
static int NC_rec_find_nc_type (int ncid1, nc_type tid1, int ncid2, nc_type *tid2)
 
static int searchgroup (int ncid1, int tid1, int grp, int *tid2)
 
static int searchgrouptree (int ncid1, int tid1, int grp, int *tid2)
 

Detailed Description

Copyright 2018 University Corporation for Atmospheric Research/Unidata. See COPYRIGHT file for more info.

This file has the var and att copy functions.

Author
Dennis Heimbigner

Definition in file dcopy.c.

Function Documentation

◆ NC_copy_att()

static int NC_copy_att ( int  ncid_in,
int  varid_in,
const char *  name,
int  ncid_out,
int  varid_out 
)
static

Copy an attribute from one open file to another.

This is called by nc_copy_att().

Parameters
ncid_inFile ID to copy from.
varid_inVariable ID to copy from.
nameName of attribute to copy.
ncid_outFile ID to copy to.
varid_outVariable ID to copy to.
Returns
NC_NOERR No error.
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

USE_NETCDF4

Definition at line 508 of file dcopy.c.

◆ nc_copy_att()

int nc_copy_att ( int  ncid_in,
int  varid_in,
const char *  name,
int  ncid_out,
int  varid_out 
)

Copy an attribute from one open file to another.

Special programming challenge: this function must work even if one of the other of the files is a netcdf version 1.0 file (i.e. not HDF5). So only use top level netcdf api functions.

From the netcdf-3 docs: 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.

Parameters
ncid_inFile ID to copy from.
varid_inVariable ID to copy from.
nameName of attribute to copy.
ncid_outFile ID to copy to.
varid_outVariable ID to copy to.
Returns
NC_NOERR No error.
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 628 of file dcopy.c.

◆ nc_copy_var()

int nc_copy_var ( int  ncid_in,
int  varid_in,
int  ncid_out 
)

This will copy a variable that is an array of primitive type and its attributes from one file to another, assuming dimensions in the output file are already defined and have same dimension IDs and length.

However it doesn't work for copying netCDF-4 variables of type string or a user-defined type.

This function works even if the files are different formats, (for example, one netcdf classic, the other netcdf-4).

If you're copying into a classic-model file, from a netcdf-4 file, you must be copying a variable of one of the six classic-model types, and similarly for the attributes.

For large netCDF-3 files, this can be a very inefficient way to copy data from one file to another, because adding a new variable to the target file may require more space in the header and thus result in moving data for other variables in the target file. This is not a problem for netCDF-4 files, which support efficient addition of variables without moving data for other variables.

Parameters
ncid_inFile ID to copy from.
varid_inVariable ID to copy.
ncid_outFile ID to copy to.
Returns
NC_NOERR No error.
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 273 of file dcopy.c.