#include <nc4internal.h>#include <netcdf.h>#include <nc_tests.h>Include dependency graph for tst_converts.c:

Go to the source code of this file.
Defines | |
| #define | FILE_NAME "tst_converts.nc" |
| #define | ATT1_NAME "att1" |
| #define | ATT2_NAME "att2" |
| #define | DIM1_NAME "dim1" |
| #define | DIM1_LEN 3 |
| #define | DIM2_NAME "dim2" |
| #define | DIM2_LEN 15 |
| #define | VAR1_NAME "var1" |
| #define | VAR2_NAME "var2" |
Functions | |
| void | check_file (int format, unsigned char *uchar_out) |
| void | create_file (int format, unsigned char *uchar_out) |
| int | main (int argc, char **argv) |
|
|
Definition at line 15 of file tst_converts.c. Referenced by main(). |
|
|
Definition at line 16 of file tst_converts.c. Referenced by main(). |
|
|
Definition at line 18 of file tst_converts.c. |
|
|
Definition at line 17 of file tst_converts.c. |
|
|
Definition at line 20 of file tst_converts.c. |
|
|
Definition at line 19 of file tst_converts.c. |
|
|
Definition at line 14 of file tst_converts.c. |
|
|
Definition at line 21 of file tst_converts.c. |
|
|
Definition at line 22 of file tst_converts.c. |
|
||||||||||||
|
Definition at line 75 of file tst_converts.c. References DIM1_LEN, ERR, FILE_NAME, natts, NC_BYTE, nc_close, NC_ERANGE, NC_FORMAT_NETCDF4, NC_FORMAT_NETCDF4_CLASSIC, nc_get_var_int, nc_get_var_longlong(), nc_get_var_schar, nc_get_var_short, nc_get_var_uchar, nc_get_var_uint(), nc_get_var_ulonglong(), nc_get_var_ushort(), nc_inq_var, NC_MAX_NAME, NC_NOWRITE, nc_open, ncid, ndims, VAR1_NAME, var_name, and var_type. Referenced by main(), test_nc_abort(), and test_nc_redef(). 00076 { 00077 00078 int ncid; 00079 int ndims, natts; 00080 int dimids_var[1], var_type; 00081 char var_name[NC_MAX_NAME+1]; 00082 unsigned char uchar_in[DIM1_LEN]; 00083 signed char char_in[DIM1_LEN]; 00084 unsigned short ushort_in[DIM1_LEN]; 00085 short short_in[DIM1_LEN]; 00086 unsigned int uint_in[DIM1_LEN]; 00087 int int_in[DIM1_LEN]; 00088 long long int64_in[DIM1_LEN]; 00089 unsigned long long uint64_in[DIM1_LEN]; 00090 int i, res; 00091 00092 /* Read it back in, and check conversions. */ 00093 if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; 00094 if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR; 00095 if (strcmp(var_name, VAR1_NAME) || natts !=0 || ndims != 1 || 00096 dimids_var[0] != 0 || var_type != NC_BYTE) ERR; 00097 00098 /* This is actually an NC_BYTE, with some negatives, so this should 00099 * generate a range error for netcdf-4, but not for netcdf-3, 00100 * because range errors are not generated for byte type 00101 * conversions. */ 00102 res = nc_get_var_uchar(ncid, 0, uchar_in); 00103 if (format == NC_FORMAT_NETCDF4) 00104 { 00105 if (res != NC_ERANGE) ERR; 00106 } 00107 else if (res) ERR; 00108 00109 for (i=0; i<DIM1_LEN; i++) 00110 if (uchar_in[i] != uchar_out[i]) ERR; 00111 00112 if (nc_get_var_schar(ncid, 0, char_in)) ERR; 00113 for (i=0; i<DIM1_LEN; i++) 00114 if (char_in[i] != (signed char)uchar_out[i]) ERR; 00115 00116 if (nc_get_var_short(ncid, 0, short_in)) ERR; 00117 for (i=0; i<DIM1_LEN; i++) 00118 if (short_in[i] != (signed char)uchar_out[i]) ERR; 00119 00120 if (nc_get_var_int(ncid, 0, int_in)) ERR; 00121 for (i=0; i<DIM1_LEN; i++) 00122 if (int_in[i] != (signed char)uchar_out[i]) ERR; 00123 00124 if (format == NC_FORMAT_NETCDF4 || format == NC_FORMAT_NETCDF4_CLASSIC) 00125 { 00126 /* Since we wrote them as NC_BYTE, some of these are negative 00127 * values, and will return a range error when reading into 00128 * unsigned type. To compare values, first cast uchar_out to 00129 * signed int, then cast again to the type we are reading it 00130 * as. */ 00131 if (nc_get_var_ushort(ncid, 0, ushort_in) != NC_ERANGE) ERR; 00132 for (i=0; i<DIM1_LEN; i++) 00133 if (ushort_in[i] != (unsigned short)(signed char)uchar_out[i]) ERR; 00134 00135 if (nc_get_var_uint(ncid, 0, uint_in) != NC_ERANGE) ERR; 00136 for (i=0; i<DIM1_LEN; i++) 00137 if (uint_in[i] != (unsigned int)(signed char)uchar_out[i]) ERR; 00138 00139 if (nc_get_var_ulonglong(ncid, 0, uint64_in) != NC_ERANGE) ERR; 00140 for (i=0; i<DIM1_LEN; i++) 00141 if (uint64_in[i] != (unsigned long long)(signed char)uchar_out[i]) ERR; 00142 00143 if (nc_get_var_longlong(ncid, 0, int64_in)) ERR; 00144 for (i=0; i<DIM1_LEN; i++) 00145 if (int64_in[i] != (signed char)uchar_out[i]) ERR; 00146 00147 } 00148 00149 if (nc_close(ncid)) ERR; 00150 }
|
|
||||||||||||
|
Definition at line 50 of file tst_converts.c. References DIM1_LEN, DIM1_NAME, ERR, FILE_NAME, NC_64BIT_OFFSET, NC_BYTE, NC_CLASSIC_MODEL, nc_close, nc_create, nc_def_dim, nc_def_var, nc_enddef, NC_ERANGE, NC_FORMAT_64BIT, NC_FORMAT_NETCDF4, NC_FORMAT_NETCDF4_CLASSIC, NC_NETCDF4, nc_put_var_uchar, ncid, and VAR1_NAME. Referenced by main(). 00051 { 00052 int ncid, varid, cflags=0, dimids[1]; 00053 int retval; 00054 00055 if (format == NC_FORMAT_64BIT) 00056 cflags |= NC_64BIT_OFFSET; 00057 else if (format == NC_FORMAT_NETCDF4_CLASSIC) 00058 { 00059 cflags |= (NC_NETCDF4|NC_CLASSIC_MODEL); 00060 } 00061 else if (format == NC_FORMAT_NETCDF4) 00062 cflags |= NC_NETCDF4; 00063 00064 if (nc_create(FILE_NAME, cflags, &ncid)) ERR; 00065 if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; 00066 if (nc_def_var(ncid, VAR1_NAME, NC_BYTE, 1, dimids, &varid)) ERR; 00067 if (nc_enddef(ncid)) ERR; 00068 retval = nc_put_var_uchar(ncid, varid, uchar_out); 00069 if ((format != NC_FORMAT_NETCDF4) && retval) ERR; 00070 if ((format == NC_FORMAT_NETCDF4) && (retval != NC_ERANGE)) ERR; 00071 if (nc_close(ncid)) ERR; 00072 }
|
|
||||||||||||
|
Definition at line 29 of file tst_converts.c. References check_file(), create_file(), DIM1_LEN, FINAL_RESULTS, format_name, and SUMMARIZE_ERR. 00030 { 00031 unsigned char uchar_out[DIM1_LEN] = {0, 128, 255}; 00032 int format; 00033 00034 printf("\n*** Testing netcdf data conversion.\n"); 00035 /*nc_set_log_level(3);*/ 00036 00037 for (format = 1; format < 5; format++) 00038 { 00039 printf("*** Testing conversion in netCDF %s files... ", format_name[format]); 00040 create_file(format, uchar_out); 00041 check_file(format, uchar_out); 00042 SUMMARIZE_ERR; 00043 } 00044 00045 FINAL_RESULTS; 00046 }
|
1.4.4