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

Last change on this file since 650 was 591, checked in by rlacroix, 9 years ago

Remove leftovers from the XMLIO age.

  • 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: 55.0 KB
RevLine 
[313]1#ifndef __XIOS_GENERATE_INTERFACE_IMPL_HPP__
2#define __XIOS_GENERATE_INTERFACE_IMPL_HPP__
3
[591]4#include "xios_spl.hpp"
[313]5#include "generate_interface.hpp"
6#include "type_util.hpp"
7#include "indent.hpp"
[369]8#include "enum.hpp"
9#include "array_new.hpp"
[532]10#include "date.hpp"
[313]11
[335]12namespace xios
[509]13{
[581]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))"); }
[509]20
[581]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(""); }
[509]27
[581]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(""); }
[509]34
[581]35  template<> bool CInterface::matchingTypeCFortran<int>(void) { return true; }
36  template<> bool CInterface::matchingTypeCFortran<bool>(void) { return false; }
[352]37  template<> bool CInterface::matchingTypeCFortran<double>(void) { return true; }
38  template<> bool CInterface::matchingTypeCFortran<float>(void) { return true; }
[532]39  template<> bool CInterface::matchingTypeCFortran<CDate>(void) { return true; }
[537]40  template<> bool CInterface::matchingTypeCFortran<CDuration>(void) { return true; }
[313]41
42// /////////////////////////////////////////////////
43// //                 C Interface                 //
44// /////////////////////////////////////////////////
45
[581]46  void CInterface::AttributeIsDefinedCInterface(ostream& oss, const string& className, const string& name)
[432]47  {
[581]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;
[432]55  }
[509]56
[313]57  template <class T>
[581]58  void CInterface::AttributeCInterface(ostream& oss, const string& className, const string& name)
[313]59  {
[581]60    string typeName = getStrType<T>();
[509]61
[581]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 << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl;
67    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
68    oss << "}" << std::endl;
[509]69
[581]70    oss << iendl;
71    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ")" << iendl;
72    oss << "{" << iendl;
73    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
74    oss << "  *" << name << " = " << className << "_hdl->" << name << ".getInheritedValue();" << iendl;
75    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
76    oss << "}" << std::endl;
[313]77  }
[509]78
[313]79  template<>
[581]80  void CInterface::AttributeCInterface<string>(ostream& oss, const string& className, const string& name)
[313]81  {
[581]82    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, const char * " << name << ", int " << name << "_size)" << iendl;
83    oss << "{" << iendl;
84    oss << "  std::string " << name << "_str;" << iendl;
85    oss << "  if (!cstr2string(" << name << ", " << name << "_size, " << name << "_str)) return;" << iendl;
86    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
87    oss << "  " << className << "_hdl->" << name << ".setValue(" << name << "_str);" << iendl;
88//  oss << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl;
89    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
90    oss << "}" << std::endl;
[509]91
[581]92    oss << iendl;
[509]93
[581]94    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, char * " << name << ", int " << name << "_size)" << iendl;
95    oss << "{" << iendl;
96    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
97    oss << "  if (!string_copy(" << className << "_hdl->" << name << ".getInheritedValue(), " << name << ", " << name << "_size))" << iendl;
98    oss << "    ERROR(\"void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, char * " << name << ", int "
99       << name << "_size)\", << \"Input string is too short\");" << iendl;
100    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
101    oss << "}" << std::endl;
[313]102  }
103
[369]104  template<>
[581]105  void CInterface::AttributeCInterface<CEnumBase>(ostream& oss, const string& className, const string& name)
[369]106  {
[581]107    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, const char * " << name << ", int " << name << "_size)" << iendl;
108    oss << "{" << iendl;
109    oss << "  std::string " << name << "_str;" << iendl;
110    oss << "  if (!cstr2string(" << name << ", " << name << "_size, " << name << "_str)) return;" << iendl;
111    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
112    oss << "  " << className << "_hdl->" << name << ".fromString(" << name << "_str);" << iendl;
113//  oss << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl;
114    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
115    oss << "}" << std::endl;
[509]116
[581]117    oss << iendl;
[509]118
[581]119    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, char * " << name << ", int " << name << "_size)" << iendl;
120    oss << "{" << iendl;
121    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
122    oss << "  if (!string_copy(" << className << "_hdl->" << name << ".getInheritedStringValue(), " << name << ", " << name << "_size))" << iendl;
123    oss << "    ERROR(\"void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, char * " << name << ", int "
124       << name << "_size)\", << \"Input string is too short\");" << iendl;
125    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
126    oss << "}" << std::endl;
[369]127  }
[313]128
[532]129  template<>
[581]130  void CInterface::AttributeCInterface<CDate>(ostream& oss, const string& className, const string& name)
[532]131  {
132    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, cxios_date " << name << "_c)" << iendl;
133    oss << "{" << iendl;
134    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
135    oss << "  " << className << "_hdl->" << name << ".allocate();" << iendl;
[581]136    oss << "  CDate& " << name << " = " << className << "_hdl->" << name << ".get();" << iendl;
[532]137    oss << "  " << name << ".setDate(" << name << "_c.year," << iendl;
138    oss << "                         " << name << "_c.month," << iendl;
139    oss << "                         " << name << "_c.day," << iendl;
140    oss << "                         " << name << "_c.hour," << iendl;
141    oss << "                         " << name << "_c.minute," << iendl;
142    oss << "                         " << name << "_c.second);" << iendl;
143    oss << "  if (" << name << ".hasRelCalendar())" << iendl;
144    oss << "    " << name << ".checkDate();" << iendl;
145    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
[581]146    oss << "}" << std::endl;
[532]147
148    oss << iendl;
149
150    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, cxios_date* " << name << "_c)" << iendl;
151    oss << "{" << iendl;
152    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
[581]153    oss << "  CDate " << name << " = " << className << "_hdl->" << name << ".getInheritedValue();" << iendl;
[532]154    oss << "  " << name << "_c->year = " << name << ".getYear();" << iendl;
155    oss << "  " << name << "_c->month = " << name << ".getMonth();" << iendl;
156    oss << "  " << name << "_c->day = " << name << ".getDay();" << iendl;
157    oss << "  " << name << "_c->hour = " << name << ".getHour();" << iendl;
158    oss << "  " << name << "_c->minute = " << name << ".getMinute();" << iendl;
159    oss << "  " << name << "_c->second = " << name << ".getSecond();" << iendl;
160    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
[581]161    oss << "}" << std::endl;
[532]162  }
163
[537]164  template<>
[581]165  void CInterface::AttributeCInterface<CDuration>(ostream& oss, const string& className, const string& name)
[537]166  {
167    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, cxios_duration " << name << "_c)" << iendl;
168    oss << "{" << iendl;
169    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
170    oss << "  " << className << "_hdl->" << name << ".allocate();" << iendl;
[581]171    oss << "  CDuration& " << name << " = " << className << "_hdl->" << name << ".get();" << iendl;
[537]172    oss << "  " << name << ".year = " << name << "_c.year;" << iendl;
173    oss << "  " << name << ".month = " << name << "_c.month;" << iendl;
174    oss << "  " << name << ".day = " << name << "_c.day;" << iendl;
175    oss << "  " << name << ".hour = " << name << "_c.hour;" << iendl;
176    oss << "  " << name << ".minute = " << name << "_c.minute;" << iendl;
177    oss << "  " << name << ".second = " << name << "_c.second;" << iendl;
178    oss << "  " << name << ".timestep = " << name << "_c.timestep;" << iendl;
179    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
[581]180    oss << "}" << std::endl;
[537]181
182    oss << iendl;
183
184    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, cxios_duration* " << name << "_c)" << iendl;
185    oss << "{" << iendl;
186    oss << "  CTimer::get(\"XIOS\").resume();" << iendl;
[581]187    oss << "  CDuration " << name << " = " << className << "_hdl->" << name << ".getInheritedValue();" << iendl;
[537]188    oss << "  " << name << "_c->year = " << name << ".year;" << iendl;
189    oss << "  " << name << "_c->month = " << name << ".month;" << iendl;
190    oss << "  " << name << "_c->day = " << name << ".day;" << iendl;
191    oss << "  " << name << "_c->hour = " << name << ".hour;" << iendl;
192    oss << "  " << name << "_c->minute = " << name << ".minute;" << iendl;
193    oss << "  " << name << "_c->second = " << name << ".second;" << iendl;
194    oss << "  " << name << "_c->timestep = " << name << ".timestep;" << iendl;
195    oss << "  CTimer::get(\"XIOS\").suspend();" << iendl;
[581]196    oss << "}" << std::endl;
[537]197  }
198
[369]199/*
[313]200#define macro(T) \
[581]201  template <> \
202  void CInterface::AttributeCInterface<ARRAY(T,1)>(ostream& oss, const string& className, const string& name) \
203  { \
204    string typeName=getStrType<T>(); \
[313]205\
[581]206    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1)" << iendl; \
207    oss << "{" << iendl; \
208    oss << "   CTimer::get(\"XIOS\").resume();" << iendl; \
209    oss << "  ARRAY(" << typeName << ",1) array_tmp(new CArray<" << typeName << ",1>(boost::extents[extent1]));" << iendl; \
210    oss << "  std::copy(" << name << ", &(" << name << "[array_tmp->num_elements()]), array_tmp->data());" << iendl; \
211    oss << "  " << className << "_hdl->" << name << ".setValue(array_tmp);" << iendl; \
212//  oss << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl; \
213    oss << "}" << std::endl; \
214    oss << iendl; \
215    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1)" << iendl; \
216    oss << "{" << iendl; \
217    oss << "  if (!array_copy(" << className << "_hdl->" << name << ".getValue(), " << name << ", extent1))" << iendl; \
218    oss << "   ERROR(\"void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1)\", << " \
219       << "\"Output array size is not conform to array size attribute\");" << iendl; \
220    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
221    oss << "}" << std::endl; \
222  } \
[313]223\
224  template <> \
[581]225  void CInterface::AttributeCInterface<ARRAY(T,2)>(ostream& oss, const string& className, const string& name) \
226  { \
227    string typeName=getStrType<T>(); \
[313]228\
[581]229    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2)" << iendl; \
230    oss << "{" << iendl; \
231    oss << "   CTimer::get(\"XIOS\").resume();" << iendl; \
232    oss << "  ARRAY(" << typeName << ",2) array_tmp(new CArray<" << typeName << ",2>(boost::extents[extent1][extent2]));" << iendl; \
233    oss << "  std::copy(" << name << ", &(" << name << "[array_tmp->num_elements()]), array_tmp->data());" << iendl; \
234    oss << "  " << className << "_hdl->" << name << ".setValue(array_tmp);" << iendl; \
235//  oss << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl; \
236    oss << "}" << std::endl; \
237    oss << iendl; \
238    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2)" << iendl; \
239    oss << "{" << iendl; \
240    oss << "  if (!array_copy(" << className << "_hdl->" << name << ".getValue(), " << name << ", extent1, extent2))" << iendl; \
241    oss << "   ERROR(\"void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2)\", << " \
242       << "\"Output array size is not conform to array size attribute\");" << iendl; \
243    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
244    oss << "}" << std::endl; \
245  } \
[313]246\
[581]247  template <> \
248  void CInterface::AttributeCInterface<ARRAY(T,3)>(ostream& oss, const string& className, const string& name) \
249  { \
250    string typeName=getStrType<T>(); \
[313]251\
[581]252    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2, int extent3)" << iendl; \
253    oss << "{" << iendl; \
254    oss << "   CTimer::get(\"XIOS\").resume();" << iendl; \
255    oss << "  ARRAY(" << typeName << ",3) array_tmp(new CArray<" << typeName << ",3>(boost::extents[extent1][extent2][extent3]));" << iendl; \
256    oss << "  std::copy(" << name << ", &(" << name << "[array_tmp->num_elements()]), array_tmp->data());" << iendl; \
257    oss << "  " << className << "_hdl->" << name << ".setValue(array_tmp);" << iendl; \
258//  oss << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl; \
259    oss << "}" << std::endl; \
260    oss << iendl; \
261    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2, int extent3)" << iendl; \
262    oss << "{" << iendl; \
263    oss << "  if (!array_copy(" << className << "_hdl->" << name << ".getValue(), " << name << ", extent1))" << iendl; \
264    oss << "   ERROR(\"void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2, int extent3)\", << " \
265       << "\"Output array size is not conform to array size attribute\");" << iendl; \
266    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
267    oss << "}" << std::endl; \
[313]268  }
269
270macro(bool)
271macro(double)
272macro(int)
[369]273*/
[313]274
[509]275#undef macro
[313]276
277// /////////////////////////////////////////////////
278// //          Fortran 2003 Interface             //
279// /////////////////////////////////////////////////
[581]280   void CInterface::AttributeIsDefinedFortran2003Interface(ostream& oss, const string& className, const string& name)
[432]281   {
[581]282     oss << "FUNCTION cxios_is_defined_" << className << "_" << name << "(" << className << "_hdl) BIND(C)" << iendl;
283     oss << "  USE ISO_C_BINDING" << iendl;
284     oss << "  LOGICAL(kind=C_BOOL) :: cxios_is_defined_" << className << "_" << name << iendl;
285     oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
286     oss << "END FUNCTION cxios_is_defined_" << className << "_" << name << std::endl;
[432]287   }
[509]288
[313]289   template <class T>
[581]290   void CInterface::AttributeFortran2003Interface(ostream& oss, const string& className, const string& name)
[313]291   {
[581]292     string fortranType=getStrFortranType<T>();
293     string fortranKindC=getStrFortranKindC<T>();
[509]294
[581]295     oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
296     oss << "  USE ISO_C_BINDING" << iendl;
297     oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
298     oss << "  " << fortranType << " " << fortranKindC << "      , VALUE :: " << name << iendl;
299     oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl;
300     oss << iendl;
301     oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
302     oss << "  USE ISO_C_BINDING" << iendl;
303     oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
304     oss << "  " << fortranType << " " << fortranKindC << "             :: " << name << iendl;
305     oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl;
[313]306   }
[509]307
[313]308   template <>
[581]309   void CInterface::AttributeFortran2003Interface<string>(ostream& oss, const string& className, const string& name)
[313]310   {
[581]311     oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", " << name << "_size) BIND(C)" << iendl;
312     oss << "  USE ISO_C_BINDING" << iendl;
313     oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
314     oss << "  CHARACTER(kind = C_CHAR)    , DIMENSION(*) :: " << name << iendl;
315     oss << "  INTEGER  (kind = C_INT)     , VALUE        :: " << name << "_size" << iendl;
316     oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl;
317     oss << iendl;
318     oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", " << name << "_size) BIND(C)" << iendl;
319     oss << "  USE ISO_C_BINDING" << iendl;
320     oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
321     oss << "  CHARACTER(kind = C_CHAR)    , DIMENSION(*) :: " << name << iendl;
322     oss << "  INTEGER  (kind = C_INT)     , VALUE        :: " << name << "_size" << iendl;
323     oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl;
[313]324   }
[369]325
[532]326  template <>
327  void CInterface::AttributeFortran2003Interface<CDate>(ostream& oss, const string& className, const string& name)
328  {
329    oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
330    oss << "  USE ISO_C_BINDING" << iendl;
331    oss << "  USE IDATE" << iendl;
332    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
[537]333    oss << "  TYPE(txios(date)), VALUE :: " << name << iendl;
[581]334    oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl;
[532]335    oss << iendl;
336    oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
337    oss << "  USE ISO_C_BINDING" << iendl;
338    oss << "  USE IDATE" << iendl;
339    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
340    oss << "  TYPE(txios(date)) :: " << name << iendl;
[581]341    oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl;
[532]342  }
343
[537]344  template <>
345  void CInterface::AttributeFortran2003Interface<CDuration>(ostream& oss, const string& className, const string& name)
346  {
347    oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
348    oss << "  USE ISO_C_BINDING" << iendl;
[545]349    oss << "  USE IDURATION" << iendl;
[537]350    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
351    oss << "  TYPE(txios(duration)), VALUE :: " << name << iendl;
[581]352    oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl;
[537]353    oss << iendl;
354    oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ") BIND(C)" << iendl;
355    oss << "  USE ISO_C_BINDING" << iendl;
[545]356    oss << "  USE IDURATION" << iendl;
[537]357    oss << "  INTEGER (kind = C_INTPTR_T), VALUE :: " << className << "_hdl" << iendl;
358    oss << "  TYPE(txios(duration)) :: " << name << iendl;
[581]359    oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl;
[537]360  }
361
[369]362/*
[581]363#define macro(T) \
364   template <> \
365   void CInterface::AttributeFortran2003Interface<ARRAY(T,1)>(ostream& oss, const string& className, const string& name) \
[313]366   { \
[581]367     string fortranType=getStrFortranType<T>(); \
368     string fortranKindC=getStrFortranKindC<T>(); \
[313]369      \
[581]370     oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1) BIND(C)" << iendl; \
371     oss << "  USE ISO_C_BINDING" << iendl; \
372     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
373     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
374     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
375     oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl; \
376     oss << iendl; \
377     oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1) BIND(C)" << iendl; \
378     oss << "  USE ISO_C_BINDING" << iendl; \
379     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
380     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
381     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
382     oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl; \
[313]383   } \
384 \
385   template <> \
[581]386   void CInterface::AttributeFortran2003Interface<ARRAY(T,2)>(ostream& oss, const string& className, const string& name) \
[313]387   { \
[581]388     string fortranType=getStrFortranType<T>(); \
389     string fortranKindC=getStrFortranKindC<T>(); \
[313]390      \
[581]391     oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2) BIND(C)" << iendl; \
392     oss << "  USE ISO_C_BINDING" << iendl; \
393     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
394     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
395     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
396     oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
397     oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl; \
398     oss << iendl; \
399     oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2) BIND(C)" << iendl; \
400     oss << "  USE ISO_C_BINDING" << iendl; \
401     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
402     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
403     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
404     oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
405     oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl; \
[313]406   } \
407     \
408   template <> \
[581]409   void CInterface::AttributeFortran2003Interface<ARRAY(T,3)>(ostream& oss, const string& className, const string& name) \
[313]410   { \
[581]411     string fortranType=getStrFortranType<T>(); \
412     string fortranKindC=getStrFortranKindC<T>(); \
[313]413      \
[581]414     oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2, extent3) BIND(C)" << iendl; \
415     oss << "  USE ISO_C_BINDING" << iendl; \
416     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
417     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
418     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
419     oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
420     oss << "  INTEGER (kind = C_INT), VALUE  :: extent3" << iendl; \
421     oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl; \
422     oss << iendl; \
423     oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2, extent3) BIND(C)" << iendl; \
424     oss << "  USE ISO_C_BINDING" << iendl; \
425     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
426     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
427     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
428     oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
429     oss << "  INTEGER (kind = C_INT), VALUE  :: extent3" << iendl; \
430     oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl; \
[313]431   }
[509]432
[313]433  macro(bool)
434  macro(double)
435  macro(int)
[369]436
[313]437  #undef macro
[509]438*/
[313]439   template <class T>
[581]440   void CInterface::AttributeFortranInterfaceDeclaration(ostream& oss, const string& className, const string& name)
[313]441   {
[581]442     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(IN) :: " << name;
443     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " :: " << name << "_tmp";
[313]444   }
445
446   template <class T>
[581]447   void CInterface::AttributeFortranInterfaceGetDeclaration(ostream& oss, const string& className, const string& name)
[313]448   {
[581]449     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(OUT) :: " << name;
450     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " :: " << name << "_tmp";
[313]451   }
[509]452
[581]453   void CInterface::AttributeFortranInterfaceIsDefinedDeclaration(ostream& oss, const string& className, const string& name)
[432]454   {
[581]455     oss << "LOGICAL, OPTIONAL, INTENT(OUT) :: " << name << iendl;
456     oss << "LOGICAL(KIND=C_BOOL) :: " << name << "_tmp";
[432]457   }
[509]458
[313]459   template <>
[581]460   void CInterface::AttributeFortranInterfaceDeclaration<string>(ostream& oss, const string& className, const string& name)
[313]461   {
[581]462     oss << "CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: " << name;
[313]463   }
[509]464
[313]465   template <>
[581]466   void CInterface::AttributeFortranInterfaceGetDeclaration<string>(ostream& oss, const string& className, const string& name)
[313]467   {
[581]468     oss << "CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: " << name;
[313]469   }
470
[369]471/*
[581]472#define macro(T) \
[313]473   template <> \
[581]474   void CInterface::AttributeFortranInterfaceDeclaration<ARRAY(T,1)>(ostream& oss, const string& className, const string& name) \
[313]475   { \
[581]476     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(IN) :: " << name << "(:)"; \
477     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:)"; \
[313]478   } \
479   template <> \
[581]480   void CInterface::AttributeFortranInterfaceGetDeclaration<ARRAY(T,1)>(ostream& oss, const string& className, const string& name) \
[313]481   { \
[581]482     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(OUT) :: " << name << "(:)"; \
483     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:)"; \
[313]484   } \
485 \
486   template <> \
[581]487   void CInterface::AttributeFortranInterfaceDeclaration<ARRAY(T,2)>(ostream& oss, const string& className, const string& name) \
[313]488   { \
[581]489     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(IN) :: " << name << "(:,:)"; \
490     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:)"; \
[313]491   } \
492 \
493   template <> \
[581]494   void CInterface::AttributeFortranInterfaceGetDeclaration<ARRAY(T,2)>(ostream& oss, const string& className, const string& name) \
[313]495   { \
[581]496     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(OUT) :: " << name << "(:,:)"; \
497     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:)"; \
[313]498   } \
499 \
500   template <> \
[581]501   void CInterface::AttributeFortranInterfaceDeclaration<ARRAY(T,3)>(ostream& oss, const string& className, const string& name) \
[313]502   { \
[581]503     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(IN) :: " << name << "(:,:,:)"; \
504     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:,:)"; \
505   } \
[313]506 \
507   template <> \
[581]508   void CInterface::AttributeFortranInterfaceGetDeclaration<ARRAY(T,3)>(ostream& oss, const string& className, const string& name) \
[313]509   { \
[581]510     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(OUT) :: " << name << "(:,:,:)"; \
511     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:,:)"; \
[509]512   }
513
[313]514  macro(bool)
515  macro(double)
516  macro(int)
517
518#undef macro
[369]519*/
[509]520
[313]521   template <class T>
[581]522   void CInterface::AttributeFortranInterfaceBody(ostream& oss, const string& className, const string& name)
[313]523   {
[581]524     string name_tmp=name+"__tmp";
[509]525
[581]526     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl;
[509]527     if (!matchingTypeCFortran<T>())
[313]528     {
[581]529       oss << "  " << name_tmp << " = " << name << "_" << iendl;
530       oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ")" << iendl;
[313]531     }
[581]532     else oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_)" << iendl;
533     oss << "ENDIF";
[313]534   }
[509]535
[313]536   template <class T>
[581]537   void CInterface::AttributeFortranInterfaceGetBody(ostream& oss, const string& className, const string& name)
[313]538   {
[581]539     string name_tmp=name+"__tmp";
[509]540
[581]541     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl;
[509]542     if (!matchingTypeCFortran<T>())
[313]543     {
[581]544       oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ")" << iendl;
545       oss << "  " << name << "_ = " << name_tmp << iendl;
[313]546     }
[581]547     else oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_)" << iendl;
548     oss << "ENDIF";
[313]549   }
[432]550
[581]551   void CInterface::AttributeFortranInterfaceIsDefinedBody(ostream& oss, const string& className, const string& name)
[432]552   {
[581]553     string name_tmp=name+"__tmp";
[509]554
[581]555     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl;
556     oss << "  " << name << "__tmp = cxios_is_defined_" << className << "_" << name << "(" << className << "_hdl%daddr)" << iendl;
557     oss << "  " << name << "_ = " << name_tmp << iendl;
558     oss << "ENDIF";
[432]559   }
[509]560
[313]561   template <>
[581]562   void CInterface::AttributeFortranInterfaceBody<string>(ostream& oss, const string& className, const string& name)
[313]563   {
[581]564      oss << "IF (PRESENT(" << name << "_)) THEN" << iendl;
565      oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, len(" << name << "_))" << iendl;
566      oss << "ENDIF";
[313]567   }
568
569   template <>
[581]570   void CInterface::AttributeFortranInterfaceGetBody<string>(ostream& oss, const string& className, const string& name)
[313]571   {
[581]572      oss << "IF (PRESENT(" << name << "_)) THEN" << iendl;
573      oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, len(" << name << "_))" << iendl;
574      oss << "ENDIF";
[313]575   }
576
[369]577/*
[313]578#define macro(T) \
579   template <>  \
[581]580   void CInterface::AttributeFortranInterfaceBody< ARRAY(T,1) >(ostream& oss, const string& className, const string& name) \
[313]581   {  \
[581]582     string name_tmp=name+"__tmp"; \
[313]583      \
[581]584     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[313]585     if (!matchingTypeCFortran<T>())  \
586     { \
[581]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; \
[313]590     } \
[581]591     else oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1))" << iendl; \
592     oss << "ENDIF"; \
[313]593   } \
594 \
595   template <>  \
[581]596   void CInterface::AttributeFortranInterfaceBody< ARRAY(T,2) >(ostream& oss, const string& className, const string& name) \
[313]597   {  \
[581]598     string name_tmp=name+"__tmp"; \
[313]599      \
[581]600     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[313]601     if (!matchingTypeCFortran<T>())  \
602     { \
[581]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; \
[313]606     } \
[581]607     else oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1), size(" << name << "_,2))" << iendl; \
608     oss << "ENDIF"; \
[313]609   } \
610    \
611   template <>  \
[581]612   void CInterface::AttributeFortranInterfaceBody< ARRAY(T,3) >(ostream& oss, const string& className, const string& name) \
[313]613   {  \
[581]614     string name_tmp=name+"__tmp"; \
[313]615      \
[581]616     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[313]617     if (!matchingTypeCFortran<T>())  \
618     { \
[581]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; \
[313]622     } \
[581]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"; \
[313]625   }
[509]626
[313]627  macro(bool)
628  macro(double)
629  macro(int)
630
631#undef macro
[369]632*/
[313]633
[369]634/*
[313]635#define macro(T) \
636   template <>  \
[581]637   void CInterface::AttributeFortranInterfaceGetBody< ARRAY(T,1) >(ostream& oss, const string& className, const string& name) \
[313]638   {  \
[581]639     string name_tmp=name+"__tmp"; \
[313]640      \
[581]641     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[313]642     if (!matchingTypeCFortran<T>())  \
643     { \
[581]644       oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1)))" << iendl; \
645       oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1))" << iendl; \
646       oss << "  " << name << "_ = " << name_tmp << iendl; \
[313]647     } \
[581]648     else oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1))" << iendl; \
649     oss << "ENDIF"; \
[313]650   } \
651 \
652   template <>  \
[581]653   void CInterface::AttributeFortranInterfaceGetBody< ARRAY(T,2) >(ostream& oss, const string& className, const string& name) \
[313]654   {  \
[581]655     string name_tmp=name+"__tmp"; \
[313]656      \
[581]657     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[313]658     if (!matchingTypeCFortran<T>())  \
659     { \
[581]660       oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1), size(" << name << "_,2)))" << iendl; \
661       oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1), size(" << name << "_,2))" << iendl; \
662       oss << "  " << name << "_ = " << name_tmp << iendl; \
[313]663     } \
[581]664     else oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1), size(" << name << "_,2))" << iendl; \
665     oss << "ENDIF"; \
[313]666   } \
667    \
668   template <>  \
[581]669   void CInterface::AttributeFortranInterfaceGetBody< ARRAY(T,3) >(ostream& oss, const string& className, const string& name) \
[313]670   {  \
[581]671     string name_tmp=name+"__tmp"; \
[313]672      \
[581]673     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[313]674     if (!matchingTypeCFortran<T>())  \
675     { \
[581]676       oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3)))" << iendl; \
677       oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3))" << iendl; \
678       oss << "  " << name << "_ = " << name_tmp << iendl; \
[313]679      } \
[581]680     else oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3))" << iendl; \
681     oss << "ENDIF"; \
[313]682   }
[509]683
[313]684  macro(bool)
685  macro(double)
686  macro(int)
687
688#undef macro
[369]689*/
690
691// declaration for CArray
692
693#define macro(T) \
[581]694  template <> \
695  void CInterface::AttributeCInterface<CArray<T,1> >(ostream& oss, const string& className, const string& name) \
696  { \
697    string typeName=getStrType<T>(); \
[369]698\
[581]699    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1)" << iendl; \
700    oss << "{" << iendl; \
701    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
702    oss << "  CArray<" << typeName << ",1> tmp(" << name << ", shape(extent1), neverDeleteData);" << iendl; \
703    oss << "  " << className << "_hdl->" << name << ".reference(tmp.copy());" << iendl; \
704    /*oss << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl;*/ \
705    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
706    oss << "}" << std::endl; \
707    oss << iendl; \
708    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1)" << iendl; \
709    oss << "{" << iendl; \
710    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
711    oss << "  CArray<" << typeName << ",1> tmp(" << name << ", shape(extent1), neverDeleteData);" << iendl; \
712    oss << "  tmp=" << className << "_hdl->" << name << ".getInheritedValue();" << iendl; \
713    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
714    oss << "}" << std::endl; \
715  } \
[369]716\
717  template <> \
[581]718  void CInterface::AttributeCInterface<CArray<T,2> >(ostream& oss, const string& className, const string& name) \
719  { \
720    string typeName=getStrType<T>(); \
[369]721\
[581]722    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2)" << iendl; \
723    oss << "{" << iendl; \
724    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
725    oss << "  CArray<" << typeName << ",2> tmp(" << name << ", shape(extent1, extent2), neverDeleteData);" << iendl; \
726    oss << "  " << className << "_hdl->" << name << ".reference(tmp.copy());" << iendl; \
727    /*oss << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl;*/ \
728    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
729    oss << "}" << std::endl; \
730    oss << iendl; \
731    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2)" << iendl; \
732    oss << "{" << iendl; \
733    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
734    oss << "  CArray<" << typeName << ",2> tmp(" << name << ", shape(extent1, extent2), neverDeleteData);" << iendl; \
735    oss << "  tmp=" << className << "_hdl->" << name << ".getInheritedValue();" << iendl; \
736    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
737    oss << "}" << std::endl; \
738  } \
[369]739\
[581]740  template <> \
741  void CInterface::AttributeCInterface<CArray<T,3> >(ostream& oss, const string& className, const string& name) \
742  { \
743    string typeName=getStrType<T>(); \
[369]744\
[581]745    oss << "void cxios_set_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2, int extent3)" << iendl; \
746    oss << "{" << iendl; \
747    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
748    oss << "  CArray<" << typeName << ",3> tmp(" << name << ", shape(extent1, extent2, extent3), neverDeleteData);" << iendl; \
749    oss << "  " << className << "_hdl->" << name << ".reference(tmp.copy());" << iendl; \
750    /*oss << "  " << className << "_hdl->sendAttributToServer(" << className << "_hdl->" << name << ");" << iendl;*/ \
751    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
752    oss << "}" << std::endl; \
753    oss << iendl; \
754    oss << "void cxios_get_" << className << "_" << name << "(" << className << "_Ptr " << className << "_hdl, " << typeName << "* " << name << ", int extent1, int extent2, int extent3)" << iendl; \
755    oss << "{" << iendl; \
756    oss << "  CTimer::get(\"XIOS\").resume();" << iendl; \
757    oss << "  CArray<" << typeName << ",3> tmp(" << name << ", shape(extent1, extent2, extent3), neverDeleteData);" << iendl; \
758    oss << "  tmp=" << className << "_hdl->" << name << ".getInheritedValue();" << iendl; \
759    oss << "   CTimer::get(\"XIOS\").suspend();" << iendl; \
760    oss << "}" << std::endl; \
[369]761  }
762
763macro(bool)
764macro(double)
765macro(int)
766
[509]767#undef macro
[369]768
769// /////////////////////////////////////////////////
770// //          Fortran 2003 Interface             //
771// /////////////////////////////////////////////////
772
[581]773#define macro(T) \
774   template <> \
775   void CInterface::AttributeFortran2003Interface<CArray<T,1> >(ostream& oss, const string& className, const string& name) \
[369]776   { \
[581]777     string fortranType=getStrFortranType<T>(); \
778     string fortranKindC=getStrFortranKindC<T>(); \
[369]779      \
[581]780     oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1) BIND(C)" << iendl; \
781     oss << "  USE ISO_C_BINDING" << iendl; \
782     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
783     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
784     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
785     oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl; \
786     oss << iendl; \
787     oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1) BIND(C)" << iendl; \
788     oss << "  USE ISO_C_BINDING" << iendl; \
789     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
790     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
791     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
792     oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl; \
[369]793   } \
794 \
795   template <> \
[581]796   void CInterface::AttributeFortran2003Interface<CArray<T,2> >(ostream& oss, const string& className, const string& name) \
[369]797   { \
[581]798     string fortranType=getStrFortranType<T>(); \
799     string fortranKindC=getStrFortranKindC<T>(); \
[369]800      \
[581]801     oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2) BIND(C)" << iendl; \
802     oss << "  USE ISO_C_BINDING" << iendl; \
803     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
804     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
805     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
806     oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
807     oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl; \
808     oss << iendl; \
809     oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2) BIND(C)" << iendl; \
810     oss << "  USE ISO_C_BINDING" << iendl; \
811     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
812     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
813     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
814     oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
815     oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl; \
[369]816   } \
817     \
818   template <> \
[581]819   void CInterface::AttributeFortran2003Interface<CArray<T,3> >(ostream& oss, const string& className, const string& name) \
[369]820   { \
[581]821     string fortranType=getStrFortranType<T>(); \
822     string fortranKindC=getStrFortranKindC<T>(); \
[369]823      \
[581]824     oss << "SUBROUTINE cxios_set_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2, extent3) BIND(C)" << iendl; \
825     oss << "  USE ISO_C_BINDING" << iendl; \
826     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
827     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
828     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
829     oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
830     oss << "  INTEGER (kind = C_INT), VALUE  :: extent3" << iendl; \
831     oss << "END SUBROUTINE cxios_set_" << className << "_" << name << std::endl; \
832     oss << iendl; \
833     oss << "SUBROUTINE cxios_get_" << className << "_" << name << "(" << className << "_hdl, " << name << ", extent1, extent2, extent3) BIND(C)" << iendl; \
834     oss << "  USE ISO_C_BINDING" << iendl; \
835     oss << "  INTEGER (kind = C_INTPTR_T), VALUE       :: " << className << "_hdl" << iendl; \
836     oss << "  " << fortranType << " " << fortranKindC << "     , DIMENSION(*) :: " << name << iendl; \
837     oss << "  INTEGER (kind = C_INT), VALUE  :: extent1" << iendl; \
838     oss << "  INTEGER (kind = C_INT), VALUE  :: extent2" << iendl; \
839     oss << "  INTEGER (kind = C_INT), VALUE  :: extent3" << iendl; \
840     oss << "END SUBROUTINE cxios_get_" << className << "_" << name << std::endl; \
[369]841   }
[509]842
[369]843  macro(bool)
844  macro(double)
845  macro(int)
[509]846
[369]847  #undef macro
848
[581]849#define macro(T) \
[369]850   template <> \
[581]851   void CInterface::AttributeFortranInterfaceDeclaration<CArray<T,1> >(ostream& oss, const string& className, const string& name) \
[369]852   { \
[581]853     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(IN) :: " << name << "(:)"; \
854     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:)"; \
[369]855   } \
856   template <> \
[581]857   void CInterface::AttributeFortranInterfaceGetDeclaration<CArray<T,1> >(ostream& oss, const string& className, const string& name) \
[369]858   { \
[581]859     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(OUT) :: " << name << "(:)"; \
860     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:)"; \
[369]861   } \
862 \
863   template <> \
[581]864   void CInterface::AttributeFortranInterfaceDeclaration<CArray<T,2> >(ostream& oss, const string& className, const string& name) \
[369]865   { \
[581]866     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(IN) :: " << name << "(:,:)"; \
867     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:)"; \
[369]868   } \
869 \
870   template <> \
[581]871   void CInterface::AttributeFortranInterfaceGetDeclaration<CArray<T,2> >(ostream& oss, const string& className, const string& name) \
[369]872   { \
[581]873     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(OUT) :: " << name << "(:,:)"; \
874     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:)"; \
[369]875   } \
876 \
877   template <> \
[581]878   void CInterface::AttributeFortranInterfaceDeclaration<CArray<T,3> >(ostream& oss, const string& className, const string& name) \
[369]879   { \
[581]880     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(IN) :: " << name << "(:,:,:)"; \
881     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:,:)"; \
882   } \
[369]883 \
884   template <> \
[581]885   void CInterface::AttributeFortranInterfaceGetDeclaration<CArray<T,3> >(ostream& oss, const string& className, const string& name) \
[369]886   { \
[581]887     oss << getStrFortranType<T>() << " " << getStrFortranKind<T>() << " , OPTIONAL, INTENT(OUT) :: " << name << "(:,:,:)"; \
888     if (!matchingTypeCFortran<T>()) oss << iendl << getStrFortranType<T>() << " " << getStrFortranKindC<T>() << " , ALLOCATABLE :: " << name << "_tmp(:,:,:)"; \
[509]889   }
890
[369]891  macro(bool)
892  macro(double)
893  macro(int)
894
895#undef macro
896
897#define macro(T) \
898   template <>  \
[581]899   void CInterface::AttributeFortranInterfaceBody< CArray<T,1> >(ostream& oss, const string& className, const string& name) \
[369]900   {  \
[581]901     string name_tmp=name+"__tmp"; \
[369]902      \
[581]903     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[369]904     if (!matchingTypeCFortran<T>())  \
905     { \
[581]906       oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1)))" << iendl; \
907       oss << "  " << name_tmp << " = " << name << "_" << iendl; \
908       oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1))" << iendl; \
[369]909     } \
[581]910     else oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1))" << iendl; \
911     oss << "ENDIF"; \
[369]912   } \
913 \
914   template <>  \
[581]915   void CInterface::AttributeFortranInterfaceBody< CArray<T,2> >(ostream& oss, const string& className, const string& name) \
[369]916   {  \
[581]917     string name_tmp=name+"__tmp"; \
[369]918      \
[581]919     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[369]920     if (!matchingTypeCFortran<T>())  \
921     { \
[581]922       oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1), size(" << name << "_,2)))" << iendl; \
923       oss << "  " << name_tmp << " = " << name << "_" << iendl; \
924       oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1), size(" << name << "_,2))" << iendl; \
[369]925     } \
[581]926     else oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1), size(" << name << "_,2))" << iendl; \
927     oss << "ENDIF"; \
[369]928   } \
929    \
930   template <>  \
[581]931   void CInterface::AttributeFortranInterfaceBody< CArray<T,3> >(ostream& oss, const string& className, const string& name) \
[369]932   {  \
[581]933     string name_tmp=name+"__tmp"; \
[369]934      \
[581]935     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[369]936     if (!matchingTypeCFortran<T>())  \
937     { \
[581]938       oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3)))" << iendl; \
939       oss << "  " << name_tmp << " = " << name << "_" << iendl; \
940       oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3))" << iendl; \
[369]941     } \
[581]942     else oss << "  CALL cxios_set_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3))" << iendl; \
943     oss << "ENDIF"; \
[369]944   }
[509]945
[369]946  macro(bool)
947  macro(double)
948  macro(int)
949
950#undef macro
951
952#define macro(T) \
953   template <>  \
[581]954   void CInterface::AttributeFortranInterfaceGetBody< CArray<T,1> >(ostream& oss, const string& className, const string& name) \
[369]955   {  \
[581]956     string name_tmp=name+"__tmp"; \
[369]957      \
[581]958     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[369]959     if (!matchingTypeCFortran<T>())  \
960     { \
[581]961       oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1)))" << iendl; \
962       oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1))" << iendl; \
963       oss << "  " << name << "_ = " << name_tmp << iendl; \
[369]964     } \
[581]965     else oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1))" << iendl; \
966     oss << "ENDIF"; \
[369]967   } \
968 \
969   template <>  \
[581]970   void CInterface::AttributeFortranInterfaceGetBody< CArray<T,2> >(ostream& oss, const string& className, const string& name) \
[369]971   {  \
[581]972     string name_tmp=name+"__tmp"; \
[369]973      \
[581]974     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[369]975     if (!matchingTypeCFortran<T>())  \
976     { \
[581]977       oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1), size(" << name << "_,2)))" << iendl; \
978       oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1), size(" << name << "_,2))" << iendl; \
979       oss << "  " << name << "_ = " << name_tmp << iendl; \
[369]980     } \
[581]981     else oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1), size(" << name << "_,2))" << iendl; \
982     oss << "ENDIF"; \
[369]983   } \
984    \
985   template <>  \
[581]986   void CInterface::AttributeFortranInterfaceGetBody< CArray<T,3> >(ostream& oss, const string& className, const string& name) \
[369]987   {  \
[581]988     string name_tmp=name+"__tmp"; \
[369]989      \
[581]990     oss << "IF (PRESENT(" << name << "_)) THEN" << iendl; \
[369]991     if (!matchingTypeCFortran<T>())  \
992     { \
[581]993       oss << "  ALLOCATE(" << name_tmp << "(size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3)))" << iendl; \
994       oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name_tmp << ", size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3))" << iendl; \
995       oss << "  " << name << "_ = " << name_tmp << iendl; \
[369]996      } \
[581]997     else oss << "  CALL cxios_get_" << className << "_" << name << "(" << className << "_hdl%daddr, " << name << "_, size(" << name << "_,1), size(" << name << "_,2), size(" << name << "_,3))" << iendl; \
998     oss << "ENDIF"; \
[369]999   }
[509]1000
[369]1001  macro(bool)
1002  macro(double)
1003  macro(int)
1004
1005#undef macro
[313]1006}
1007#endif
Note: See TracBrowser for help on using the repository browser.