Skip to content

Commit 06ac972

Browse files
authored
Merge pull request #1394 from NetCDF-World-Domination-Council/ejh_test
uncommented test
2 parents 30c44d8 + 26f97cf commit 06ac972

File tree

5 files changed

+243
-242
lines changed

5 files changed

+243
-242
lines changed

examples/C/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# See netcdf-c/COPYRIGHT file for more info.
77

8-
SET(exam_C_tests simple_xy_wr simple_xy_rd sfc_pres_temp_wr sfc_pres_temp_rd pres_temp_4D_wr pres_temp_4D_rd)
8+
SET(exam_C_tests simple_xy_wr simple_xy_rd sfc_pres_temp_wr sfc_pres_temp_rd pres_temp_4D_wr pres_temp_4D_rd format)
99
SET(exam_C_tests_source "")
1010
FOREACH(F ${exam_C_tests})
1111
set(exam_C_tests_source ${exam_C_test_source} ${F}.c)
@@ -19,5 +19,5 @@ SET_TESTS_PROPERTIES(C_tests_simple_xy_rd PROPERTIES DEPENDS C_tests_simple_xy_w
1919
SET_TESTS_PROPERTIES(C_tests_sfc_pres_temp_rd PROPERTIES DEPENDS C_tests_sfc_pres_temp_wr)
2020
SET_TESTS_PROPERTIES(C_tests_pres_temp_4D_rd PROPERTIES DEPENDS C_tests_pres_temp_4D_wr)
2121

22-
SET(CLEANFILES sfc_pres_temp.nc simple_xy.nc pres_temp_4D.nc simple_nc4.nc simple_xy_nc4.nc)
22+
SET(CLEANFILES *.nc)
2323
SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CLEANFILES}")

examples/C/Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ AM_LDFLAGS = ${top_builddir}/liblib/libnetcdf.la
1616

1717
# These are the netCDF-3 examples.
1818
check_PROGRAMS = simple_xy_wr simple_xy_rd sfc_pres_temp_wr \
19-
sfc_pres_temp_rd pres_temp_4D_wr pres_temp_4D_rd
19+
sfc_pres_temp_rd pres_temp_4D_wr pres_temp_4D_rd format \
20+
quick_large_files
2021

21-
TESTS = run_examples.sh
22+
TESTS = run_examples.sh format quick_large_files
2223

2324
# To build netcdf-4, or not to build netcdf-4, that is the question...
2425
if USE_HDF5

examples/C/format.c

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
2-
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
3-
2013, 2014, 2015, 2016, 2017, 2018 University Corporation for
4-
Atmospheric Research/Unidata. See \ref copyright file for more
5-
info. */
2+
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
3+
2013, 2014, 2015, 2016, 2017, 2018 University Corporation for
4+
Atmospheric Research/Unidata. See \ref copyright file for more
5+
info. */
66
/**
77
* @file
88
* This example program is part of Unidata's netCDF library for
@@ -12,7 +12,7 @@ info. */
1212
* netcdf formats (i.e. classic vs. 64-bit-offset).
1313
*
1414
* @author Ed Hartnett, 7/13/4
15-
*/
15+
*/
1616

1717
#include <config.h>
1818
#include <netcdf.h>
@@ -22,11 +22,11 @@ info. */
2222
/* This macro handles errors by outputting a message to stdout and
2323
then exiting. */
2424
#define NC_EXAMPLE_ERROR 2 /* This is the exit code for failure. */
25-
#define BAIL(e) do { \
26-
printf("Bailing out in file %s, line %d, error:%s.\n", \
27-
__FILE__, __LINE__, nc_strerror(e)); \
28-
return NC_EXAMPLE_ERROR; \
29-
} while (0)
25+
#define BAIL(e) do { \
26+
printf("Bailing out in file %s, line %d, error:%s.\n", \
27+
__FILE__, __LINE__, nc_strerror(e)); \
28+
return NC_EXAMPLE_ERROR; \
29+
} while (0)
3030

