SCALE-RM
gtool_file.h
Go to the documentation of this file.
1 #ifndef __FILE_SCALE_H__
2 #define __FILE_SCALE_H__
3 
4 #include <stdio.h>
5 #include <stdint.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <math.h>
9 
10 /* character length */
11 #define File_HSHORT 16
12 #define File_HMID 64
13 #define File_HLONG 256
14 
15 /* data type */
16 #define File_REAL4 0
17 #define File_REAL8 1
18 #define File_INTEGER2 2
19 #define File_INTEGER4 3
20 #define File_INTEGER8 4
21 
22 /* action type */
23 #define File_FREAD 0
24 #define File_FWRITE 1
25 #define File_FAPPEND 2
26 
27 /* return type */
28 #define ERROR_CODE -1
29 #define SUCCESS_CODE 0
30 #define ALREADY_CLOSED_CODE 1
31 #define ALREADY_EXISTED_CODE 2
32 
33 /* limit of dimension */
34 #define MAX_RANK 10
35 
36 
37 typedef float (real32_t);
38 typedef double(real64_t);
39 
40 /* data item information */
41 typedef struct{
42  char varname[File_HSHORT];
43  char description[File_HMID];
44  char units[File_HSHORT];
45  int32_t datatype;
46  int32_t rank;
47  char dim_name[File_HSHORT*MAX_RANK];
48  int32_t dim_size[MAX_RANK];
49  int32_t step;
50  real64_t time_start;
51  real64_t time_end;
52  char time_units[File_HMID];
53  int32_t fid;
54 } datainfo_t;
55 
56 
57 extern int32_t file_open( int32_t *fid, // (out)
58  char *fname, // (in)
59  int32_t mode); // (in)
60 
61 extern int32_t file_set_option( int32_t fid, // (in)
62  char *filetype, // (in)
63  char *key, // (in)
64  char *val); // (in)
65 
66 extern int32_t file_get_datainfo( datainfo_t *dinfo, // (out)
67  int32_t fid, // (in)
68  char *varname, // (in)
69  int32_t step, // (in)
70  int32_t suppress);// (in)
71 
72 extern int32_t file_read_data( void *var, // (out)
73  datainfo_t *dinfo, // (in)
74  int32_t precision); // (in)
75 
76 extern int32_t file_get_global_attribute_text( int32_t fid, // (in)
77  char *key, // (in)
78  char *value, // (out)
79  int32_t len); // (in)
80 
81 extern int32_t file_get_global_attribute_int( int32_t fid, // (in)
82  char *key, // (in)
83  int32_t *value, // (out)
84  size_t len); // (in)
85 
86 extern int32_t file_get_global_attribute_float( int32_t fid, // (in)
87  char *key, // (in)
88  float *value, // (out)
89  size_t len); // (in)
90 
91 extern int32_t file_get_global_attribute_double( int32_t fid, // (in)
92  char *key, // (in)
93  double *value, // (out)
94  size_t len); // (in)
95 
96 extern int32_t file_set_global_attribute_text( int32_t fid, // (in)
97  char *key, // (in)
98  char *value); // (in)
99 
100 extern int32_t file_set_global_attribute_int( int32_t fid, // (in)
101  char *key, // (in)
102  int32_t *value, // (in)
103  size_t len); // (in)
104 
105 extern int32_t file_set_global_attribute_float( int32_t fid, // (in)
106  char *key, // (in)
107  float *value, // (in)
108  size_t len); // (in)
109 
110 extern int32_t file_set_global_attribute_double( int32_t fid, // (in)
111  char *key, // (in)
112  double *value, // (in)
113  size_t len); // (in)
114 
115 extern int32_t file_set_tunits( int32_t fid, // (in)
116  char *time_units); // (in)
117 
118 extern int32_t file_set_tattr( int32_t fid, // (in)
119  char *vname, // (in)
120  char *key, // (in)
121  char *val); // (in)
122 
123 extern int32_t file_put_axis( int32_t fid, // (in)
124  char *name, // (in)
125  char *desc, // (in)
126  char *units, // (in)
127  char *dim_name, // (in)
128  int32_t dtype, // (in)
129  void *val, // (in)
130  int32_t size, // (in)
131  int32_t precision); // (in)
132 
133 extern int32_t file_def_axis( int32_t fid, // (in)
134  char *name, // (in)
135  char *desc, // (in)
136  char *units, // (in)
137  char *dim_name, // (in)
138  int32_t dtype, // (in)
139  int32_t dim_size); // (in)
140 
141 extern int32_t file_write_axis( int32_t fid, // (in)
142  char *name, // (in)
143  void *val, // (in)
144  int32_t precision); // (in)
145 
146 extern int32_t file_put_associated_coordinates( int32_t fid, // (in)
147  char *name, // (in)
148  char *desc, // (in)
149  char *units, // (in)
150  char **dim_names, // (in)
151  int32_t ndims, // (in)
152  int32_t dtype, // (in)
153  void *val, // (in)
154  int32_t precision); // (in)
155 
156 extern int32_t file_def_associated_coordinates( int32_t fid, // (in)
157  char *name, // (in)
158  char *desc, // (in)
159  char *units, // (in)
160  char **dim_names, // (in)
161  int32_t ndims, // (in)
162  int32_t dtype); // (in)
163 
164 extern int32_t file_write_associated_coordinates( int32_t fid, // (in)
165  char *name, // (in)
166  void *val, // (in)
167  int32_t precision); // (in)
168 
169 extern int32_t file_add_variable( int32_t *vid, // (out)
170  int32_t fid, // (in)
171  char *varname, // (in)
172  char *desc, // (in)
173  char *units, // (in)
174  char **dims, // (in)
175  int32_t ndims, // (in)
176  int32_t dtype, // (in)
177  real64_t tint, // (in)
178  int32_t tavg); // (in)
179 
180 extern int32_t file_write_data( int32_t fid, // (in)
181  int32_t vid, // (in)
182  void *var, // (in)
183  real64_t t_start, // (in)
184  real64_t t_end, // (in)
185  int32_t precision); // (in)
186 
187 extern int32_t file_write_var( int32_t vid, // (in)
188  void *var, // (in)
189  real64_t t_start, // (in)
190  real64_t t_end, // (in)
191  int32_t precision); // (in)
192 
193 extern int32_t file_enddef( int32_t fid ); // (in)
194 
195 extern int32_t file_close( int32_t fid ); // (in)
196 
197 #endif
int32_t file_set_tunits(int32_t fid, char *time_units)
Definition: gtool_netcdf.c:455
#define File_HMID
Definition: gtool_file.h:12
int32_t step
Definition: gtool_file.h:49
#define MAX_RANK
Definition: gtool_file.h:34
int32_t file_set_tattr(int32_t fid, char *vname, char *key, char *val)
Definition: gtool_netcdf.c:463
int32_t file_set_global_attribute_text(int32_t fid, char *key, char *value)
Definition: gtool_netcdf.c:368
int32_t file_set_global_attribute_double(int32_t fid, char *key, double *value, size_t len)
Definition: gtool_netcdf.c:433
int32_t file_set_global_attribute_float(int32_t fid, char *key, float *value, size_t len)
Definition: gtool_netcdf.c:411
int32_t file_get_global_attribute_int(int32_t fid, char *key, int32_t *value, size_t len)
int32_t file_get_global_attribute_float(int32_t fid, char *key, float *value, size_t len)
Definition: gtool_netcdf.c:332
int32_t file_get_datainfo(datainfo_t *dinfo, int32_t fid, char *varname, int32_t step, int32_t suppress)
Definition: gtool_netcdf.c:162
int32_t file_enddef(int32_t fid)
#define File_HSHORT
Definition: gtool_file.h:11
int32_t file_set_global_attribute_int(int32_t fid, char *key, int32_t *value, size_t len)
real64_t time_start
Definition: gtool_file.h:50
int32_t file_get_global_attribute_double(int32_t fid, char *key, double *value, size_t len)
Definition: gtool_netcdf.c:350
int32_t file_open(int32_t *fid, char *fname, int32_t mode)
Definition: gtool_netcdf.c:97
typedef float(real32_t)
int32_t file_put_axis(int32_t fid, char *name, char *desc, char *units, char *dim_name, int32_t dtype, void *val, int32_t size, int32_t precision)
Definition: gtool_netcdf.c:492
int32_t file_def_axis(int32_t fid, char *name, char *desc, char *units, char *dim_name, int32_t dtype, int32_t dim_size)
Definition: gtool_netcdf.c:546
int32_t file_write_data(int32_t fid, int32_t vid, void *var, real64_t t_start, real64_t t_end, int32_t precision)
Definition: gtool_netcdf.c:948
int32_t fid
Definition: gtool_file.h:53
int32_t file_get_global_attribute_text(int32_t fid, char *key, char *value, int32_t len)
Definition: gtool_netcdf.c:294
real64_t time_end
Definition: gtool_file.h:51
int32_t file_def_associated_coordinates(int32_t fid, char *name, char *desc, char *units, char **dim_names, int32_t ndims, int32_t dtype)
Definition: gtool_netcdf.c:673
int32_t file_write_axis(int32_t fid, char *name, void *val, int32_t precision)
Definition: gtool_netcdf.c:581
int32_t file_put_associated_coordinates(int32_t fid, char *name, char *desc, char *units, char **dim_names, int32_t ndims, int32_t dtype, void *val, int32_t precision)
Definition: gtool_netcdf.c:615
int32_t file_write_var(int32_t vid, void *var, real64_t t_start, real64_t t_end, int32_t precision)
int32_t file_write_associated_coordinates(int32_t fid, char *name, void *val, int32_t precision)
Definition: gtool_netcdf.c:712
int32_t file_read_data(void *var, datainfo_t *dinfo, int32_t precision)
Definition: gtool_netcdf.c:245
int32_t file_add_variable(int32_t *vid, int32_t fid, char *varname, char *desc, char *units, char **dims, int32_t ndims, int32_t dtype, real64_t tint, int32_t tavg)
Definition: gtool_netcdf.c:746
int32_t datatype
Definition: gtool_file.h:45
int32_t file_close(int32_t fid)
typedef double(real64_t)
int32_t file_set_option(int32_t fid, char *filetype, char *key, char *val)
Definition: gtool_netcdf.c:146
int32_t rank
Definition: gtool_file.h:46