00001 //===================================================== 00002 // File : f77_interface_base.hh 00003 // Author : L. Plagne <laurent.plagne@edf.fr)> 00004 // Copyright (C) EDF R&D, lun sep 30 14:23:25 CEST 2002 00005 //===================================================== 00006 // 00007 // This program is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 00010 // of the License, or (at your option) any later version. 00011 // 00012 // This program is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 // 00020 #ifndef F77_INTERFACE_BASE_HH 00021 #define F77_INTERFACE_BASE_HH 00022 00023 #include "utilities.h" 00024 #include <vector> 00025 template<class real> 00026 class f77_interface_base{ 00027 00028 public: 00029 00030 typedef real real_type ; 00031 typedef std::vector<real> stl_vector; 00032 typedef std::vector<stl_vector > stl_matrix; 00033 00034 typedef real * gene_matrix; 00035 typedef real * gene_vector; 00036 00037 static void free_matrix(gene_matrix & A, int N){ 00038 delete A; 00039 } 00040 00041 static void free_vector(gene_vector & B){ 00042 delete B; 00043 } 00044 00045 static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){ 00046 int N = A_stl.size(); 00047 A = new real[N*N]; 00048 for (int j=0;j<N;j++) 00049 for (int i=0;i<N;i++) 00050 A[i+N*j] = A_stl[j][i]; 00051 } 00052 00053 static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){ 00054 int N = B_stl.size(); 00055 B = new real[N]; 00056 for (int i=0;i<N;i++) 00057 B[i] = B_stl[i]; 00058 } 00059 00060 static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){ 00061 int N = B_stl.size(); 00062 for (int i=0;i<N;i++) 00063 B_stl[i] = B[i]; 00064 } 00065 00066 static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){ 00067 int N = A_stl.size(); 00068 for (int j=0;j<N;j++){ 00069 A_stl[j].resize(N); 00070 for (int i=0;i<N;i++) 00071 A_stl[j][i] = A[i+N*j]; 00072 } 00073 } 00074 00075 static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){ 00076 for (int i=0;i<N;i++) 00077 cible[i]=source[i]; 00078 } 00079 00080 static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){ 00081 for (int j=0;j<N;j++){ 00082 for (int i=0;i<N;i++){ 00083 cible[i+N*j] = source[i+N*j]; 00084 } 00085 } 00086 } 00087 00088 }; 00089 00090 00091 #endif