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 #include <mpi.h>
10 
11 /* character length */
12 #define File_HSHORT 32
13 #define File_HMID 128
14 #define File_HLONG 1024
15 
16 /* data type */
17 #define File_REAL4 0
18 #define File_REAL8 1
19 #define File_INTEGER2 2
20 #define File_INTEGER4 3
21 #define File_INTEGER8 4
22 
23 /* action type */
24 #define File_FREAD 0
25 #define File_FWRITE 1
26 #define File_FAPPEND 2
27 
28 /* return type */
29 #define ERROR_CODE -1
30 #define SUCCESS_CODE 0
31 #define ALREADY_CLOSED_CODE 1
32 #define ALREADY_EXISTED_CODE 2
33 
34 /* limit of dimension */
35 #define MAX_RANK 10
36 
37 
38 typedef float (real32_t);
39 typedef double(real64_t);
40 
41 /* data item information */
42 typedef struct{
43  char varname[File_HSHORT];
44  char description[File_HMID];
45  char units[File_HSHORT];
46  int32_t datatype;
47  int32_t rank;
48  char dim_name[File_HSHORT*MAX_RANK];
49  int32_t dim_size[MAX_RANK];
50  int32_t step;
51  real64_t time_start;
52  real64_t time_end;
53  char time_units[File_HMID];
54  int32_t fid;
55 } datainfo_t;
56 
57 
58 extern int32_t file_open( int32_t *fid, // (out)
59  char *fname, // (in)
60  int32_t mode, // (in)
61  MPI_Comm comm); // (in)
62 
63 extern int32_t file_set_option( int32_t fid, // (in)
64  char *filetype, // (in)
65  char *key, // (in)
66  char *val); // (in)
67 
68 extern int32_t file_get_datainfo( datainfo_t *dinfo, // (out)
69  int32_t fid, // (in)
70  char *varname, // (in)
71  int32_t step, // (in)
72  int32_t suppress);// (in)
73 
74 extern int32_t file_read_data( void *var, // (out)
75  datainfo_t *dinfo, // (in)
76  int32_t precision); // (in)
77 
78 extern int32_t file_read_data_par( void *var, // (out)
79  datainfo_t *dinfo, // (in)
80  MPI_Offset ntypes, // (in)
81  MPI_Datatype dtype, // (in)
82  MPI_Offset *start, // (in)
83  MPI_Offset *count); // (in)
84 
85 
86 extern int32_t file_get_global_attribute_text( int32_t fid, // (in)
87  char *key, // (in)
88  char *value, // (out)
89  int32_t len); // (in)
90 
91 extern int32_t file_get_global_attribute_int( int32_t fid, // (in)
92  char *key, // (in)
93  int32_t *value, // (out)
94  size_t len); // (in)
95 
96 extern int32_t file_get_global_attribute_float( int32_t fid, // (in)
97  char *key, // (in)
98  float *value, // (out)
99  size_t len); // (in)
100 
101 extern int32_t file_get_global_attribute_double( int32_t fid, // (in)
102  char *key, // (in)
103  double *value, // (out)
104  size_t len); // (in)
105 
106 extern int32_t file_set_global_attribute_text( int32_t fid, // (in)
107  char *key, // (in)
108  char *value); // (in)
109 
110 extern int32_t file_set_global_attribute_int( int32_t fid, // (in)
111  char *key, // (in)
112  int32_t *value, // (in)
113  size_t len); // (in)
114 
115 extern int32_t file_set_global_attribute_float( int32_t fid, // (in)
116  char *key, // (in)
117  float *value, // (in)
118  size_t len); // (in)
119 
120 extern int32_t file_set_global_attribute_double( int32_t fid, // (in)
121  char *key, // (in)
122  double *value, // (in)
123  size_t len); // (in)
124 
125 extern int32_t file_set_tunits( int32_t fid, // (in)
126  char *time_units); // (in)
127 
128 extern int32_t file_set_tattr( int32_t fid, // (in)
129  char *vname, // (in)
130  char *key, // (in)
131  char *val); // (in)
132 
133 extern int32_t file_put_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  void *val, // (in)
140  int32_t size, // (in)
141  int32_t precision); // (in)
142 
143 extern int32_t file_def_axis( int32_t fid, // (in)
144  char *name, // (in)
145  char *desc, // (in)
146  char *units, // (in)
147  char *dim_name, // (in)
148  int32_t dtype, // (in)
149  int32_t dim_size); // (in)
150 
151 extern int32_t file_write_axis( int32_t fid, // (in)
152  char *name, // (in)
153  void *val, // (in)
154  int32_t precision, // (in)
155  MPI_Offset *start, // (in)
156  MPI_Offset *count); // (in)
157 
158 extern int32_t file_put_associated_coordinates( int32_t fid, // (in)
159  char *name, // (in)
160  char *desc, // (in)
161  char *units, // (in)
162  char **dim_names, // (in)
163  int32_t ndims, // (in)
164  int32_t dtype, // (in)
165  void *val, // (in)
166  int32_t precision); // (in)
167 
168 extern int32_t file_def_associated_coordinates( int32_t fid, // (in)
169  char *name, // (in)
170  char *desc, // (in)
171  char *units, // (in)
172  char **dim_names, // (in)
173  int32_t ndims, // (in)
174  int32_t dtype); // (in)
175 
176 extern int32_t file_write_associated_coordinates( int32_t fid, // (in)
177  char *name, // (in)
178  void *val, // (in)
179  int32_t precision, // (in)
180  MPI_Offset *start, // (in)
181  MPI_Offset *count); // (in)
182 
183 extern int32_t file_add_variable( int32_t *vid, // (out)
184  int32_t fid, // (in)
185  char *varname, // (in)
186  char *desc, // (in)
187  char *units, // (in)
188  char **dims, // (in)
189  int32_t ndims, // (in)
190  int32_t dtype, // (in)
191  real64_t tint, // (in)
192  int32_t tavg); // (in)
193 
194 extern int32_t file_write_data( int32_t fid, // (in)
195  int32_t vid, // (in)
196  void *var, // (in)
197  real64_t t_start, // (in)
198  real64_t t_end, // (in)
199  int32_t precision, // (in)
200  MPI_Offset *start, // (in)
201  MPI_Offset *count); // (in)
202 
203 extern int32_t file_enddef( int32_t fid ); // (in)
204 
205 extern int32_t file_attach_buffer( int32_t fid, int32_t buf_amount ); // (in)
206 
207 extern int32_t file_detach_buffer( int32_t fid ); // (in)
208 
209 extern int32_t file_flush( int32_t fid ); // (in)
210 
211 extern int32_t file_close( int32_t fid ); // (in)
212 
213 #endif
int32_t file_set_tunits(int32_t fid, char *time_units)
Definition: gtool_netcdf.c:647
#define File_HMID
Definition: gtool_file.h:13
int32_t step
Definition: gtool_file.h:50
int32_t file_open(int32_t *fid, char *fname, int32_t mode, MPI_Comm comm)
Definition: gtool_netcdf.c:132
#define MAX_RANK
Definition: gtool_file.h:35
int32_t file_set_tattr(int32_t fid, char *vname, char *key, char *val)
Definition: gtool_netcdf.c:655
int32_t file_set_global_attribute_text(int32_t fid, char *key, char *value)
Definition: gtool_netcdf.c:540
int32_t file_attach_buffer(int32_t fid, int32_t buf_amount)
int32_t file_set_global_attribute_double(int32_t fid, char *key, double *value, size_t len)
Definition: gtool_netcdf.c:620
int32_t file_set_global_attribute_float(int32_t fid, char *key, float *value, size_t len)
Definition: gtool_netcdf.c:593
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:504
int32_t file_get_datainfo(datainfo_t *dinfo, int32_t fid, char *varname, int32_t step, int32_t suppress)
Definition: gtool_netcdf.c:218
int32_t file_enddef(int32_t fid)
#define File_HSHORT
Definition: gtool_file.h:12
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:51
int32_t file_get_global_attribute_double(int32_t fid, char *key, double *value, size_t len)
Definition: gtool_netcdf.c:522
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:694
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:748
int32_t fid
Definition: gtool_file.h:54
int32_t file_read_data_par(void *var, datainfo_t *dinfo, MPI_Offset ntypes, MPI_Datatype dtype, MPI_Offset *start, MPI_Offset *count)
Definition: gtool_netcdf.c:439
int32_t file_write_axis(int32_t fid, char *name, void *val, int32_t precision, MPI_Offset *start, MPI_Offset *count)
Definition: gtool_netcdf.c:797
int32_t file_get_global_attribute_text(int32_t fid, char *key, char *value, int32_t len)
Definition: gtool_netcdf.c:466
real64_t time_end
Definition: gtool_file.h:52
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:900
int32_t file_write_data(int32_t fid, int32_t vid, void *var, real64_t t_start, real64_t t_end, int32_t precision, MPI_Offset *start, MPI_Offset *count)
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:842
int32_t file_write_associated_coordinates(int32_t fid, char *name, void *val, int32_t precision, MPI_Offset *start, MPI_Offset *count)
Definition: gtool_netcdf.c:956
int32_t file_read_data(void *var, datainfo_t *dinfo, int32_t precision)
Definition: gtool_netcdf.c:390
int32_t file_flush(int32_t fid)
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)
int32_t file_detach_buffer(int32_t fid)
int32_t datatype
Definition: gtool_file.h:46
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:202
int32_t rank
Definition: gtool_file.h:47