00001 /* Copyright (C) 2003-2008 Oliver Lemke <olemke@core-dump.info> 00002 00003 This program is free software; you can redistribute it and/or 00004 modify it under the terms of the GNU General Public License as 00005 published by the Free Software Foundation; either version 2 of the 00006 License, or (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00016 USA. */ 00017 00018 #include <iostream> 00019 #if HAVE_CONFIG_H 00020 #include <config.h> 00021 #else 00022 #error "Please run ./configure in the top arts directory before compiling." 00023 #endif 00024 00025 #if HAVE_UNISTD_H 00026 # include <sys/types.h> 00027 # include <unistd.h> 00028 #endif 00029 #ifdef _POSIX_VERSION 00030 #include <sys/times.h> 00031 #endif 00032 #include "legendre.h" 00033 #include "exceptions.h" 00034 00035 int 00036 main (int argc, char *argv[]) 00037 { 00038 Index l, m; 00039 Numeric x; 00040 00041 if (argc != 4) 00042 { 00043 cerr << "Usage: " << argv[0] << " l m x" << endl; 00044 exit (1); 00045 } 00046 00047 l = atoi (argv[1]); 00048 m = atoi (argv[2]); 00049 x = strtod (argv[3], NULL); 00050 00051 try 00052 { 00053 cout << "l = " << l << " m = " << m << " x = " << x << endl; 00054 cout << "Pml = " << legendre_poly (l, m, x) << endl; 00055 cout << "dPml = " << legendre_poly_deriv (l, m, x) << endl; 00056 cout << "Norm Pml = " << legendre_poly_norm_schmidt (l, m, x) << endl; 00057 cout << "Norm dPml = " << legendre_poly_norm_schmidt_deriv (l, m, x) << endl; 00058 } 00059 catch (runtime_error e) 00060 { 00061 cerr << e.what (); 00062 } 00063 00064 /* struct tms cput_start, cput_end; 00065 const Index n = 1000000; 00066 Index clktck; 00067 Vector v2 (n), r2 (n); 00068 00069 cout << endl << "Timing (" 00070 << n << " loops):" << endl; 00071 00072 for (Index i = 0; i < n; i++) 00073 { 00074 v2[i] = -1.0 + Numeric (i) / n * 2.0; 00075 } 00076 00077 if ((clktck = sysconf (_SC_CLK_TCK)) < 0) 00078 throw runtime_error ("Timer error: Unable to determine CPU clock ticks"); 00079 00080 if (times (&cput_start) == -1) 00081 throw runtime_error ("Timer error: Unable to get current CPU time"); 00082 00083 for (Index i = 0; i < n; i++) 00084 r2[i] = legendre_poly (l, m, v2[i]); 00085 00086 if (times (&cput_end) == -1) 00087 throw runtime_error ("Timer error: Unable to get current CPU time"); 00088 00089 cout << "CPU time: " << setprecision (2) 00090 << ((cput_end.tms_stime - cput_start.tms_stime) 00091 + (cput_end.tms_utime - cput_start.tms_utime)) 00092 / (Numeric)clktck << " s" << endl; 00093 */ 00094 00095 return (0); 00096 } 00097