17 int createNCDF(
int ncid,
const char *sname,
const char *lname,
20 const char *flag_values,
const char *flag_meanings,
21 double low,
double high,
int nt,
22 int rank,
int *dimids,
size_t *chunksize) {
28 status = nc_def_var(ncid, sname, nt,
rank, dimids, &varid);
30 printf(
"-E- %s %d: %s for %s\n",
31 __FILE__, __LINE__, nc_strerror(
status), sname);
36 double fill_value_dbl;
37 memcpy(&fill_value_dbl, fill_value,
sizeof (
double));
46 if ((low < high) && (low != fill_value_dbl)) {
50 status = nc_def_var_fill(ncid, varid, 0, (
void *) &i8);
51 }
else if (nt == NC_UBYTE) {
54 status = nc_def_var_fill(ncid, varid, 0, (
void *) &ui8);
55 }
else if (nt == NC_SHORT) {
58 status = nc_def_var_fill(ncid, varid, 0, (
void *) &i16);
59 }
else if (nt == NC_INT) {
62 status = nc_def_var_fill(ncid, varid, 0, (
void *) &i32);
63 }
else if (nt == NC_FLOAT) {
66 status = nc_def_var_fill(ncid, varid, 0, (
void *) &
f32);
69 status = nc_def_var_fill(ncid, varid, 0, (
void *) &fill_value_dbl);
81 status = nc_put_att_text(ncid, varid,
"long_name", strlen(lname), lname);
83 printf(
"-E- %s %d: %s for %s\n",
84 __FILE__, __LINE__, nc_strerror(
status),
"long_name");
89 if (strcmp(flag_values,
"") != 0) {
90 status = nc_put_att_text(ncid, varid,
"flag_values",
91 strlen(flag_values), flag_values);
93 printf(
"-E- %s %d: %s for %s\n",
94 __FILE__, __LINE__, nc_strerror(
status),
"flag_values");
100 if (strcmp(flag_meanings,
"") != 0) {
101 status = nc_put_att_text(ncid, varid,
"flag_meanings",
102 strlen(flag_meanings), flag_meanings);
104 printf(
"-E- %s %d: %s for %s\n",
105 __FILE__, __LINE__, nc_strerror(
status),
"flag_meanings");
116 vr[0] = (uint8_t) low;
117 vr[1] = (uint8_t) high;
118 status = nc_put_att_uchar(ncid, varid,
"valid_min", NC_BYTE, 1, &vr[0]);
120 printf(
"-E- %s %d: %s for %s\n",
121 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
124 status = nc_put_att_uchar(ncid, varid,
"valid_max", NC_BYTE, 1, &vr[1]);
126 printf(
"-E- %s %d: %s for %s\n",
127 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
135 vr[0] = (uint8_t) low;
136 vr[1] = (uint8_t) high;
137 status = nc_put_att_uchar(ncid, varid,
"valid_min", NC_UBYTE, 1, &vr[0]);
139 printf(
"-E- %s %d: %s for %s\n",
140 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
143 status = nc_put_att_uchar(ncid, varid,
"valid_max", NC_UBYTE, 1, &vr[1]);
145 printf(
"-E- %s %d: %s for %s\n",
146 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
154 vr[0] = (int16_t) low;
155 vr[1] = (int16_t) high;
156 status = nc_put_att_short(ncid, varid,
"valid_range", NC_SHORT, 1, &vr[0]);
158 printf(
"-E- %s %d: %s for %s\n",
159 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
162 status = nc_put_att_short(ncid, varid,
"valid_max", NC_SHORT, 1, &vr[1]);
164 printf(
"-E- %s %d: %s for %s\n",
165 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
173 vr[0] = (int32_t) low;
174 vr[1] = (int32_t) high;
175 status = nc_put_att_int(ncid, varid,
"valid_min", NC_INT, 1, &vr[0]);
177 printf(
"-E- %s %d: %s for %s\n",
178 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
181 status = nc_put_att_int(ncid, varid,
"valid_max", NC_INT, 1, &vr[1]);
183 printf(
"-E- %s %d: %s for %s\n",
184 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
193 vr[1] = (
float) high;
194 status = nc_put_att_float(ncid, varid,
"valid_min", NC_FLOAT, 1, &vr[0]);
196 printf(
"-E- %s %d: %s for %s\n",
197 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
200 status = nc_put_att_float(ncid, varid,
"valid_max", NC_FLOAT, 1, &vr[1]);
202 printf(
"-E- %s %d: %s for %s\n",
203 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
213 status = nc_put_att_double(ncid, varid,
"valid_min", NC_DOUBLE, 1, &vr[0]);
215 printf(
"-E- %s %d: %s for %s\n",
216 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
219 status = nc_put_att_double(ncid, varid,
"valid_max", NC_DOUBLE, 1, &vr[1]);
221 printf(
"-E- %s %d: %s for %s\n",
222 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
228 fprintf(
stderr,
"-E- %s line %d: ", __FILE__, __LINE__);
229 fprintf(
stderr,
"Got unsupported number type (%d) ", nt);
230 fprintf(
stderr,
"while trying to create NCDF variable, \"%s\", ", sname);
231 return (EXIT_FAILURE);
239 printf(
"-E- %s %d: %s for %s\n",
240 __FILE__, __LINE__, nc_strerror(
status),
"units");
247 status = nc_put_att_text(ncid, varid,
"standard_name",
250 printf(
"-E- %s %d: %s for %s\n",
251 __FILE__, __LINE__, nc_strerror(
status),
"standard_name");