2015-05-02 05:28:59 +08:00
|
|
|
/*! Test program for netcdf issue NCF-330
|
2018-12-07 06:36:53 +08:00
|
|
|
|
|
|
|
Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
|
|
|
2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
|
|
|
|
2015, 2016, 2017, 2018
|
|
|
|
University Corporation for Atmospheric Research/Unidata.
|
|
|
|
|
|
|
|
See \ref copyright file for more info.
|
|
|
|
|
2015-05-02 05:28:59 +08:00
|
|
|
* This test was provided by Ellen Johnson at Mathworks and
|
|
|
|
* illustrates an issue currently only seen on Windows.
|
|
|
|
*
|
|
|
|
* See https://bugtracking.unidata.ucar.edu/browse/NCF-330
|
|
|
|
*/
|
|
|
|
|
2015-08-16 06:26:35 +08:00
|
|
|
#include "config.h"
|
|
|
|
#ifdef HAVE_STDLIB_H
|
2015-08-03 06:09:47 +08:00
|
|
|
#include <stdlib.h>
|
2015-08-16 06:26:35 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STDIO_H
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
2015-05-02 05:28:59 +08:00
|
|
|
#include <netcdf.h>
|
2015-05-09 04:51:43 +08:00
|
|
|
|
2015-05-06 06:13:51 +08:00
|
|
|
#ifdef _MSC_VER
|
2015-05-09 04:51:43 +08:00
|
|
|
#include <malloc.h>
|
2015-05-06 06:13:51 +08:00
|
|
|
#include <crtdbg.h>
|
|
|
|
#endif
|
2015-05-02 05:28:59 +08:00
|
|
|
|
|
|
|
static char* URL="http://data.nodc.noaa.gov/thredds/dodsC/testdata/pathfinderAgg/pathFinderV5.2_night.ncml";
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
int ncid;
|
|
|
|
int ncstatus;
|
|
|
|
int lat_id;
|
|
|
|
nc_type lat_type;
|
|
|
|
int lat_ndims;
|
|
|
|
int lat_dimids[NC_MAX_VAR_DIMS];
|
|
|
|
int lat_natts;
|
|
|
|
int format_p;
|
|
|
|
float lat_data[4320];
|
|
|
|
|
2015-05-06 06:13:51 +08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
/* See https://msdn.microsoft.com/en-us/library/5at7yxcs(v=vs.120).aspx
|
|
|
|
for more information re: these. */
|
2015-08-16 06:26:35 +08:00
|
|
|
/*int tmpFlag = _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF);*/
|
2015-05-06 06:13:51 +08:00
|
|
|
#endif
|
2015-05-02 05:28:59 +08:00
|
|
|
printf(" \n");
|
|
|
|
printf("********************\n");
|
|
|
|
printf("open URL %s\n",URL);
|
|
|
|
printf(" \n");
|
|
|
|
ncstatus = nc_open(URL, NC_NOWRITE, &ncid);
|
|
|
|
if(ncstatus != NC_NOERR) {
|
|
|
|
printf("Could not open: %s; server may be down; test ignored\n",URL);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
printf("status after open = %d\n", ncstatus);
|
|
|
|
|
2015-08-16 06:26:35 +08:00
|
|
|
/* get the format */
|
2015-05-02 05:28:59 +08:00
|
|
|
ncstatus = nc_inq_format(ncid, &format_p);
|
|
|
|
printf("lat id = %d\n", format_p);
|
|
|
|
|
2015-08-16 06:26:35 +08:00
|
|
|
/* get varid for latitude */
|
2015-05-02 05:28:59 +08:00
|
|
|
ncstatus = nc_inq_varid(ncid,"lat",&lat_id);
|
|
|
|
printf("status after inq lat id = %d\n", ncstatus);
|
|
|
|
printf("lat id = %d\n", lat_id);
|
|
|
|
|
|
|
|
ncstatus = nc_inq_var(ncid, lat_id, 0, &lat_type, &lat_ndims, lat_dimids, &lat_natts);
|
|
|
|
printf("status after inq lat var = %d\n", ncstatus);
|
|
|
|
printf("lat type = %d\n", lat_type);
|
|
|
|
|
2015-08-16 06:26:35 +08:00
|
|
|
/* extract the first latitude value */
|
2015-05-02 05:28:59 +08:00
|
|
|
ncstatus = nc_get_var_float(ncid, lat_id, &lat_data[0]);
|
|
|
|
printf("status after get = %d\n", ncstatus);
|
|
|
|
printf("my datum = %f\n", lat_data[0]);
|
|
|
|
|
2015-08-16 06:26:35 +08:00
|
|
|
/* This code works okay in Linux and Mac
|
|
|
|
Everything works okay up until here in Windows then an exception occurs
|
|
|
|
*/
|
2015-05-02 05:28:59 +08:00
|
|
|
ncstatus = nc_close(ncid);
|
|
|
|
printf("status after close = %d\n", ncstatus);
|
|
|
|
printf("End of test.\n\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|