20 const char *flag_values,
const char *flag_meanings,
21 double low,
double high,
int nt,
22 int rank,
int *dimids) {
32 status = nc_def_var(ncid, sname, nt,
rank, dimids, &varid);
34 printf(
"-E- %s %d: %s for %s\n",
35 __FILE__, __LINE__, nc_strerror(
status), sname);
40 double fill_value_dbl;
41 memcpy( &fill_value_dbl, fill_value,
sizeof(
double));
50 if ( low != fill_value_dbl) {
53 status = nc_def_var_fill( ncid, varid, 0, (
void *) &i8);
54 }
else if ( nt == NC_UBYTE) {
56 status = nc_def_var_fill( ncid, varid, 0, (
void *) &ui8);
57 }
else if ( nt == NC_SHORT) {
59 status = nc_def_var_fill( ncid, varid, 0, (
void *) &i16);
60 }
else if ( nt == NC_INT) {
62 status = nc_def_var_fill( ncid, varid, 0, (
void *) &i32);
63 }
else if ( nt == NC_FLOAT) {
65 status = nc_def_var_fill( ncid, varid, 0, (
void *) &
f32);
67 status = nc_def_var_fill( ncid, varid, 0, (
void *) &fill_value_dbl);
75 status = nc_inq_dimlen(ncid, dimids[2], &dimlength);
76 if ( dimlength >= 3200) {
87 status = nc_def_var_chunking(ncid, varid, NC_CHUNKED, chunksize);
89 printf(
"-E- %s %d: %s for %s\n", __FILE__, __LINE__,
90 nc_strerror(
status), sname);
96 status = nc_def_var_deflate(ncid, varid, NC_SHUFFLE, 1, 5);
98 printf(
"-E- %s %d: %s for %s\n", __FILE__, __LINE__,
99 nc_strerror(
status), sname);
106 status = nc_put_att_text(ncid, varid,
"long_name", strlen(lname), lname);
108 printf(
"-E- %s %d: %s for %s\n",
109 __FILE__, __LINE__, nc_strerror(
status),
"long_name");
115 if ( strcmp( flag_values,
"") != 0) {
120 fv.assign( flag_values);
121 size_t pos = fv.find(
"=", curPos);
122 fv = fv.substr(
pos+1);
124 size_t semicln = fv.find(
";");
129 while(
pos != semicln) {
130 pos = fv.find(
",", curPos);
131 if (
pos == string::npos)
135 istringstream iss(fv.substr(curPos,
pos-curPos));
136 iss >> skipws >> flag_value;
137 vec[n++] = atoi( flag_value.c_str());
141 status = nc_put_att_schar(ncid, varid,
"flag_values", NC_BYTE, n, vec);
143 printf(
"-E- %s %d: %s for %s\n",
144 __FILE__, __LINE__, nc_strerror(
status),
"flag_values");
150 if ( strcmp( flag_meanings,
"") != 0) {
151 status = nc_put_att_text(ncid, varid,
"flag_meanings",
152 strlen(flag_meanings), flag_meanings);
154 printf(
"-E- %s %d: %s for %s\n",
155 __FILE__, __LINE__, nc_strerror(
status),
"flag_meanings");
166 vr[0] = (uint8_t)low;
167 vr[1] = (uint8_t)high;
168 status = nc_put_att_uchar(ncid, varid,
"valid_min",NC_BYTE,1,&vr[0]);
170 printf(
"-E- %s %d: %s for %s\n",
171 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
174 status = nc_put_att_uchar(ncid, varid,
"valid_max",NC_BYTE,1,&vr[1]);
176 printf(
"-E- %s %d: %s for %s\n",
177 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
185 vr[0] = (uint8_t)low;
186 vr[1] = (uint8_t)high;
187 status = nc_put_att_uchar(ncid, varid,
"valid_min",NC_UBYTE,1,&vr[0]);
189 printf(
"-E- %s %d: %s for %s\n",
190 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
193 status = nc_put_att_uchar(ncid, varid,
"valid_max",NC_UBYTE,1,&vr[1]);
195 printf(
"-E- %s %d: %s for %s\n",
196 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
204 vr[0] = (int16_t)low;
205 vr[1] = (int16_t)high;
206 status = nc_put_att_short(ncid, varid,
"valid_min",NC_SHORT,1,&vr[0]);
208 printf(
"-E- %s %d: %s for %s\n",
209 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
212 status = nc_put_att_short(ncid, varid,
"valid_max",NC_SHORT,1,&vr[1]);
214 printf(
"-E- %s %d: %s for %s\n",
215 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
223 vr[0] = (uint16_t)low;
224 vr[1] = (uint16_t)high;
225 status = nc_put_att_ushort(ncid, varid,
"valid_min",NC_USHORT,1,&vr[0]);
227 printf(
"-E- %s %d: %s for %s\n",
228 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
231 status = nc_put_att_ushort(ncid, varid,
"valid_max",NC_USHORT,1,&vr[1]);
233 printf(
"-E- %s %d: %s for %s\n",
234 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
242 vr[0] = (int32_t)low;
243 vr[1] = (int32_t)high;
244 status = nc_put_att_int(ncid, varid,
"valid_min",NC_INT,1,&vr[0]);
246 printf(
"-E- %s %d: %s for %s\n",
247 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
250 status = nc_put_att_int(ncid, varid,
"valid_max",NC_INT,1,&vr[1]);
252 printf(
"-E- %s %d: %s for %s\n",
253 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
263 status = nc_put_att_float(ncid, varid,
"valid_min",NC_FLOAT,1,&vr[0]);
265 printf(
"-E- %s %d: %s for %s\n",
266 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
269 status = nc_put_att_float(ncid, varid,
"valid_max",NC_FLOAT,1,&vr[1]);
271 printf(
"-E- %s %d: %s for %s\n",
272 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
282 status = nc_put_att_double(ncid, varid,
"valid_min",NC_DOUBLE,1,&vr[0]);
284 printf(
"-E- %s %d: %s for %s\n",
285 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
288 status = nc_put_att_double(ncid, varid,
"valid_max",NC_DOUBLE,1,&vr[1]);
290 printf(
"-E- %s %d: %s for %s\n",
291 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
297 fprintf(
stderr,
"-E- %s line %d: ",__FILE__,__LINE__);
298 fprintf(
stderr,
"Got unsupported number type (%d) ",nt);
299 fprintf(
stderr,
"while trying to create NCDF variable, \"%s\", ",sname);
300 return(EXIT_FAILURE);
308 printf(
"-E- %s %d: %s for %s\n",
309 __FILE__, __LINE__, nc_strerror(
status),
"units");
316 status = nc_put_att_text(ncid, varid,
"standard_name",
319 printf(
"-E- %s %d: %s for %s\n",
320 __FILE__, __LINE__, nc_strerror(
status),
"standard_name");