source: CPL/oasis3-mct_5.0/lib/cbindings/c_src/oasis_c.h @ 6328

Last change on this file since 6328 was 6328, checked in by aclsce, 17 months ago

First import of oasis3-mct_5.0 (from oasis git server, branch OASIS3-MCT_5.0)

File size: 6.5 KB
Line 
1/* pyOASIS - A Python wrapper for OASIS
2   Authors: Philippe Gambron, Rupert Ford
3   Copyright (C) 2019 UKRI - STFC
4 
5   This program is free software: you can redistribute it and/or modify
6   it under the terms of the GNU Lesser General Public License as
7   published by the Free Software Foundation, either version 3 of the
8   License, or any later version.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   GNU Lesser General Public License for more details.
14 
15   A copy of the GNU Lesser General Public License, version 3, is supplied
16   with this program, in the file lgpl-3.0.txt. It is also available at
17   <https://www.gnu.org/licenses/lgpl-3.0.html>. */
18
19
20#ifndef __OASIS_C_ROUTINES_C_H__
21#define __OASIS_C_ROUTINES_C_H__
22
23
24#include <stdbool.h>
25#include <mpi.h>
26
27
28#if defined(c_plusplus) || defined(__cplusplus)
29extern "C" {
30#endif
31
32#define OASIS_CHECK_ERR(x) { \
33  int retval = (x); \
34  if (retval != OASIS_Ok) { \
35     fprintf(stderr, "Runtime error: %s returned %d at %s:%d\n", #x, retval, __FILE__, __LINE__); \
36     fflush(stderr); \
37     oasis_c_abort(0, #x, "Runtime error", __FILE__, __LINE__); \
38  } \
39}
40
41#define OASIS_CHECK_MPI_ERR(x) { \
42  int retval = (x); \
43  if (retval != MPI_SUCCESS) { \
44     fprintf(stderr, "Runtime MPI error: %s returned %d at %s:%d\n", #x, retval, __FILE__, __LINE__); \
45     fflush(stderr); \
46     oasis_c_abort(0, #x, "Runtime MPI error", __FILE__, __LINE__); \
47  } \
48}
49
50enum mnemonic_params
51{
52  OASIS_Real          = 4,
53  OASIS_REAL          = 4,
54  OASIS_Double        = 8,
55  OASIS_DOUBLE        = 8,
56  OASIS_ROW_MAJOR     = 0,
57  OASIS_COL_MAJOR     = 1,
58  OASIS_Out           = 20,
59  OASIS_OUT           = 20,
60  OASIS_In            = 21,
61  OASIS_IN            = 21,
62  OASIS_Coupled       = 1,
63  OASIS_COUPLED       = 1,
64  OASIS_Not_Coupled   = 0,
65  OASIS_NOT_COUPLED   = 0,
66  OASIS_Write_Restart = 1,
67  OASIS_WRITE_RESTART = 1,
68  OASIS_No_Restart    = 0,
69  OASIS_NO_RESTART    = 0,
70  OASIS_No_Part       = -1,
71  OASIS_NO_PART       = -1
72};
73
74#define OASIS_No_Companion "NULL-STRING"
75
76enum partition_params {
77  OASIS_Serial        = 0,
78  OASIS_Apple         = 1,
79  OASIS_Box           = 2,
80  OASIS_Orange        = 3,
81  OASIS_Points        = 4,
82  OASIS_Strategy      = 0,
83  OASIS_Segments      = 1,
84  OASIS_Npoints       = 1,
85  OASIS_Offset        = 1,
86  OASIS_Length        = 2,
87  OASIS_SizeX         = 2,
88  OASIS_SizeY         = 3,
89  OASIS_LdX           = 4,
90  OASIS_Serial_Params = 3,
91  OASIS_Apple_Params  = 3,
92  OASIS_Box_Params    = 5,
93  OASIS_No_Gsize      = 0
94};
95
96#define OASIS_No_Name ""
97#define OASIS_Orange_Params(n_segments) (2 + 2*n_segments)
98#define OASIS_Points_Params(n_points) (2 + n_points)
99
100enum return_codes
101{
102  OASIS_Ok            = 0,
103  OASIS_Success       = 0,
104  OASIS_Error         = -10,
105  OASIS_NotDef        = -2,
106  OASIS_Var_Uncpl     = -1,
107  OASIS_InOut         = 2,
108  OASIS_Recvd         = 3,
109  OASIS_Sent          = 4,
110  OASIS_LocTrans      = 5,
111  OASIS_ToRest        = 6,
112  OASIS_Output        = 7,
113  OASIS_SentOut       = 8,
114  OASIS_ToRestOut     = 9,
115  OASIS_FromRest      = 10,
116  OASIS_Input         = 11,
117  OASIS_RecvOut       = 12,
118  OASIS_FromRestOut   = 13,
119  OASIS_Waitgroup     = 14
120};
121
122/* C interfaces with MPI Communicator defined as C MPI_Comm (for C) */
123
124int oasis_c_get_localcomm(MPI_Comm* localcomm);
125
126int oasis_c_create_couplcomm(const int icpl, const MPI_Comm allcomm, MPI_Comm* cplcomm);
127
128int oasis_c_set_couplcomm(const MPI_Comm localcomm);
129
130int oasis_c_get_intercomm(MPI_Comm* new_comm, char* cdnam);
131
132int oasis_c_get_intracomm(MPI_Comm* new_comm, char* cdnam);
133
134int oasis_c_get_multi_intracomm(MPI_Comm* new_comm, const int cdnam_size, char** cdnam, int* root_ranks);
135
136int oasis_c_set_debug(const int debug);
137
138int oasis_c_get_debug(int* debug);
139
140int oasis_c_put_inquire(int varid, int msec, int *kinfo);
141
142int oasis_c_get_ncpl(const int varid, int* ncpl);
143
144int oasis_c_get_freqs(const int varid, const int mop, const int ncpl, int* cpl_freqs);
145
146int oasis_c_put(const int var_id, const int kstep, const int x_size, const int y_size, const int bundle_size, const int fkind, const int storage, const void* fld1, const bool write_restart, int* kinfo);
147
148int oasis_c_get(const int var_id, const int kstep, const int x_size, const int y_size, const int bundle_size, const int fkind, const int storage, void* fld1, int* kinfo);
149
150int oasis_c_start_grids_writing();
151
152int oasis_c_write_grid(const char* cgrid, const int nx, const int ny, const int nx_loc, const int ny_loc, const double* lon, const double* lat, const int partid);
153
154int oasis_c_write_corner(const char* cgrid, const int nx, const int ny, const int nc, const int nx_loc, const int ny_loc, const double* clo, const double* cla, const int partid);
155
156int oasis_c_write_mask(const char* cgrid, const int nx, const int ny, const int nx_loc, const int ny_loc, const int* mask, const int partid, const char* companion);
157
158int oasis_c_write_frac(const char* cgrid, const int nx, const int ny, const int nx_loc, const int ny_loc, const double* frac, const int partid, const char* companion);
159
160int oasis_c_write_area(const char* cgrid, const int nx, const int ny, const int nx_loc, const int ny_loc, const double* area, const int partid);
161
162int oasis_c_write_angle(const char* cgrid, const int nx, const int ny, const int nx_loc, const int ny_loc, const double* angle, const int partid);
163
164int oasis_c_terminate_grids_writing();
165
166int oasis_c_init_comp_with_comm(int* mynummod, const char* cdnam, const bool coupled, const MPI_Comm commworld);
167
168int oasis_c_init_comp(int* mynummod, const char* cdnam, const bool coupled);
169
170int oasis_c_enddef();
171
172int oasis_c_terminate();
173
174int oasis_c_def_partition(int* id_part, const int kparal_size, const int* kparal, const int ig_size, const char* name);
175
176int oasis_c_abort(const int id_compid, const char* cd_routine, const char* cd_message, const char* file, const int line);
177
178int oasis_c_def_var(int* id_nports, const char* cdport, const int id_part, const int bundle_size, const int kinout, const int ktype);
179
180#define IS_VALID_PUT(k) ( k == OASIS_Ok) || ( k == OASIS_Output ) || ( k == OASIS_ToRestOut ) || \
181      ( k == OASIS_ToRest ) || ( k == OASIS_SentOut ) || ( k == OASIS_Sent ) || \
182      ( k == OASIS_LocTrans ) || ( k == OASIS_Waitgroup )
183
184#define IS_VALID_GET(k) ( k == OASIS_Ok) || ( k == OASIS_Input ) || ( k == OASIS_FromRestOut ) || \
185      ( k == OASIS_Recvd ) || ( k == OASIS_RecvOut ) || ( k == OASIS_Output )
186
187#if defined(c_plusplus) || defined(__cplusplus)
188}
189#endif
190
191
192#endif
Note: See TracBrowser for help on using the repository browser.