I'm trying to use ncks to copy the attributes of a variable to the same variable name in another file. I would like to only copy the attributes and not the values of the variable or any of the associated coordinate variables.
From what I can understand from the documentation, ncks normally changes the variable and associated coordinate variable values when the input and output names are the same. Is there a way to get around this?
Thanks,
Andrew
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
your understanding of ncks is correct. there is no elegant way to do what you wish with ncks.
i have added this feature request as TODO nco1105.
can anyone think of a quick way to do what Andrew wishes?
cz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Andrew,
I just committed some changes to ncks that enable your request.
The switches were there, it was just a matter of connecting them.
When copying/subsetting/appending files (as opposed to printing them), the
copying of data, variable metadata, and global/group metadata are now turned OFF by -H, -m, and -M, respectively.
This is the opposite sense in which these switches work when _printing_ a file.
To prove/demonstrate their use:
# Extract naked (data-only) copies of two variables
ncks -h -M -m -O -C -v one,three_dmn_rec_var ~/nco/data/in.nc ~/out.nc
# Change values to be sure original values are not copied in following step
ncap2 -O -v -s 'one=2*one;three_dmn_rec_var=73+0.*three_dmn_rec_var' ~/nco/data/in.nc ~/in2.nc
# Copy in2.nc metadata but not data to out.nc
ncks -A -C -H -v one,three_dmn_rec_var ~/in2.nc ~/out.nc
Variables in out.nc now contain data from in.nc and metadata from in2.nc
This functionality will be in NCO 4.3.7.
If you can, I would appreciate it if you would install the current snapshot
and let us know if it works for you.
cz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm trying to use ncks to copy the attributes of a variable to the same variable name in another file. I would like to only copy the attributes and not the values of the variable or any of the associated coordinate variables.
From what I can understand from the documentation, ncks normally changes the variable and associated coordinate variable values when the input and output names are the same. Is there a way to get around this?
Thanks,
Andrew
your understanding of ncks is correct. there is no elegant way to do what you wish with ncks.
i have added this feature request as TODO nco1105.
can anyone think of a quick way to do what Andrew wishes?
cz
There's this function in the netCDF public C API:
int nc_copy_att(int ncid, int varid_in, const char name, int ncid_out, int varid_out)
-Russ
Thanks Charlie and Russ!
Andrew
Andrew,
I just committed some changes to ncks that enable your request.
The switches were there, it was just a matter of connecting them.
When copying/subsetting/appending files (as opposed to printing them), the
copying of data, variable metadata, and global/group metadata are now turned OFF by -H, -m, and -M, respectively.
This is the opposite sense in which these switches work when _printing_ a file.
To prove/demonstrate their use:
# Extract naked (data-only) copies of two variables
ncks -h -M -m -O -C -v one,three_dmn_rec_var ~/nco/data/in.nc ~/out.nc
# Change values to be sure original values are not copied in following step
ncap2 -O -v -s 'one=2*one;three_dmn_rec_var=73+0.*three_dmn_rec_var' ~/nco/data/in.nc ~/in2.nc
# Copy in2.nc metadata but not data to out.nc
ncks -A -C -H -v one,three_dmn_rec_var ~/in2.nc ~/out.nc
Variables in out.nc now contain data from in.nc and metadata from in2.nc
This functionality will be in NCO 4.3.7.
If you can, I would appreciate it if you would install the current snapshot
and let us know if it works for you.
cz
Thanks so much Charlie.
I'm using NCO from macports, which is currently at version 4.3.6.
Is there another way that I could install the snapshot?
Andrew