SCALE-RM
scale_file_f.c
Go to the documentation of this file.
1 #include "scale_file.h"
2 
3 static void fstr2cstr( char *cstr, // (out)
4  const char *fstr, // (in)
5  const int32_t len)
6 {
7  int i;
8 
9  if ( cstr != fstr )
10  for ( i=0; i<len; i++ )
11  cstr[i] = fstr[i];
12 
13  for ( i=len-1; i>=0; i-- ) {
14  if ( cstr[i] != ' ' ) break;
15  }
16  cstr[i+1] = '\0';
17 }
18 
19 static void cstr2fstr( char *fstr, // (out)
20  const char *cstr, // (in)
21  const int32_t len)
22 {
23  int i;
24 
25  if ( fstr != cstr )
26  for ( i=0; i<len; i++ )
27  fstr[i] = cstr[i];
28 
29  for ( i=0; i<len; i++ )
30  if ( cstr[i] == '\0' ) break;
31 
32  for ( ; i < len; i++ )
33  fstr[i] = ' ';
34 }
35 
36 void file_open_c_( int32_t *fid, // (out)
37  const char *fname, // (in)
38  const int32_t *mode, // (in)
39  const int32_t *comm, // (in)
40  int32_t *error, // (out)
41  const int32_t fname_len) // (in)
42 {
43  char _fname[File_HLONG+1];
44  int32_t len;
45 
46  len = fname_len > File_HLONG ? File_HLONG : fname_len;
47  fstr2cstr(_fname, fname, len);
48 
49  *error = file_open_c( fid, _fname, *mode, MPI_Comm_f2c(*comm) );
50 }
51 
52 void file_get_dim_length_c_( const int32_t *fid, // (in)
53  const char *dimname, // (in)
54  int32_t *len, // (out)
55  int32_t *error, // (out)
56  const int32_t dimname_len ) // (in)
57 {
58  char _dimname[File_HSHORT+1];
59  int32_t clen;
60 
61  clen = dimname_len > File_HSHORT ? File_HSHORT : dimname_len;
62  fstr2cstr(_dimname, dimname, clen);
63 
64  *error = file_get_dim_length_c( *fid, _dimname, len );
65 }
66 
67 void file_set_option_c_( const int32_t *fid, // (in)
68  const char *filetype, // (in)
69  const char *key, // (in)
70  const char *val, // (in)
71  int32_t *error, // (out)
72  const int32_t filetype_len, // (in)
73  const int32_t key_len, // (in)
74  const int32_t val_len) // (in)
75 {
76  char _filetype[File_HSHORT+1];
77  char _key[File_HMID+1];
78  char _val[File_HMID+1];
79  int32_t len;
80 
81  len = filetype_len > File_HSHORT ? File_HSHORT : filetype_len;
82  fstr2cstr(_filetype, filetype, len);
83 
84  len = key_len > File_HMID ? File_HMID : key_len;
85  fstr2cstr(_key, key, len);
86 
87  len = val_len > File_HMID ? File_HMID : val_len;
88  fstr2cstr(_val, val, len);
89 
90  *error = file_set_option_c(*fid, _filetype, _key, _val);
91 }
92 
93 void file_get_nvars_c_( const int32_t *fid, // (in)
94  int32_t *nvars, // (out)
95  int32_t *error ) // (out)
96 {
97  *error = file_get_nvars_c( *fid, nvars );
98 }
99 
100 void file_get_varname_c_( const int32_t *fid, // (in)
101  const int32_t *vid, // (in)
102  char *varname, // (out)
103  int32_t *error, // (out)
104  const int32_t varname_len ) // (in)
105 {
106  char _varname[File_HSHORT+1];
107  int32_t len;
108 
109  *error = file_get_varname_c( *fid, *vid, _varname, varname_len );
110 
111  len = varname_len > File_HSHORT ? File_HSHORT : varname_len;
112  cstr2fstr(varname, _varname, len);
113 }
114 
115 void file_get_datainfo_c_( datainfo_t *dinfo, // (out)
116  const int32_t *fid, // (in)
117  const char *varname, // (in)
118  const int32_t *step, // (in)
119  const int32_t *suppress, // (in)
120  int32_t *error, // (out)
121  const int32_t varname_len) // (in)
122 {
123  char _varname[File_HSHORT+1];
124  int32_t len;
125  int i;
126 
127  len = varname_len > File_HSHORT ? File_HSHORT : varname_len;
128  fstr2cstr(_varname, varname, len);
129 
130  *error = file_get_datainfo_c( dinfo, *fid, _varname, *step, *suppress );
131 
132  if ( *error != SUCCESS_CODE ) return;
133 
134  cstr2fstr(dinfo->varname, dinfo->varname, File_HSHORT);
135  cstr2fstr(dinfo->description, dinfo->description, File_HMID);
136  cstr2fstr(dinfo->units, dinfo->units, File_HSHORT);
137  cstr2fstr(dinfo->standard_name,dinfo->standard_name,File_HMID);
138  cstr2fstr(dinfo->time_units, dinfo->time_units, File_HMID);
139  cstr2fstr(dinfo->calendar, dinfo->calendar, File_HSHORT);
140  for ( i=0; i<dinfo->rank; i++ )
141  cstr2fstr(dinfo->dim_name+i*File_HSHORT, dinfo->dim_name+i*File_HSHORT, File_HSHORT);
142  for ( i=0; i<dinfo->natts; i++ )
143  cstr2fstr(dinfo->att_name+i*File_HSHORT, dinfo->att_name+i*File_HSHORT, File_HSHORT);
144 }
145 
146 void file_get_step_size_c_( const int32_t *fid, // (in)
147  const char *varname, // (in)
148  int32_t *len, // (out)
149  int32_t *error, // (out)
150  const int32_t varname_len ) // (in)
151 {
152  char _varname[File_HSHORT+1];
153  int32_t clen;
154 
155  clen = varname_len > File_HSHORT ? File_HSHORT : varname_len;
156  fstr2cstr(_varname, varname, clen);
157 
158  *error = file_get_step_size_c( *fid, _varname, len );
159 }
160 
161 void file_read_data_c_( void *var, // (out)
162  const datainfo_t *dinfo, // (in)
163  const int32_t *precision, // (in)
164  const int32_t *ntypes, // (in)
165  const int32_t *dtype, // (in)
166  const int32_t *start, // (in)
167  const int32_t *count, // (in)
168  int32_t *error) // (out)
169 {
170  datainfo_t cdinfo;
171  MPI_Offset ntypes_;
172  MPI_Datatype dtype_;
173  int i;
174 
175  cdinfo.datatype = dinfo->datatype;
176  cdinfo.rank = dinfo->rank;
177  for ( i=0; i<dinfo->rank; i++ ) cdinfo.dim_size[i] = dinfo->dim_size[i];
178  cdinfo.step = dinfo->step;
179  cdinfo.time_start = dinfo->time_start;
180  cdinfo.time_end = dinfo->time_end;
181  cdinfo.fid = dinfo->fid;
182  fstr2cstr(cdinfo.varname, dinfo->varname, File_HSHORT-1);
183  fstr2cstr(cdinfo.description, dinfo->description, File_HMID-1);
184  fstr2cstr(cdinfo.units, dinfo->units, File_HSHORT-1);
185  fstr2cstr(cdinfo.standard_name, dinfo->standard_name, File_HMID-1);
186  fstr2cstr(cdinfo.time_units, dinfo->time_units, File_HMID-1);
187  fstr2cstr(cdinfo.calendar, dinfo->calendar, File_HSHORT-1);
188  for ( i=0; i<RANK_MAX; i++ )
189  fstr2cstr(cdinfo.dim_name+i*File_HSHORT, dinfo->dim_name+i*File_HSHORT, File_HSHORT-1);
190  for ( i=0; i<ATT_MAX; i++ )
191  fstr2cstr(cdinfo.att_name+i*File_HSHORT, dinfo->att_name+i*File_HSHORT, File_HSHORT-1);
192 
193  ntypes_ = (MPI_Offset) (*ntypes);
194 
195  dtype_ = dtype==0 ? MPI_DATATYPE_NULL : MPI_Type_f2c(*dtype);
196 
197  if ( *start == -1 )
198  *error = file_read_data_c( var, &cdinfo, *precision, ntypes_, dtype_, NULL, NULL );
199  else
200  *error = file_read_data_c( var, &cdinfo, *precision, ntypes_, dtype_, start, count );
201 }
202 
203 void file_get_attribute_text_c_( const int32_t *fid, // (in)
204  const char *vname, // (in)
205  const char *key, // (in)
206  const int32_t *suppress, // (in)
207  char *value, // (out)
208  int32_t *error, // (out)
209  const int32_t vname_len, // (in)
210  const int32_t key_len, // (in)
211  const int32_t value_len ) // (in)
212 {
213  char _vname[File_HSHORT+1];
214  char _key[File_HMID+1];
215  char _value[File_HLONG+1];
216  int32_t l;
217 
218  l = vname_len > File_HSHORT ? File_HSHORT : vname_len;
219  fstr2cstr(_vname, vname, l);
220 
221  l = key_len > File_HMID ? File_HMID : key_len;
222  fstr2cstr(_key, key, l);
223 
224  *error = file_get_attribute_text_c( *fid, _vname, _key, *suppress, _value, value_len );
225 
226  if ( *error != SUCCESS_CODE ) return;
227 
228  l = value_len > File_HLONG ? File_HLONG : value_len;
229  cstr2fstr(value, _value, l);
230 }
231 
232 void file_get_attribute_int_c_( const int32_t *fid, // (in)
233  const char *vname, // (in)
234  const char *key, // (in)
235  const int32_t *len, // (in)
236  const int32_t *suppress, // (in)
237  int32_t *value, // (out)
238  int32_t *error, // (out)
239  const int32_t vname_len, // (in)
240  const int32_t key_len ) // (in)
241 {
242  char _vname[File_HSHORT+1];
243  char _key[File_HMID+1];
244  int32_t l;
245 
246  l = vname_len > File_HSHORT ? File_HSHORT : vname_len;
247  fstr2cstr(_vname, vname, l);
248 
249  l = key_len > File_HMID ? File_HMID : key_len;
250  fstr2cstr(_key, key, l);
251 
252  *error = file_get_attribute_int_c( *fid, _vname, _key, *suppress, value, (size_t)*len );
253 }
254 
255 void file_get_attribute_float_c_( const int32_t *fid, // (in)
256  const char *vname, // (in)
257  const char *key, // (in)
258  const int32_t *len, // (in)
259  const int32_t *suppress, // (in)
260  float *value, // (out)
261  int32_t *error, // (out)
262  const int32_t vname_len, // (in)
263  const int32_t key_len ) // (in)
264 {
265  char _vname[File_HSHORT+1];
266  char _key[File_HMID+1];
267  int32_t l;
268 
269  l = vname_len > File_HSHORT ? File_HSHORT : vname_len;
270  fstr2cstr(_vname, vname, l);
271 
272  l = key_len > File_HMID ? File_HMID : key_len;
273  fstr2cstr(_key, key, l);
274 
275  *error = file_get_attribute_float_c( *fid, _vname, _key, *suppress, value, (size_t)*len );
276 }
277 
278 void file_get_attribute_double_c_( const int32_t *fid, // (in)
279  const char *vname, // (in)
280  const char *key, // (in)
281  const int32_t *len, // (in)
282  const int32_t *suppress, // (in)
283  double *value, // (out)
284  int32_t *error, // (out)
285  const int32_t vname_len, // (in)
286  const int32_t key_len ) // (in)
287 {
288  char _vname[File_HSHORT+1];
289  char _key[File_HMID+1];
290  int32_t l;
291 
292  l = vname_len > File_HSHORT ? File_HSHORT : vname_len;
293  fstr2cstr(_vname, vname, l);
294 
295  l = key_len > File_HMID ? File_HMID : key_len;
296  fstr2cstr(_key, key, l);
297 
298  *error = file_get_attribute_double_c( *fid, _vname, _key, *suppress, value, (size_t)*len );
299 }
300 
301 void file_set_attribute_text_c_( const int32_t *fid, // (in)
302  const char *vname, // (in)
303  const char *key, // (in)
304  const char *value, // (in)
305  int32_t *error, // (out)
306  const int32_t vname_len, // (in)
307  const int32_t key_len, // (in)
308  const int32_t value_len ) // (in)
309 {
310  char _vname[File_HSHORT+1];
311  char _key[File_HMID+1];
312  char _value[File_HLONG+1];
313  int32_t l;
314 
315  l = vname_len > File_HSHORT ? File_HSHORT : vname_len;
316  fstr2cstr(_vname, vname, l);
317 
318  l = key_len > File_HMID ? File_HMID : key_len;
319  fstr2cstr(_key, key, l);
320 
321  l = value_len > File_HLONG ? File_HLONG : value_len;
322  fstr2cstr(_value, value, l);
323 
324  *error = file_set_attribute_text_c( *fid, _vname, _key, _value );
325 }
326 
327 void file_set_attribute_int_c_( const int32_t *fid, // (in)
328  const char *vname, // (in)
329  const char *key, // (in)
330  const int32_t *value, // (in)
331  const int32_t *len, // (in)
332  int32_t *error, // (out)
333  const int32_t vname_len, // (in)
334  const int32_t key_len ) // (in)
335 {
336  char _vname[File_HSHORT+1];
337  char _key[File_HMID+1];
338  int32_t l;
339 
340  l = vname_len > File_HSHORT ? File_HSHORT : vname_len;
341  fstr2cstr(_vname, vname, l);
342 
343  l = key_len > File_HMID ? File_HMID : key_len;
344  fstr2cstr(_key, key, l);
345 
346  *error = file_set_attribute_int_c( *fid, _vname, _key, value, (size_t)*len );
347 }
348 
349 void file_set_attribute_float_c_( const int32_t *fid, // (in)
350  const char *vname, // (in)
351  const char *key, // (in)
352  const float *value, // (in)
353  const int32_t *len, // (in)
354  int32_t *error, // (out)
355  const int32_t vname_len, // (in)
356  const int32_t key_len ) // (in)
357 {
358  char _vname[File_HSHORT+1];
359  char _key[File_HMID+1];
360  int32_t l;
361 
362  l = vname_len > File_HSHORT ? File_HSHORT : vname_len;
363  fstr2cstr(_vname, vname, l);
364 
365  l = key_len > File_HMID ? File_HMID : key_len;
366  fstr2cstr(_key, key, l);
367 
368  *error = file_set_attribute_float_c( *fid, _vname, _key, value, (size_t)*len );
369 }
370 
371 void file_set_attribute_double_c_( const int32_t *fid, // (in)
372  const char *vname, // (in)
373  const char *key, // (in)
374  const double *value, // (in)
375  const int32_t *len, // (in)
376  int32_t *error, // (out)
377  const int32_t vname_len, // (in)
378  const int32_t key_len ) // (in)
379 {
380  char _vname[File_HSHORT+1];
381  char _key[File_HMID+1];
382  int32_t l;
383 
384  l = vname_len > File_HSHORT ? File_HSHORT : vname_len;
385  fstr2cstr(_vname, vname, l);
386 
387  l = key_len > File_HMID ? File_HMID : key_len;
388  fstr2cstr(_key, key, l);
389 
390  *error = file_set_attribute_double_c( *fid, _vname, _key, value, (size_t)*len );
391 }
392 
393 void file_add_associatedvariable_c_( const int32_t *fid, // (in)
394  const char *vname, // (in)
395  int32_t *error, // (out)
396  const int32_t vname_len ) // (in)
397 {
398  char _vname[File_HSHORT+1];
399  int32_t l;
400 
401  l = vname_len > File_HSHORT ? File_HSHORT : vname_len;
402  fstr2cstr(_vname, vname, l);
403 
404  *error = file_add_associatedvariable_c( *fid, _vname );
405 }
406 
407 void file_set_tunits_c_( const int32_t *fid, // (in)
408  const char *time_units, // (in)
409  const char *calendar, // (in)
410  int32_t *error, // (out)
411  const int32_t unit_len, // (in)
412  const int32_t cal_len) // (in)
413 {
414  char _time_units[File_HMID+1];
415  char _calendar[File_HSHORT+1];
416  int32_t l;
417 
418  l = unit_len > File_HMID ? File_HMID : unit_len;
419  fstr2cstr(_time_units, time_units, l);
420 
421  l = cal_len > File_HSHORT ? File_HSHORT : cal_len;
422  fstr2cstr(_calendar, calendar, l);
423 
424  *error = file_set_tunits_c( *fid, _time_units, _calendar );
425 }
426 
427 void file_put_axis_c_( const int32_t *fid, // (in)
428  const char *name, // (in)
429  const char *desc, // (in)
430  const char *units, // (in)
431  const char *dim_name, // (in)
432  const int32_t *dtype, // (in)
433  const void *val, // (in)
434  const int32_t *size, // (in)
435  const int32_t *precision, // (in)
436  int32_t *error, // (out)
437  const int32_t name_len, // (in)
438  const int32_t desc_len, // (in)
439  const int32_t units_len, // (in)
440  const int32_t dim_name_len) // (in)
441 {
442  char _name[File_HSHORT+1];
443  char _desc[File_HMID+1];
444  char _units[File_HMID+1];
445  char _dim_name[File_HSHORT+1];
446  int len;
447 
448  len = name_len > File_HSHORT ? File_HSHORT : name_len;
449  fstr2cstr(_name, name, len);
450 
451  len = desc_len > File_HMID ? File_HMID : desc_len;
452  fstr2cstr(_desc, desc, len);
453 
454  len = units_len > File_HMID ? File_HMID : units_len;
455  fstr2cstr(_units, units, len);
456 
457  len = dim_name_len > File_HSHORT ? File_HSHORT : dim_name_len;
458  fstr2cstr(_dim_name, dim_name, len);
459 
460  *error = file_put_axis_c( *fid, _name, _desc, _units, _dim_name, *dtype, val, *size, *precision );
461 }
462 
463 void file_def_axis_c_( const int32_t *fid, // (in)
464  const char *name, // (in)
465  const char *desc, // (in)
466  const char *units, // (in)
467  const char *dim_name, // (in)
468  const int32_t *dtype, // (in)
469  const int32_t *dim_size, // (in)
470  const int32_t *bounds, // (in)
471  int32_t *error, // (out)
472  const int32_t name_len, // (in)
473  const int32_t desc_len, // (in)
474  const int32_t units_len, // (in)
475  const int32_t dim_name_len) // (in)
476 {
477  char _name[File_HSHORT+1];
478  char _desc[File_HMID+1];
479  char _units[File_HMID+1];
480  char _dim_name[File_HSHORT+1];
481  int len;
482 
483  len = name_len > File_HSHORT ? File_HSHORT : name_len;
484  fstr2cstr(_name, name, len);
485 
486  len = desc_len > File_HMID ? File_HMID : desc_len;
487  fstr2cstr(_desc, desc, len);
488 
489  len = units_len > File_HMID ? File_HMID : units_len;
490  fstr2cstr(_units, units, len);
491 
492  len = dim_name_len > File_HSHORT ? File_HSHORT : dim_name_len;
493  fstr2cstr(_dim_name, dim_name, len);
494 
495  *error = file_def_axis_c( *fid, _name, _desc, _units, _dim_name, *dtype, *dim_size, *bounds );
496 }
497 
498 void file_write_axis_c_( const int32_t *fid, // (in)
499  const char *name, // (in)
500  const void *val, // (in)
501  const int32_t *precision, // (in)
502  const int32_t *start, // (in)
503  const int32_t *count, // (in)
504  int32_t *error, // (out)
505  const int32_t name_len) // (in)
506 {
507  char _name[File_HSHORT+1];
508  int len;
509  MPI_Offset start_[1], count_[1];
510 
511  len = name_len > File_HSHORT ? File_HSHORT : name_len;
512  fstr2cstr(_name, name, len);
513 
514  /* all axes are 1D */
515  start_[0] = *start - 1; /* C index is 0-based */
516  count_[0] = *count;
517 
518  *error = file_write_axis_c( *fid, _name, val, *precision, start_, count_ );
519 }
520 
521 void file_put_associatedcoordinate_c_( const int32_t *fid, // (in)
522  const char *name, // (in)
523  const char *desc, // (in)
524  const char *units, // (in)
525  const char *dim_names, // (in)
526  const int32_t *ndims, // (in)
527  const int32_t *dtype, // (in)
528  const void *val, // (in)
529  const int32_t *precision, // (in)
530  int32_t *error, // (out)
531  const int32_t name_len, // (in)
532  const int32_t desc_len, // (in)
533  const int32_t units_len, // (in)
534  const int32_t dim_name_len) // (in)
535 {
536  char _name[File_HSHORT+1];
537  char _desc[File_HMID+1];
538  char _units[File_HMID+1];
539  char **_dim_names;
540  int len;
541  int i;
542 
543  len = name_len > File_HSHORT ? File_HSHORT : name_len;
544  fstr2cstr(_name, name, len);
545 
546  len = desc_len > File_HMID ? File_HMID : desc_len;
547  fstr2cstr(_desc, desc, len);
548 
549  len = units_len > File_HMID ? File_HMID : units_len;
550  fstr2cstr(_units, units, len);
551 
552  _dim_names = (char**) malloc(sizeof(char*)*(*ndims));
553  len = dim_name_len > File_HSHORT ? File_HSHORT : dim_name_len;
554  for ( i=0; i<*ndims; i++ ) {
555  _dim_names[i] = (char*) malloc(sizeof(char)*(File_HSHORT+1));
556  fstr2cstr(_dim_names[i], dim_names+i*dim_name_len, len);
557  }
558 
559  *error = file_put_associatedcoordinate_c( *fid, _name, _desc, _units, (const char**)_dim_names, *ndims, *dtype, val, *precision );
560 
561  for ( i=0; i<*ndims; i++ ) free(_dim_names[i]);
562  free(_dim_names);
563 }
564 
565 void file_def_associatedcoordinate_c_( const int32_t *fid, // (in)
566  const char *name, // (in)
567  const char *desc, // (in)
568  const char *units, // (in)
569  const char *dim_names, // (in)
570  const int32_t *ndims, // (in)
571  const int32_t *dtype, // (in)
572  int32_t *error, // (out)
573  const int32_t name_len, // (in)
574  const int32_t desc_len, // (in)
575  const int32_t units_len, // (in)
576  const int32_t dim_name_len) // (in)
577 {
578  char _name[File_HSHORT+1];
579  char _desc[File_HMID+1];
580  char _units[File_HMID+1];
581  char **_dim_names;
582  int len;
583  int i;
584 
585  len = name_len > File_HSHORT ? File_HSHORT : name_len;
586  fstr2cstr(_name, name, len);
587 
588  len = desc_len > File_HMID ? File_HMID : desc_len;
589  fstr2cstr(_desc, desc, len);
590 
591  len = units_len > File_HMID ? File_HMID : units_len;
592  fstr2cstr(_units, units, len);
593 
594  _dim_names = (char**) malloc(sizeof(char*)*(*ndims));
595  len = dim_name_len > File_HSHORT ? File_HSHORT : dim_name_len;
596  for ( i=0; i<*ndims; i++ ) {
597  _dim_names[i] = (char*) malloc(sizeof(char)*(File_HSHORT+1));
598  fstr2cstr(_dim_names[i], dim_names+i*dim_name_len, len);
599  }
600 
601  *error = file_def_associatedcoordinate_c( *fid, _name, _desc, _units, (const char**)_dim_names, *ndims, *dtype );
602 
603  for ( i=0; i<*ndims; i++ ) free(_dim_names[i]);
604  free(_dim_names);
605 }
606 
607 void file_write_associatedcoordinate_c_( const int32_t *fid, // (in)
608  const char *name, // (in)
609  const void *val, // (in)
610  const int32_t *precision, // (in)
611  const int32_t *ndims, // (in)
612  const int32_t *start, // (in)
613  const int32_t *count, // (in)
614  int32_t *error, // (out)
615  const int32_t name_len) // (in)
616 {
617  char _name[File_HSHORT+1];
618  int i, len;
619  MPI_Offset start_[4], count_[4];
620  /* all associated coordinate are up to 4D */
621 
622  len = name_len > File_HSHORT ? File_HSHORT : name_len;
623  fstr2cstr(_name, name, len);
624 
625  for (i=0; i<*ndims; i++) {
626  start_[i] = start[*ndims - i - 1] - 1;
627  count_[i] = count[*ndims - i - 1];
628  }
629  *error = file_write_associatedcoordinate_c( *fid, _name, val, *precision, start_, count_ );
630 }
631 
632 void file_add_variable_c_( const int32_t *fid, // (in)
633  const char *varname, // (in)
634  const char *desc, // (in)
635  const char *units, // (in)
636  const char *standard_name, // (in)
637  const char *dims, // (in)
638  const int32_t *ndims, // (in)
639  const int32_t *dtype, // (in)
640  const real64_t *tint, // (in)
641  const int32_t *tavg, // (in)
642  int32_t *vid, // (out)
643  int32_t *error, // (out)
644  const int32_t varname_len, // (in)
645  const int32_t desc_len, // (in)
646  const int32_t units_len, // (in)
647  const int32_t stdname_len, // (in)
648  const int32_t dims_len) // (in)
649 {
650  char _varname[File_HSHORT+1];
651  char _desc[File_HMID+1];
652  char _stdname[File_HMID+1];
653  char _units[File_HMID+1];
654  char **_dims;
655  int len;
656  int i;
657 
658  len = varname_len > File_HSHORT ? File_HSHORT : varname_len;
659  fstr2cstr(_varname, varname, len);
660 
661  len = desc_len > File_HMID ? File_HMID : desc_len;
662  fstr2cstr(_desc, desc, len);
663 
664  len = stdname_len > File_HMID ? File_HMID : stdname_len;
665  fstr2cstr(_stdname, standard_name, len);
666 
667  len = units_len > File_HMID ? File_HMID : units_len;
668  fstr2cstr(_units, units, len);
669 
670  _dims = (char**) malloc(sizeof(char*)*(*ndims));
671  len = dims_len > File_HSHORT ? File_HSHORT : dims_len;
672  for ( i=0; i<*ndims; i++ ) {
673  _dims[i] = (char*) malloc(sizeof(char)*(File_HSHORT+1));
674  fstr2cstr(_dims[i], dims+i*dims_len, len);
675  }
676 
677  *error = file_add_variable_c( *fid, _varname, _desc, _units, _stdname, (const char**)_dims, *ndims, *dtype, *tint, *tavg, vid );
678 
679  for ( i=0; i<*ndims; i++ ) free( _dims[i] );
680  free( _dims );
681 }
682 
683 void file_write_data_c_( const int32_t *fid, // (in)
684  const int32_t *vid, // (in)
685  const void *var, // (in)
686  const real64_t *t_start, // (in)
687  const real64_t *t_end, // (in)
688  const int32_t *precision, // (in)
689  const int32_t *ndims, // (in)
690  const int32_t *start, // (in)
691  const int32_t *count, // (in)
692  int32_t *error) // (out)
693 {
694  *error = file_write_data_c( *fid, *vid, var, *t_start, *t_end, *precision, *ndims, start, count );
695 }
696 
697 void file_close_c_( const int32_t *fid , // (in)
698  const int32_t *abort, // (in)
699  int32_t *error ) // (out)
700 {
701  *error = file_close_c( *fid, *abort );
702 }
703 
704 void file_enddef_c_( const int32_t *fid , // (in)
705  int32_t *error ) // (out)
706 {
707  *error = file_enddef_c( *fid );
708 }
709 
710 void file_redef_c_( const int32_t *fid , // (in)
711  int32_t *error ) // (out)
712 {
713  *error = file_redef_c( *fid );
714 }
715 
716 void file_attach_buffer_c_( const int32_t *fid , // (in)
717  const int64_t *buf_amount, // (in)
718  int32_t *error ) // (out)
719 {
720  *error = file_attach_buffer_c( *fid, *buf_amount );
721 }
722 
723 void file_detach_buffer_c_( const int32_t *fid , // (in)
724  int32_t *error ) // (out)
725 {
726  *error = file_detach_buffer_c( *fid );
727 }
728 
729 void file_flush_c_( const int32_t *fid , // (in)
730  int32_t *error ) // (out)
731 {
732  *error = file_flush_c( *fid );
733 }
file_put_associatedcoordinate_c
int32_t file_put_associatedcoordinate_c(const int32_t fid, const char *name, const char *desc, const char *units, const char **dim_names, const int32_t ndims, const int32_t dtype, const void *val, const int32_t precision)
Definition: scale_file_netcdf.c:1381
datainfo_t
Definition: scale_file.h:19
file_get_nvars_c
int32_t file_get_nvars_c(const int32_t fid, int32_t *nvars)
Definition: scale_file_netcdf.c:296
file_get_attribute_int_c_
void file_get_attribute_int_c_(const int32_t *fid, const char *vname, const char *key, const int32_t *len, const int32_t *suppress, int32_t *value, int32_t *error, const int32_t vname_len, const int32_t key_len)
Definition: scale_file_f.c:232
file_set_attribute_text_c
int32_t file_set_attribute_text_c(const int32_t fid, const char *vname, const char *key, const char *value)
Definition: scale_file_netcdf.c:1028
file_flush_c_
void file_flush_c_(const int32_t *fid, int32_t *error)
Definition: scale_file_f.c:729
file_set_option_c_
void file_set_option_c_(const int32_t *fid, const char *filetype, const char *key, const char *val, int32_t *error, const int32_t filetype_len, const int32_t key_len, const int32_t val_len)
Definition: scale_file_f.c:67
datainfo_t::time_end
real64_t time_end
Definition: scale_file.h:30
file_write_axis_c
int32_t file_write_axis_c(const int32_t fid, const char *name, const void *val, const int32_t precision, const MPI_Offset *start, const MPI_Offset *count)
Definition: scale_file_netcdf.c:1339
file_set_option_c
int32_t file_set_option_c(const int32_t fid, const char *filetype, const char *key, const char *val)
Definition: scale_file_netcdf.c:280
file_flush_c
int32_t file_flush_c(const int32_t fid)
Definition: scale_file_netcdf.c:1843
file_get_attribute_text_c_
void file_get_attribute_text_c_(const int32_t *fid, const char *vname, const char *key, const int32_t *suppress, char *value, int32_t *error, const int32_t vname_len, const int32_t key_len, const int32_t value_len)
Definition: scale_file_f.c:203
file_set_attribute_text_c_
void file_set_attribute_text_c_(const int32_t *fid, const char *vname, const char *key, const char *value, int32_t *error, const int32_t vname_len, const int32_t key_len, const int32_t value_len)
Definition: scale_file_f.c:301
file_get_dim_length_c_
void file_get_dim_length_c_(const int32_t *fid, const char *dimname, int32_t *len, int32_t *error, const int32_t dimname_len)
Definition: scale_file_f.c:52
file_redef_c_
void file_redef_c_(const int32_t *fid, int32_t *error)
Definition: scale_file_f.c:710
file_detach_buffer_c_
void file_detach_buffer_c_(const int32_t *fid, int32_t *error)
Definition: scale_file_f.c:723
file_get_dim_length_c
int32_t file_get_dim_length_c(const int32_t fid, const char *dimname, int32_t *len)
Definition: scale_file_netcdf.c:256
file_add_variable_c_
void file_add_variable_c_(const int32_t *fid, const char *varname, const char *desc, const char *units, const char *standard_name, const char *dims, const int32_t *ndims, const int32_t *dtype, const real64_t *tint, const int32_t *tavg, int32_t *vid, int32_t *error, const int32_t varname_len, const int32_t desc_len, const int32_t units_len, const int32_t stdname_len, const int32_t dims_len)
Definition: scale_file_f.c:632
file_add_associatedvariable_c
int32_t file_add_associatedvariable_c(const int32_t fid, const char *vname)
Definition: scale_file_netcdf.c:1192
file_def_axis_c
int32_t file_def_axis_c(const int32_t fid, const char *name, const char *desc, const char *units, const char *dim_name, const int32_t dtype, const int32_t dim_size, const int32_t bounds)
Definition: scale_file_netcdf.c:1274
SUCCESS_CODE
#define SUCCESS_CODE
Definition: scale_file_const.h:21
file_add_variable_c
int32_t file_add_variable_c(const int32_t fid, const char *varname, const char *desc, const char *units, const char *stdname, const char **dims, const int32_t ndims, const int32_t dtype, const real64_t tint, const int32_t tavg, int32_t *vid)
Definition: scale_file_netcdf.c:1526
file_close_c
int32_t file_close_c(const int32_t fid, const int32_t abort)
Definition: scale_file_netcdf.c:1982
file_attach_buffer_c
int32_t file_attach_buffer_c(const int32_t fid, const int64_t buf_amount)
Definition: scale_file_netcdf.c:1816
file_open_c_
void file_open_c_(int32_t *fid, const char *fname, const int32_t *mode, const int32_t *comm, int32_t *error, const int32_t fname_len)
Definition: scale_file_f.c:36
datainfo_t::calendar
char calendar[File_HSHORT]
Definition: scale_file.h:32
file_put_axis_c_
void file_put_axis_c_(const int32_t *fid, const char *name, const char *desc, const char *units, const char *dim_name, const int32_t *dtype, const void *val, const int32_t *size, const int32_t *precision, int32_t *error, const int32_t name_len, const int32_t desc_len, const int32_t units_len, const int32_t dim_name_len)
Definition: scale_file_f.c:427
datainfo_t::dim_size
int32_t dim_size[RANK_MAX]
Definition: scale_file.h:27
file_set_tunits_c_
void file_set_tunits_c_(const int32_t *fid, const char *time_units, const char *calendar, int32_t *error, const int32_t unit_len, const int32_t cal_len)
Definition: scale_file_f.c:407
RANK_MAX
#define RANK_MAX
Definition: scale_file_const.h:30
datainfo_t::att_name
char att_name[File_HSHORT *ATT_MAX]
Definition: scale_file.h:34
datainfo_t::fid
int32_t fid
Definition: scale_file.h:37
datainfo_t::units
char units[File_HSHORT]
Definition: scale_file.h:22
file_get_step_size_c
int32_t file_get_step_size_c(const int32_t fid, const char *varname, int32_t *len)
Definition: scale_file_netcdf.c:633
file_set_attribute_double_c
int32_t file_set_attribute_double_c(const int32_t fid, const char *vname, const char *key, const double *value, const size_t len)
Definition: scale_file_netcdf.c:1154
File_HLONG
#define File_HLONG
Definition: scale_file_const.h:4
scale_file::i
logical, public i
Definition: scale_file.F90:182
datainfo_t::standard_name
char standard_name[File_HMID]
Definition: scale_file.h:23
file_set_attribute_float_c_
void file_set_attribute_float_c_(const int32_t *fid, const char *vname, const char *key, const float *value, const int32_t *len, int32_t *error, const int32_t vname_len, const int32_t key_len)
Definition: scale_file_f.c:349
datainfo_t::datatype
int32_t datatype
Definition: scale_file.h:24
datainfo_t::description
char description[File_HMID]
Definition: scale_file.h:21
datainfo_t::time_units
char time_units[File_HMID]
Definition: scale_file.h:31
file_put_associatedcoordinate_c_
void file_put_associatedcoordinate_c_(const int32_t *fid, const char *name, const char *desc, const char *units, const char *dim_names, const int32_t *ndims, const int32_t *dtype, const void *val, const int32_t *precision, int32_t *error, const int32_t name_len, const int32_t desc_len, const int32_t units_len, const int32_t dim_name_len)
Definition: scale_file_f.c:521
scale_file.h
file_redef_c
int32_t file_redef_c(const int32_t fid)
Definition: scale_file_netcdf.c:1805
file_set_attribute_int_c_
void file_set_attribute_int_c_(const int32_t *fid, const char *vname, const char *key, const int32_t *value, const int32_t *len, int32_t *error, const int32_t vname_len, const int32_t key_len)
Definition: scale_file_f.c:327
file_get_varname_c
int32_t file_get_varname_c(const int32_t fid, const int32_t vid, char *name, const int32_t len)
Definition: scale_file_netcdf.c:313
file_def_axis_c_
void file_def_axis_c_(const int32_t *fid, const char *name, const char *desc, const char *units, const char *dim_name, const int32_t *dtype, const int32_t *dim_size, const int32_t *bounds, int32_t *error, const int32_t name_len, const int32_t desc_len, const int32_t units_len, const int32_t dim_name_len)
Definition: scale_file_f.c:463
File_HSHORT
#define File_HSHORT
Definition: scale_file_const.h:2
datainfo_t::rank
int32_t rank
Definition: scale_file.h:25
file_write_associatedcoordinate_c
int32_t file_write_associatedcoordinate_c(const int32_t fid, const char *name, const void *val, const int32_t precision, const MPI_Offset *start, const MPI_Offset *count)
Definition: scale_file_netcdf.c:1484
file_set_attribute_int_c
int32_t file_set_attribute_int_c(const int32_t fid, const char *vname, const char *key, const int32_t *value, const size_t len)
Definition: scale_file_netcdf.c:1069
file_open_c
int32_t file_open_c(int32_t *fid, const char *fname, const int32_t mode, const MPI_Comm comm)
Definition: scale_file_netcdf.c:170
file_set_attribute_float_c
int32_t file_set_attribute_float_c(const int32_t fid, const char *vname, const char *key, const float *value, const size_t len)
Definition: scale_file_netcdf.c:1112
file_get_attribute_int_c
int32_t file_get_attribute_int_c(const int32_t fid, const char *vname, const char *key, const int32_t suppress, int32_t *value, const size_t len)
file_close_c_
void file_close_c_(const int32_t *fid, const int32_t *abort, int32_t *error)
Definition: scale_file_f.c:697
file_set_attribute_double_c_
void file_set_attribute_double_c_(const int32_t *fid, const char *vname, const char *key, const double *value, const int32_t *len, int32_t *error, const int32_t vname_len, const int32_t key_len)
Definition: scale_file_f.c:371
file_get_varname_c_
void file_get_varname_c_(const int32_t *fid, const int32_t *vid, char *varname, int32_t *error, const int32_t varname_len)
Definition: scale_file_f.c:100
file_get_step_size_c_
void file_get_step_size_c_(const int32_t *fid, const char *varname, int32_t *len, int32_t *error, const int32_t varname_len)
Definition: scale_file_f.c:146
file_get_attribute_double_c
int32_t file_get_attribute_double_c(const int32_t fid, const char *vname, const char *key, const int32_t suppress, double *value, const size_t len)
Definition: scale_file_netcdf.c:985
file_read_data_c_
void file_read_data_c_(void *var, const datainfo_t *dinfo, const int32_t *precision, const int32_t *ntypes, const int32_t *dtype, const int32_t *start, const int32_t *count, int32_t *error)
Definition: scale_file_f.c:161
file_write_data_c_
void file_write_data_c_(const int32_t *fid, const int32_t *vid, const void *var, const real64_t *t_start, const real64_t *t_end, const int32_t *precision, const int32_t *ndims, const int32_t *start, const int32_t *count, int32_t *error)
Definition: scale_file_f.c:683
file_write_associatedcoordinate_c_
void file_write_associatedcoordinate_c_(const int32_t *fid, const char *name, const void *val, const int32_t *precision, const int32_t *ndims, const int32_t *start, const int32_t *count, int32_t *error, const int32_t name_len)
Definition: scale_file_f.c:607
datainfo_t::natts
int32_t natts
Definition: scale_file.h:33
file_get_datainfo_c
int32_t file_get_datainfo_c(datainfo_t *dinfo, const int32_t fid, const char *varname, const int32_t step, const int32_t suppress)
Definition: scale_file_netcdf.c:338
file_read_data_c
int32_t file_read_data_c(void *var, const datainfo_t *dinfo, const int32_t precision, const MPI_Offset ntypes, const MPI_Datatype dtype, const int32_t *start, const int32_t *count)
Definition: scale_file_netcdf.c:687
File_HMID
#define File_HMID
Definition: scale_file_const.h:3
datainfo_t::dim_name
char dim_name[File_HSHORT *RANK_MAX]
Definition: scale_file.h:26
file_get_attribute_double_c_
void file_get_attribute_double_c_(const int32_t *fid, const char *vname, const char *key, const int32_t *len, const int32_t *suppress, double *value, int32_t *error, const int32_t vname_len, const int32_t key_len)
Definition: scale_file_f.c:278
datainfo_t::time_start
real64_t time_start
Definition: scale_file.h:29
file_attach_buffer_c_
void file_attach_buffer_c_(const int32_t *fid, const int64_t *buf_amount, int32_t *error)
Definition: scale_file_f.c:716
file_get_attribute_float_c_
void file_get_attribute_float_c_(const int32_t *fid, const char *vname, const char *key, const int32_t *len, const int32_t *suppress, float *value, int32_t *error, const int32_t vname_len, const int32_t key_len)
Definition: scale_file_f.c:255
file_get_datainfo_c_
void file_get_datainfo_c_(datainfo_t *dinfo, const int32_t *fid, const char *varname, const int32_t *step, const int32_t *suppress, int32_t *error, const int32_t varname_len)
Definition: scale_file_f.c:115
ATT_MAX
#define ATT_MAX
Definition: scale_file_const.h:32
file_put_axis_c
int32_t file_put_axis_c(const int32_t fid, const char *name, const char *desc, const char *units, const char *dim_name, const int32_t dtype, const void *val, const int32_t size, const int32_t precision)
Definition: scale_file_netcdf.c:1225
datainfo_t::step
int32_t step
Definition: scale_file.h:28
datainfo_t::varname
char varname[File_HSHORT]
Definition: scale_file.h:20
file_def_associatedcoordinate_c_
void file_def_associatedcoordinate_c_(const int32_t *fid, const char *name, const char *desc, const char *units, const char *dim_names, const int32_t *ndims, const int32_t *dtype, int32_t *error, const int32_t name_len, const int32_t desc_len, const int32_t units_len, const int32_t dim_name_len)
Definition: scale_file_f.c:565
file_get_attribute_text_c
int32_t file_get_attribute_text_c(const int32_t fid, const char *vname, const char *key, const int32_t suppress, char *value, const int32_t len)
Definition: scale_file_netcdf.c:852
file_get_attribute_float_c
int32_t file_get_attribute_float_c(const int32_t fid, const char *vname, const char *key, const int32_t suppress, float *value, const size_t len)
Definition: scale_file_netcdf.c:942
file_enddef_c_
void file_enddef_c_(const int32_t *fid, int32_t *error)
Definition: scale_file_f.c:704
file_set_tunits_c
int32_t file_set_tunits_c(const int32_t fid, const char *time_units, const char *calendar)
Definition: scale_file_netcdf.c:1215
file_write_axis_c_
void file_write_axis_c_(const int32_t *fid, const char *name, const void *val, const int32_t *precision, const int32_t *start, const int32_t *count, int32_t *error, const int32_t name_len)
Definition: scale_file_f.c:498
file_def_associatedcoordinate_c
int32_t file_def_associatedcoordinate_c(const int32_t fid, const char *name, const char *desc, const char *units, const char **dim_names, const int32_t ndims, const int32_t dtype)
Definition: scale_file_netcdf.c:1434
scale_tracer::name
character(len=h_short), public name
Definition: scale_tracer.F90:38
file_get_nvars_c_
void file_get_nvars_c_(const int32_t *fid, int32_t *nvars, int32_t *error)
Definition: scale_file_f.c:93
file_add_associatedvariable_c_
void file_add_associatedvariable_c_(const int32_t *fid, const char *vname, int32_t *error, const int32_t vname_len)
Definition: scale_file_f.c:393
file_detach_buffer_c
int32_t file_detach_buffer_c(const int32_t fid)
Definition: scale_file_netcdf.c:1830
file_write_data_c
int32_t file_write_data_c(const int32_t fid, const int32_t vid, const void *var, const real64_t t_start, const real64_t t_end, const int32_t precision, const int32_t ndims, const int32_t *start, const int32_t *count)
Definition: scale_file_netcdf.c:1858
file_enddef_c
int32_t file_enddef_c(const int32_t fid)
Definition: scale_file_netcdf.c:1794