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

Go to the source code of this file.
Defines | |
| #define | FILE_NAME "tst_enums.nc" |
| #define | DIM_LEN 4 |
| #define | NUM_MEMBERS 4 |
| #define | DIM_NAME "dim" |
| #define | BASE_SIZE 20 |
| #define | VAR_NAME "Advice" |
| #define | TYPE_NAME "Mysterous_Word" |
| #define | NUM_BRADYS 9 |
| #define | BRADYS "Bradys" |
| #define | BRADY_DIM_LEN 3 |
| #define | ATT_NAME "brady_attribute" |
Functions | |
| int | main (int argc, char **argv) |
|
|
|
Definition at line 17 of file tst_enums.c. Referenced by main(). |
|
|
Referenced by main(). |
|
|
Referenced by main(). |
|
|
Definition at line 14 of file tst_enums.c. |
|
|
Definition at line 16 of file tst_enums.c. |
|
|
Definition at line 13 of file tst_enums.c. |
|
|
Referenced by main(). |
|
|
Definition at line 15 of file tst_enums.c. Referenced by main(). |
|
|
Definition at line 19 of file tst_enums.c. Referenced by main(). |
|
|
Definition at line 18 of file tst_enums.c. |
|
||||||||||||
|
Definition at line 22 of file tst_enums.c. References ATT_NAME, BRADY_DIM_LEN, BRADYS, DIM_LEN, ERR, FILE_NAME, FINAL_RESULTS, nc_close, nc_create, nc_def_enum(), NC_ENUM, NC_GLOBAL, nc_inq_enum(), nc_inq_enum_member(), nc_inq_typeids(), nc_inq_user_type(), nc_insert_enum(), NC_INT, NC_MAX_NAME, NC_NETCDF4, NC_NOWRITE, nc_open, nc_put_att, NC_UBYTE, ncid, NUM_BRADYS, NUM_MEMBERS, SUMMARIZE_ERR, and TYPE_NAME. 00023 { 00024 int ncid; 00025 nc_type typeid; 00026 int i; 00027 char name_in[NC_MAX_NAME+1]; 00028 int ntypes, typeids[1] = {0}; 00029 nc_type base_nc_type, base_nc_type_in; 00030 size_t nfields_in, num_members, base_size_in; 00031 int class_in; 00032 00033 printf("\n*** Testing netcdf-4 enum type.\n"); 00034 /*nc_set_log_level(3);*/ 00035 00036 printf("*** creating enum type..."); 00037 { 00038 int value_in; 00039 unsigned char data[DIM_LEN]; 00040 /* Can't use the same name twice! */ 00041 char member_name[NUM_MEMBERS][NC_MAX_NAME + 1] = {"Mene1", "Mene2", 00042 "Tekel", "Upharsin"}; 00043 int member_value[NUM_MEMBERS] = {0, 99, 81232, 12}; 00044 00045 for (i=0; i<DIM_LEN; i++) 00046 data[i] = i; 00047 00048 /* Create a file. */ 00049 if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; 00050 00051 /* Create an enum type. */ 00052 if (nc_def_enum(ncid, NC_INT, TYPE_NAME, &typeid)) ERR; 00053 for (i = 0; i < NUM_MEMBERS; i++) 00054 if (nc_insert_enum(ncid, typeid, member_name[i], 00055 &member_value[i])) ERR; 00056 00057 /* Check it out. */ 00058 if (nc_inq_user_type(ncid, typeid, name_in, &base_size_in, &base_nc_type_in, 00059 &nfields_in, &class_in)) ERR; 00060 if (strcmp(name_in, TYPE_NAME) || base_size_in != sizeof(int) || 00061 base_nc_type_in != NC_INT || nfields_in != NUM_MEMBERS || class_in != NC_ENUM) ERR; 00062 if (nc_inq_enum(ncid, typeid, name_in, &base_nc_type, &base_size_in, &num_members)) ERR; 00063 if (strcmp(name_in, TYPE_NAME) || base_nc_type != NC_INT || 00064 num_members != NUM_MEMBERS) ERR; 00065 for (i = 0; i < NUM_MEMBERS; i++) 00066 { 00067 if (nc_inq_enum_member(ncid, typeid, i, name_in, &value_in)) ERR; 00068 if (strcmp(name_in, member_name[i]) || value_in != member_value[i]) ERR; 00069 } 00070 00071 /* Write the file. */ 00072 if (nc_close(ncid)) ERR; 00073 00074 /* Reopen the file. */ 00075 if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; 00076 00077 /* Get type info. */ 00078 if (nc_inq_typeids(ncid, &ntypes, typeids)) ERR; 00079 if (ntypes != 1 || !typeids[0]) ERR; 00080 00081 /* Check it out. */ 00082 if (nc_inq_user_type(ncid, typeids[0], name_in, &base_size_in, &base_nc_type_in, 00083 &nfields_in, &class_in)) ERR; 00084 if (strcmp(name_in, TYPE_NAME) || base_size_in != sizeof(int) || 00085 base_nc_type_in != NC_INT || nfields_in != NUM_MEMBERS || class_in != NC_ENUM) ERR; 00086 if (nc_inq_enum(ncid, typeids[0], name_in, &base_nc_type, &base_size_in, &num_members)) ERR; 00087 if (strcmp(name_in, TYPE_NAME) || base_nc_type != NC_INT || num_members != NUM_MEMBERS) ERR; 00088 for (i = 0; i < NUM_MEMBERS; i++) 00089 { 00090 if (nc_inq_enum_member(ncid, typeid, i, name_in, &value_in)) ERR; 00091 if (strcmp(name_in, member_name[i]) || value_in != member_value[i]) ERR; 00092 } 00093 00094 if (nc_close(ncid)) ERR; 00095 } 00096 00097 SUMMARIZE_ERR; 00098 00099 #define NUM_BRADYS 9 00100 #define BRADYS "Bradys" 00101 #define BRADY_DIM_LEN 3 00102 #define ATT_NAME "brady_attribute" 00103 00104 printf("*** testing enum attribute..."); 00105 { 00106 char brady_name[NUM_BRADYS][NC_MAX_NAME + 1] = {"Mike", "Carol", "Greg", "Marsha", 00107 "Peter", "Jan", "Bobby", "Whats-her-face", 00108 "Alice"}; 00109 unsigned char brady_value[NUM_BRADYS] = {0, 1,2,3,4,5,6,7,8}; 00110 unsigned char data[BRADY_DIM_LEN] = {0, 4, 8}; 00111 unsigned char value_in; 00112 00113 /* Create a file. */ 00114 if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; 00115 00116 /* Create an enum type based on unsigned bytes. */ 00117 if (nc_def_enum(ncid, NC_UBYTE, BRADYS, &typeid)) ERR; 00118 for (i = 0; i < NUM_BRADYS; i++) 00119 if (nc_insert_enum(ncid, typeid, brady_name[i], 00120 &brady_value[i])) ERR; 00121 00122 /* Check it out. */ 00123 if (nc_inq_user_type(ncid, typeid, name_in, &base_size_in, &base_nc_type_in, 00124 &nfields_in, &class_in)) ERR; 00125 if (strcmp(name_in, BRADYS) || base_size_in != 1 || 00126 base_nc_type_in != NC_UBYTE || nfields_in != NUM_BRADYS || class_in != NC_ENUM) ERR; 00127 if (nc_inq_enum(ncid, typeid, name_in, &base_nc_type, &base_size_in, &num_members)) ERR; 00128 if (strcmp(name_in, BRADYS) || base_nc_type != NC_UBYTE || base_size_in != 1 || 00129 num_members != NUM_BRADYS) ERR; 00130 for (i = 0; i < NUM_BRADYS; i++) 00131 { 00132 if (nc_inq_enum_member(ncid, typeid, i, name_in, &value_in)) ERR; 00133 if (strcmp(name_in, brady_name[i]) || value_in != brady_value[i]) ERR; 00134 } 00135 00136 /* Write an att of this enum type. */ 00137 if (nc_put_att(ncid, NC_GLOBAL, ATT_NAME, typeid, BRADY_DIM_LEN, data)) ERR; 00138 00139 /* Close the file. */ 00140 if (nc_close(ncid)) ERR; 00141 00142 /* /\* Reopen. *\/ */ 00143 /* if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; */ 00144 00145 /* /\* Check it out. *\/ */ 00146 /* if (nc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &typeid, &size_in)) ERR; */ 00147 /* if (size_in != BRADY_DIM_LEN) ERR; */ 00148 /* if (nc_inq_user_type(ncid, typeid, name_in, &base_size_in, &base_nc_type_in, &nfields_in, &class_in)) ERR; */ 00149 /* if (strcmp(name_in, TYPE_NAME) || base_size_in != BASE_SIZE || */ 00150 /* base_nc_type_in != 0 || nfields_in != 0 || class_in != NC_OPAQUE) ERR; */ 00151 /* if (nc_inq_opaque(ncid, typeid, name_in, &base_size_in)) ERR; */ 00152 /* if (strcmp(name_in, TYPE_NAME) || base_size_in != BASE_SIZE) ERR; */ 00153 /* if (nc_get_att(ncid, NC_GLOBAL, ATT_NAME, data_in)) ERR; */ 00154 /* for (i=0; i<BRADY_DIM_LEN; i++) */ 00155 /* for (j=0; j<BASE_SIZE; j++) */ 00156 /* if (data_in[i][j] != data[i][j]) ERR; */ 00157 00158 /* if (nc_close(ncid)) ERR; */ 00159 } 00160 00161 SUMMARIZE_ERR; 00162 printf("*** testing opaque variable..."); 00163 00164 { 00165 /* int dimid, varid, dimids[] = {0}; */ 00166 /* char name_in[NC_MAX_NAME+1]; */ 00167 /* nc_type base_nc_type_in, var_type; */ 00168 /* size_t base_size_in; */ 00169 /* int nfields_in, class_in; */ 00170 /* char var_name[NC_MAX_NAME+1]; */ 00171 /* int nvars, natts, ndims, unlimdimid, dimids_var[1]; */ 00172 /* char var_data[] = "Even a fool, when he holdeth his peace, is counted wise:" */ 00173 /* " and he that shutteth his lips is esteemed a man of understanding."; */ 00174 00175 /* /\* Create a file that has an opaque variable. *\/ */ 00176 /* if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR; */ 00177 /* if (nc_def_opaque(ncid, BASE_SIZE, TYPE_NAME, &xtype)) ERR; */ 00178 /* if (nc_inq_user_type(ncid, xtype, name_in, &base_size_in, &base_nc_type_in, &nfields_in, &class_in)) ERR; */ 00179 /* if (strcmp(name_in, TYPE_NAME) || base_size_in != BASE_SIZE || */ 00180 /* base_nc_type_in != 0 || nfields_in != 0 || class_in != NC_OPAQUE) ERR; */ 00181 /* if (nc_inq_opaque(ncid, xtype, name_in, &base_size_in)) ERR; */ 00182 /* if (strcmp(name_in, TYPE_NAME) || base_size_in != BASE_SIZE) ERR; */ 00183 /* if (nc_def_dim(ncid, DIM_NAME, DIM_LEN, &dimid)) ERR; */ 00184 /* if (nc_def_var(ncid, VAR_NAME, xtype, 1, dimids, &varid)) ERR; */ 00185 /* if (nc_put_var(ncid, varid, data)) ERR; */ 00186 /* if (nc_close(ncid)) ERR; */ 00187 00188 /* /\* Check it out. *\/ */ 00189 /* if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; */ 00190 /* if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; */ 00191 /* if (ndims != 1 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR; */ 00192 /* if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR; */ 00193 /* if (ndims != 1 || strcmp(var_name, VAR_NAME) || */ 00194 /* dimids_var[0] != dimids[0] || natts != 0) ERR; */ 00195 /* if (nc_get_var(ncid, 0, data_in)) ERR; */ 00196 /* for (i=0; i<DIM_LEN; i++) */ 00197 /* for (j=0; j<BASE_SIZE; j++) */ 00198 /* if (data_in[i][j] != data[i][j]) ERR; */ 00199 /* if (nc_close(ncid)) ERR; */ 00200 } 00201 00202 SUMMARIZE_ERR; 00203 00204 FINAL_RESULTS; 00205 }
|
1.4.4