source: XIOS/trunk/src/parse_expr/operator_expr.hpp @ 501

Last change on this file since 501 was 501, checked in by ymipsl, 10 years ago

Add licence copyright to all file ond directory src using the command :
svn propset -R copyright -F header_licence src

XIOS is now officialy under CeCILL licence

YM

  • 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: 7.7 KB
Line 
1#ifndef __XIOS_OPERATOR_EXPR_HPP__
2#define __XIOS_OPERATOR_EXPR_HPP__
3
4#include <map>
5#include <string>
6#include <cmath>
7#include "exception.hpp"
8#include "array_new.hpp"
9
10using namespace std ;
11
12namespace xios
13{
14  class COperatorExpr
15  {
16    public: 
17    typedef double (*functionScalar)(double) ;
18    typedef double (*functionScalarScalar)(double, double) ;
19    typedef CArray<double,1> (*functionField)(const CArray<double,1>&) ;
20    typedef CArray<double,1> (*functionFieldField)(const CArray<double,1>&, const CArray<double,1>&) ;
21    typedef CArray<double,1> (*functionFieldScalar)(const CArray<double,1>&, double) ;
22    typedef CArray<double,1> (*functionScalarField)(double, const CArray<double,1>&) ;
23   
24    COperatorExpr(void)
25    {
26      opScalar[string("neg")]=neg_s ;
27      opScalar[string("cos")]=cos_s ;
28      opScalar[string("sin")]=sin_s ;
29      opScalar[string("tan")]=tan_s ;
30      opScalar[string("exp")]=exp_s ;
31      opScalar[string("log")]=log_s ;
32      opScalar[string("log10")]=log10_s ;
33      opScalar[string("sqrt")]=sqrt_s ;
34 
35      opScalarScalar[string("add")]=add_ss ;
36      opScalarScalar[string("minus")]=minus_ss ;
37      opScalarScalar[string("mult")]=mult_ss ;
38      opScalarScalar[string("div")]=div_ss ;
39      opScalarScalar[string("pow")]=pow_ss ;
40
41      opField[string("neg")]=neg_f ;
42      opField[string("cos")]=cos_f ;
43      opField[string("sin")]=sin_f ;
44      opField[string("tan")]=tan_f ;
45      opField[string("exp")]=exp_f ;
46      opField[string("log")]=log_f ;
47      opField[string("log10")]=log10_f ;
48      opField[string("sqrt")]=sqrt_f ;
49 
50      opFieldField[string("add")]=add_ff ;
51      opFieldField[string("minus")]=minus_ff ;
52      opFieldField[string("mult")]=mult_ff ;
53      opFieldField[string("div")]=div_ff ;
54      opFieldField[string("pow")]=pow_ff ;
55
56      opFieldScalar[string("add")]=add_fs ;
57      opFieldScalar[string("minus")]=minus_fs ;
58      opFieldScalar[string("mult")]=mult_fs ;
59      opFieldScalar[string("div")]=div_fs ;
60      opFieldScalar[string("pow")]=pow_fs ;
61     
62      opScalarField[string("add")]=add_sf ;
63      opScalarField[string("minus")]=minus_sf ;
64      opScalarField[string("mult")]=mult_sf ;
65      opScalarField[string("div")]=div_sf ;
66    }   
67
68    functionScalar getOpScalar(const string& id)
69    {
70      map<string,double (*)(double)>::iterator it ;
71      it=opScalar.find(id) ;
72      if (it==opScalar.end()) ERROR("double (*)(double) COperatorExpr::getOpScalar(const string& id)",<<"unknown operator : "<<id) 
73      return it->second ;
74    }
75 
76    functionScalarScalar getOpScalarScalar(const string& id)
77    {
78      map<string,double (*)(double,double)>::iterator it ;
79      it=opScalarScalar.find(id) ;
80      if (it==opScalarScalar.end()) ERROR("double (*)(double) COperatorExpr::getOpScalarScalar(const string& id)",<<"unknown operator : "<<id)
81      return it->second ;   
82    }
83   
84    functionField getOpField(const string& id)
85    {
86      map<string,functionField>::iterator it ;
87      it=opField.find(id) ;
88      if (it==opField.end()) ERROR("functionField COperatorExpr::getOpField(const string& id)",<<"unknown operator : "<<id)
89      return it->second ;   
90    }
91 
92    functionFieldField getOpFieldField(const string& id)
93    {
94      map<string,functionFieldField>::iterator it ;
95      it=opFieldField.find(id) ;
96      if (it==opFieldField.end()) ERROR("dfunctionFieldField COperatorExpr::getOpFieldField(const string& id)",<<"unknown operator : "<<id)
97      return it->second ;   
98    }
99   
100    functionFieldScalar getOpFieldScalar(const string& id)
101    {
102      map<string,functionFieldScalar>::iterator it ;
103      it=opFieldScalar.find(id) ;
104      if (it==opFieldScalar.end()) ERROR("functionFieldScalar COperatorExpr::getOpFieldScalar(const string& id)",<<"unknown operator : "<<id)
105      return it->second ;   
106    }
107   
108    functionScalarField getOpScalarField(const string& id)
109    {
110      map<string,functionScalarField>::iterator it ;
111      it=opScalarField.find(id) ;
112      if (it==opScalarField.end()) ERROR("functionScalarField COperatorExpr::getOpFieldField(const string& id)",<<"unknown operator : "<<id)
113      return it->second ;   
114    }
115   
116    map<string,functionScalar> opScalar ;
117    map<string,functionScalarScalar> opScalarScalar ;
118    map<string,functionField> opField ;
119    map<string,functionFieldField> opFieldField ;
120    map<string,functionFieldScalar> opFieldScalar ;
121    map<string,functionScalarField> opScalarField ;
122
123    static inline double neg_s(double x)   {return -x;}
124    static inline double cos_s(double x)   {return std::cos(x);}
125    static inline double sin_s(double x)   {return std::sin(x);}
126    static inline double tan_s(double x)   {return std::tan(x);}
127    static inline double exp_s(double x)   {return std::exp(x);}
128    static inline double log_s(double x)   {return std::log(x);}
129    static inline double log10_s(double x) {return std::log10(x);}
130    static inline double sqrt_s(double x)  {return std::sqrt(x);}
131 
132    static inline double add_ss(double x, double y)    {return x+y;}
133    static inline double minus_ss(double x, double y)  {return x-y;}
134    static inline double mult_ss(double x, double y)   {return x*y;}
135    static inline double div_ss(double x, double y)    {return x/y;}
136    static inline double pow_ss(double x, double y)    {return std::pow(x,y);}
137   
138    static inline CArray<double,1> neg_f(const CArray<double,1>& x)   {return Array<double,1>(-x);}
139    static inline CArray<double,1> cos_f(const CArray<double,1>& x)   {return Array<double,1>(cos(x));}
140    static inline CArray<double,1> sin_f(const CArray<double,1>& x)   {return Array<double,1>(sin(x));}
141    static inline CArray<double,1> tan_f(const CArray<double,1>& x)   {return Array<double,1>(tan(x));}
142    static inline CArray<double,1> exp_f(const CArray<double,1>& x)   {return Array<double,1>(exp(x));}
143    static inline CArray<double,1> log_f(const CArray<double,1>& x)   {return Array<double,1>(log(x));}
144    static inline CArray<double,1> log10_f(const CArray<double,1>& x) {return Array<double,1>(log10(x));}
145    static inline CArray<double,1> sqrt_f(const CArray<double,1>& x)  {return Array<double,1>(sqrt(x));}
146   
147    static inline CArray<double,1> add_ff(const CArray<double,1>& x, const CArray<double,1>& y)    {return Array<double,1>(x+y);}
148    static inline CArray<double,1> minus_ff(const CArray<double,1>& x, const CArray<double,1>& y)  {return Array<double,1>(x-y);}
149    static inline CArray<double,1> mult_ff(const CArray<double,1>& x, const CArray<double,1>& y)   {return Array<double,1>(x*y);}
150    static inline CArray<double,1> div_ff(const CArray<double,1>& x, const CArray<double,1>& y)    {return Array<double,1>(x/y);}
151    static inline CArray<double,1> pow_ff(const CArray<double,1>& x, const CArray<double,1>& y)    {return Array<double,1>(pow(x,y));}
152
153    static inline CArray<double,1> add_fs(const CArray<double,1>& x, double y)    {return Array<double,1>(x+y);}
154    static inline CArray<double,1> minus_fs(const CArray<double,1>& x, double y)  {return Array<double,1>(x-y);}
155    static inline CArray<double,1> mult_fs(const CArray<double,1>& x, double y)   {return Array<double,1>(x*y);}
156    static inline CArray<double,1> div_fs(const CArray<double,1>& x, double y)    {return Array<double,1>(x/y);}
157    static inline CArray<double,1> pow_fs(const CArray<double,1>& x, double y)    {return Array<double,1>(pow(x,y));} 
158
159    static inline CArray<double,1> add_sf(double x, const CArray<double,1>& y)    {return Array<double,1>(x+y);}
160    static inline CArray<double,1> minus_sf(double x, const CArray<double,1>& y)  {return Array<double,1>(x-y);}
161    static inline CArray<double,1> mult_sf(double x, const CArray<double,1>& y)   {return Array<double,1>(x*y);}
162    static inline CArray<double,1> div_sf(double x, const CArray<double,1>& y)    {return Array<double,1>(x/y);}
163   
164     
165  } ;
166 
167  extern COperatorExpr operatorExpr ;
168 
169}
170
171#endif
172
Note: See TracBrowser for help on using the repository browser.