[2696] | 1 | #ifndef UTIL |
---|
| 2 | #define UTIL 1 |
---|
| 3 | |
---|
| 4 | // ############################################################################ |
---|
| 5 | // |
---|
| 6 | // create_mz_kpp_module |
---|
| 7 | // |
---|
| 8 | // create scalar code from .f90 sources created by KPP to be used in MESSy |
---|
| 9 | // |
---|
| 10 | // COPYRIGHT Klaus Ketelsen and MPI-CH April 2007 |
---|
| 11 | // |
---|
| 12 | // ############################################################################ |
---|
[3458] | 13 | // |
---|
| 14 | // |
---|
| 15 | // Former revisions: |
---|
| 16 | // ----------------------- |
---|
[3799] | 17 | // Deleted $Id since document_changes does not work for C and C++ (15.03.2019, forkel) |
---|
[3458] | 18 | // |
---|
| 19 | // initial version (Nov. 2016, ketelsen) |
---|
| 20 | // |
---|
[2696] | 21 | |
---|
| 22 | #include <string> |
---|
| 23 | #include <list> |
---|
| 24 | #include <vector> |
---|
| 25 | |
---|
| 26 | #include <iostream> |
---|
| 27 | #include <string> |
---|
| 28 | |
---|
| 29 | using namespace std; |
---|
| 30 | |
---|
| 31 | extern void my_abort(string s); |
---|
| 32 | extern string my_to_upper(string sinp); |
---|
| 33 | |
---|
| 34 | class Vvar { |
---|
| 35 | public: |
---|
| 36 | string name; |
---|
| 37 | vector<string> dim_var; |
---|
| 38 | |
---|
| 39 | int nr_dim() {return dim_var.size(); }; |
---|
| 40 | void clear() {name.clear(); dim_var.clear(); return; }; |
---|
| 41 | }; |
---|
| 42 | |
---|
| 43 | class control_switches { |
---|
| 44 | private: |
---|
| 45 | bool vector_mode; // false Generate scalar code |
---|
| 46 | // true Generate vector code |
---|
| 47 | |
---|
| 48 | string vector_length; |
---|
| 49 | |
---|
| 50 | int de_index_mode; // 0: no de-indexing |
---|
| 51 | // 1: normal de-indexing |
---|
| 52 | // 2: 'fast' de-indexing (LU) |
---|
| 53 | // 3: 'old' de-indexing |
---|
| 54 | |
---|
| 55 | public: |
---|
| 56 | |
---|
| 57 | void set_vector_mode() {vector_mode = true; return;}; |
---|
| 58 | void set_vector_length (string s) {vector_length=s; return;}; |
---|
| 59 | void set_de_index_mode(int i) {de_index_mode = i; return;}; |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | bool is_vector() {return vector_mode;}; |
---|
| 63 | string get_vector_length () {return vector_length;}; |
---|
| 64 | int de_indexing () {return de_index_mode;}; |
---|
| 65 | |
---|
| 66 | control_switches () {vector_mode = false; vector_length="1"; de_index_mode=0;} |
---|
| 67 | }; |
---|
| 68 | |
---|
| 69 | extern control_switches kpp_switches; |
---|
| 70 | |
---|
| 71 | class string_token { |
---|
| 72 | private: |
---|
| 73 | int size_val; |
---|
| 74 | string seperator; |
---|
| 75 | vector <string> tokens; |
---|
| 76 | vector <string>::iterator is; |
---|
| 77 | vector <int> position; |
---|
| 78 | |
---|
| 79 | public: |
---|
| 80 | void set_separator (string s) {seperator.clear();seperator=s; return; }; |
---|
| 81 | |
---|
| 82 | void fill_token (string s); |
---|
| 83 | bool get_next_token(string &s) { s=*is++; return (is == tokens.end()); }; |
---|
| 84 | string get_token_by_index (int index) { if(index <= size_val-1) { |
---|
| 85 | return tokens[index]; |
---|
| 86 | } else { |
---|
| 87 | return " "; }; }; |
---|
| 88 | int size() { return size_val; }; |
---|
| 89 | void update (int i, string s) { tokens[i].clear(); tokens[i] = s;return;}; |
---|
| 90 | int get_position(int i) { return position[i]; }; |
---|
| 91 | void reset (string s) { tokens.clear(); fill_token (s); return; }; |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | string_token () {size_val=0;seperator=" ";}; |
---|
| 95 | string_token (string s) {size_val=0;seperator=s;}; |
---|
| 96 | |
---|
| 97 | }; |
---|
| 98 | |
---|
| 99 | #endif |
---|