ARTS  1.0.222
make_auto_wsv_h.cc
Go to the documentation of this file.
1 /* Copyright (C) 2000, 2001 Stefan Buehler <sbuehler@uni-bremen.de>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA. */
17 
30 #include "arts.h"
31 #include "matpackI.h"
32 #include "array.h"
33 #include "file.h"
34 #include "absorption.h"
35 #include "los.h"
36 #include "auto_wsv_groups.h"
37 #include "wsv_aux.h"
38 #include "mystring.h"
39 
40 int main()
41 {
42  try
43  {
44  // Initialize wsv data and wsv group names.
47 
48  // Make the data visible.
49  extern const Array<WsvRecord> wsv_data;
50  extern const ArrayOfString wsv_group_names;
51 
52  const Index n_wsv = wsv_data.nelem();
53 
54  // cout << "size = " << wsv_data.nelem() << '\n';
55 
56  ofstream ofs,ofs2;
57  open_output_file(ofs,"auto_wsv.h");
58  open_output_file(ofs2,"auto_wsv.txt");
59 
60  ofs << "/*! \\file auto_wsv.h\n"
61  << " \\brief Declares the enum type that acts as a\n"
62  << " handle for workspace variables. Also declares the\n"
63  << " workspace itself.\n\n"
64 
65  << " This file was generated automatically by make_auto_wsv_h.cc.\n"
66 
67  << " <b>DO NOT EDIT!</b>\n\n"
68 
69  << " \\date "
70  << __DATE__ << ", "
71  << __TIME__ << " */\n\n";
72 
73  ofs << "#ifndef auto_wsv_h\n";
74  ofs << "#define auto_wsv_h\n\n";
75 
76  ofs << "#include \"absorption.h\"\n"
77  << "#include \"los.h\"\n\n";
78 
79  ofs << "/*! This is only used for a consistency check. You can get the\n"
80  << " number of workspace variables from wsv_data.nelem(). */\n"
81  << "#define N_WSV " << n_wsv << "\n\n";
82 
83  ofs << "enum WsvHandle{\n";
84  for (Index i=0; i<n_wsv-1; ++i)
85  {
86  ofs << " " << wsv_data[i].Name() << "_,\n";
87  }
88  ofs << " " << wsv_data[n_wsv-1].Name() << "_\n";
89  ofs << "};\n\n";
90 
91  // Now the workspace itself:
92 
93  ofs << "/** The declaration of the (great) workspace. */\n";
94  ofs << "class WorkSpace {\n"
95  << "public:\n";
96  for (Index i=0; i<n_wsv; ++i)
97  {
98  // First of all write the comment as a doxygen header.
99  // For this we have to make some small replacements for
100  // indendation and put everything starting from the second
101  // sentence into a verbatim environment.
102  {
103  // Local copy of the description String:
104  String s = wsv_data[i].Description();
105 
106  // Add indentation:
107  replace_all(s,"\n","\n ");
108 
109  // Look for the end of the first sentence. There we have
110  // to include the beginning of the verbatim
111  // environment. Not earlier, because the first sentence
112  // has a special meaning.
113  Index full_stop = (Index)s.find('.');
114 
115  // We have to check against the case that the point was
116  // not found. In that case we set full_stop to the length
117  // of the entire test. If it was found, we increase the
118  // value by one, since we want to include the point in the
119  // first part.
120  if ( full_stop==s.npos )
121  full_stop = s.nelem();
122  else
123  full_stop += 1;
124 
125  String first(s,0,full_stop);
126 
127  // Rest will contain the rest of the documentation. It could
128  // be empty!
129  String rest = "";
130 
131  if ( full_stop!=s.nelem() )
132  rest = String(s,full_stop);
133 
134  // Remove leading whitespace and linebreaks in rest:
135  while (
136  0 < rest.nelem() &&
137  ( ' ' == rest[0] || '\n' == rest[0] )
138  )
139  {
140  rest.erase(0,1);
141  }
142 
143  ofs << "/** " << first;
144  if ( 0==rest.nelem() )
145  {
146  ofs << " */\n";
147  }
148  else
149  {
150  ofs << '\n'
151  << " \\verbatim\n"
152  << " " << rest << '\n'
153  << " \\endverbatim */\n";
154  }
155  }
156 
157  ofs << " "
158  << wsv_group_names[wsv_data[i].Group()]
159  << " "
160  << wsv_data[i].Name() << ";\n";
161 
162  }
163  ofs << "};\n\n";
164 
165  ofs << "#endif // auto_wsv_h\n";
166 
167  // Write text information file
168  // If you make changes here for the "VARIABLE" and "DATA TYPE" rows,
169  // you probably need to change get_artstype.m in AMI.
170  for ( Index i=0; i<n_wsv; i++ )
171  {
172  ofs2 << "VARIABLE : " << wsv_data[i].Name() << "\n"
173  << "DATA TYPE: " << wsv_group_names[wsv_data[i].Group()] <<"\n"
174  << "DESCRIPTION:\n"
175  << wsv_data[i].Description() << "\n\n";
176  }
177 
178  }
179  catch (runtime_error x)
180  {
181  cout << "Something went wrong. Message text:\n";
182  cout << x.what() << '\n';
183  return 1;
184  }
185 
186  return 0;
187 }
188 
absorption.h
Declarations required for the calculation of absorption coefficients.
los.h
This file contains the definition of the LOS structure and functions related to this structure.
auto_wsv_groups.h
Defines the enum type that acts as a handle for workspace variables groups.
first
Numeric first(ConstVectorView x)
Gives the first value of a vector.
Definition: math_funcs.cc:70
define_wsv_data
void define_wsv_data()
Define the lookup data for the workspace variables.
Definition: workspace.cc:44
wsv_data
const Array< WsvRecord > wsv_data
Definition: workspace.cc:42
array.h
This file contains the definition of Array.
matpackI.h
Array
This can be used to make arrays out of anything.
Definition: array.h:48
main
int main()
Definition: make_auto_wsv_h.cc:40
my_basic_string< char >
wsv_group_names
ArrayOfString wsv_group_names
Definition: groups.cc:36
define_wsv_group_names
void define_wsv_group_names()
Define the array of workspace variable group names.
Definition: groups.cc:51
open_output_file
void open_output_file(ofstream &file, const String &name)
Open a file for writing.
Definition: file.cc:91
my_basic_string::nelem
Index nelem() const
Number of elements.
Definition: mystring.h:185
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: arts.h:153
String
my_basic_string< char > String
The String type for ARTS.
Definition: mystring.h:281
file.h
This file contains basic functions to handle ASCII and binary (HDF) data files.
my_basic_string::npos
static const Index npos
Define npos:
Definition: mystring.h:87
wsv_aux.h
Auxiliary header stuff related to workspace variable groups.
mystring.h
This file contains the definition of String, the ARTS string class.
arts.h
The global header file for ARTS.
replace_all
void replace_all(String &s, const String &what, const String &with)
Replace all occurances of ‘what’ in ‘s’ with ‘with’.
Definition: file.cc:242