00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00031 #include <algorithm>
00032 #include <map>
00033 #include "arts.h"
00034 #include "parameters.h"
00035 #include "messages.h"
00036 #include "exceptions.h"
00037 #include "file.h"
00038 #include "methods.h"
00039 #include "parser.h"
00040 #include "auto_md.h"
00041 #include "absorption.h"
00042 #include "wsv_aux.h"
00043 #include "agenda_record.h"
00044 #include "mystring.h"
00045 #include "workspace_ng.h"
00046 #include "arts_omp.h"
00047
00048
00050 void polite_goodby()
00051 {
00052 cerr << "Try `arts --help' for help.\n";
00053 arts_exit ();
00054 }
00055
00068 void set_reporting_level(Index r)
00069 {
00070 extern Messages arts_messages;
00071
00072 if ( -1 == r )
00073 {
00074
00075
00076
00077 arts_messages.va = 0;
00078 arts_messages.vs = 1;
00079 arts_messages.vf = 0;
00080 }
00081 else
00082 {
00083
00084
00085
00086
00087 arts_messages.va = r/100;
00088 arts_messages.vs = (r%100)/10;
00089 arts_messages.vf = r%10;
00090
00091 if ( !arts_messages.valid() )
00092 {
00093 cerr << "Illegal value specified for --reporting (-r).\n"
00094 << "The specified value is " << r << ", which would be\n"
00095 << "interpreted as:\n"
00096 << "Verbosity for agendas: " << arts_messages.va << "\n"
00097 << "Verbosity for screen: " << arts_messages.vs << "\n"
00098 << "Verbosity for report file: " << arts_messages.vf << "\n"
00099 << "Only values of 0-3 are allowed for each verbosity.\n";
00100 arts_exit ();
00101 }
00102 }
00103 }
00104
00105
00113 void option_methods(const String& methods)
00114 {
00115 Workspace workspace;
00116 workspace.initialize();
00117
00118 extern const Array<MdRecord> md_data_raw;
00119 extern const Parameters parameters;
00120
00121 extern const ArrayOfString wsv_group_names;
00122
00123
00124
00125 Index hitcount;
00126
00127
00128
00129 if ( "all" == methods )
00130 {
00131 if (!parameters.plain)
00132 {
00133 cout
00134 << "\n*-------------------------------------------------------------------*\n"
00135 << "Complete list of ARTS workspace methods:\n"
00136 << "---------------------------------------------------------------------\n";
00137 }
00138 for ( Index i=0; i<md_data_raw.nelem(); ++i )
00139 {
00140 if (!parameters.plain) cout << "- ";
00141 cout << md_data_raw[i].Name() << "\n";
00142 }
00143
00144 if (!parameters.plain)
00145 cout << "*-------------------------------------------------------------------*\n\n";
00146
00147 return;
00148 }
00149
00150
00151
00152
00153
00154 map<String, Index>::const_iterator mi =
00155 Workspace::WsvMap.find(methods);
00156 if ( mi != Workspace::WsvMap.end() )
00157 {
00158
00159 Index wsv_key = mi->second;
00160
00161
00162 hitcount = 0;
00163 cout
00164 << "\n*-------------------------------------------------------------------*\n"
00165 << "Generic and supergeneric methods that can generate " << Workspace::wsv_data[wsv_key].Name()
00166 << ":\n"
00167 << "---------------------------------------------------------------------\n";
00168 for ( Index i=0; i<md_data_raw.nelem(); ++i )
00169 {
00170
00171 const MdRecord& mdd = md_data_raw[i];
00172
00173
00174
00175
00176
00177 if ( count( mdd.GOutType().begin(),
00178 mdd.GOutType().end(),
00179 Workspace::wsv_data[wsv_key].Group() ) )
00180 {
00181 cout << "- " << mdd.Name() << "\n";
00182 ++hitcount;
00183 }
00184 else if ( count( mdd.GOutType().begin(),
00185 mdd.GOutType().end(),
00186 get_wsv_group_id("Any") ) )
00187 {
00188 for (Index j = 0; j < mdd.GOutType().nelem(); j++)
00189 {
00190 if (mdd.GOutType()[j] == get_wsv_group_id("Any"))
00191 {
00192 if (mdd.GOutSpecType()[j].nelem())
00193 {
00194 if (count( mdd.GOutSpecType()[j].begin(),
00195 mdd.GOutSpecType()[j].end(),
00196 Workspace::wsv_data[wsv_key].Group() ) )
00197 {
00198 cout << "- " << mdd.Name() << "\n";
00199 ++hitcount;
00200 }
00201 }
00202 else
00203 {
00204 cout << "- " << mdd.Name() << "\n";
00205 ++hitcount;
00206 }
00207 }
00208 }
00209 }
00210 }
00211 if ( 0==hitcount )
00212 cout << "none\n";
00213
00214
00215 hitcount = 0;
00216 cout
00217 << "\n---------------------------------------------------------------------\n"
00218 << "Specific methods that can generate " << Workspace::wsv_data[wsv_key].Name()
00219 << ":\n"
00220 << "---------------------------------------------------------------------\n";
00221 for ( Index i=0; i<md_data_raw.nelem(); ++i )
00222 {
00223
00224 const MdRecord& mdd = md_data_raw[i];
00225
00226
00227
00228
00229 if ( count( mdd.Out().begin(),
00230 mdd.Out().end(),
00231 wsv_key ) )
00232 {
00233 cout << "- " << mdd.Name() << "\n";
00234 ++hitcount;
00235 }
00236 }
00237 if ( 0==hitcount )
00238 cout << "none\n";
00239
00240 cout
00241 << "*-------------------------------------------------------------------*\n\n";
00242
00243 return;
00244 }
00245
00246
00247
00248
00249
00250
00251 Index group_key =
00252 find( wsv_group_names.begin(),
00253 wsv_group_names.end(),
00254 methods ) - wsv_group_names.begin();
00255
00256
00257
00258 if ( group_key != wsv_group_names.nelem() )
00259 {
00260
00261 hitcount = 0;
00262 cout
00263 << "\n*-------------------------------------------------------------------*\n"
00264 << "Generic and supergeneric methods that can generate variables of group "
00265 << wsv_group_names[group_key] << ":\n"
00266 << "---------------------------------------------------------------------\n";
00267 for ( Index i=0; i<md_data_raw.nelem(); ++i )
00268 {
00269
00270 const MdRecord& mdd = md_data_raw[i];
00271
00272
00273
00274
00275
00276 if ( count( mdd.GOutType().begin(),
00277 mdd.GOutType().end(),
00278 group_key ) )
00279 {
00280 cout << "- " << mdd.Name() << "\n";
00281 ++hitcount;
00282 }
00283 else if ( count( mdd.GOutType().begin(),
00284 mdd.GOutType().end(),
00285 get_wsv_group_id("Any") ) )
00286 {
00287 for (Index j = 0; j < mdd.GOutType().nelem(); j++)
00288 {
00289 if (mdd.GOutType()[j] == get_wsv_group_id("Any"))
00290 {
00291 if (mdd.GOutSpecType()[j].nelem())
00292 {
00293 if (count( mdd.GOutSpecType()[j].begin(),
00294 mdd.GOutSpecType()[j].end(),
00295 group_key ) )
00296 {
00297 cout << "- " << mdd.Name() << "\n";
00298 ++hitcount;
00299 }
00300 }
00301 else
00302 {
00303 cout << "- " << mdd.Name() << "\n";
00304 ++hitcount;
00305 }
00306 }
00307 }
00308 }
00309 }
00310 if ( 0==hitcount )
00311 cout << "none\n";
00312
00313 cout
00314 << "*-------------------------------------------------------------------*\n\n";
00315
00316 return;
00317 }
00318
00319
00320
00321 cerr << "The name " << methods << " matches neither `all',\n"
00322 << "nor the name of a workspace variable, nor the name\n"
00323 << "of a workspace variable group.\n";
00324 arts_exit ();
00325 }
00326
00334 void option_input(const String& input)
00335 {
00336
00337 extern const Array<MdRecord> md_data_raw;
00338
00339 extern const ArrayOfString wsv_group_names;
00340
00341
00342
00343 Index hitcount;
00344
00345
00346
00347
00348
00349 map<String, Index>::const_iterator mi =
00350 Workspace::WsvMap.find(input);
00351 if ( mi != Workspace::WsvMap.end() )
00352 {
00353
00354 Index wsv_key = mi->second;
00355
00356
00357 hitcount = 0;
00358 cout
00359 << "\n*-------------------------------------------------------------------*\n"
00360 << "Generic and supergeneric methods that can use " << Workspace::wsv_data[wsv_key].Name() << ":\n"
00361 << "---------------------------------------------------------------------\n";
00362 for ( Index i=0; i<md_data_raw.nelem(); ++i )
00363 {
00364
00365 const MdRecord& mdd = md_data_raw[i];
00366
00367
00368
00369
00370
00371 if ( count( mdd.GInType().begin(),
00372 mdd.GInType().end(),
00373 Workspace::wsv_data[wsv_key].Group() ) )
00374 {
00375 cout << "- " << mdd.Name() << "\n";
00376 ++hitcount;
00377 }
00378 else if ( count( mdd.GInType().begin(),
00379 mdd.GInType().end(),
00380 get_wsv_group_id("Any") ) )
00381 {
00382 for (Index j = 0; j < mdd.GInType().nelem(); j++)
00383 {
00384 if (mdd.GInType()[j] == get_wsv_group_id("Any"))
00385 {
00386 if (mdd.GInSpecType()[j].nelem())
00387 {
00388 if (count( mdd.GInSpecType()[j].begin(),
00389 mdd.GInSpecType()[j].end(),
00390 Workspace::wsv_data[wsv_key].Group() ) )
00391 {
00392 cout << "- " << mdd.Name() << "\n";
00393 ++hitcount;
00394 }
00395 }
00396 else
00397 {
00398 cout << "- " << mdd.Name() << "\n";
00399 ++hitcount;
00400 }
00401 }
00402 }
00403 }
00404 }
00405 if ( 0==hitcount )
00406 cout << "none\n";
00407
00408
00409 hitcount = 0;
00410 cout
00411 << "\n---------------------------------------------------------------------\n"
00412 << "Specific methods that require " << Workspace::wsv_data[wsv_key].Name()
00413 << ":\n"
00414 << "---------------------------------------------------------------------\n";
00415 for ( Index i=0; i<md_data_raw.nelem(); ++i )
00416 {
00417
00418 const MdRecord& mdd = md_data_raw[i];
00419
00420
00421
00422
00423 if ( count( mdd.In().begin(),
00424 mdd.In().end(),
00425 wsv_key ) )
00426 {
00427 cout << "- " << mdd.Name() << "\n";
00428 ++hitcount;
00429 }
00430 }
00431 if ( 0==hitcount )
00432 cout << "none\n";
00433
00434 cout
00435 << "*-------------------------------------------------------------------*\n\n";
00436
00437 return;
00438 }
00439
00440
00441
00442
00443
00444
00445 Index group_key =
00446 find( wsv_group_names.begin(),
00447 wsv_group_names.end(),
00448 input ) - wsv_group_names.begin();
00449
00450
00451
00452 if ( group_key != wsv_group_names.nelem() )
00453 {
00454
00455 hitcount = 0;
00456 cout
00457 << "\n*-------------------------------------------------------------------*\n"
00458 << "Generic and supergeneric methods that require a variable of group "
00459 << wsv_group_names[group_key] << ":\n"
00460 << "---------------------------------------------------------------------\n";
00461 for ( Index i=0; i<md_data_raw.nelem(); ++i )
00462 {
00463
00464 const MdRecord& mdd = md_data_raw[i];
00465
00466
00467
00468
00469
00470 if ( count( mdd.GInType().begin(),
00471 mdd.GInType().end(),
00472 group_key ) )
00473 {
00474 cout << "- " << mdd.Name() << "\n";
00475 ++hitcount;
00476 }
00477 else if ( count( mdd.GInType().begin(),
00478 mdd.GInType().end(),
00479 get_wsv_group_id("Any") ) )
00480 {
00481 for (Index j = 0; j < mdd.GInType().nelem(); j++)
00482 {
00483 if (mdd.GInType()[j] == get_wsv_group_id("Any"))
00484 {
00485 if (mdd.GInSpecType()[j].nelem())
00486 {
00487 if (count( mdd.GInSpecType()[j].begin(),
00488 mdd.GInSpecType()[j].end(),
00489 group_key ) )
00490 {
00491 cout << "- " << mdd.Name() << "\n";
00492 ++hitcount;
00493 }
00494 }
00495 else
00496 {
00497 cout << "- " << mdd.Name() << "\n";
00498 ++hitcount;
00499 }
00500 }
00501 }
00502 }
00503 }
00504 if ( 0==hitcount )
00505 cout << "none\n";
00506
00507 cout
00508 << "*-------------------------------------------------------------------*\n\n";
00509
00510 return;
00511 }
00512
00513
00514
00515 cerr << "The name " << input << " matches neither the name of a\n"
00516 << "workspace variable, nor the name of a workspace variable group.\n";
00517 arts_exit ();
00518 }
00519
00520
00528 void option_workspacevariables(const String& workspacevariables)
00529 {
00530
00531 extern const Array<MdRecord> md_data;
00532 extern const map<String, Index> MdMap;
00533 extern const Parameters parameters;
00534
00535 extern const ArrayOfString wsv_group_names;
00536
00537
00538
00539 Index hitcount;
00540
00541
00542
00543 if ( "all" == workspacevariables )
00544 {
00545 if (!parameters.plain)
00546 {
00547 cout
00548 << "\n*-------------------------------------------------------------------*\n"
00549 << "Complete list of ARTS workspace variables:\n"
00550 << "---------------------------------------------------------------------\n";
00551 }
00552
00553 for ( Index i=0; i<Workspace::wsv_data.nelem(); ++i )
00554 {
00555 if (!parameters.plain) cout << "- ";
00556 cout << Workspace::wsv_data[i].Name() << "\n";
00557 }
00558
00559 if (!parameters.plain)
00560 cout << "*-------------------------------------------------------------------*\n\n";
00561 return;
00562 }
00563
00564
00565
00566 map<String, Index>::const_iterator mi =
00567 MdMap.find(workspacevariables);
00568 if ( mi != MdMap.end() )
00569 {
00570
00571
00572
00573 const MdRecord& mdr = md_data[mi->second];
00574
00575
00576 hitcount = 0;
00577 cout
00578 << "\n*-------------------------------------------------------------------*\n"
00579 << "Generic workspace variables required by " << mdr.Name()
00580 << " are of type:\n"
00581 << "---------------------------------------------------------------------\n";
00582 for ( Index i=0; i<mdr.GInType().nelem(); ++i )
00583 {
00584 cout << "- " << wsv_group_names[mdr.GInType()[i]] << "\n";
00585 ++hitcount;
00586 }
00587 if ( 0==hitcount )
00588 cout << "none\n";
00589
00590
00591 hitcount = 0;
00592 cout
00593 << "\n---------------------------------------------------------------------\n"
00594 << "Specific workspace variables required by " << mdr.Name() << ":\n"
00595 << "---------------------------------------------------------------------\n";
00596 for ( Index i=0; i<mdr.In().nelem(); ++i )
00597 {
00598 cout << "- " << Workspace::wsv_data[mdr.In()[i]].Name() << "\n";
00599 ++hitcount;
00600 }
00601 if ( 0==hitcount )
00602 cout << "none\n";
00603
00604 cout
00605 << "*-------------------------------------------------------------------*\n\n";
00606
00607 return;
00608 }
00609
00610
00611 cerr << "The name " << workspacevariables << " matches neither `all',\n"
00612 << "nor the name of a workspace method.\n";
00613 arts_exit ();
00614 }
00615
00616
00622 void option_describe(const String& describe)
00623 {
00624
00625 extern const Array<MdRecord> md_data_raw;
00626 extern const map<String, Index> MdRawMap;
00627
00628
00629
00630
00631
00632
00633 map<String, Index>::const_iterator i =
00634 MdRawMap.find(describe);
00635 if ( i != MdRawMap.end() )
00636 {
00637
00638 cout << md_data_raw[i->second] << "\n";
00639 return;
00640 }
00641
00642
00643
00644
00645
00646 i = Workspace::WsvMap.find(describe);
00647 if ( i != Workspace::WsvMap.end() )
00648 {
00649
00650
00651 cout << Workspace::wsv_data[i->second] << "\n";
00652 return;
00653 }
00654
00655
00656 cerr << "The name " << describe
00657 << " matches neither method nor variable.\n";
00658 arts_exit ();
00659 }
00660
00661
00676 int main (int argc, char **argv)
00677 {
00678 extern const Parameters parameters;
00679
00680
00681
00682 if ( get_parameters(argc, argv) )
00683 {
00684
00685 polite_goodby();
00686 }
00687
00688
00689 if (parameters.help)
00690 {
00691
00692 cout << "\n" << parameters.usage << "\n\n";
00693 cout << parameters.helptext << "\n\n";
00694 arts_exit (EXIT_SUCCESS);
00695 }
00696
00697 if (parameters.version)
00698 {
00699 extern const String full_name;
00700
00701 cout << full_name
00702 << " (compiled " << __DATE__ << " " << __TIME__
00703 << " on " << OS_NAME << " " << OS_VERSION << ")" << endl
00704 << "Compile flags: " << COMPILE_FLAGS << endl
00705 << "Features in this build: " << endl
00706 << " Numeric precision: "
00707 << ((sizeof (Numeric) == sizeof (double)) ? "double" : "float") << endl
00708 << " OpenMP support: "
00709 #ifdef _OPENMP
00710 << "enabled" << endl
00711 #else
00712 << "disabled" << endl
00713 #endif
00714 << " Zipped XML support: "
00715 #ifdef ENABLE_ZLIB
00716 << "enabled" << endl
00717 #else
00718 << "disabled" << endl
00719 #endif
00720 << " NetCDF support: "
00721 #ifdef ENABLE_NETCDF
00722 << "enabled" << endl
00723 #else
00724 << "disabled" << endl
00725 #endif
00726 << " Disort algorithm: "
00727 #ifdef ENABLE_DISORT
00728 << "enabled" << endl
00729 #else
00730 << "disabled" << endl
00731 #endif
00732 << "";
00733 arts_exit (EXIT_SUCCESS);
00734 }
00735
00736 if (parameters.numthreads)
00737 {
00738 #ifdef _OPENMP
00739 omp_set_num_threads ((int)parameters.numthreads);
00740 #else
00741 cerr << "Ignoring commandline option --numthreads/-n.\n"
00742 << "This option only works with an OpenMP enabled ARTS build.\n";
00743 #endif
00744 }
00745
00746
00747
00748
00749
00750
00751 define_wsv_group_names();
00752
00753
00754 Workspace::define_wsv_data();
00755
00756
00757 Workspace::define_wsv_map();
00758
00759
00760 define_md_data_raw();
00761
00762
00763 expand_md_data_raw_to_md_data();
00764
00765
00766 define_md_map();
00767
00768
00769 define_md_raw_map();
00770
00771
00772 define_agenda_data();
00773
00774
00775 define_agenda_map();
00776
00777
00778 assert( check_agenda_data() );
00779
00780
00781
00782
00783 define_species_data();
00784
00785
00786 define_species_map();
00787
00788
00789 define_lineshape_data();
00790 define_lineshape_norm_data();
00791
00792
00793
00794
00795 extern const ArrayOfString wsv_group_names;
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805 if ( "" != parameters.methods )
00806 {
00807 option_methods(parameters.methods);
00808 arts_exit (EXIT_SUCCESS);
00809 }
00810
00811
00812
00813
00814 if ( "" != parameters.input )
00815 {
00816 option_input(parameters.input);
00817 arts_exit (EXIT_SUCCESS);
00818 }
00819
00820
00821
00822
00823
00824 if ( "" != parameters.workspacevariables )
00825 {
00826 option_workspacevariables(parameters.workspacevariables);
00827 arts_exit (EXIT_SUCCESS);
00828 }
00829
00830
00831
00832 if ( "" != parameters.describe )
00833 {
00834 option_describe(parameters.describe);
00835 arts_exit (EXIT_SUCCESS);
00836 }
00837
00838
00839
00840
00841 if ( parameters.groups )
00842 {
00843 if (!parameters.plain)
00844 {
00845 cout
00846 << "\n*-------------------------------------------------------------------*\n"
00847 << "Complete list of ARTS workspace variable groups:\n"
00848 << "---------------------------------------------------------------------\n";
00849 }
00850
00851 for ( Index i=0; i<wsv_group_names.nelem(); ++i )
00852 {
00853 if (!parameters.plain) cout << "- ";
00854 cout << wsv_group_names[i] << "\n";
00855 }
00856
00857 if (!parameters.plain)
00858 cout << "*-------------------------------------------------------------------*\n\n";
00859 arts_exit (EXIT_SUCCESS);
00860 }
00861
00862
00863
00864
00865
00866 if ( 0 == parameters.controlfiles.nelem() )
00867 {
00868 cerr << "You must specify at least one control file name.\n";
00869 polite_goodby();
00870 }
00871
00872
00873
00874 if ( "" == parameters.basename )
00875 {
00876 extern String out_basename;
00877 out_basename = parameters.controlfiles[0];
00878
00879 String::size_type p = out_basename.rfind(".arts");
00880
00881 if (String::npos==p)
00882 {
00883
00884
00885
00886
00887 cerr << "The controlfile must have the extension .arts.\n";
00888 polite_goodby();
00889 }
00890
00891
00892 out_basename.erase(p);
00893 }
00894 else
00895 {
00896 extern String out_basename;
00897 out_basename = parameters.basename;
00898 }
00899
00900
00901
00902 set_reporting_level(parameters.reporting);
00903
00904
00905
00906
00907
00908
00909 try
00910 {
00911 extern String out_basename;
00912 extern ofstream report_file;
00913 ostringstream report_file_ext;
00914
00915 report_file_ext << ".rep";
00916 open_output_file(report_file, out_basename + report_file_ext.str ());
00917 }
00918 catch (runtime_error x)
00919 {
00920 cerr << x.what() << "\n"
00921 << "I have to be able to write to my report file.\n";
00922 arts_exit ();
00923 }
00924 catch (ios_base::failure x)
00925 {
00926 cerr << x.what() << "\n"
00927 << "I have to be able to write to my report file.\n"
00928 << "Make sure you have write permissions for the directory where\n"
00929 << "the report file is written.\n";
00930 arts_exit ();
00931 }
00932
00933
00934
00935 try
00936 {
00937 {
00938
00939
00940
00941
00942
00943 extern const String full_name;
00944 out1 << full_name << "\n";
00945 }
00946
00947
00948 #ifdef _OPENMP
00949 out2 << "Running with OpenMP, "
00950 << "maximum number of threads = "
00951 << arts_omp_get_max_threads() << ".\n";
00952 #else
00953 out2 << "Running without OpenMP.\n";
00954 #endif
00955
00956 {
00957
00958
00959 extern Messages arts_messages;
00960 out3 << "Verbosity settings: Agendas: " << arts_messages.va << "\n"
00961 << " Screen: " << arts_messages.vs << "\n"
00962 << " Report file: " << arts_messages.vf << "\n";
00963 }
00964
00965 out3 << "\nReading control files:\n";
00966 for ( Index i=0; i<parameters.controlfiles.nelem(); ++i )
00967 {
00968 out3 << "- " << parameters.controlfiles[i] << "\n";
00969
00970
00971
00972 Agenda tasklist;
00973
00974 Workspace workspace;
00975
00976
00977 ArtsParser arts_parser(tasklist, parameters.controlfiles[i]);
00978
00979 arts_parser.parse_tasklist();
00980
00981 tasklist.set_name("Arts");
00982
00983 tasklist.set_main_agenda();
00984
00985 workspace.initialize ();
00986
00987
00988 Arts(workspace, tasklist);
00989 }
00990 }
00991 catch (runtime_error x)
00992 {
00993 arts_exit_with_error_message(x.what());
00994 }
00995
00996 out1 << "Goodbye.\n";
00997 arts_exit (EXIT_SUCCESS);
00998 }