00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00025 
00026 
00027 #ifndef absorption_h
00028 #define absorption_h
00029 
00030 #include <stdexcept>
00031 #include "matpackI.h"
00032 #include "array.h"
00033 #include "mystring.h"
00034 #include "make_array.h"
00035 
00038 typedef void (*lsf_type)(Vector&,
00039                          Vector&,
00040                          Numeric,
00041                          Numeric,
00042                          Numeric,
00043                          VectorView,
00044                          const Index);
00045 
00051 class LineshapeRecord{
00052 public:
00053 
00055   LineshapeRecord(){};
00056 
00058   LineshapeRecord(const String& name,
00059                   const String& description,
00060                   lsf_type      function)
00061     : mname(name),
00062       mdescription(description),
00063       mfunction(function)
00064   {  }
00066   const String&  Name()        const { return mname;        }   
00068   const String&  Description() const { return mdescription; }
00070   lsf_type Function() const { return mfunction; }
00071 private:        
00072   String  mname;        
00073   String  mdescription; 
00074   lsf_type mfunction;   
00075 
00076 };
00077 
00080 typedef void (*lsnf_type)(Vector&,
00081                           Numeric,
00082                           VectorView,
00083                           const Numeric,
00084                           const Index);
00085 
00092 class LineshapeNormRecord{
00093 public:
00094 
00096   LineshapeNormRecord(){};
00097 
00099   LineshapeNormRecord(const String& name,
00100                       const String& description,
00101                       lsnf_type      function)
00102     : mname(name),
00103       mdescription(description),
00104       mfunction(function)
00105   {  }
00107   const String&  Name()        const { return mname;        }   
00109   const String&  Description() const { return mdescription; }
00111   lsnf_type Function() const { return mfunction; }
00112 private:        
00113   String  mname;        
00114   String  mdescription; 
00115   lsnf_type mfunction;  
00116 };
00117 
00123 class LineshapeSpec{
00124 public:
00125 
00127   LineshapeSpec(){};
00128 
00130   LineshapeSpec(const Index&    ind_ls,
00131                 const Index&    ind_lsn,
00132                 const Numeric&   cutoff)
00133     : mind_ls(ind_ls),
00134       mind_lsn(ind_lsn),
00135       mcutoff(cutoff)
00136   {  }
00137 
00139   const Index&  Ind_ls()        const { return mind_ls; }   
00141   void SetInd_ls( Index ind_ls ) { mind_ls = ind_ls; }
00142 
00144   const Index&  Ind_lsn()       const { return mind_lsn; }
00146   void SetInd_lsn( Index ind_lsn ) { mind_lsn = ind_lsn; }
00147 
00151   const Numeric& Cutoff() const { return mcutoff; }
00153   void SetCutoff( Numeric cutoff ) { mcutoff = cutoff; }
00154 private:        
00155   Index  mind_ls;
00156   Index  mind_lsn;
00157   Numeric mcutoff;
00158 };
00159 
00162 typedef Array<LineshapeSpec> ArrayOfLineshapeSpec;
00163 
00164 
00165 
00168 class IsotopeRecord{
00169 public:
00170 
00172   IsotopeRecord() {  }
00173 
00176   IsotopeRecord(const IsotopeRecord& x) :
00177     mname(x.mname),
00178     mabundance(x.mabundance),
00179     mmass(x.mmass),
00180     mmytrantag(x.mmytrantag),
00181     mhitrantag(x.mhitrantag),
00182     mjpltags(x.mjpltags)
00183   {  }
00184 
00186   IsotopeRecord(const String&           name,
00187                 const Numeric&          abundance,
00188                 const Numeric&          mass,
00189                 const Index&            mytrantag,
00190                 const Index&            hitrantag,
00191                 const MakeArray<Index>& jpltags) :
00192     mname(name),
00193     mabundance(abundance),
00194     mmass(mass),
00195     mmytrantag(mytrantag),
00196     mhitrantag(hitrantag),
00197     mjpltags(jpltags)
00198   {
00199     
00200 
00201     
00202 #ifndef NDEBUG
00203       {
00204         
00205         assert( (0<mmytrantag) || (-1==mmytrantag) );
00206         assert( (0<mhitrantag) || (-1==mhitrantag) );
00207         for ( Index i=0; i<mjpltags.nelem(); ++i )
00208           assert( (0<mjpltags[i]) || (-1==mjpltags[i]) );
00209       }
00210 #endif // ifndef NDEBUG
00211   }
00212 
00214   const String&       Name()         const { return mname;  }
00216   const Numeric&      Abundance()    const { return mabundance; }
00219   const Numeric&      Mass()         const { return mmass;    }
00221   const Index&          MytranTag()    const { return mmytrantag;    }
00223   const Index&          HitranTag()    const { return mhitrantag;    }
00227   const ArrayOfIndex&   JplTags()      const { return mjpltags;      }
00228 
00229   void SetPartitionFctCoeff( const ArrayOfNumeric& qcoeff )
00230   {
00231     mqcoeff = qcoeff;
00232   }
00233 
00235 
00247   Numeric CalculatePartitionFctRatio( Numeric reference_temperature,
00248                                       Numeric actual_temperature ) const
00249   {
00250     Numeric qcoeff_at_t_ref =
00251       CalculatePartitionFctAtTemp( reference_temperature );
00252     Numeric qtemp =
00253       CalculatePartitionFctAtTemp( actual_temperature    );
00254 
00255     if ( qtemp <= 0. ) 
00256       {
00257         ostringstream os;
00258         os << "Negative value of partition function was obtained for "
00259            << mname << ".\nProbably caused by low or negative temperature.";
00260         throw runtime_error(os.str());
00261       }
00262     return qcoeff_at_t_ref / qtemp;
00263   }
00264 
00265 private:
00266 
00267   
00268   
00269   Numeric CalculatePartitionFctAtTemp( Numeric temperature ) const;
00270 
00271   String mname;
00272   Numeric mabundance;
00273   Numeric mmass;
00274   Index mmytrantag;
00275   Index mhitrantag;
00276   ArrayOfIndex mjpltags;
00277   ArrayOfNumeric mqcoeff;
00278 };
00279 
00280 
00284 class SpeciesRecord{
00285 public:
00286 
00288   SpeciesRecord(){}  ;
00289   
00291   SpeciesRecord(const char name[],
00292                 const Index degfr,
00293                 const MakeArray<IsotopeRecord>& isotope)
00294     : mname(name),
00295       mdegfr(degfr),
00296       misotope(isotope)
00297   {
00298 
00299     
00300     
00301 
00302 #ifndef NDEBUG
00303       {
00304         
00305         for ( Index i=0; i<misotope.nelem()-1; ++i )
00306           {
00307             assert( misotope[i].Abundance() >= misotope[i+1].Abundance() );
00308           }
00309 
00310         
00311         for ( Index i=0; i<misotope.nelem()-1; ++i )
00312           {
00313             if ( (0<misotope[i].MytranTag()) && (0<misotope[i+1].MytranTag()) )
00314               {
00315                 assert( misotope[i].MytranTag() < misotope[i+1].MytranTag() );
00316             
00317                 
00318                 assert( misotope[i].MytranTag()/10 == misotope[i].MytranTag()/10 );
00319               }
00320           }
00321 
00322         
00323         for ( Index i=0; i<misotope.nelem()-1; ++i )
00324           {
00325             if ( (0<misotope[i].HitranTag()) && (0<misotope[i+1].HitranTag()) )
00326               {
00327                 assert( misotope[i].HitranTag() < misotope[i+1].HitranTag() );
00328             
00329                 
00330                 assert( misotope[i].HitranTag()/10 == misotope[i+1].HitranTag()/10 );
00331               }
00332           }
00333       }
00334 #endif // #ifndef NDEBUG
00335   }
00336 
00337   const String&               Name()     const { return mname;     }   
00338   Index                         Degfr()    const { return mdegfr;    }
00339   const Array<IsotopeRecord>& Isotope()  const { return misotope;  }
00340   Array<IsotopeRecord>&       Isotope()        { return misotope;  }
00341   
00342 private:
00344   String mname;
00346   Index mdegfr;
00348   Array<IsotopeRecord> misotope;
00349 };
00350 
00438 class LineRecord {
00439 public:
00440 
00444   friend void linesElowToJoule(Array<LineRecord>& lines);
00445 
00449   LineRecord()
00450     : mspecies (1000000),
00451       misotope (1000000),
00452       mf       (0.     ),
00453       mpsf     (0.     ),
00454       mi0      (0.     ),
00455       mti0     (0.     ),
00456       melow    (0.     ),
00457       magam    (0.     ),
00458       msgam    (0.     ),
00459       mnair    (0.     ),
00460       mnself   (0.     ),
00461       mtgam    (0.     ),
00462       maux     (       ),
00463       mdf      (-1.    ),
00464       mdi0     (-1.    ),
00465       mdagam   (-1.    ),
00466       mdsgam   (-1.    ),
00467       mdnair   (-1.    ),
00468       mdnself  (-1.    ),
00469       mdpsf    (-1.    )
00470  {  }
00471 
00476   LineRecord( Index                 species,
00477               Index                 isotope,
00478               Numeric               f,
00479               Numeric               psf,
00480               Numeric               i0,
00481               Numeric               ti0,
00482               Numeric               elow,
00483               Numeric               agam,
00484               Numeric               sgam,
00485               Numeric               nair,
00486               Numeric               nself,
00487               Numeric               tgam,
00488               const ArrayOfNumeric& aux,
00489               Numeric               ,
00490               Numeric               ,
00491               Numeric               ,
00492               Numeric               ,
00493               Numeric               ,
00494               Numeric               ,
00495               Numeric               )
00496     : mspecies (species    ),
00497       misotope (isotope    ),
00498       mf       (f          ),
00499       mpsf     (psf        ),
00500       mi0      (i0         ),
00501       mti0     (ti0        ),
00502       melow    (elow       ),
00503       magam    (agam       ),
00504       msgam    (sgam       ),
00505       mnair    (nair       ),
00506       mnself   (nself      ),
00507       mtgam    (tgam       ), 
00508       maux     (aux        )
00509   {
00510     
00511     
00512 
00513     
00514     
00515     extern Array<SpeciesRecord> species_data;
00516     assert( mspecies < species_data.nelem() );
00517     assert( misotope < species_data[mspecies].Isotope().nelem() );
00518   }
00519 
00521   String Version() const
00522   {
00523     ostringstream os;
00524     os << "ARTSCAT-" << mversion;
00525     return os.str();
00526   }
00527 
00530   Index Species() const { return mspecies; }
00531 
00535   Index Isotope() const { return misotope; }
00536 
00540   String Name() const {
00541     
00542     extern const Array<SpeciesRecord> species_data;
00543     const SpeciesRecord& sr = species_data[mspecies];
00544     return sr.Name() + "-" + sr.Isotope()[misotope].Name();
00545   }
00546 
00556   const SpeciesRecord& SpeciesData() const {
00557     
00558     extern const Array<SpeciesRecord> species_data;
00559     return species_data[mspecies];
00560   }
00561 
00573   const IsotopeRecord& IsotopeData() const {
00574     
00575     extern const Array<SpeciesRecord> species_data;
00576     return species_data[mspecies].Isotope()[misotope];
00577   }
00578 
00580   Numeric F() const     { return mf; }
00581 
00583   void setF( Numeric new_mf ) { mf = new_mf; }
00584 
00586   Numeric Psf() const   { return mpsf; }
00587 
00589   void setPsf( Numeric new_mpsf ) { mpsf = new_mpsf; }
00590 
00603   Numeric I0() const    { return mi0; }
00604 
00606   void setI0( Numeric new_mi0 ) { mi0 = new_mi0; }
00607 
00609   Numeric Ti0() const   { return mti0; }
00610 
00612   Numeric Elow() const  { return melow; }
00613 
00615   Numeric Agam() const  { return magam; }
00616 
00618   void setAgam( Numeric new_agam ) { magam = new_agam; }
00619 
00621   Numeric Sgam() const  { return msgam; }
00622 
00624   void setSgam( Numeric new_sgam ) { msgam = new_sgam; }
00625 
00627   Numeric Nair() const  { return mnair; }
00628 
00630   void setNair( Numeric new_mnair ) { mnair = new_mnair; }
00631 
00633   Numeric Nself() const { return mnself; }
00634 
00636   void setNself( Numeric new_mnself ) { mnself = new_mnself; }
00637 
00639   Numeric Tgam() const  { return mtgam; }
00640 
00646   Index Naux() const   { return maux.nelem(); }
00647 
00649   const ArrayOfNumeric& Aux() const { return maux; }
00650   
00651 
00653   Numeric dF() const  { return mdf; }
00654 
00656   Numeric dI0() const  { return mdi0; }
00657 
00659   Numeric dAgam() const  { return mdagam; }
00660 
00662   Numeric dSgam() const  { return mdsgam; }
00663 
00665   Numeric dNair() const  { return mdnair; }
00666 
00668   Numeric dNself() const { return mdnself; }
00669 
00671   Numeric dPsf() const { return mdpsf; }
00672 
00673 
00733   bool ReadFromHitranStream(istream& is);
00734 
00735 
00736 
00806   bool ReadFromHitran2004Stream(istream& is);
00807 
00808 
00809 
00810 
00879   bool ReadFromMytran2Stream(istream& is);
00880 
00881 
00934   bool ReadFromJplStream(istream& is);
00935 
00957   bool ReadFromArtsStream(istream& is);
00958 
00959 
00960 private:
00961   
00962   static const Index mversion = 3;
00963   
00964   Index mspecies;
00965   
00966   Index misotope;
00967   
00968   Numeric mf;
00969   
00970   Numeric mpsf;
00971   
00972   Numeric mi0;
00973   
00974   Numeric mti0;
00975   
00976   Numeric melow;
00977   
00978   Numeric magam;
00979   
00980   Numeric msgam;
00981   
00982   Numeric mnair;
00983   
00984   Numeric mnself;
00985   
00986   Numeric mtgam;
00987   
00988   ArrayOfNumeric maux;
00989   
00990   
00991   
00992   
00993   Numeric mdf;
00994   
00995   Numeric mdi0;
00996   
00997   Numeric mdagam;
00998   
00999   Numeric mdsgam;
01000   
01001   Numeric mdnair;
01002   
01003   Numeric mdnself;
01004  
01005   Numeric mdpsf;
01006 };
01007 
01008 
01009 class SpecIsoMap{
01010 public:
01011   SpecIsoMap():mspeciesindex(0), misotopeindex(0){}
01012   SpecIsoMap(const Index& speciesindex,
01013                 const Index& isotopeindex)
01014     : mspeciesindex(speciesindex),
01015       misotopeindex(isotopeindex) 
01016   {}
01017 
01018   
01019   const Index& Speciesindex() const { return mspeciesindex; }
01020   
01021   const Index& Isotopeindex() const { return misotopeindex; }
01022 
01023 private:
01024   Index mspeciesindex;
01025   Index misotopeindex;
01026 };
01027 
01028 
01029 
01032 typedef Array<LineRecord> ArrayOfLineRecord;
01033 
01037 typedef Array< Array<LineRecord> > ArrayOfArrayOfLineRecord;
01038 
01039 
01040 
01045 ostream& operator << (ostream& os, const LineRecord& lr);
01046 
01047 
01048 
01052 void define_species_map();
01053 
01054 
01055 
01056 
01057 
01061 class OneTag {
01062 public:
01064   OneTag() {  }
01065 
01071   OneTag(String def); 
01072 
01080   String Name() const;
01081     
01083   Index Species() const { return mspecies; }
01084 
01088   Index Isotope() const { return misotope; }
01089 
01092   Numeric Lf() const { return mlf; }
01093 
01096   Numeric Uf() const { return muf; }
01097 
01098 private:
01099   
01100   Index mspecies;
01101   
01102   
01103   
01104   Index misotope;
01105   
01106   
01107   Numeric mlf;
01108   
01109   
01110   Numeric muf;
01111 };
01112 
01113 
01117 ostream& operator << (ostream& os, const OneTag& ot);
01118 
01119 
01126 typedef  Array< Array<OneTag> > TagGroups;
01127 
01128 
01129 void get_tagindex_for_Strings( 
01130               ArrayOfIndex&   tags1_index, 
01131         const TagGroups&      tags1, 
01132         const ArrayOfString&  tags2_Strings );
01133 
01134 void get_tag_group_index_for_tag_group( 
01135               Index&         tags1_index, 
01136         const TagGroups&      tags1, 
01137         const Array<OneTag>&  tags2 );
01138 
01139 String get_tag_group_name( const Array<OneTag>& tg );
01140 
01141 
01142 void write_lines_to_stream(ostream& os,
01143                            const ArrayOfLineRecord& lines);
01144 
01145 
01146 void xsec_species( MatrixView              xsec,
01147                    ConstVectorView         f_mono,
01148                    ConstVectorView         p_abs,
01149                    ConstVectorView         t_abs,           
01150                    ConstVectorView         h2o_abs,           
01151                    ConstVectorView            vmr,
01152                    const ArrayOfLineRecord& lines,
01153                    const Index             ind_ls,
01154                    const Index             ind_lsn,
01155                    const Numeric            cutoff);
01156 
01157 
01158 
01159 Numeric wavenumber_to_joule(Numeric e);
01160 
01161 
01162 
01163 
01164 
01165 
01166 void refr_index_BoudourisDryAir (
01167                     Vector&     refr_index,
01168               ConstVectorView   p_abs,
01169               ConstVectorView   t_abs );
01170 
01171 void refr_index_Boudouris (
01172                     Vector&     refr_index,
01173               ConstVectorView   p_abs,
01174               ConstVectorView   t_abs,
01175               ConstVectorView   h2o_abs );
01176 
01177 
01178 
01179 
01180 
01181 
01182 
01183 void convHitranIERF(     
01184                     Numeric&     mdf,
01185               const Index&       df 
01186                     );
01187 
01188 
01189 
01190 void convHitranIERSH(     
01191                     Numeric&     mdh,
01192               const Index&       dh 
01193                     );
01194 
01195 
01196 
01197 void convMytranIER(     
01198                     Numeric&     mdh,
01199               const Index  &      dh 
01200                     );
01201 
01202 #endif // absorption_h