@@ -22,7 +22,9 @@ void check_err(int stat, int line) {
22
22
23
23
int main () {
24
24
int ncid , time_dim , xt_dim , yt_dim , pfull_dim , phalf_dim ;
25
- int times_id , xt_id , yt_id , phalf_id , pfull_id , pk_id , bk_id , ps_id , temp_id ;
25
+ int times_id , xt_id , yt_id , phalf_id , pfull_id , pk_id , bk_id ;
26
+ int ps_id , temp_id , dummy_id ;
27
+
26
28
int stat ;
27
29
28
30
size_t start_ps [3 ] = {0 , 0 , 0 };
@@ -61,10 +63,11 @@ int main() {
61
63
check_err (stat , __LINE__ );
62
64
stat = nc_def_var (ncid , "bk" , NC_FLOAT , 1 , & phalf_dim , & bk_id );
63
65
check_err (stat , __LINE__ );
64
- stat = nc_def_var (ncid , "ps" , NC_FLOAT , 3 , (int []){time_dim , yt_dim , xt_dim }, & ps_id );
66
+ stat = nc_def_var (ncid , "ps" , NC_FLOAT , 3 , (int []){time_dim , xt_dim , yt_dim }, & ps_id );
65
67
check_err (stat , __LINE__ );
66
68
stat = nc_def_var (ncid , "temp" , NC_FLOAT , 4 , (int []){time_dim , pfull_dim , xt_dim , yt_dim }, & temp_id );
67
69
check_err (stat , __LINE__ );
70
+ stat = nc_def_var (ncid , "dummy" , NC_FLOAT , 3 , (int []){time_dim , yt_dim , xt_dim }, & dummy_id );
68
71
69
72
// Assign global attributes
70
73
stat = nc_put_att_text (ncid , NC_GLOBAL , "description" , 40 , "Sample netCDF file for testing run_timepressure_interp" );
@@ -84,7 +87,8 @@ int main() {
84
87
// Allocate memory for sample data and write to file
85
88
double times_data [TIME ] = {0 };
86
89
float xt_data [NX ], yt_data [NY ], temp_data [PFULL ][NX ][NY ];
87
- float ps_data [NY ][NX ];
90
+ float ps_data [NX ][NY ];
91
+ float dummy_data [NX ][NY ];
88
92
89
93
for (int i = 0 ; i < NX ; i ++ ) xt_data [i ] = i ;
90
94
for (int i = 0 ; i < NY ; i ++ ) yt_data [i ] = i ;
@@ -130,10 +134,14 @@ int main() {
130
134
for (int k = 0 ; k < NY ; k ++ )
131
135
temp_data [i ][j ][k ] = (rand () % (TEMP_MAX - TEMP_MIN )) + TEMP_MIN ;
132
136
133
- for (int i = 0 ; i < NY ; i ++ )
134
- for (int j = 0 ; j < NX ; j ++ )
137
+ for (int i = 0 ; i < NX ; i ++ )
138
+ for (int j = 0 ; j < NY ; j ++ )
135
139
ps_data [i ][j ] = (rand () % (PS_MAX - PS_MIN )) + PS_MIN ;
136
140
141
+ for (int i = 0 ; i < NX ; i ++ )
142
+ for (int j = 0 ; j < NY ; j ++ )
143
+ dummy_data [i ][j ] = i * NX + j ;
144
+
137
145
// Writing data
138
146
stat = nc_put_var_double (ncid , times_id , & times_data [0 ]);
139
147
check_err (stat , __LINE__ );
@@ -156,9 +164,14 @@ int main() {
156
164
check_err (stat , __LINE__ );
157
165
stat = nc_put_vara_float (ncid , ps_id ,
158
166
(size_t [3 ]){0 , 0 , 0 },
159
- (size_t [4 ]){1 , NY , NX },
167
+ (size_t [3 ]){1 , NX , NY },
160
168
& ps_data [0 ][0 ]);
161
169
check_err (stat , __LINE__ );
170
+ stat = nc_put_vara_float (ncid , dummy_id ,
171
+ (size_t [3 ]){0 , 0 , 0 },
172
+ (size_t [3 ]){1 , NX , NY },
173
+ & dummy_data [0 ][0 ]);
174
+ check_err (stat , __LINE__ );
162
175
163
176
// Close the file
164
177
stat = nc_close (ncid );
0 commit comments