This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Russ: Right - my c example was flawed (and not consistent with the python example). The python interface uses set_default_format to set the output format of a new file created by nc_create. Here's an updated C example: #include <stdio.h> #include <stdlib.h> #include <netcdf.h> #define handle_error(e) {printf("Error: %s\n", nc_strerror(e)); exit(2);} int main(int *argc, char **argv) { char flnm[] = "http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/hindcasts/wave_gom3"; char flnm2[] = "http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3"; char flnmo[] = "dummy.nc"; int status; /* error status */ int ncid, ncid2, ncido; /* netCDF ID */ status = nc_open(flnm, NC_NOWRITE, &ncid); if (status != NC_NOERR) handle_error(status); status = nc_set_default_format(NC_FORMAT_NETCDF4, NULL); if (status != NC_NOERR) handle_error(status); status = nc_create(flnmo, NC_WRITE | NC_CLOBBER, &ncid); if (status != NC_NOERR) handle_error(status); status = nc_open(flnm2, NC_NOWRITE, &ncid); if (status != NC_NOERR) handle_error(status); return ( 0 ); } This still produces Error: NetCDF: Invalid argument and this error message is (apparently) being emitted from the last nc_open call (after the nc_create). The error goes away if the nc_set_default format code sets the file format to anything other than NC_FORMAT_NETCDF. I understand that the DAP protocol does not yet support the NETCDF4 data model, but since the last nc_open call is NC_NOWRITE, I wouldn't expect the nc_set_default call to affect it at all. Does that make sense? -Jeff
-- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : address@hidden 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg |