NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
Hi Simon, > we have quite big output files from a seismic wavefield simulation and > want to fourier transform them for further use. > > The idea would be that the output file is opened, the wavefields are > read and transformed and copied into a new file. > However, there are a lot of smaller variables in the file, which should > be copied to the new file as well. I do not want to declare temporary > arrays for all of them and so I gave NF_COPY_VAR a try. > > > The questions: > > 1. NetCDF-C has the routine nc_copy_var, which seems to be perfectly > suited. Can you call it from a Fortran90 code? The only portable way (that would work with different Fortran compilers) is if you use the Fortran-2003 C interoperability feature that provides a standard way to call C functions from Fortran. Otherwise you have to either customize your solution to the Fortran compiler you have, adapting to it's non-standard way of referring to a C function and character string arguments, or learn to use a more general solution such as the cfortran.h macros that come with the netCDF Fortran software. We are providing a beta-release of netcdf-fortran software that implements use of the Fortran-2003 solution for calling C functions from Fortran, including nf_copy_var, as well as a more recent daily snapshot of that software that has additional bug fixes: ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-fortran-4.4-beta1.tar.gz ftp://ftp.unidata.ucar.edu/pub/netcdf/snapshot/netcdf-fortran-4.4-daily.tar.gz > 2. There is the undocumented NF_COPY_VAR. However, using this like > > status = nf_copy_var(ncin_grpid, varid, ncout_id) > print *, nf_strerror(status), status > > Results in > > NetCDF: Invalid dimension ID or name -46 > > even though nf90_get_var can read perfectly from this variable with the > same group and variable id. Also, the error does not seem to make much > sense, since neither dimensions or names are even involved. Note that nc_copy_var (and nf_copy_var that calls it) both depend on the dimensions that the variable uses having already been defined in the output file. If you try to copy a variable with a dimension not yet defined, you will get that error. That assumption seems to have been omitted from the documentation. We'll fix that. > 3. Is there any reliable documentation for NF_COPY_VAR or a Fortran90 > version of it? No, the Fortran documentation doesn't appear to include that function. We'll fix that too. > Since the code is to be distributed, we would not like it to rely on NCO > or similar external routines and do everything with the normal Fortran > interface. > > Any ideas? Keep in mind that using nc_copy_var or nf_copy_var can be very inefficient if the target is a large netCDF-3 (classic or 64-bit offset format) file, as described by this paragraph from the documentation: 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. --Russ Russ Rew UCAR Unidata Program russ@xxxxxxxxxxxxxxxx http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: AYG-518147 Department: Support netCDF Priority: Normal Status: Closed
netcdfgroup
archives: