netcdf-c icon indicating copy to clipboard operation
netcdf-c copied to clipboard

Trying NUG BNF example using ncgen for empty netCDF file, wrong size

Open ethanrd opened this issue 1 year ago • 2 comments

While working on reorganizing the NUG, I started adding CDF-2 and CDF-5 to the nc-3 (CDF-1) BNF description. I tried out some of the examples using ncgen to generate simple files and then looking at a dump (od -c file.nc). When I tried using ncgen for an empty netCDF file, I got 4096 byte netCDF files instead of getting 32 byte files for CDF-1 and CDF-2 and a 48 byte file for CDF-5.

I was using this CDL

netcdf empty { }

When I called ncgen against it to generate CDF-1, -2, and -5 files:

edavis@patrice NUG % ncgen -1 -o empty_CDF-1.nc empty.cdl
edavis@patrice NUG % ncgen -6 -o empty_CDF-2.nc empty.cdl
edavis@patrice NUG % ncgen -5 -o empty_CDF-5.nc empty.cdl

I got larger than expected files

edavis@patrice NUG % ls -l empty*.nc
-rw-r--r--  1 edavis  staff  4096 May 23 17:43 empty_CDF-1.nc
-rw-r--r--  1 edavis  staff  4096 May 23 17:44 empty_CDF-2.nc
-rw-r--r--  1 edavis  staff  4096 May 23 17:45 empty_CDF-5.nc

When I dump the content, it looks like this

edavis@patrice NUG % od -c empty_CDF-1.nc   
0000000    C   D   F 001  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000020   \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
0010000
edavis@patrice NUG % od -c empty_CDF-2.nc
0000000    C   D   F 002  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000020   \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
0010000
edavis@patrice NUG % od -c empty_CDF-5.nc
0000000    C   D   F 005  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000020   \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
0010000

I tried the other NUG example, a CDL describing a dataset with a single dimension and a single variable, and it was generated as expected (size and layout for CDF-1, -2, and -5).

I did this with ncgen version 4.9.2 installed from conda-forge NCO (5.1.5). I also tried with ncgen version 4.8.1 and got the same results. I'm running on a Mac with M1, osx-arm64.

ethanrd avatar May 24 '23 22:05 ethanrd

Huh, interesting. Let me take a look and I'll see if I can tell what's going on; any idea @DennisHeimbigner ? I'll be out for the holiday but back afterwards and will follow up. I'm wondering about the underlying filesystem, but at this point all I have is conjecture. I'll follow up.

WardF avatar May 25 '23 00:05 WardF

Ugh. This is being set at posixio.c:740. But I have no insight into the posixio code; it is hopelessly complicated (Thanks Glenn :-))

DennisHeimbigner avatar Jun 03 '23 22:06 DennisHeimbigner