source: XIOS/trunk/src/generate_interface_impl.hpp @ 672

Last change on this file since 672 was 672, checked in by rlacroix, 6 years ago

generate_interface_impl.hpp: Remove old code.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 36.9 KB
Line 
1#ifndef __XIOS_GENERATE_INTERFACE_IMPL_HPP__
2#define __XIOS_GENERATE_INTERFACE_IMPL_HPP__
3
4#include "xios_spl.hpp"
5#include "generate_interface.hpp"
6#include "type_util.hpp"
7#include "indent.hpp"
8#include "enum.hpp"
9#include "array_new.hpp"
10#include "date.hpp"
11
12namespace xios
13{
14  template<> string CInterface::getStrFortranType<int>(void) { return string("INTEGER"); }
15  template<> string CInterface::getStrFortranType<bool>(void) { return string("LOGICAL"); }
16  template<> string CInterface::getStrFortranType<double>(void) { return string("REAL"); }
17  template<> string CInterface::getStrFortranType<float>(void) { return string("REAL"); }
18  template<> string CInterface::getStrFortranType<CDate>(void) { return string("TYPE(txios(date))"); }
19  template<> string CInterface::getStrFortranType<CDuration>(void) { return string("TYPE(txios(duration))"); }
20
21  template<> string CInterface::getStrFortranKind<int>(void) { return string(""); }
22  template<> string CInterface::getStrFortranKind<bool>(void) { return string(""); }
23  template<> string CInterface::getStrFortranKind<double>(void) { return string("(KIND=8)"); }
24  template<> string CInterface::getStrFortranKind<float>(void) { return string("(KIND=4)"); }
25  template<> string CInterface::getStrFortranKind<CDate>(void) { return string(""); }
26  template<> string CInterface::getStrFortranKind<CDuration>(void) { return string(""); }
27
28  template<> string CInterface::getStrFortranKindC<int>(void) { return string("(KIND=C_INT)"); }
29  template<> string CInterface::getStrFortranKindC<bool>(void) { return string("(KIND=C_BOOL)"); }
30  template<> string CInterface::getStrFortranKindC<double>(void) { return string("(KIND=C_DOUBLE)"); }
31  template<> string CInterface::getStrFortranKindC<float>(void) { return string("(KIND=C_FLOAT)"); }
32  template<> string CInterface::getStrFortranKindC<CDate>(void) { return string(""); }
33  template<> string CInterface::getStrFortranKindC<CDuration>(void) { return string(""); }
34
35  template<> bool CInterface::matchingTypeCFortran<int>(void) { return true; }
36  template<> bool CInterface::matchingTypeCFortran<bool>(void) { return false; }
37  template<> bool CInterface::matchingTypeCFortran<double>(void) { return true; }
38  template<> bool CInterface::matchingTypeCFortran<float>(void) { return true; }
39  template<> bool CInterface::matchingTypeCFortran<CDate>(void) { return true; }
40  template<> bool CInterface::matchingTypeCFortran<CDuration>(void) { return true; }
41
42// /////////////////////////////////////////////////
43// //                 C Interface                 //
44// /////////////////////////////////////////////////
45
46  void CInterface::AttributeIsDefinedCInterface(ostream& oss, const string& className, const string& name)
47  {
48    oss << "bool cxios_is_defined_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl)" << iendl;
49    oss << "{" << iendl;
50    oss << "   CTimer::get(\"XIOS\").resume();" << iendl;
51    oss << "   bool isDefined = " << className << "_hdl->" << name << ".hasInheritedValue();" << iendl;
52    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl;
53    oss << "   return isDefined;" << iendl;
54    oss << "}" << std::endl;
55  }
56
57  template <class T>
58  void CInterface::AttributeCInterface(ostream& oss, const string& className, const string& name)
59  {
60    string typeName = getStrType<T>();
61
62    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << " " << name << ")" << iendl;
63    oss << "{" << iendl;
64    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
65    oss << "  " << className << "_hdl->" << name << ".setValue(" << name << ");" << iendl;
66    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
67    oss << "}" << std::endl;
68
69    oss << iendl;
70    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ")" << iendl;
71    oss << "{" << iendl;
72    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
73    oss << "  *" << name << " = " << className << "_hdl->" << name << ".getInheritedValue();" << iendl;
74    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
75    oss << "}" << std::endl;
76  }
77
78  template<>
79  void CInterface::AttributeCInterface<string>(ostream& oss, const string& className, const string& name)
80  {
81    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, const char * " << name << ", int " << name << "_size)" << iendl;
82    oss << "{" << iendl;
83    oss << "  std::string " << name << "_str;" << iendl;
84    oss << "  if (!cstr2string(" << name << ", " << name << "_size, " << name << "_str)) return;" << iendl;
85    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
86    oss << "  " << className << "_hdl->" << name << ".setValue(" << name << "_str);" << iendl;
87    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
88    oss << "}" << std::endl;
89
90    oss << iendl;
91
92    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, char * " << name << ", int " << name << "_size)" << iendl;
93    oss << "{" << iendl;
94    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
95    oss << "  if (!string_copy(" << className << "_hdl->" << name << ".getInheritedValue(), " << name << ", " << name << "_size))" << iendl;
96    oss << "    ERROR(\"void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, char * " << name << ", int "
97        << name << "_size)\", << \"Input string is too short\");" << iendl;
98    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
99    oss << "}" << std::endl;
100  }
101
102  template<>
103  void CInterface::AttributeCInterface<CEnumBase>(ostream& oss, const string& className, const string& name)
104  {
105    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, const char * " << name << ", int " << name << "_size)" << iendl;
106    oss << "{" << iendl;
107    oss << "  std::string " << name << "_str;" << iendl;
108    oss << "  if (!cstr2string(" << name << ", " << name << "_size, " << name << "_str)) return;" << iendl;
109    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
110    oss << "  " << className << "_hdl->" << name << ".fromString(" << name << "_str);" << iendl;
111    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
112    oss << "}" << std::endl;
113
114    oss << iendl;
115
116    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, char * " << name << ", int " << name << "_size)" << iendl;
117    oss << "{" << iendl;
118    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
119    oss << "  if (!string_copy(" << className << "_hdl->" << name << ".getInheritedStringValue(), " << name << ", " << name << "_size))" << iendl;
120    oss << "    ERROR(\"void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, char * " << name << ", int "
121        << name << "_size)\", << \"Input string is too short\");" << iendl;
122    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
123    oss << "}" << std::endl;
124  }
125
126  template<>
127  void CInterface::AttributeCInterface<CDate>(ostream& oss, const string& className, const string& name)
128  {
129    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, cxios_date " << name << "_c)" << iendl;
130    oss << "{" << iendl;
131    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
132    oss << "  " << className << "_hdl->" << name << ".allocate();" << iendl;
133    oss << "  CDate& " << name << " = " << className << "_hdl->" << name << ".get();" << iendl;
134    oss << "  " << name << ".setDate(" << name << "_c.year," << iendl;
135    oss << "                         " << name << "_c.month," << iendl;
136    oss << "                         " << name << "_c.day," << iendl;
137    oss << "                         " << name << "_c.hour," << iendl;
138    oss << "                         " << name << "_c.minute," << iendl;
139    oss << "                         " << name << "_c.second);" << iendl;
140    oss << "  if (" << name << ".hasRelCalendar())" << iendl;
141    oss << "    " << name << ".checkDate();" << iendl;
142    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
143    oss << "}" << std::endl;
144
145    oss << iendl;
146
147    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, cxios_date* " << name << "_c)" << iendl;
148    oss << "{" << iendl;
149    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
150    oss << "  CDate " << name << " = " << className << "_hdl->" << name << ".getInheritedValue();" << iendl;
151    oss << "  " << name << "_c->year = " << name << ".getYear();" << iendl;
152    oss << "  " << name << "_c->month = " << name << ".getMonth();" << iendl;
153    oss << "  " << name << "_c->day = " << name << ".getDay();" << iendl;
154    oss << "  " << name << "_c->hour = " << name << ".getHour();" << iendl;
155    oss << "  " << name << "_c->minute = " << name << ".getMinute();" << iendl;
156    oss << "  " << name << "_c->second = " << name << ".getSecond();" << iendl;
157    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
158    oss << "}" << std::endl;
159  }
160
161  template<>
162  void CInterface::AttributeCInterface<CDuration>(ostream& oss, const string& className, const string& name)
163  {
164    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, cxios_duration " << name << "_c)" << iendl;
165    oss << "{" << iendl;
166    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
167    oss << "  " << className << "_hdl->" << name << ".allocate();" << iendl;
168    oss << "  CDuration& " << name << " = " << className << "_hdl->" << name << ".get();" << iendl;
169    oss << "  " << name << ".year = " << name << "_c.year;" << iendl;
170    oss << "  " << name << ".month = " << name << "_c.month;" << iendl;
171    oss << "  " << name << ".day = " << name << "_c.day;" << iendl;
172    oss << "  " << name << ".hour = " << name << "_c.hour;" << iendl;
173    oss << "  " << name << ".minute = " << name << "_c.minute;" << iendl;
174    oss << "  " << name << ".second = " << name << "_c.second;" << iendl;
175    oss << "  " << name << ".timestep = " << name << "_c.timestep;" << iendl;
176    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
177    oss << "}" << std::endl;
178
179    oss << iendl;
180
181    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, cxios_duration* " << name << "_c)" << iendl;
182    oss << "{" << iendl;
183    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
184    oss << "  CDuration " << name << " = " << className << "_hdl->" << name << ".getInheritedValue();" << iendl;
185    oss << "  " << name << "_c->year = " << name << ".year;" << iendl;
186    oss << "  " << name << "_c->month = " << name << ".month;" << iendl;
187    oss << "  " << name << "_c->day = " << name << ".day;" << iendl;
188    oss << "  " << name << "_c->hour = " << name << ".hour;" << iendl;
189    oss << "  " << name << "_c->minute = " << name << ".minute;" << iendl;
190    oss << "  " << name << "_c->second = " << name << ".second;" << iendl;
191    oss << "  " << name << "_c->timestep = " << name << ".timestep;" << iendl;
192    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
193    oss << "}" << std::endl;
194  }
195
196#undef macro
197
198// /////////////////////////////////////////////////
199// //          Fortran 2003 Interface             //
200// /////////////////////////////////////////////////
201
202  void CInterface::AttributeIsDefinedFortran2003Interface(ostream& oss, const string& className, const string& name)
203  {
204    oss << "FUNCTION cxios_is_defined_" << className << "_" << name << "(" << className << "_hdl) BIND(C)" << iendl;
205    oss << "  USE ISO_C_BINDING" << iendl;
206    oss << "  LOGICAL(kind=C_BOOL) :: cxios_is_defined_" << className << "_" << name << iendl;
207    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
208    oss << "END FUNCTION cxios_is_defined_" << className << "_" << name << std::endl;
209  }
210
211  template <class T>
212  void CInterface::AttributeFortran2003Interface(ostream& oss, const string& className, const string& name)
213  {
214    string fortranType=getStrFortranType<T>();
215    string fortranKindC=getStrFortranKindC<T>();
216
217    oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
218    oss << "  USE ISO_C_BINDING" << iendl;
219    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
220    oss << "  " << fortranType << " " << fortranKindC << "      , VALUE :: " << name << iendl;
221    oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl;
222    oss << iendl;
223    oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
224    oss << "  USE ISO_C_BINDING" << iendl;
225    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
226    oss << "  " << fortranType << " " << fortranKindC << "             :: " << name << iendl;
227    oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl;
228  }
229
230  template <>
231  void CInterface::AttributeFortran2003Interface<string>(ostream& oss, const string& className, const string& name)
232  {
233    oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", " << name << "_size) BIND(C)" << iendl;
234    oss << "  USE ISO_C_BINDING" << iendl;
235    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
236    oss << "  CHARACTER(kind = C_CHAR)    , DIMENSION(*) :: " << name << iendl;
237    oss << "  INTEGER  (kind = C_INT)     , VALUE        :: " << name << "_size" << iendl;
238    oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl;
239    oss << iendl;
240    oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", " << name << "_size) BIND(C)" << iendl;
241    oss << "  USE ISO_C_BINDING" << iendl;
242    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
243    oss << "  CHARACTER(kind = C_CHAR)    , DIMENSION(*) :: " << name << iendl;
244    oss << "  INTEGER  (kind = C_INT)     , VALUE        :: " << name << "_size" << iendl;
245    oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl;
246  }
247
248  template <>
249  void CInterface::AttributeFortran2003Interface<CDate>(ostream& oss, const string& className, const string& name)
250  {
251    oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
252    oss << "  USE ISO_C_BINDING" << iendl;
253    oss << "  USE IDATE" << iendl;
254    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
255    oss << "  TYPE(txios(date)), VALUE :: " << name << iendl;
256    oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl;
257    oss << iendl;
258    oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
259    oss << "  USE ISO_C_BINDING" << iendl;
260    oss << "  USE IDATE" << iendl;
261    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
262    oss << "  TYPE(txios(date)) :: " << name << iendl;
263    oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl;
264  }
265
266  template <>
267  void CInterface::AttributeFortran2003Interface<CDuration>(ostream& oss, const string& className, const string& name)
268  {
269    oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
270    oss << "  USE ISO_C_BINDING" << iendl;
271    oss << "  USE IDURATION" << iendl;
272    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
273    oss << "  TYPE(txios(duration)), VALUE :: " << name << iendl;
274    oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl;
275    oss << iendl;
276    oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
277    oss << "  USE ISO_C_BINDING" << iendl;
278    oss << "  USE IDURATION" << iendl;
279    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
280    oss << "  TYPE(txios(duration)) :: " << name << iendl;
281    oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl;
282  }
283
284  template <class T>
285  void CInterface::AttributeFortranInterfaceDeclaration(ostream& oss, const string& className, const string& name)
286  {
287    oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(IN) :: " << name;
288    if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " :: " << name << "_tmp";
289  }
290
291  template <class T>
292  void CInterface::AttributeFortranInterfaceGetDeclaration(ostream& oss, const string& className, const string& name)
293  {
294    oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(OUT) :: " << name;
295    if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " :: " << name << "_tmp";
296  }
297
298  void CInterface::AttributeFortranInterfaceIsDefinedDeclaration(ostream& oss, const string& className, const string& name)
299  {
300    oss << "LOGICAL, OPTIONAL, INTENT(OUT) :: " << name << iendl;
301    oss << "LOGICAL(KIND=C_BOOL) :: " << name << "_tmp";
302  }
303
304  template <>
305  void CInterface::AttributeFortranInterfaceDeclaration<string>(ostream& oss, const string& className, const string& name)
306  {
307    oss << "CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: " << name;
308  }
309
310  template <>
311  void CInterface::AttributeFortranInterfaceGetDeclaration<string>(ostream& oss, const string& className, const string& name)
312  {
313    oss << "CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: " << name;
314  }
315
316  template <class T>
317  void CInterface::AttributeFortranInterfaceBody(ostream& oss, const string& className, const string& name)
318  {
319    string name_tmp=name+"__tmp";
320
321    oss << "IF (PRESENT(" << name << "_)) THEN" << iendl;
322    if (!matchingTypeCFortran<T>())
323    {
324      oss << "  " << name_tmp << " = " << name << "_" << iendl;
325      oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ")" << iendl;
326    }
327    else oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_)" << iendl;
328    oss << "ENDIF";
329  }
330
331  template <class T>
332  void CInterface::AttributeFortranInterfaceGetBody(ostream& oss, const string& className, const string& name)
333  {
334    string name_tmp=name+"__tmp";
335
336    oss << "IF (PRESENT(" << name << "_)) THEN" << iendl;
337    if (!matchingTypeCFortran<T>())
338    {
339      oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ")" << iendl;
340      oss << "  " << name << "_ = " << name_tmp << iendl;
341    }
342    else oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_)" << iendl;
343    oss << "ENDIF";
344  }
345
346  void CInterface::AttributeFortranInterfaceIsDefinedBody(ostream& oss, const string& className, const string& name)
347  {
348    string name_tmp=name+"__tmp";
349
350    oss << "IF (PRESENT(" << name << "_)) THEN" << iendl;
351    oss << "  " << name << "__tmp = cxios_is_defined_" << className << "_" << name << "(" << className << "_hdl%daddr)" << iendl;
352    oss << "  " << name << "_ = " << name_tmp << iendl;
353    oss << "ENDIF";
354  }
355
356  template <>
357  void CInterface::AttributeFortranInterfaceBody<string>(ostream& oss, const string& className, const string& name)
358  {
359    oss << "IF (PRESENT(" << name << "_)) THEN" << iendl;
360    oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, len(" << name << "_))" << iendl;
361    oss << "ENDIF";
362  }
363
364  template <>
365  void CInterface::AttributeFortranInterfaceGetBody<string>(ostream& oss, const string& className, const string& name)
366  {
367    oss << "IF (PRESENT(" << name << "_)) THEN" << iendl;
368    oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, len(" << name << "_))" << iendl;
369    oss << "ENDIF";
370  }
371
372// declaration for CArray
373
374#define macro(T) \
375  template <> \
376  void CInterface::AttributeCInterface<CArray<T,1> >(ostream& oss, const string& className, const string& name) \
377  { \
378    string typeName=getStrType<T>(); \
379\
380    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1)" << iendl; \
381    oss << "{" << iendl; \
382    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
383    oss << "  CArray<" << typeName << ",1> tmp(" << name << ", shape(extent1), neverDeleteData);" << iendl; \
384    oss << "  " << className << "_hdl->" << name << ".reference(tmp.copy());" << iendl; \
385    /*oss << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl;*/ \
386    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
387    oss << "}" << std::endl; \
388    oss << iendl; \
389    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1)" << iendl; \
390    oss << "{" << iendl; \
391    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
392    oss << "  CArray<" << typeName << ",1> tmp(" << name << ", shape(extent1), neverDeleteData);" << iendl; \
393    oss << "  tmp=" << className << "_hdl->" << name << ".getInheritedValue();" << iendl; \
394    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
395    oss << "}" << std::endl; \
396  } \
397\
398  template <> \
399  void CInterface::AttributeCInterface<CArray<T,2> >(ostream& oss, const string& className, const string& name) \
400  { \
401    string typeName=getStrType<T>(); \
402\
403    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2)" << iendl; \
404    oss << "{" << iendl; \
405    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
406    oss << "  CArray<" << typeName << ",2> tmp(" << name << ", shape(extent1, extent2), neverDeleteData);" << iendl; \
407    oss << "  " << className << "_hdl->" << name << ".reference(tmp.copy());" << iendl; \
408    /*oss << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl;*/ \
409    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
410    oss << "}" << std::endl; \
411    oss << iendl; \
412    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2)" << iendl; \
413    oss << "{" << iendl; \
414    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
415    oss << "  CArray<" << typeName << ",2> tmp(" << name << ", shape(extent1, extent2), neverDeleteData);" << iendl; \
416    oss << "  tmp=" << className << "_hdl->" << name << ".getInheritedValue();" << iendl; \
417    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
418    oss << "}" << std::endl; \
419  } \
420\
421  template <> \
422  void CInterface::AttributeCInterface<CArray<T,3> >(ostream& oss, const string& className, const string& name) \
423  { \
424    string typeName=getStrType<T>(); \
425\
426    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2, int extent3)" << iendl; \
427    oss << "{" << iendl; \
428    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
429    oss << "  CArray<" << typeName << ",3> tmp(" << name << ", shape(extent1, extent2, extent3), neverDeleteData);" << iendl; \
430    oss << "  " << className << "_hdl->" << name << ".reference(tmp.copy());" << iendl; \
431    /*oss << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl;*/ \
432    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
433    oss << "}" << std::endl; \
434    oss << iendl; \
435    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2, int extent3)" << iendl; \
436    oss << "{" << iendl; \
437    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
438    oss << "  CArray<" << typeName << ",3> tmp(" << name << ", shape(extent1, extent2, extent3), neverDeleteData);" << iendl; \
439    oss << "  tmp=" << className << "_hdl->" << name << ".getInheritedValue();" << iendl; \
440    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
441    oss << "}" << std::endl; \
442  }
443
444macro(bool)
445macro(double)
446macro(int)
447
448#undef macro
449
450// /////////////////////////////////////////////////
451// //          Fortran 2003 Interface             //
452// /////////////////////////////////////////////////
453
454#define macro(T) \
455  template <> \
456  void CInterface::AttributeFortran2003Interface<CArray<T,1> >(ostream& oss, const string& className, const string& name) \
457  { \
458    string fortranType=getStrFortranType<T>(); \
459    string fortranKindC=getStrFortranKindC<T>(); \
460      \
461    oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1) BIND(C)" << iendl; \
462    oss << "  USE ISO_C_BINDING" << iendl; \
463    oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
464    oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
465    oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
466    oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl; \
467    oss << iendl; \
468    oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1) BIND(C)" << iendl; \
469    oss << "  USE ISO_C_BINDING" << iendl; \
470    oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
471    oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
472    oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
473    oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl; \
474  } \
475 \
476  template <> \
477  void CInterface::AttributeFortran2003Interface<CArray<T,2> >(ostream& oss, const string& className, const string& name) \
478  { \
479    string fortranType=getStrFortranType<T>(); \
480    string fortranKindC=getStrFortranKindC<T>(); \
481      \
482    oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2) BIND(C)" << iendl; \
483    oss << "  USE ISO_C_BINDING" << iendl; \
484    oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
485    oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
486    oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
487    oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
488    oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl; \
489    oss << iendl; \
490    oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2) BIND(C)" << iendl; \
491    oss << "  USE ISO_C_BINDING" << iendl; \
492    oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
493    oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
494    oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
495    oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
496    oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl; \
497  } \
498    \
499  template <> \
500  void CInterface::AttributeFortran2003Interface<CArray<T,3> >(ostream& oss, const string& className, const string& name) \
501  { \
502    string fortranType=getStrFortranType<T>(); \
503    string fortranKindC=getStrFortranKindC<T>(); \
504      \
505    oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2, extent3) BIND(C)" << iendl; \
506    oss << "  USE ISO_C_BINDING" << iendl; \
507    oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
508    oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
509    oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
510    oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
511    oss << "  INTEGER (kind = C_INT), VALUE  :: extent3" << iendl; \
512    oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl; \
513    oss << iendl; \
514    oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2, extent3) BIND(C)" << iendl; \
515    oss << "  USE ISO_C_BINDING" << iendl; \
516    oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
517    oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
518    oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
519    oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
520    oss << "  INTEGER (kind = C_INT), VALUE  :: extent3" << iendl; \
521    oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl; \
522  }
523
524  macro(bool)
525  macro(double)
526  macro(int)
527
528  #undef macro
529
530#define macro(T) \
531  template <> \
532  void CInterface::AttributeFortranInterfaceDeclaration<CArray<T,1> >(ostream& oss, const string& className, const string& name) \
533  { \
534    oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(IN) :: " << name << "(:)"; \
535    if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:)"; \
536  } \
537  template <> \
538  void CInterface::AttributeFortranInterfaceGetDeclaration<CArray<T,1> >(ostream& oss, const string& className, const string& name) \
539  { \
540    oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(OUT) :: " << name << "(:)"; \
541    if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:)"; \
542  } \
543 \
544  template <> \
545  void CInterface::AttributeFortranInterfaceDeclaration<CArray<T,2> >(ostream& oss, const string& className, const string& name) \
546  { \
547    oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(IN) :: " << name << "(:,:)"; \
548    if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:)"; \
549  } \
550 \
551  template <> \
552  void CInterface::AttributeFortranInterfaceGetDeclaration<CArray<T,2> >(ostream& oss, const string& className, const string& name) \
553  { \
554    oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(OUT) :: " << name << "(:,:)"; \
555    if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:)"; \
556  } \
557 \
558  template <> \
559  void CInterface::AttributeFortranInterfaceDeclaration<CArray<T,3> >(ostream& oss, const string& className, const string& name) \
560  { \
561    oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(IN) :: " << name << "(:,:,:)"; \
562    if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:,:)"; \
563  } \
564 \
565  template <> \
566  void CInterface::AttributeFortranInterfaceGetDeclaration<CArray<T,3> >(ostream& oss, const string& className, const string& name) \
567  { \
568    oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(OUT) :: " << name << "(:,:,:)"; \
569    if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:,:)"; \
570  }
571
572  macro(bool)
573  macro(double)
574  macro(int)
575
576#undef macro
577
578#define macro(T) \
579  template <>  \
580  void CInterface::AttributeFortranInterfaceBody< CArray<T,1> >(ostream& oss, const string& className, const string& name) \
581  {  \
582    string name_tmp=name+"__tmp"; \
583      \
584    oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
585    if (!matchingTypeCFortran<T>())  \
586    { \
587      oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1)))" << iendl; \
588      oss << "  " << name_tmp << " = " << name << "_" << iendl; \
589      oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1))" << iendl; \
590    } \
591    else oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1))" << iendl; \
592    oss << "ENDIF"; \
593  } \
594 \
595  template <>  \
596  void CInterface::AttributeFortranInterfaceBody< CArray<T,2> >(ostream& oss, const string& className, const string& name) \
597  {  \
598    string name_tmp=name+"__tmp"; \
599      \
600    oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
601    if (!matchingTypeCFortran<T>())  \
602    { \
603      oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1), size(" << name << "_,2)))" << iendl; \
604      oss << "  " << name_tmp << " = " << name << "_" << iendl; \
605      oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1), size(" << name << "_,2))" << iendl; \
606    } \
607    else oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1), size(" << name << "_,2))" << iendl; \
608    oss << "ENDIF"; \
609  } \
610    \
611  template <>  \
612  void CInterface::AttributeFortranInterfaceBody< CArray<T,3> >(ostream& oss, const string& className, const string& name) \
613  {  \
614    string name_tmp=name+"__tmp"; \
615      \
616    oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
617    if (!matchingTypeCFortran<T>())  \
618    { \
619      oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3)))" << iendl; \
620      oss << "  " << name_tmp << " = " << name << "_" << iendl; \
621      oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3))" << iendl; \
622    } \
623    else oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3))" << iendl; \
624    oss << "ENDIF"; \
625  }
626
627  macro(bool)
628  macro(double)
629  macro(int)
630
631#undef macro
632
633#define macro(T) \
634  template <>  \
635  void CInterface::AttributeFortranInterfaceGetBody< CArray<T,1> >(ostream& oss, const string& className, const string& name) \
636  {  \
637    string name_tmp=name+"__tmp"; \
638      \
639    oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
640    if (!matchingTypeCFortran<T>())  \
641    { \
642      oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1)))" << iendl; \
643      oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1))" << iendl; \
644      oss << "  " << name << "_ = " << name_tmp << iendl; \
645    } \
646    else oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1))" << iendl; \
647    oss << "ENDIF"; \
648  } \
649 \
650  template <>  \
651  void CInterface::AttributeFortranInterfaceGetBody< CArray<T,2> >(ostream& oss, const string& className, const string& name) \
652  {  \
653    string name_tmp=name+"__tmp"; \
654      \
655    oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
656    if (!matchingTypeCFortran<T>())  \
657    { \
658      oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1), size(" << name << "_,2)))" << iendl; \
659      oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1), size(" << name << "_,2))" << iendl; \
660      oss << "  " << name << "_ = " << name_tmp << iendl; \
661    } \
662    else oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1), size(" << name << "_,2))" << iendl; \
663    oss << "ENDIF"; \
664  } \
665    \
666  template <>  \
667  void CInterface::AttributeFortranInterfaceGetBody< CArray<T,3> >(ostream& oss, const string& className, const string& name) \
668  {  \
669    string name_tmp=name+"__tmp"; \
670      \
671    oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
672    if (!matchingTypeCFortran<T>())  \
673    { \
674      oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3)))" << iendl; \
675      oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3))" << iendl; \
676      oss << "  " << name << "_ = " << name_tmp << iendl; \
677      } \
678    else oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3))" << iendl; \
679    oss << "ENDIF"; \
680  }
681
682  macro(bool)
683  macro(double)
684  macro(int)
685
686#undef macro
687}
688#endif
Note: See TracBrowser for help on using the repository browser.