00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00022 
00024 
00040 
00041 
00043 
00044 #include <math.h>
00045 #include "arts.h"
00046 #include "atm_funcs.h"          
00047 #include "file.h"
00048 #include "math_funcs.h"
00049 #include "messages.h"
00050 #include "auto_md.h"
00051 #include "make_array.h"
00052 
00053 #include "complex.h"
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00068 void Echo(const String& message,
00069           const Index& output_level)
00070 {
00071   ostringstream os;
00072   os <<  message << '\n';
00073 
00074   switch (output_level)
00075     {
00076     case 0: out0 << os.str (); break;
00077     case 1: out1 << os.str (); break;
00078     case 2: out2 << os.str (); break;
00079     case 3: out3 << os.str (); break;
00080     default:
00081        throw runtime_error ("Output level must have value from 0-3");
00082     }
00083 
00084 }
00085 
00086 
00093 void Exit()
00094 {
00095   out1 << "  Forced exit.\n";
00096   exit(0);
00097 }
00098 
00099 
00100 
00107 extern const Numeric DEG2RAD;
00108 
00109 void Test( )
00110 {
00111   
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 }
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00172 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 void IndexWriteAscii(
00182         const Index&      v,
00183         const String&   v_name,
00184         const String&   f )
00185 {
00186   String filename = f;
00187 
00188   
00189   filename_ascii( filename, v_name );
00190 
00191   
00192   ArrayOfMatrix am(1);
00193   am[0].resize( 1, 1 );
00194   am[0] = static_cast<Numeric>(v); 
00195   write_array_of_matrix_to_file(filename,am);
00196 }
00197 
00198 
00199 
00200 void IndexReadAscii(
00201               Index&      v,
00202         const String&   v_name,
00203         const String&   f )
00204 {
00205   String filename = f;
00206   
00207   
00208   filename_ascii( filename, v_name );
00209 
00210   
00211   ArrayOfMatrix am;
00212   read_array_of_matrix_from_file(am,filename);
00213   if ( (am.nelem()!=1) || (am[0].nrows()!=1) || (am[0].ncols()!=1) )
00214   {
00215     ostringstream os;
00216     os << "The file " << filename << " contains not a single value.";
00217     throw runtime_error(os.str());
00218   }
00219 
00220   Numeric a = am[0](0,0);
00221 
00222   if ( (a-floor(a)) != 0 )
00223     throw runtime_error("The value in the file is not an integer.");
00224   if ( a < 0 )
00225     throw runtime_error("The value in the file is negative.");
00226 
00227   v = (int) a;
00228 }
00229 
00230 
00231 
00232 
00233 
00234 void NumericWriteAscii(
00235         const Numeric&  v,
00236         const String&   v_name,
00237         const String&   f )
00238 {
00239   String filename = f;
00240 
00241   
00242   filename_ascii( filename, v_name );
00243 
00244   
00245   ArrayOfMatrix am(1);
00246   am[0].resize( 1, 1 );
00247   am[0] = v;                    
00248   write_array_of_matrix_to_file(filename,am);
00249 }
00250 
00251 
00252 void NumericReadAscii(
00253               Numeric&  v,
00254         const String&   v_name,
00255         const String&   f )
00256 {
00257   String filename = f;
00258   
00259   
00260   filename_ascii( filename, v_name );
00261 
00262   
00263   ArrayOfMatrix am;
00264   read_array_of_matrix_from_file(am,filename);
00265   if ( (am.nelem()!=1) || (am[0].nrows()!=1) || (am[0].ncols()!=1) )
00266   {
00267     ostringstream os;
00268     os << "The file " << filename << " contains not a single numeric value";
00269     throw runtime_error(os.str());
00270   }
00271 
00272   v = am[0](0,0);
00273 }
00274 
00275 
00276 
00277 
00278 
00279 void VectorWriteAscii(
00280                        const Vector& v,
00281                        
00282                        const String& v_name,
00283                        
00284                        const String& f)
00285 {
00286   String filename = f;
00287 
00288   
00289   filename_ascii( filename, v_name );
00290 
00291   
00292   Matrix m(v);
00293   
00294   
00295   
00296 
00297   
00298   MakeArray<Matrix> am(m);
00299   
00300   
00301   
00302 
00303   
00304   write_array_of_matrix_to_file(filename,am);
00305 }
00306 
00307 
00308 
00309 void VectorReadAscii(
00310                         Vector& v,
00311                         
00312                         const String& v_name,
00313                         
00314                         const String& f)
00315 {
00316   String filename = f;
00317   
00318   
00319   filename_ascii( filename, v_name );
00320 
00321   
00322   ArrayOfMatrix am;
00323   read_array_of_matrix_from_file(am,filename);
00324 
00325   
00326   if ( 1 != am.nelem() )
00327    throw runtime_error("You tried to convert an array of matrix to a matrix,\n"
00328                        "but the dimension of the array is not 1.");
00329   Matrix m(am[0]);
00330 
00331   
00332   if ( 1 != m.ncols() )
00333     throw runtime_error("You tried to convert a matrix to a vector,\n"
00334                         "but it has more than one column.");
00335 
00336   
00337   v.resize(m.nrows());
00338   v = m(Range(joker),0);        
00339   
00340   
00341 }
00342 
00343 
00344 
00345 
00346 
00347 void MatrixWriteAscii(
00348                        const Matrix& m,
00349                        
00350                        const String& m_name,
00351                        
00352                        const String& f)
00353 {
00354   String filename = f;
00355   
00356   
00357   filename_ascii( filename, m_name );
00358 
00359   
00360   MakeArray<Matrix> am(m);
00361   
00362   
00363   
00364 
00365   
00366   write_array_of_matrix_to_file(filename,am);
00367 }
00368 
00369 
00370 
00371 void MatrixReadAscii(
00372                      Matrix& m,
00373                      
00374                      const String& m_name,
00375                      
00376                      const String& f)
00377 {
00378   String filename = f;
00379   
00380   
00381   filename_ascii( filename, m_name );
00382 
00383   
00384   ArrayOfMatrix am;
00385   read_array_of_matrix_from_file(am,filename);
00386 
00387   
00388 
00389   
00390   if ( 1 != am.nelem() )
00391    throw runtime_error("You tried to convert an array of matrix to a matrix,\n"
00392                        "but the dimension of the array is not 1.");
00393 
00394   m.resize( am[0].nrows(), am[0].ncols() );
00395   m = am[0];
00396 }
00397 
00398 
00399 
00400 
00401 
00402 
00403 void ArrayOfIndexWriteAscii(
00404         const ArrayOfIndex&   v,
00405         const String&         v_name,
00406         const String&         f )
00407 {
00408   String filename = f;
00409 
00410   
00411   filename_ascii( filename, v_name );
00412 
00413   
00414   const Index  n = v.nelem();
00415   ArrayOfMatrix am(1);
00416   am[0].resize(n,1);
00417   for ( Index i=0; i<n; i++ )
00418     am[0](i,0) = static_cast<Numeric>(v[i]);
00419   write_array_of_matrix_to_file(filename,am);
00420 }
00421 
00422 
00423 
00424 void ArrayOfIndexReadAscii(
00425                            ArrayOfIndex&   v,
00426                            const String&   v_name,
00427                            const String&   f )
00428 {
00429   
00430   
00431   
00432   String filename = f;
00433   
00434   
00435   filename_ascii( filename, v_name );
00436 
00437   
00438   ArrayOfMatrix am;
00439   read_array_of_matrix_from_file(am,filename);
00440   if ( (am.nelem()!=1) )
00441   {
00442     ostringstream os;
00443     os << "The file " << filename << " contains more than one vector.";
00444     throw runtime_error(os.str());
00445   }
00446   
00447   Matrix m(am[0]);              
00448                                 
00449 
00450   
00451   if ( 1 != m.ncols() )
00452     throw runtime_error("You tried to convert a matrix to a vector,\n"
00453                         "but it has more than one column.");
00454 
00455   
00456   Vector x(m(Range(joker),0));
00457   
00458   
00459 
00460   const Index  n = x.nelem();
00461   v.resize(n);
00462   for ( Index i=0; i<n; i++ )
00463   {  
00464     if ( (x[i]-floor(x[i])) != 0 )
00465       throw runtime_error("A value in the file is not an integer.");
00466     if ( x[i] < 0 )
00467       throw runtime_error("A value in the file is negative.");
00468     v[i] = (Index) x[i];
00469   }
00470 }
00471 
00472 
00473 
00474 
00475 
00476 void ArrayOfVectorWriteAscii(
00477                               const ArrayOfVector& av,
00478                               
00479                               const String& av_name,
00480                               
00481                               const String& f)
00482 {
00483   String filename = f;
00484   
00485   
00486   filename_ascii( filename, av_name );
00487 
00488   
00489   ArrayOfMatrix am(av.nelem());
00490   for (Index i=0; i<av.nelem(); ++i)
00491     {
00492       
00493       am[i].resize( av[i].nelem(), 1 );
00494       am[i] = av[i];            
00495                                 
00496     }
00497 
00498   
00499   write_array_of_matrix_to_file(filename,am);
00500 }
00501 
00502 
00503 
00504 void ArrayOfVectorReadAscii(
00505                                ArrayOfVector& av,
00506                                
00507                                const String& av_name,
00508                                
00509                                const String& f)
00510 {
00511   String filename = f;
00512   
00513   
00514   filename_ascii( filename, av_name );
00515 
00516   
00517   ArrayOfMatrix am;
00518   read_array_of_matrix_from_file(am,filename);
00519 
00520   
00521   av.resize(am.nelem());
00522   for (Index i=0; i<am.nelem(); ++i)
00523     {
00524       
00525       if ( 1 != am[i].ncols() )
00526         throw runtime_error("You tried to convert a matrix to a vector,\n"
00527                             "but it has more than one column.");
00528 
00529       
00530       av[i].resize(am[i].nrows());
00531       av[i] = am[i](Range(joker),0);    
00532       
00533       
00534     }
00535 }
00536 
00537 
00538 
00539 
00540 
00541 void ArrayOfMatrixWriteAscii(
00542                               const ArrayOfMatrix& am,
00543                               
00544                               const String& am_name,
00545                               
00546                               const String& f)
00547 {
00548   String filename = f;
00549   
00550   
00551   filename_ascii( filename, am_name );
00552 
00553   
00554   write_array_of_matrix_to_file(filename,am);
00555 }
00556 
00557 
00558 
00559 void ArrayOfMatrixReadAscii(
00560                                ArrayOfMatrix& am,
00561                                
00562                                const String& am_name,
00563                                
00564                                const String& f)
00565 {
00566   String filename = f;
00567   
00568   
00569   filename_ascii( filename, am_name );
00570 
00571   
00572   read_array_of_matrix_from_file(am,filename);
00573 }
00574 
00575 
00576 
00577 
00578 
00579 void StringWriteAscii( 
00580                        const String& s,
00581                        
00582                        const String& s_name,
00583                        
00584                        const String& f)
00585 {
00586   String filename = f;
00587   
00588   
00589   filename_ascii( filename, s_name );
00590 
00591   
00592   ArrayOfString as(1);
00593   as[0] = s;
00594 
00595   
00596   write_array_of_String_to_file(filename,as);
00597 }
00598 
00599 
00600 
00601 void StringReadAscii(   
00602                         String& s,
00603                         
00604                         const String& s_name,
00605                         
00606                         const String& f)
00607 {
00608   String filename = f;
00609   
00610   
00611   filename_ascii( filename, s_name );
00612 
00613   
00614   ArrayOfString as;
00615   read_array_of_String_from_file(as,filename);
00616 
00617   
00618   if ( 1 != as.nelem() )
00619    throw runtime_error("You tried to convert an array of String to a String,\n"
00620                        "but the dimension of the array is not 1.");
00621 
00622   s = as[0];
00623 }
00624 
00625 
00626 
00627 
00628 
00629 void ArrayOfStringWriteAscii( 
00630                               const ArrayOfString& as,
00631                               
00632                               const String& as_name,
00633                               
00634                               const String& f)
00635 {
00636   String filename = f;
00637   
00638   
00639   filename_ascii( filename, as_name );
00640 
00641   
00642   write_array_of_String_to_file(filename,as);
00643 }
00644 
00645 
00646 
00647 void ArrayOfStringReadAscii(   
00648                                ArrayOfString& as,
00649                                
00650                                const String& as_name,
00651                                
00652                                const String& f)
00653 {
00654   String filename = f;
00655   
00656   
00657   filename_ascii( filename, as_name );
00658 
00659   
00660   read_array_of_String_from_file(as,filename);
00661 }
00662 
00663 
00664 
00665 
00666 void TagGroupsSpeciesWriteAscii( 
00667                                 const TagGroups& tgs,
00668                                 
00669                                 const String& tgs_name,
00670                                 
00671                                 const String& f)
00672 {
00673   String filename = f;
00674   
00675   
00676   filename_ascii( filename, tgs_name );
00677 
00678   
00679   write_tag_groups_species_to_file(filename,tgs);
00680 }
00681 
00682 
00683 
00684 
00685 
00686 
00687 
00688 
00689 
00690 
00691 
00698 void IndexSet(
00699             Index& x,
00700             
00701             const String& x_name,
00702             
00703             const Index& value)
00704 {
00705   x = value;
00706   out3 << "  Setting " << x_name << " to " << value << ".\n";
00707 }
00708 
00709 
00710 
00711 
00712 
00719 void NumericSet(
00720                 Numeric& x,
00721                 
00722                 const String& x_name,
00723                 
00724                 const Numeric& value)
00725 {
00726   x = value;
00727   out3 << "  Setting " << x_name << " to " << value << ".\n";
00728 }
00729 
00730 
00737 void NumericCopyFirstOfVector(
00738                 
00739                       Numeric&  x,
00740                 
00741                 const String&   x_name,
00742                 
00743                 const Vector&   v,
00744                 const String&   v_name )
00745 {
00746   x = v[0];
00747   out3 << "  Setting " << x_name << " to the first value of " << v_name << ".\n";
00748 }
00749 
00750 
00751 
00758 void NumericCopyLastOfVector(
00759                 
00760                       Numeric&  x,
00761                 
00762                 const String&   x_name,
00763                 
00764                 const Vector&   v,
00765                 const String&   v_name )
00766 {
00767   x = v[v.nelem()-1];
00768   out3 << "  Setting " << x_name << " to the last value of " << v_name << ".\n";
00769 }
00770 
00771 
00772 
00773 
00774 
00781 void VectorSet(           Vector&  x, 
00782                     const String&  x_name,
00783                     const Index&     n,
00784                     const Numeric& value )
00785 {
00786   x.resize(n);
00787   x = value;                    
00788   out2 << "  Creating " << x_name << " as a constant vector\n"; 
00789   out3 << "         length : " << n << "\n";
00790   out3 << "          value : " << value << "\n";
00791 }
00792 
00793 
00794 
00801 void VectorSetLengthFromVector(
00802               Vector&  x, 
00803         const String&  x_name,
00804         const Vector&  z,
00805         const String&  ,
00806         const Numeric& value )
00807 {
00808   const Index  n = z.nelem();
00809   x.resize(n);
00810   x = value;                    
00811   out2 << "  Creating " << x_name << " as a constant vector\n"; 
00812   out3 << "         length : " << n << "\n";
00813   out3 << "          value : " << value << "\n";
00814 }
00815 
00816 
00817 
00824 void VectorLinSpace(      Vector&  x, 
00825                     const String&  x_name,
00826                     const Numeric& start,
00827                     const Numeric& stop,
00828                     const Numeric& step )
00829 {
00830   linspace(x,start,stop,step);
00831   out2 << "  Creating " << x_name << " as linearly spaced vector\n";
00832   out3 << "         length: " << x.nelem() << "\n";
00833   out3 << "    first value: " << x[0] << "\n";
00834   if ( x.nelem() > 1 )
00835   {
00836     out3 << "      step size: " << x[1]-x[0] << "\n";
00837     out3 << "     last value: " << x[x.nelem()-1] << "\n";
00838   }
00839 }
00840 
00841 
00842 
00849 void VectorNLinSpace(     Vector&  x, 
00850                     const String&  x_name,
00851                     const Numeric& start,
00852                     const Numeric& stop,
00853                     const Index& n )
00854 {
00855   if ( n<2 ) 
00856     throw runtime_error("The number of points must be > 1."); 
00857   nlinspace(x,start,stop,n);
00858   out2 << "  Creating " << x_name << " as linearly spaced vector\n";
00859   out3 << "         length: " << n << "\n";
00860   out3 << "    first value: " << x[0] << "\n";
00861   if ( x.nelem() > 1 )
00862   {
00863     out3 << "      step size: " << x[1]-x[0] << "\n";
00864     out3 << "     last value: " << x[x.nelem()-1] << "\n";
00865   }
00866 }
00867 
00868 
00869 
00870 void VectorPressuresForLinAltitudes(
00871                      
00872                      Vector&         p,
00873                      
00874                      const String&   ,
00875                      
00876                      const Vector&   p_abs,
00877                      const Vector&   z_abs,
00878                      
00879                      const Numeric&  delta_z,
00880                      const Numeric&  p_start,
00881                      const Numeric&  p_stop)
00882 
00883 {
00884   Vector p_lim(2), z_lim(2);
00885   p_lim[0] = p_start; 
00886   p_lim[1] = p_stop; 
00887   
00888   interpp(z_lim,p_abs,z_abs,p_lim);
00889 
00890   Vector z;
00891   linspace(z,z_lim[0],z_lim[1],delta_z);
00892   p.resize( z.nelem());
00893   z2p(p, z_abs, p_abs, z);
00894 }
00895 
00896 
00897 
00904 void VectorNLogSpace( Vector&  x, 
00905                       const String&  x_name,
00906                       const Numeric& start,
00907                       const Numeric& stop,
00908                       const Index&     n )
00909 {
00910   if ( n<2 )
00911     throw runtime_error("The number of points must be > 1."); 
00912   if ( (start<=0) || (stop<=0) )
00913     throw runtime_error("Only positive numbers are allowed."); 
00914 
00915   x.resize(n);
00916   x = nlogspace(start,stop,n);
00917   out2 << "  Creating " << x_name << " as logarithmically spaced vector\n";
00918   out3 << "         length: " << n << "\n";
00919   out3 << "    first value: " << x[0] << "\n";
00920   if ( x.nelem() > 1 )
00921     out3 << "     last value: " << x[x.nelem()-1] << "\n";
00922 }
00923 
00924 
00925 
00932 void VectorCopy(
00933                       Vector&   y2,
00934                 const String&   name_y2,
00935                 const Vector&   y1,
00936                 const String&   name_y1 )
00937 {
00938   out2 << "  " << name_y2 << " = " << name_y1 << "\n";
00939   y2.resize( y1.nelem() );
00940   y2 = y1;                      
00941                                 
00942                                 
00943 }
00944 
00945 
00952 void VectorCopyFromMatrix(
00953                       Vector&   v,
00954                 const String&  ,
00955                 const Matrix&   m,
00956                 const String&  ,
00957                 const String&   orientation,
00958                 const Index&    index )
00959 {
00960   if (orientation == String ("col"))
00961     {
00962       if (index < m.ncols ())
00963         {
00964           v.resize (m.nrows ());
00965           v = m (joker, index);
00966         }
00967       else
00968         throw runtime_error ("Index out of column bounds");
00969     }
00970   else if (orientation == String ("row"))
00971     {
00972       if (index < m.nrows ())
00973         {
00974           v.resize (m.ncols ());
00975           v = m (index, joker);
00976         }
00977       else
00978         throw runtime_error ("Index out of row bounds");
00979     }
00980   else
00981     throw runtime_error ("Orientation must be either \"row\" or \"col\"");
00982 }
00983 
00984 
00991 void VectorFlip(
00992                       Vector&   y2,
00993                 const String&   name_y2,
00994                 const Vector&   y1,
00995                 const String&   name_y1 )
00996 {
00997   out2 << "  Flips " << name_y2 << " to create " << name_y1 << "\n";
00998 
00999   Index n = y1.nelem();
01000 
01001   Vector dum( n );
01002   for ( Index i=0; i<n; i++ )
01003     dum[n-1-i] = y1[i];
01004 
01005   y2.resize( n );
01006   y2 = dum;                     
01007                                 
01008                                 
01009 }
01010 
01011 
01012 
01019 void VectorPlanck(
01020                     Vector&   y,
01021               const String&   y_name,
01022               const Vector&   f,
01023               const String&   ,
01024               const Numeric&  t )
01025 {
01026   if ( t > 0 )
01027   {
01028     y.resize( f.nelem() );
01029     planck( y, f, t );
01030     out2<<"  Setting " << y_name << " to blackbody radiation for "<<t<<" K.\n";
01031   }
01032   else
01033     throw runtime_error("The temperature must be > 0.");
01034 }
01035 
01036 
01037 
01044 void VectorCalcLog10(
01045                     Vector&   out,
01046               const String&   out_name,
01047               const Vector&   in,
01048               const String&   in_name )
01049 {
01050   out2<<"  " << out_name << " = log10( " << in_name << " )\n";
01051 
01052   out.resize( in.nelem() );
01053   transform( out, log10, in );  
01054 }
01055 
01056 
01057 
01064 void VectorAdd(
01065                     Vector&   out,
01066               const String&   out_name,
01067               const Vector&   in,
01068               const String&   in_name,
01069               const Numeric&  value )
01070 {
01071   out2<<"  " << out_name << " = " << in_name << " + " << value << "\n";
01072 
01073   
01074   if (&out==&in)
01075     {
01076       
01077       out += value;             
01078                                 
01079                                 
01080     }
01081   else
01082     {
01083       
01084       
01085 
01086       out.resize( in.nelem() );
01087       out = in;                 
01088                                 
01089                                 
01090       out += value;
01091     }
01092 }
01093 
01094 
01095 
01102 void VectorScale(
01103                     Vector&   out,
01104               const String&   out_name,
01105               const Vector&   in,
01106               const String&   in_name,
01107               const Numeric&  value )
01108 {
01109   out2<<"  " << out_name << " = " << in_name << " * " << value << "\n";
01110 
01111   
01112   if (&out==&in)
01113     {
01114       
01115       out *= value;             
01116                                 
01117                                 
01118     }
01119   else
01120     {
01121       
01122       
01123 
01124       out.resize( in.nelem() );
01125       out = in;                 
01126                                 
01127                                 
01128       out *= value;
01129     }
01130 }
01131 
01143 void VectorMatrixMultiply(
01144                           Vector& y,
01145                           
01146                           const String& ,
01147                           
01148                           const Matrix& M,
01149                           const Vector& x,
01150                           
01151                           const String& M_name,
01152                           const String& x_name)
01153 {
01154   
01155   check_length_ncol( x, x_name, M, M_name );
01156 
01157   
01158   Vector dummy( M.nrows() );
01159 
01160   mult( dummy, M, x );
01161 
01162   
01163 
01164   y.resize( dummy.nelem() );
01165 
01166   y = dummy;
01167 }
01168 
01169 
01170 
01171 
01178 void MatrixSet(           Matrix&  x, 
01179                     const String&  x_name,
01180                     const Index&     nrows,
01181                     const Index&     ncols,
01182                     const Numeric& value )
01183 {
01184   x.resize( nrows, ncols );
01185   x = value;                    
01186   out2 << "  Creating " << x_name << " as a constant matrix\n"; 
01187   out3 << "          nrows : " << nrows << "\n";
01188   out3 << "          ncols : " << ncols << "\n";
01189   out3 << "          value : " << value << "\n";
01190 }
01191 
01192 
01193 
01194 void MatrixCopy(
01195               Matrix&   y2,
01196         const String&   name_y2,
01197         const Matrix&   y1,
01198         const String&   name_y1 )
01199 {
01200   out2 << "  " << name_y2 << " = " << name_y1 << "\n";
01201   y2.resize( y1.nrows(), y1.ncols() );
01202   y2 = y1;                      
01203                                 
01204                                 
01205 }
01206 
01207 
01208 
01209 void MatrixFillWithVector(
01210               Matrix&   m,
01211         const String&   name_m,
01212         const Vector&   y,
01213         const String&   name_y,
01214         const Index&      n )
01215 {
01216   out2 << "  Creates" << name_m << " by copying " << name_y << n << "times.\n";
01217   m.resize( y.nelem(), n );
01218   for ( Index i=0; i<n; ++i ) 
01219     m(Range(joker),i) = y;      
01220                                 
01221 }
01222 
01223 
01224 
01231 void MatrixScale(
01232                     Matrix&   out,
01233               const String&   out_name,
01234               const Matrix&   in,
01235               const String&   in_name,
01236               const Numeric&  value )
01237 {
01238   out2<<"  " << out_name << " = " << in_name << " * " << value << "\n";
01239 
01240   
01241   if (&out==&in)
01242     {
01243       
01244       out *= value;             
01245                                 
01246                                 
01247     }
01248   else
01249     {
01250       
01251       
01252 
01253       out.resize( in.nrows(), in.ncols() );
01254       out = in;                 
01255                                 
01256                                 
01257       out *= value;
01258     }
01259 }
01260 
01261 
01262 
01269 void MatrixDiagonal(
01270                     Matrix&           x, 
01271                     const String&     x_name,
01272                     const Index&      nrows,
01273                     const Numeric&    value )
01274 {
01275   x.resize( nrows, nrows );
01276   for ( Index i=0; i<Index(nrows); i++ )
01277     x(i,i) = value;
01278 
01279   out2 << "  Creating " << x_name << " as a diagonal matrix\n"; 
01280   out3 << "          nrows : " << nrows << "\n";
01281   out3 << "          value : " << value << "\n";
01282 }
01283 
01295 void MatrixMatrixMultiply(
01296                           Matrix& Y,
01297                           
01298                           const String& ,
01299                           
01300                           const Matrix& M,
01301                           const Matrix& X,
01302                           
01303                           const String& M_name,
01304                           const String& X_name)
01305 {
01306   
01307   check_ncol_nrow( M, M_name, X, X_name );
01308 
01309   
01310   Matrix dummy( M.nrows(), X.ncols() );
01311 
01312   mult( dummy, M, X );
01313 
01314   
01315 
01316   Y.resize( dummy.nrows(), dummy.ncols() );
01317 
01318   Y = dummy;
01319 }
01320 
01321 void ArrayOfMatrixMatrixMultiply(
01322                                  ArrayOfMatrix& Y,
01323                                  
01324                                  const String& ,
01325                                  
01326                                  const Matrix& M,
01327                                  const ArrayOfMatrix& X,
01328                                  
01329                                  const String& M_name,
01330                                  const String& X_name)
01331 {
01332   
01333   
01334 
01335   
01336   ArrayOfMatrix dummy( X.nelem() );
01337   
01338   
01339   for ( Index i=0; i<X.nelem(); i++ )
01340     {
01341       
01342       check_ncol_nrow( M, M_name, X[i], X_name );
01343       
01344       
01345       Matrix dummymat( M.nrows(), X[i].ncols() );
01346       
01347       mult( dummymat, M, X[i] );
01348       
01349       
01350       
01351       dummy[i].resize( dummymat.nrows(), dummymat.ncols() );
01352       
01353       dummy[i] = dummymat;
01354     }
01355   
01356   Y.resize( dummy.nelem() );
01357   for (Index i = 0; i < dummy.nelem(); i++)
01358     {
01359       Y[i].resize( dummy[i].nrows(), dummy[i].ncols() );
01360       Y[i] = dummy[i];
01361     }
01362 }
01363 
01364 
01376 void MatrixMatrixAdd(
01377                           Matrix& Y,
01378                           
01379                           const String& ,
01380                           
01381                           const Matrix& M,
01382                           const Matrix& X,
01383                           
01384                           const String& M_name,
01385                           const String& X_name)
01386 {
01387   Index m = M.nrows();
01388   Index n = M.ncols();
01389 
01390   
01391   if ( n != X.ncols() || m != X.nrows() )
01392   {
01393     ostringstream os;
01394     os << "The size of the two matrices must be identical. \n"
01395        << "Size of " << M_name << " is " << M.nrows() << " x " << M.ncols() 
01396        << "\n"
01397        << "Size of " << X_name << " is " << X.nrows() << " x " << X.ncols();
01398     throw runtime_error( os.str() );
01399   }
01400 
01401   
01402   Matrix dummy( m, n );
01403   Index i,j;
01404   
01405   for ( i=0; i<m; i++ )
01406   {
01407     for ( j=0; j<n; j++ )
01408       dummy(i,j) = M(i,j) + X(i,j);
01409   }
01410 
01411   
01412   Y.resize( m, n );
01413 
01414   Y = dummy;
01415 }
01416 
01417 
01418 
01419 
01420 
01421 
01428 void StringSet(           String&  s, 
01429                     const String&  s_name,
01430                     const String&  s2 )
01431 {
01432   s = s2;
01433   out3 << "  Setting " << s_name << " to " << s2 << "\n"; 
01434 }
01435 
01436 
01437 
01438 
01439 
01446 void ArrayOfStringSet(    
01447               ArrayOfString&  sa, 
01448         const String&         sa_name,
01449         const ArrayOfString&  sa2 )
01450 {
01451   sa.resize(sa2.nelem());
01452   sa = sa2;                     
01453   out3 << "  Setting " << sa_name << "\n"; 
01454 }
01455