Size of Fortran Integer ----------------------- Author: Tom Goodale Date: June 2001 Why --- (From Jonathan Thornburg) New code that lives inside of Cactus can indeed use the various Cactus generic datatypes. The problem is with calling *3rd-party* Fortran code, eg routines from BLAS, LAPACK, QUADPACK, ODEPACK, the ACM TOMS routines (all these are freely available on netlib), the NAG or IMSL libraries, etc etc. This code has never heard of Cactus, and declares its parameters as Fortran INTEGER, REAL, and/or DOUBLE PRECISION. If I get this code as Fortran source, I still don't want to modify its INTEGER variables & parameters to be one of the Cactus types, for all the obvious configuration- -control and software-engineering reasons. (Not to mention that some of this code -- eg ODEPACK -- plays real/integer overlaying tricks which will break if I change the size of its INTEGER variables.) If I get this code as a binary .o/.a file for a given machine (eg many vendors offer heavily-optimized machine-coded BLAS this way), then obviously I can't change it to make use of the Cactus types. So to call this code, I need to pass-by-reference scalars and/or arrays of some C/C++ type corresponding to Fortran INTEGER, REAL, and/or DOUBLE PRECISION. I think it's pretty safe to assume that C/C++ float corresponds to Fortran REAL, and C/C++ double corresponds to Fortran DOUBLE PRECISION. [It would be wrong to use CCTK_REAL because this depends on REAL_PRECISION in the Cactus configuration, while what's needed is something matching the 3rd-party code, which doesn't know about the Cactus configuration and thus won't change with it.] But which C/C++ type corresponds to Fortran INTEGER, i.e. which C/C++ type should I pass-by-reference to a Fortran routine which expects an INTEGER parameter? It would be wrong to use CCTK_INT, because this depends on INTEGER_PRECISION in the Cactus configuration, while again what's needed is something matching the 3rd-party code, which doesn't know about the Cactus configuration and thus won't change with it. On many platforms CCTK_INT4 corresponds to Fortran INTEGER. But this isn't portable: on some platforms it might be CCTK_INT8 or even CCTK_INT2. My request is for a Cactus typedef to tell me which of the Cactus data types (in turn ultimately resolving to C short, int, long, or long long) corresponds to Fortran INTEGER on the current platform. Solution -------- Need a typedef of something like CCTK_FORTRAN_INT which is the integer type corresponding to INTEGER in Fortran, and similarly stuff for logicical, so it is then possible to pass stuff to pre-built libraries. It shouldn't affect anything we do, but adds greater flexibility for people writing thorns. Basically need to generate a fortran file PROGRAM test LOGICAL foo_log(2) INTEGER foo_int(2) REAL foo_real(2) DOUBLE PRECISION foo_double(2) foo_log(1) = .true. foo_log(2) = .false. MakeSizes(foo_log(1), foo_log(2), foo_int(1), foo_int(2), ... END which calles a C routine void CCTK_FCALL CCTK_FNAME(MakeSizes)(int *log1, int *log2, int *integer1, int *integer2, etc) { unsigned int logical_size; unsigned int integer_size; ... logical_size = log2-log1; switch(logical_size) { case sizeof(short int): { short int *log_true; short int *log_false; log_true = (short int *)log1; etc } etc Print out a load of #defines return; } } and do this after we determine the fortran naming rules in the configure stuff.