Skip to content

Creating a CDF5 file without writing any data in it creates a "classic" CDF1 file #3213

@krisfed

Description

@krisfed

I am creating and immediately closing a netcdf file with NC_FORMAT_CDF5/NC_FORMAT_64BIT_DATA (without creating any dimensions, variables, attributes, etc.). When I query the format, it returns 1 (NC_FORMAT_CLASSIC). Is this expected?

This is on a mac (Apple Silicon). NetCDF version is 4.9.3 and the build log shows that CDF5 is enabled:

# Features
--------
Benchmarks:		no
NetCDF-2 API:		yes
HDF4 Support:		no
HDF5 Support:		yes
CDF5 Support:		yes
NC-4 Parallel Support:	no
PnetCDF Support:	no

Here is the reproduction code:

#include <iostream>
#include <netcdf.h>

void checkErrorCode(int status, const char* message){
    if (status != NC_NOERR){
        std::cout << "Error code: " << status << " from " << message << std::endl;
        std::cout << nc_strerror(status) << std::endl << std::endl;
    }
}


int main()
{
    int ncid;
    int retval;
      
    std::cout << "NC_FORMAT_64BIT_DATA: " << NC_FORMAT_64BIT_DATA << std::endl;

    retval = nc_create("myfile.nc", NC_FORMAT_64BIT_DATA, &ncid);
    checkErrorCode(retval, "nc_create");
    
    int format;
    retval = nc_inq_format(ncid, &format); 
    checkErrorCode(retval, "nc_inq_format");
    
    std::cout << "format: " << format << std::endl;
    
    retval = nc_close(ncid);
    checkErrorCode(retval, "nc_close");
    
}

It produces the following output:

$ ./a.out 
NC_FORMAT_64BIT_DATA: 5
format: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions