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 | #include "oasis_c.h" |
---|
21 | #include "oasis_c_iso.h" |
---|
22 | #include <stdlib.h> |
---|
23 | #include <string.h> |
---|
24 | |
---|
25 | int 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){ |
---|
26 | bool storage_is1D = ((int)( x_size == 1 ) + (int)( y_size == 1 ) + (int)( bundle_size == 1 )) == 2; |
---|
27 | if ( storage != OASIS_COL_MAJOR && storage != OASIS_ROW_MAJOR ) |
---|
28 | oasis_c_abort(0, "oasis_c_put", "storage argument can only be OASIS_ROW_MAJOR or OASIS_COL_MAJOR", __FILE__, __LINE__); |
---|
29 | if ( storage == OASIS_COL_MAJOR || storage_is1D ) { |
---|
30 | if ( fkind == OASIS_Real ) { |
---|
31 | oasis_put_iso_float(&var_id, &kstep, &x_size, &y_size, &bundle_size, (float*)fld1, kinfo, &write_restart); |
---|
32 | } else if ( fkind == OASIS_Double ) { |
---|
33 | oasis_put_iso_double(&var_id, &kstep, &x_size, &y_size, &bundle_size, fld1, kinfo, &write_restart); |
---|
34 | } else { |
---|
35 | oasis_c_abort(0, "oasis_c_put", "fkind argument can only be OASIS_Real or OASIS_Double", __FILE__, __LINE__); |
---|
36 | } |
---|
37 | } else { |
---|
38 | if ( fkind == OASIS_Real ) { |
---|
39 | float* fld2; |
---|
40 | int i,j,k; |
---|
41 | fld2 = (float*) malloc(x_size*y_size*bundle_size*sizeof(float)); |
---|
42 | for (i=0; i<x_size; i++) { |
---|
43 | for (j=0; j<y_size; j++) { |
---|
44 | for (k=0; k<bundle_size; k++) { |
---|
45 | memcpy(fld2+k*y_size*x_size+j*x_size+i, fld1+(i*y_size*bundle_size+j*bundle_size+k)*sizeof(float), sizeof(float)); |
---|
46 | } |
---|
47 | } |
---|
48 | } |
---|
49 | oasis_put_iso_float(&var_id, &kstep, &x_size, &y_size, &bundle_size, fld2, kinfo, &write_restart); |
---|
50 | free(fld2); |
---|
51 | } else if ( fkind == OASIS_Double ) { |
---|
52 | double* fld2; |
---|
53 | int i,j,k; |
---|
54 | fld2 = (double*) malloc(x_size*y_size*bundle_size*sizeof(double)); |
---|
55 | for (i=0; i<x_size; i++) { |
---|
56 | for (j=0; j<y_size; j++) { |
---|
57 | for (k=0; k<bundle_size; k++) { |
---|
58 | memcpy(fld2+k*y_size*x_size+j*x_size+i, fld1+(i*y_size*bundle_size+j*bundle_size+k)*sizeof(double), sizeof(double)); |
---|
59 | } |
---|
60 | } |
---|
61 | } |
---|
62 | oasis_put_iso_double(&var_id, &kstep, &x_size, &y_size, &bundle_size, fld2, kinfo, &write_restart); |
---|
63 | free(fld2); |
---|
64 | } else { |
---|
65 | oasis_c_abort(0, "oasis_c_put", "fkind argument can only be OASIS_Real or OASIS_Double", __FILE__, __LINE__); |
---|
66 | } |
---|
67 | } |
---|
68 | if ( IS_VALID_PUT(*kinfo) ) { |
---|
69 | return OASIS_Ok; |
---|
70 | } else { |
---|
71 | return OASIS_Error; |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | int 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){ |
---|
76 | bool storage_is1D = ((int)( x_size == 1 ) + (int)( y_size == 1 ) + (int)( bundle_size == 1 )) == 2; |
---|
77 | if ( storage != OASIS_COL_MAJOR && storage != OASIS_ROW_MAJOR ) |
---|
78 | oasis_c_abort(0, "oasis_c_get", "storage argument can only be OASIS_ROW_MAJOR or OASIS_COL_MAJOR", __FILE__, __LINE__); |
---|
79 | if ( storage == OASIS_COL_MAJOR || storage_is1D ) { |
---|
80 | if ( fkind == OASIS_Real ) { |
---|
81 | oasis_get_iso_float(&var_id, &kstep, &x_size, &y_size, &bundle_size, (float*)fld1, kinfo); |
---|
82 | } else if ( fkind == OASIS_Double ) { |
---|
83 | oasis_get_iso_double(&var_id, &kstep, &x_size, &y_size, &bundle_size, fld1, kinfo); |
---|
84 | } else { |
---|
85 | oasis_c_abort(0, "oasis_c_get", "fkind argument can only be OASIS_Real or OASIS_Double", __FILE__, __LINE__); |
---|
86 | } |
---|
87 | } else { |
---|
88 | if ( fkind == OASIS_Real ) { |
---|
89 | float* fld2; |
---|
90 | int i,j,k; |
---|
91 | fld2 = (float*) malloc(x_size*y_size*bundle_size*sizeof(float)); |
---|
92 | oasis_get_iso_float(&var_id, &kstep, &x_size, &y_size, &bundle_size, fld2, kinfo); |
---|
93 | for (i=0; i<x_size; i++) { |
---|
94 | for (j=0; j<y_size; j++) { |
---|
95 | for (k=0; k<bundle_size; k++) { |
---|
96 | memcpy(fld1+(i*y_size*bundle_size+j*bundle_size+k)*sizeof(float), fld2+k*y_size*x_size+j*x_size+i, sizeof(float)); |
---|
97 | } |
---|
98 | } |
---|
99 | } |
---|
100 | free(fld2); |
---|
101 | } else if ( fkind == OASIS_Double ) { |
---|
102 | double* fld2; |
---|
103 | int i,j,k; |
---|
104 | fld2 = (double*) malloc(x_size*y_size*bundle_size*sizeof(double)); |
---|
105 | oasis_get_iso_double(&var_id, &kstep, &x_size, &y_size, &bundle_size, fld2, kinfo); |
---|
106 | for (i=0; i<x_size; i++) { |
---|
107 | for (j=0; j<y_size; j++) { |
---|
108 | for (k=0; k<bundle_size; k++) { |
---|
109 | memcpy(fld1+(i*y_size*bundle_size+j*bundle_size+k)*sizeof(double), fld2+k*y_size*x_size+j*x_size+i, sizeof(double)); |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | free(fld2); |
---|
114 | } else { |
---|
115 | oasis_c_abort(0, "oasis_c_get", "fkind argument can only be OASIS_Real or OASIS_Double", __FILE__, __LINE__); |
---|
116 | } |
---|
117 | } |
---|
118 | if ( IS_VALID_GET(*kinfo) ) { |
---|
119 | return OASIS_Ok; |
---|
120 | } else { |
---|
121 | return OASIS_Error; |
---|
122 | } |
---|
123 | } |
---|