Hi Jeff,
The C program you included gets an "Invalid argument" error due to the
call
status = nc_set_default_format(NC_NETCDF4, NULL);
because NC_NETCDF4 is not a valid argument to that function. what you
intended most likely was
status = nc_set_default_format(NC_FORMAT_NETCDF4, NULL);
which doesn't return an error status.
It's also not clear what effect you intended this function call to
achieve. That function is to change the format of netCDF files to be
created by future calls to nc_create (or nc__create), but has no
relevance to calls to nc_open. In particular, it won't make it possible
to read netCDF-4 enhanced data model features using the existing DAP
protocol, because the DAP4 protocol is still being implemented as part
of the OPULS project. No clients or servers exist yet for DAP4.
Nevertheless, there's apparently an unintended interaction between the
call to nc_set_default with NC_FORMAT_NETCDF4 and a subsequent attempt
to open and read data from a DAP server. I've created a Jira ticket for
this, if you want to follow progress on it:
https://bugtracking.unidata.ucar.edu/browse/NCF-243
--Russ
> Here's a python program that triggers the error:
>
> >> import netCDF4
> >> nc=netCDF4.Dataset('http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/
> hindcasts/wave_gom3' <http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/h
> indcasts/wave_gom3%27>)
> >> nco=netCDF4.Dataset('dummy.nc', 'w', format='NETCDF4')
> >> nc2=netCDF4.Dataset('http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom
> /hindcasts/30yr_gom3' <http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/
> hindcasts/30yr_gom3%27>)
>
> Traceback (most recent call last):
> File "issue170.py", line 4, in <module>
>
> nc2=netCDF4.Dataset('http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/hin
> dcasts/30yr_gom3')
> File "netCDF4.pyx", line 1386, in netCDF4.Dataset.__init__
> (netCDF4.c:19186)
> raise RuntimeError((<char *>nc_strerror(ierr)).decode('ascii'))
> RuntimeError: NetCDF: Invalid argument
>
> and here's the C counterpart
>
> #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_set_default_format(NC_NETCDF4, NULL);
> if (status != NC_NOERR) handle_error(status);
>
> status = nc_open(flnm, NC_NOWRITE, &ncid);
> if (status != NC_NOERR) handle_error(status);
>
> status = nc_open(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 );
> }
>
> which produces
>
> Error: NetCDF: Invalid argument
>
> Note that the file write sandwiched between the DAP reads must be
> NETCDF4 format to trigger the error. Tested with 4.2.1.1 and 4.3.0rc2.
>
> Regards, Jeff
>
> --------------020300050107010207060105
> Content-Type: text/html; charset=ISO-8859-1
> Content-Transfer-Encoding: 7bit
>
> <html><head>
> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"></hea
> d><body
> style="font-family: tt; font-size: 12pt;" bgcolor="#FFFFFF"
> text="#000000">
> <div style="font-size: 12pt;font-family: tt;"><span style="font-family:
> monospace;">Here's a python program that triggers the error:<br><br></span><s
> pan><meta
> http-equiv="content-type" content="text/html; charset=ISO-8859-1"><pre>>&
> gt; import netCDF4
> >> nc=netCDF4.Dataset('<a href="http://www.smast.umassd.edu:8080/thredd
> s/dodsC/fvcom/hindcasts/wave_gom3%27" rel="nofollow">http://www.smast.umassd.
> edu:8080/thredds/dodsC/fvcom/hindcasts/wave_gom3'</a>)
> >> nco=netCDF4.Dataset('dummy.nc', 'w', format='NETCDF4')
> >> nc2=netCDF4.Dataset('<a href="http://www.smast.umassd.edu:8080/thred
> ds/dodsC/fvcom/hindcasts/30yr_gom3%27" rel="nofollow">http://www.smast.umassd
> .edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3'</a>)
> </pre>Traceback (most recent call last):<br> File "issue170.py", line
> 4, in <module><br>
> nc2=netCDF4.Dataset('<a class="moz-txt-link-freetext" href="http://www.smast.
> umassd.edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3">http://www.smast.uma
> ssd.edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3</a>')<br>
> File "netCDF4.pyx", line 1386, in netCDF4.Dataset.__init__
> (netCDF4.c:19186)<br> raise RuntimeError((<char
> *>nc_strerror(ierr)).decode('ascii'))<br>RuntimeError: NetCDF:
> Invalid argument</span><br><br>and here's the C counterpart<br><br>#include
> <stdlib.h><br>#include <netcdf.h><br>#define
> handle_error(e) {printf("Error: %s\n", nc_strerror(e)); exit(2);}<br><br>int
> main(int *argc, char **argv)<br>{<br> char flnm[] =
> <a class="moz-txt-link-rfc2396E" href="http://www.smast.umassd.edu:8080/thred
> ds/dodsC/fvcom/hindcasts/wave_gom3">"http://www.smast.umassd.edu:8080/thredds
> /dodsC/fvcom/hindcasts/wave_gom3"</a>;<br>
> char flnm2[] =
> <a class="moz-txt-link-rfc2396E" href="http://www.smast.umassd.edu:8080/thred
> ds/dodsC/fvcom/hindcasts/30yr_gom3">"http://www.smast.umassd.edu:8080/thredds
> /dodsC/fvcom/hindcasts/30yr_gom3"</a>;<br>
> char flnmo[] = "dummy.nc";<br> int status; &nbs
> p; &nb
> sp; /*
> error status */<br> int ncid, ncid2, ncido; &nb
> sp; /* netCDF ID
> */<br><br> status = nc_set_default_format(NC_NETCDF4, NULL)
> ;<br>
> if (status != NC_NOERR) handle_error(status);<br><br> statu
> s =
> nc_open(flnm, NC_NOWRITE, &ncid);<br> if (status != NC_
> NOERR)
> handle_error(status);<br><br> status = nc_open(flnmo, NC_WR
> ITE |
> NC_CLOBBER, &ncid);<br> if (status != NC_NOERR)
> handle_error(status);<br><br> status = nc_open(flnm2, NC_NO
> WRITE,
> &ncid);<br> if (status != NC_NOERR) handle_error(status
> );<br><br>
> return ( 0 );<br>}<br><br>which produces<br><br>Error: NetCDF: Invalid
> argument<br><br>Note that the file write sandwiched between the DAP
> reads must be NETCDF4 format to trigger the error. Tested with 4.2.1.1
> and 4.3.0rc2.<br><br>Regards, Jeff<br></div>
> </body>
> </html>
>
> --------------020300050107010207060105--
>
>
> --===============1553365993==
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
>
> _______________________________________________
> netcdfgroup mailing list
> netcdfgroup@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/m
> ailing_lists/
> --===============1553365993==--