3131
#define NUMDIMS 2
3232
#define NUMVARS 1
@@ -36,53 +36,53 @@ return NC_EXAMPLE_ERROR; \
3636
int
3737
main()
3838
{
39-
int ncid, temp_varid, dimids[NUMDIMS];
40-
float temp[LAT_LEN][LON_LEN], *fp;
41-
char classic_file[] = "classic.nc", offset64_file[] = "offset.nc";
42-
char *file = classic_file;
43-
int i, res;
39+
int ncid, temp_varid, dimids[NUMDIMS];
40+
float temp[LAT_LEN][LON_LEN], *fp;
41+
char classic_file[] = "classic.nc", offset64_file[] = "offset.nc";
42+
char *file = classic_file;
43+
int i, res;
4444

45-
/* Create a bunch of phoney data so we have something to write in
46-
the example file. */
47-
for (fp=(float *)temp, i=0; i<LAT_LEN*LON_LEN; i++)
48-
*fp++ = 10. + i/10.;
45+
/* Create a bunch of phoney data so we have something to write in
46+
the example file. */
47+
for (fp=(float *)temp, i=0; i<LAT_LEN*LON_LEN; i++)
48+
*fp++ = 10. + i/10.;
4949

50-
/* Now create the file in both formats with the same code. */
51-
for (i=0; i<2; i++)
52-
{
53-
if (i==1) /* 64-bit offset format file */
54-
{
55-
file = offset64_file;
56-
if ((res = nc_set_default_format(NC_FORMAT_64BIT, NULL)))
57-
BAIL(res);
58-
}
50+
/* Now create the file in both formats with the same code. */
51+
for (i=0; i<2; i++)
52+
{
53+
if (i==1) /* 64-bit offset format file */
54+
{
55+
file = offset64_file;
56+
if ((res = nc_set_default_format(NC_FORMAT_64BIT, NULL)))
57+
BAIL(res);
58+
}
5959

60-
/* Create the netCDF file. */
61-
if ((res = nc_create(file, NC_CLOBBER, &ncid)))
62-
BAIL(res);
60+
/* Create the netCDF file. */
61+
if ((res = nc_create(file, NC_CLOBBER, &ncid)))
62+
BAIL(res);
6363

64-
/* Define dimensions. */
65-
if ((res = nc_def_dim(ncid, "latitude", LAT_LEN, dimids)))
66-
BAIL(res);
67-
if ((res = nc_def_dim(ncid, "longitude", LON_LEN, &dimids[1])))
68-
BAIL(res);
64+
/* Define dimensions. */
65+
if ((res = nc_def_dim(ncid, "latitude", LAT_LEN, dimids)))
66+
BAIL(res);
67+
if ((res = nc_def_dim(ncid, "longitude", LON_LEN, &dimids[1])))
68+
BAIL(res);
6969

70-
/* Define the variable. */
71-
if ((res = nc_def_var(ncid, "sfc_temp", NC_FLOAT, NUMDIMS,
72-
dimids, &temp_varid)))
73-
BAIL(res);
70+
/* Define the variable. */
71+
if ((res = nc_def_var(ncid, "sfc_temp", NC_FLOAT, NUMDIMS,
72+
dimids, &temp_varid)))
73+
BAIL(res);
7474

75-
/* We're finished defining metadata. */
76-
if ((res = nc_enddef(ncid)))
77-
BAIL(res);
75+
/* We're finished defining metadata. */
76+
if ((res = nc_enddef(ncid)))
77+
BAIL(res);
7878

79-
if ((res = nc_put_var_float(ncid, temp_varid, (float *)temp)))
80-
BAIL(res);
79+
if ((res = nc_put_var_float(ncid, temp_varid, (float *)temp)))
80+
BAIL(res);
8181

82-
/* We're done! */
83-
if ((res = nc_close(ncid)))
84-
BAIL(res);
85-
}
82+
/* We're done! */
83+
if ((res = nc_close(ncid)))
84+
BAIL(res);
85+
}
8686

87-
return 0;
87+
return 0;
8888
}

examples/C/quick_large_files.c

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
2-
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
3-
2013, 2014, 2015, 2016, 2017, 2018 University Corporation for
4-
Atmospheric Research/Unidata. See \ref copyright file for more
5-
info. */
2+
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
3+
2013, 2014, 2015, 2016, 2017, 2018 University Corporation for
4+
Atmospheric Research/Unidata. See \ref copyright file for more
5+
info. */
66
/**
77
* @file
88
*
@@ -13,7 +13,7 @@ info. */
1313
* features.
1414
*
1515
* @author Ed Hartnett, 8/11/4
16-
*/
16+
*/
1717

