36 #ifndef FORTRAN_WRAPPER_H 37 #define FORTRAN_WRAPPER_H 55 typedef double R8_F77;
61 #define SUBROUTINE_F77 extern "C" void 62 #define INTEGER_FUNCTION_F77 extern "C" int 63 #define REAL_FUNCTION_F77 extern "C" float 64 #define LOGICAL_FUNCTION_F77 extern "C" int 65 #define DOUBLE_PRECISION_FUNCTION_F77 extern "C" double 66 #define F77NAME(X) X ## _ 94 template <
class ScalarType>
100 typedef ScalarType scalar_Type;
104 FortranMatrix ( size_t dim1, size_t dim2 = 1 );
105 FortranMatrix ( ScalarType* cppArray, size_t dim1, size_t dim2 = 1 );
106 virtual ~FortranMatrix();
111 operator ScalarType* ();
112 ScalarType& operator() ( size_t index1, size_t index2 = 0 );
116 size_t M_arrayDimensions[ 7 ];
117 ScalarType* M_cppRepresentation;
118 ScalarType* M_fortranRepresentation;
119 const size_t M_numDimensions;
152 class FortranCharacterString
157 FortranCharacterString() {}
158 FortranCharacterString (
char* cstring );
159 FortranCharacterString (
char* cstring,
const size_t stringLength );
160 virtual ~FortranCharacterString();
165 FortranCharacterString operator() ( size_t index );
166 void operator= (
char* str );
172 void pad ( size_t first, size_t paddingSize = 1 );
176 char* M_representation;
188 template <
class ScalarType>
189 FortranMatrix<ScalarType>::FortranMatrix ( size_t dim1, size_t dim2 ) :
190 M_cppRepresentation ( NULL ),
191 M_fortranRepresentation (
new ScalarType[ dim1* dim2 ] ),
192 M_numDimensions ( 2 )
194 M_arrayDimensions[ 0 ] = dim1;
195 M_arrayDimensions[ 1 ] = dim2;
196 M_arrayDimensions[ 2 ] = 0;
197 M_arrayDimensions[ 3 ] = 0;
198 M_arrayDimensions[ 4 ] = 0;
199 M_arrayDimensions[ 5 ] = 0;
200 M_arrayDimensions[ 6 ] = 0;
203 template <
class ScalarType>
204 FortranMatrix<ScalarType>::FortranMatrix ( ScalarType* cppArray, size_t dim1, size_t dim2 ) :
205 M_cppRepresentation ( cppArray ),
206 M_fortranRepresentation (
new ScalarType[ dim1* dim2 ] ),
207 M_numDimensions ( 2 )
209 M_arrayDimensions[ 0 ] = dim1;
210 M_arrayDimensions[ 1 ] = dim2;
211 M_arrayDimensions[ 2 ] = 0;
212 M_arrayDimensions[ 3 ] = 0;
213 M_arrayDimensions[ 4 ] = 0;
214 M_arrayDimensions[ 5 ] = 0;
215 M_arrayDimensions[ 6 ] = 0;
218 size_t index_cpp = 0;
220 for ( size_t i = 0; i < M_arrayDimensions[ 0 ]; i++ )
222 for ( size_t j = 0; j < M_arrayDimensions[ 1 ]; j++ )
224 index_f77 = j * M_arrayDimensions[ 0 ] + i;
225 M_fortranRepresentation[ index_f77 ] = M_cppRepresentation[ index_cpp++ ];
230 template <
class ScalarType>
231 FortranMatrix<ScalarType>::~FortranMatrix()
233 if ( M_cppRepresentation )
235 assert ( M_numDimensions == 2 );
238 size_t index_f77 = 0;
239 for ( size_t j = 0; j < M_arrayDimensions[ 1 ]; j++ )
241 for ( size_t i = 0; i < M_arrayDimensions[ 0 ]; i++ )
243 index_cpp = i * M_arrayDimensions[ 1 ] + j;
244 M_cppRepresentation[ index_cpp ] = M_fortranRepresentation[ index_f77++ ];
249 delete[] M_fortranRepresentation;
256 template <
class ScalarType>
257 FortranMatrix<ScalarType>::operator ScalarType* ()
260 return M_fortranRepresentation;
263 template <
class ScalarType>
264 ScalarType& FortranMatrix<ScalarType>::operator() ( size_t index1, size_t index2 )
266 assert ( M_numDimensions == 2 );
268 size_t index_f77 = index2 * M_arrayDimensions[ 0 ] + index1;
270 return * ( M_fortranRepresentation + index_f77 );
277 inline FortranCharacterString::FortranCharacterString (
char* cstring ) :
278 M_representation ( cstring ),
279 M_length ( strlen ( cstring ) )
282 inline FortranCharacterString::FortranCharacterString (
char* cstring,
const size_t stringLength ) :
283 M_representation ( cstring ),
284 M_length ( stringLength )
287 size_t slen = strlen ( M_representation );
288 size_t actual = ( slen < M_length ) ? slen : M_length;
289 for ( size_t i = actual; i < M_length; i++ )
291 M_representation[ i ] =
' ';
295 inline FortranCharacterString::~FortranCharacterString()
297 if ( M_representation[ M_length ] ==
'\0' )
301 for (
int i = M_length - 1; i >= 0; i-- )
303 if ( M_representation[ i ] ==
'\0' )
307 if ( M_representation[ i ] !=
' ' )
310 M_representation[ i + 1 ] =
'\0';
320 inline FortranCharacterString FortranCharacterString::operator() ( size_t index )
324 size_t pos = index * M_length;
325 FortranCharacterString element ( M_representation + pos, M_length );
329 inline void FortranCharacterString::operator= (
char* str )
331 strncpy ( M_representation, str, M_length );
332 M_representation[ M_length - 1 ] =
'\0';
333 size_t slen = strlen ( M_representation );
334 size_t actual = ( slen < M_length ) ? slen : M_length;
335 for ( size_t i = actual; i < M_length; i++ )
337 M_representation[ i ] =
' ';
341 inline FortranCharacterString::operator
char* ()
343 return M_representation;
350 inline void FortranCharacterString::pad ( size_t first, size_t paddingSize )
352 size_t pos = 0, i = 0, stop = first + paddingSize - 1;
353 for ( size_t index = first; index <= stop; index++ )
355 pos = index * M_length;
356 size_t slen = strlen ( M_representation + pos );
357 size_t actual = ( slen < M_length ) ? slen : M_length;
358 for ( i = pos + actual; i < pos + M_length; i++ )
360 M_representation[ i ] =
' ';
void updateInverseJacobian(const UInt &iQuadPt)