As demonstated, the enddef call is not required for netCDF-4 files. In the code below, it will be called automatically by the nc_put_vara_ function.
/* Create a file with one unlimied dim and nothing else. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, LEVEL_NAME, NC_UNLIMITED, &dimids[0])) ERR; if (nc_def_var(ncid, LEVEL_NAME, NC_UINT64, 1, dimids, &level_varid)) ERR; /* Now write one record of data to the var. */ start[0] = 0; count[0] = 1; if (nc_put_vara_ulonglong(ncid, 0, start, count, uint64_data)) ERR;