Re: [netcdfgroup] bug mixing dap reads and netcdf4 writes

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;&
> gt; import netCDF4
> &gt;&gt; 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>)
> &gt;&gt; nco=netCDF4.Dataset('dummy.nc', 'w', format='NETCDF4')
> &gt;&gt; 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>&nbsp; File "issue170.py", line 
> 4, in &lt;module&gt;<br>&nbsp;&nbsp;&nbsp; 
> 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>&nbsp;
>  File "netCDF4.pyx", line 1386, in netCDF4.Dataset.__init__ 
> (netCDF4.c:19186)<br>&nbsp;&nbsp;&nbsp; raise RuntimeError((&lt;char 
> *&gt;nc_strerror(ierr)).decode('ascii'))<br>RuntimeError: NetCDF: 
> Invalid argument</span><br><br>and here's the C counterpart<br><br>#include
>  &lt;stdlib.h&gt;<br>#include &lt;netcdf.h&gt;<br>#define 
> handle_error(e) {printf("Error: %s\n", nc_strerror(e)); exit(2);}<br><br>int
>  main(int *argc, char **argv)<br>{<br>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp;
>  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>&nbsp;&nbsp;&nbsp;
>  char flnmo[] = "dummy.nc";<br>&nbsp;&nbsp;&nbsp; int status;&nbsp;&nbsp;&nbs
> p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
> sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*
>  error status */<br>&nbsp;&nbsp;&nbsp; int ncid, ncid2, ncido;&nbsp;&nbsp;&nb
> sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* netCDF ID 
> */<br><br>&nbsp;&nbsp;&nbsp; status = nc_set_default_format(NC_NETCDF4, NULL)
> ;<br>&nbsp;&nbsp;&nbsp; 
> if (status != NC_NOERR) handle_error(status);<br><br>&nbsp;&nbsp;&nbsp; statu
> s = 
> nc_open(flnm, NC_NOWRITE, &amp;ncid);<br>&nbsp;&nbsp;&nbsp; if (status != NC_
> NOERR) 
> handle_error(status);<br><br>&nbsp;&nbsp;&nbsp; status = nc_open(flnmo, NC_WR
> ITE | 
> NC_CLOBBER, &amp;ncid);<br>&nbsp;&nbsp;&nbsp; if (status != NC_NOERR) 
> handle_error(status);<br><br>&nbsp;&nbsp;&nbsp; status = nc_open(flnm2, NC_NO
> WRITE, 
> &amp;ncid);<br>&nbsp;&nbsp;&nbsp; if (status != NC_NOERR) handle_error(status
> );<br><br>&nbsp;&nbsp;&nbsp;
>  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.&nbsp; 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==--



  • 2013 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: