Ignore:
Timestamp:
10/13/10 15:25:55 (14 years ago)
Author:
hozdoba
Message:

Début Interface c<->fortran

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/dev_rv/src/XMLIO/c_interface.cpp

    r128 r131  
    1 #include "xmlio.hpp" 
     1#include "c_interface.hpp" 
    22 
    3 using namespace XMLIOSERVER; 
    4 using namespace XMLIOSERVER::XML; 
     3/* ********************************************************** */ 
     4/*                      CONVERSION FUNCTION                   */ 
     5/* ********************************************************** */ 
    56 
    6 using namespace std; 
     7static inline std::string stringXtoStd(XString _str) 
     8{ 
     9   char * const temp = new char[_str.len+1](); 
     10   memset(temp, '\0', _str.len+1); 
     11   memcpy(temp, _str.str, _str.len); 
     12   std::string _retstr(temp); 
     13   size_t d = _retstr.find_first_not_of(' '); 
     14   size_t f = _retstr.find_last_not_of (' '); 
    715 
    8 extern "C" void main_c_(void) ; 
    9  
    10 // Cette fonction remplit un tableau à N dimensions de valeurs de type T (T = double ou float) de la maniÚre suivante : 
    11 // 0.0 1.0 2.0 3.0, puis 0.1 1.1 2.1 3.1 ... au second appel de la fonction, etc. 
    12 template <class T> 
    13    static void updateDataTest(T begin, T end) 
    14 { 
    15    static int called = 0; int i = 0; 
    16    for (T it = begin; it != end; it++, i++) 
    17       (*it) = i + called * 0.01; 
    18    called++; 
     16   delete[] temp; 
     17   return (_retstr.substr(d, f-d+1)); 
    1918} 
    2019 
    21 void main_c_ (void) 
     20static inline XString stringXtoStd(const std::string& _str) 
    2221{ 
    23    try 
    24    { 
    25       Array<double, 3> arr(100, 100, 20) ; // Initialisation des données (les arguments en fonction des dimensions). 
    26       string file("/local/XMLIOSERVER_DEV/dev_rv/test/iodef_simple_test.xml"); // Le fichier de définition. 
    27       ifstream istr( file.c_str() , ifstream::in ); 
     22   XString _retstr = {new char[_str.size()](), _str.size()}; 
     23   memcpy(_retstr.str, _str.c_str(), _str.size()); 
     24   return (_retstr); 
     25} 
    2826 
    29       // On commence la lecture du flux de donnée xml qui doit posséder pour racine un unique noeud nommé "simulation". 
    30       XMLNode node = XMLNode::CreateNode(istr, Context::GetRootName()); 
     27/* ********************************************************** */ 
     28/*                      HANDLE INTERFACE                      */ 
     29/* ********************************************************** */ 
    3130 
    32       // On parse le fichier xml noeud par noeud (ie on construit dynamiquement notre arbre d'objets). 
     31void xios_handle_create_(XHandle * _ret, const XDType * const _dtype, const XString * const _id) 
     32{ 
     33   try { 
     34      switch(*_dtype) 
     35      { 
     36         /*ECONTEXT, 
     37      EAXIS, EDOMAIN, EFIELD, EFILE, EGRID, 
     38      GAXIS, GDOMAIN, GFIELD, GFILE, GGRID*/ 
     39         case (ECONTEXT): 
     40            //if (Context::) 
     41            break; 
     42 
     43         default : 
     44            break; 
     45      }; 
     46   } catch(const Exception &exc) 
     47   { ERROR(exc.displayText()); } 
     48} 
     49 
     50void xios_handle_verify_(XBool * _ret, const XHandle * const _hd) 
     51{ 
     52   try { 
     53 
     54   } catch(const Exception &exc) 
     55   { ERROR(exc.displayText()); } 
     56} 
     57 
     58void xios_handle_getType_(XDType * _ret, const XHandle * const _hd) 
     59{ 
     60   try { 
     61 
     62   } catch(const Exception &exc) 
     63   { ERROR(exc.displayText()); } 
     64} 
     65 
     66void xios_handle_isType_(XBool * _ret, const XHandle * const _hd, const XDType  * const _dtype) 
     67{ 
     68   try { 
     69 
     70   } catch(const Exception &exc) 
     71   { ERROR(exc.displayText()); } 
     72} 
     73 
     74void xios_handle_isId_(XBool * _ret, const XHandle * const _hd, const XString * const _id) 
     75{ 
     76   try { 
     77 
     78   } catch(const Exception &exc) 
     79   { ERROR(exc.displayText()); } 
     80} 
     81 
     82void xios_handle_isGroup_(XBool * _ret, const XHandle * const _hd) 
     83{ 
     84   try { 
     85 
     86   } catch(const Exception &exc) 
     87   { ERROR(exc.displayText()); } 
     88} 
     89 
     90void xios_handle_isElement_(XBool * _ret, const XHandle * const _hd) 
     91{ 
     92   try { 
     93 
     94   } catch(const Exception &exc) 
     95   { ERROR(exc.displayText()); } 
     96} 
     97 
     98/* ********************************************************** */ 
     99/*                      XML INTERFACE                         */ 
     100/* ********************************************************** */ 
     101 
     102void xios_xml_parse_file_(XString _filename) 
     103{ 
     104   try { 
     105      std::string   __filename = stringXtoStd(_filename); 
     106      std::ifstream __istr( __filename.c_str() , std::ifstream::in ); 
     107 
     108      // On commence la lecture du flux de donnée xml. 
     109      XMLNode node = XMLNode::CreateNode(__istr, Context::GetRootName()); 
     110 
     111      // On parse le fichier xml noeud par noeud 
     112      // (ie on construit dynamiquement notre arbre d'objets). 
    33113      XMLParser::Parse(node); 
    34114 
    35       // On se place dans le contexte 'context1'. 
    36       Context::SetCurrentContext("context1", true) ; 
    37  
    38       std::cout << " * ----------- Début du traitement ----------- * " << std::endl << std::endl; 
    39  
    40       { 
    41          // On crée une instance de traitement de données dans le format NetCDF4. 
    42          DataTreatment dtreat; 
    43          dtreat.createDataOutput<NetCDF4DataOutput>(); 
    44  
    45          // Récupération du calendrier assossié au context courant et initialisation des delais d'écriture. 
    46          AbstractCalendar* calendar = dtreat.getCurrentContext()->getCalendar(); 
    47          calendar->setTimeStep(1 * Hour); 
    48  
    49          // Affichage de la date initiale (pour vérification). 
    50          std::cout << "Calendrier associé au contexte : " << *calendar << std::endl << std::endl; 
    51  
    52          for(int tcourant = 0, tfinal = 9; tcourant <= tfinal; tcourant++) 
    53          { /***************************** BOUCLE DE CALCUL *****************************/ 
    54  
    55             // Mise à jour de la date. 
    56             calendar->update(); 
    57  
    58             // Affichage des informations temporelles sur l'itération actuelle. 
    59             std::cout << "> Itération de calcul effectuée à la date t" << tcourant << " = " << calendar->getCurrentDate() 
    60                       << " (soit aprÚs " << (Time)calendar->getCurrentDate() << " sec.)." << std::endl; 
    61  
    62             // Mise à jour des données. 
    63             updateDataTest<Array<double, 3>::iterator>(arr.begin(), arr.end()); 
    64  
    65             // Ecriture des données. 
    66             dtreat.writeData<Array<double, 3> >("champ1", arr); 
    67          } 
    68  
    69          // Ecriture des avertissements obtenus jusqu'à présent. 
    70          std::cout << std::endl; ILogger::Flush(std::cout); 
    71  
    72          /*std::cout << " * ----------- Affichage de l'arborescence ----------- * " << std::endl << std::endl; 
    73  
    74          // On écrit l'arborescence résultante du traitement sur la sortie de log. 
    75          Context::ShowTree(std::clog); 
    76          std::cout << std::endl;*/ 
    77       } 
    78  
    79    } 
    80    catch(const Exception &exc) 
    81    {  // Pour tout type d'exceptions, on note les informations sur la sortie paramétrée. 
    82       ERROR(exc.displayText()); 
    83       // On retourne le code d'erreur en fin d'application pour traitements éventuels. 
    84       // return (exc.code()); 
    85    } 
    86  
    87    // return (0); 
     115   } catch(const Exception &exc) 
     116   { ERROR(exc.displayText()); } 
    88117} 
    89118 
     119void xios_xml_parse_string_(XString _xmlcontent) 
     120{ 
     121   try { 
     122      std::string        __xmlcontent = stringXtoStd(_xmlcontent); 
     123      std::istringstream __istr(__xmlcontent); 
    90124 
     125      // On commence la lecture du flux de donnée xml. 
     126      XMLNode node = XMLNode::CreateNode(__istr, Context::GetRootName()); 
     127 
     128      // On parse le fichier xml noeud par noeud 
     129      // (ie on construit dynamiquement notre arbre d'objets). 
     130      XMLParser::Parse(node); 
     131 
     132   } catch(const Exception &exc) 
     133   { ERROR(exc.displayText()); } 
     134} 
     135 
     136/* ********************************************************** */ 
     137/*                      MAIN ENTRY                            */ 
     138/* ********************************************************** */ 
     139 
     140void main_c_(void) // voué à disparaître 
     141{ /* Ne rien faire de plus */ } 
Note: See TracChangeset for help on using the changeset viewer.