/* Get the format (i.e. classic, 64-bit-offset, or netcdf-4) of an * open file. */ int NC4_inq_format(int ncid, int *formatp) { NC *nc; NC_HDF5_FILE_INFO_T* nc4_info; LOG((2, "nc_inq_format: ncid 0x%x", ncid)); if (!formatp) return NC_NOERR; /* Find the file metadata. */ if (!(nc = nc4_find_nc_file(ncid,&nc4_info))) return NC_EBADID; #if 0 /*def USE_PNETCDF*/ /* Take care of files created/opened with parallel-netcdf library. */ if (nc4_info->pnetcdf_file) return ncmpi_inq_format(nc->int_ncid, formatp); #endif /* USE_PNETCDF */ /* Otherwise, this is a netcdf-4 file. Check if classic NC3 rules * are in effect for this file. */ if (nc4_info->cmode & NC_CLASSIC_MODEL) *formatp = NC_FORMAT_NETCDF4_CLASSIC; else *formatp = NC_FORMAT_NETCDF4; return NC_NOERR; }
static int NC5_inq_format(int ncid, int* formatp) { NC* nc; int status = NC_check_id(ncid, &nc); if(status != NC_NOERR) return status; return ncmpi_inq_format(nc->int_ncid,formatp); }
FORTRAN_API int FORT_CALL nfmpi_inq_format_ ( int *v1, MPI_Fint *v2 ){ int ierr; ierr = ncmpi_inq_format( *v1, v2 ); return ierr; }
int main(int argc, char **argv) { char dir_name[256], filename[256]; int err, rank, nerrs=0, format, ncid; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (argc != 2) { if (!rank) printf("Usage: %s dir_name\n",argv[0]); MPI_Finalize(); return 0; } strcpy(dir_name, argv[1]); MPI_Bcast(dir_name, 256, MPI_CHAR, 0, MPI_COMM_WORLD); if (rank == 0) { char cmd_str[256]; sprintf(cmd_str, "*** TESTING C %s for inquiring CDF file formats ", argv[0]); printf("%-66s ------ ", cmd_str); } /* test CDF-1 -----------------------------------------------------------*/ sprintf(filename,"%s/test_cdf1.nc",dir_name); err = ncmpi_open(MPI_COMM_WORLD, filename, 0, MPI_INFO_NULL, &ncid); ERR err = ncmpi_inq_format(ncid, &format); ERR if (format != NC_FORMAT_CLASSIC) { printf("Error (line=%d): expecting CDF-1 format for file %s but got %d\n", __LINE__,filename,format); nerrs++; } err = ncmpi_close(ncid); ERR err = ncmpi_inq_file_format(filename, &format); ERR if (format != NC_FORMAT_CLASSIC) { printf("Error (line=%d): expecting CDF-1 format for file %s but got %d\n", __LINE__,filename,format); nerrs++; } /* test CDF-2 -----------------------------------------------------------*/ sprintf(filename,"%s/test_cdf2.nc",dir_name); err = ncmpi_open(MPI_COMM_WORLD, filename, 0, MPI_INFO_NULL, &ncid); ERR err = ncmpi_inq_format(ncid, &format); ERR if (format != NC_FORMAT_CDF2) { printf("Error (line=%d): expecting CDF-2 format for file %s but got %d\n", __LINE__,filename,format); nerrs++; } err = ncmpi_close(ncid); ERR err = ncmpi_inq_file_format(filename, &format); ERR if (format != NC_FORMAT_CDF2) { printf("Error (line=%d): expecting CDF-2 format for file %s but got %d\n", __LINE__,filename,format); nerrs++; } /* test CDF-5 -----------------------------------------------------------*/ sprintf(filename,"%s/test_cdf5.nc",dir_name); err = ncmpi_open(MPI_COMM_WORLD, filename, 0, MPI_INFO_NULL, &ncid); ERR err = ncmpi_inq_format(ncid, &format); ERR if (format != NC_FORMAT_CDF5) { printf("Error (line=%d): expecting CDF-5 format for file %s but got %d\n", __LINE__,filename,format); nerrs++; } err = ncmpi_close(ncid); ERR err = ncmpi_inq_file_format(filename, &format); ERR if (format != NC_FORMAT_CDF5) { printf("Error (line=%d): expecting CDF-5 format for file %s but got %d\n", __LINE__,filename,format); nerrs++; } MPI_Offset malloc_size, sum_size; err = ncmpi_inq_malloc_size(&malloc_size); if (err == NC_NOERR) { MPI_Reduce(&malloc_size, &sum_size, 1, MPI_OFFSET, MPI_SUM, 0, MPI_COMM_WORLD); if (rank == 0 && sum_size > 0) printf("heap memory allocated by PnetCDF internally has %lld bytes yet to be freed\n", sum_size); } MPI_Allreduce(MPI_IN_PLACE, &nerrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if (rank == 0) { if (nerrs) printf(FAIL_STR,nerrs); else printf(PASS_STR); } MPI_Finalize(); return 0; }