1818
#include <netcdf.h>
1919
#include <stdio.h>
@@ -22,11 +22,11 @@ info. */
2222
/* This macro handles errors by outputting a message to stdout and
2323
then exiting. */
2424
#define NC_EXAMPLE_ERROR 2 /* This is the exit code for failure. */
25-
#define BAIL(e) do { \
26-
printf("Bailing out in file %s, line %d, error:%s.\n", \
27-
__FILE__, __LINE__, nc_strerror(e)); \
28-
return NC_EXAMPLE_ERROR; \
29-
} while (0)
25+
#define BAIL(e) do { \
26+
printf("Bailing out in file %s, line %d, error:%s.\n", \
27+
__FILE__, __LINE__, nc_strerror(e)); \
28+
return NC_EXAMPLE_ERROR; \
29+
} while (0)
3030

3131
#define NUMDIMS 1
3232
#define NUMVARS 2
@@ -38,41 +38,41 @@ return NC_EXAMPLE_ERROR; \
3838
int
3939
main()
4040
{
41-
int ncid, spockid, kirkid, dimids[NUMDIMS];
42-
double val_in, val_out = 999.99;
43-
size_t index[NUMDIMS] = {DIM_LEN-1};
44-
int i, res;
41+
int ncid, spockid, kirkid, dimids[NUMDIMS];
42+
double val_in, val_out = 999.99;
43+
size_t index[NUMDIMS] = {DIM_LEN-1};
44+
int i, res;
4545

46-
/* Create the netCDF 64-bit offset format file. */
47-
if ((res = nc_create("example.nc", NC_CLOBBER|NC_64BIT_OFFSET, &ncid)))
48-
BAIL(res);
46+
/* Create the netCDF 64-bit offset format file. */
47+
if ((res = nc_create("example.nc", NC_CLOBBER|NC_64BIT_OFFSET, &ncid)))
48+
BAIL(res);
4949

50-
/* Turn off fill mode to speed things up. */
51-
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
52-
BAIL(res);
50+
/* Turn off fill mode to speed things up. */
51+
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
52+
BAIL(res);
5353

54-
/* Define dimension. */
55-
if ((res = nc_def_dim(ncid, "longdim", DIM_LEN, dimids)))
56-
BAIL(res);
54+
/* Define dimension. */
55+
if ((res = nc_def_dim(ncid, "longdim", DIM_LEN, dimids)))
56+
BAIL(res);
5757

58-
/* Define two variables. */
59-
if ((res = nc_def_var(ncid, "spock", NC_DOUBLE, NUMDIMS,
60-
dimids, &spockid)))
61-
BAIL(res);
62-
if ((res = nc_def_var(ncid, "kirk", NC_DOUBLE, NUMDIMS,
63-
dimids, &kirkid)))
64-
BAIL(res);
58+
/* Define two variables. */
59+
if ((res = nc_def_var(ncid, "spock", NC_DOUBLE, NUMDIMS,
60+
dimids, &spockid)))
61+
BAIL(res);
62+
if ((res = nc_def_var(ncid, "kirk", NC_DOUBLE, NUMDIMS,
63+
dimids, &kirkid)))
64+
BAIL(res);
6565

66-
/* We're finished defining metadata. */
67-
if ((res = nc_enddef(ncid)))
68-
BAIL(res);
66+
/* We're finished defining metadata. */
67+
if ((res = nc_enddef(ncid)))
68+
BAIL(res);
6969

70-
if ((res = nc_put_var1_double(ncid, kirkid, index, &val_out)))
71-
BAIL(res);
70+
if ((res = nc_put_var1_double(ncid, kirkid, index, &val_out)))
71+
BAIL(res);
7272

73-
/* We're done! */
74-
if ((res = nc_close(ncid)))
75-
BAIL(res);
73+
/* We're done! */
74+
if ((res = nc_close(ncid)))
75+
BAIL(res);
7676

77-
return 0;
77+
return 0;
7878
}

0 commit comments

Comments
 (0)