[6331] | 1 | #include <stdio.h> |
---|
| 2 | #include <math.h> |
---|
| 3 | #include "netcdf.h" |
---|
| 4 | #include "mpi.h" |
---|
| 5 | #include "oasis_c.h" |
---|
| 6 | |
---|
| 7 | int main(int argc, char *argv[]) |
---|
| 8 | { |
---|
| 9 | char *comp_name = "receiver"; |
---|
| 10 | fprintf(stdout,"Component name: %s\n", comp_name); |
---|
| 11 | fflush(stdout); |
---|
| 12 | |
---|
| 13 | int comp_id; |
---|
| 14 | OASIS_CHECK_ERR(oasis_c_init_comp(&comp_id, comp_name, OASIS_COUPLED)); |
---|
| 15 | fprintf(stdout, "Receiver: Component ID: %d\n", comp_id); |
---|
| 16 | fflush(stdout); |
---|
| 17 | |
---|
| 18 | int nx_global = 144; |
---|
| 19 | int ny_global = 143; |
---|
| 20 | int n_points = nx_global*ny_global; |
---|
| 21 | |
---|
| 22 | int ncid, varid; |
---|
| 23 | if (nc_open("grids.nc", 0, &ncid) != NC_NOERR) |
---|
| 24 | OASIS_CHECK_ERR(oasis_c_abort(comp_id, comp_name, "Receiver: Error in opening grids.nc", |
---|
| 25 | __FILE__, __LINE__)); |
---|
| 26 | |
---|
| 27 | double lon[ny_global][nx_global]; |
---|
| 28 | double lat[ny_global][nx_global]; |
---|
| 29 | if (nc_inq_varid(ncid, "bggd.lon", &varid) != NC_NOERR) |
---|
| 30 | OASIS_CHECK_ERR(oasis_c_abort(comp_id, comp_name, "Receiver: Error in getting bggd.lon id",__FILE__, __LINE__)); |
---|
| 31 | if (nc_get_var(ncid, varid, &lon[0][0]) != NC_NOERR) |
---|
| 32 | OASIS_CHECK_ERR(oasis_c_abort(comp_id, comp_name, "Receiver: Error in getting bggd.lon values",__FILE__, __LINE__)); |
---|
| 33 | if (nc_inq_varid(ncid, "bggd.lat", &varid) != NC_NOERR) |
---|
| 34 | OASIS_CHECK_ERR(oasis_c_abort(comp_id, comp_name, "Receiver: Error in getting bggd.lat id",__FILE__, __LINE__)); |
---|
| 35 | if (nc_get_var(ncid, varid, &lat[0][0]) != NC_NOERR) |
---|
| 36 | OASIS_CHECK_ERR(oasis_c_abort(comp_id, comp_name, "Receiver: Error in getting bggd.lat values",__FILE__, __LINE__)); |
---|
| 37 | if (nc_close(ncid)) |
---|
| 38 | OASIS_CHECK_ERR(oasis_c_abort(comp_id, comp_name, "Receiver: Error in closing grids.nc",__FILE__, __LINE__)); |
---|
| 39 | |
---|
| 40 | if (nc_open("masks.nc", 0, &ncid) != NC_NOERR) |
---|
| 41 | OASIS_CHECK_ERR(oasis_c_abort(comp_id, comp_name, "Receiver: Error in opening grids.nc", |
---|
| 42 | __FILE__, __LINE__)); |
---|
| 43 | int mask[ny_global][nx_global]; |
---|
| 44 | if (nc_inq_varid(ncid, "bggd.msk", &varid) != NC_NOERR) |
---|
| 45 | OASIS_CHECK_ERR(oasis_c_abort(comp_id, comp_name, "Receiver: Error in getting bggd.msk id",__FILE__, __LINE__)); |
---|
| 46 | if (nc_get_var(ncid, varid, &mask[0][0]) != NC_NOERR) |
---|
| 47 | OASIS_CHECK_ERR(oasis_c_abort(comp_id, comp_name, "Receiver: Error in getting bggd.msk values",__FILE__, __LINE__)); |
---|
| 48 | if (nc_close(ncid)) |
---|
| 49 | OASIS_CHECK_ERR(oasis_c_abort(comp_id, comp_name, "Receiver: Error in closing grids.nc",__FILE__, __LINE__)); |
---|
| 50 | |
---|
| 51 | int part_params[OASIS_Serial_Params]; |
---|
| 52 | part_params[OASIS_Strategy] = OASIS_Serial; |
---|
| 53 | part_params[OASIS_Length] = n_points; |
---|
| 54 | int part_id; |
---|
| 55 | OASIS_CHECK_ERR(oasis_c_def_partition(&part_id, OASIS_Serial_Params, |
---|
| 56 | part_params, OASIS_No_Gsize, |
---|
| 57 | OASIS_No_Name)); |
---|
| 58 | |
---|
| 59 | char *var_name = "FRECVANA"; |
---|
| 60 | int bundle_size = 2; |
---|
| 61 | int var_id; |
---|
| 62 | OASIS_CHECK_ERR(oasis_c_def_var(&var_id, var_name, part_id, bundle_size, OASIS_IN, OASIS_DOUBLE)); |
---|
| 63 | OASIS_CHECK_ERR(oasis_c_enddef()); |
---|
| 64 | |
---|
| 65 | double bundle[bundle_size][ny_global][nx_global]; |
---|
| 66 | int date = 0; |
---|
| 67 | int kinfo; |
---|
| 68 | OASIS_CHECK_ERR(oasis_c_get(var_id, date, n_points, 1, bundle_size, OASIS_DOUBLE, OASIS_COL_MAJOR, bundle, &kinfo)); |
---|
| 69 | fprintf(stdout, "Receiver: oasis_c_get returned kinfo = %d\n", kinfo); |
---|
| 70 | fflush(stdout); |
---|
| 71 | |
---|
| 72 | OASIS_CHECK_ERR(oasis_c_terminate()); |
---|
| 73 | |
---|
| 74 | double dp_conv = atan(1.)/45.0; |
---|
| 75 | double expected[bundle_size][ny_global][nx_global]; |
---|
| 76 | int i, j, k; |
---|
| 77 | for (i = 0; i<nx_global; i++) |
---|
| 78 | for (j = 0; j<ny_global; j++) { |
---|
| 79 | expected[0][j][i] = 2.0 + pow(sin(2.0 * lat[j][i]*dp_conv),4.0) * |
---|
| 80 | cos(4.0 * lon[j][i]*dp_conv);; |
---|
| 81 | expected[1][j][i] = 2.0 - cos(atan(1.)*4.* |
---|
| 82 | (acos(cos(lon[j][i]*dp_conv)*cos(lat[j][i]*dp_conv))/ |
---|
| 83 | (1.2*atan(1.)*4)));; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | double epsilon = 1.e-3; |
---|
| 87 | |
---|
| 88 | bool success = 1; |
---|
| 89 | double error; |
---|
| 90 | for (k = 0; k<bundle_size; k++) { |
---|
| 91 | error = 0.; |
---|
| 92 | for (i = 0; i<nx_global; i++) |
---|
| 93 | for (j = 0; j<ny_global; j++) |
---|
| 94 | if (mask[j][i] == 0) |
---|
| 95 | error += fabs((bundle[k][j][i] - expected[k][j][i])/expected[k][j][i]); |
---|
| 96 | |
---|
| 97 | success = success && (error/(double)n_points < epsilon); |
---|
| 98 | if (error/(double)n_points < epsilon) { |
---|
| 99 | fprintf(stdout, "Receiver: Data for bundle %d is ok\n", k); |
---|
| 100 | fflush(stdout); |
---|
| 101 | } else { |
---|
| 102 | fprintf(stdout, "Receiver: Error for bundle %d %f\n", k, error/(double)n_points); |
---|
| 103 | fflush(stdout); |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | if (success) { |
---|
| 108 | fprintf(stdout, "Receiver: Data received successfully\n"); |
---|
| 109 | fflush(stdout); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | } |
---|