diff options
author | James Laird <jlaird@hdfgroup.org> | 2005-04-25 19:00:06 (GMT) |
---|---|---|
committer | James Laird <jlaird@hdfgroup.org> | 2005-04-25 19:00:06 (GMT) |
commit | a05061f512a52832cc69211db0e382d30eecaaa5 (patch) | |
tree | 1a4d5a3e93700a3b493171e9e32527ae151d63f6 /fortran/src | |
parent | 1cc3666a270a15783574a2f2a7c6d9bc1209a76b (diff) | |
download | hdf5-a05061f512a52832cc69211db0e382d30eecaaa5.zip hdf5-a05061f512a52832cc69211db0e382d30eecaaa5.tar.gz hdf5-a05061f512a52832cc69211db0e382d30eecaaa5.tar.bz2 |
[svn-r10657] Purpose:
Configuration feature
Description:
Fortran integer types (not reals) are now automatically detected at
build-time.
Solution:
Two helper programs are used, one to detect what types the Fortran compiler
has access to, and one to generate header files for C and Fortran matching
up types.
Platforms tested:
mir, copper, modi4, pommier (last week)
Misc. update:
MANIFEST updated, H5f90fortran_types.f90 removed from configure.in, since
it is not longer generated by configure.
Diffstat (limited to 'fortran/src')
-rw-r--r-- | fortran/src/H5_f.c | 2 | ||||
-rw-r--r-- | fortran/src/H5f90i.h | 101 | ||||
-rw-r--r-- | fortran/src/H5f90proto.h | 2 | ||||
-rw-r--r-- | fortran/src/H5fortran_detect.f90 | 95 | ||||
-rw-r--r-- | fortran/src/H5fortran_detect_gen.f90 | 59 | ||||
-rw-r--r-- | fortran/src/H5fortran_types.f90.in | 45 | ||||
-rw-r--r-- | fortran/src/H5match_types.c | 352 | ||||
-rw-r--r-- | fortran/src/Makefile.am | 43 | ||||
-rw-r--r-- | fortran/src/Makefile.in | 92 |
9 files changed, 629 insertions, 162 deletions
diff --git a/fortran/src/H5_f.c b/fortran/src/H5_f.c index 6ba85fc..302d67e 100644 --- a/fortran/src/H5_f.c +++ b/fortran/src/H5_f.c @@ -186,7 +186,7 @@ nh5close_types_c( hid_t_f * types, int_f *lentypes, *---------------------------------------------------------------------------*/ int_f nh5init_flags_c( int_f *h5d_flags, int_f *h5f_flags, - int_f *h5fd_flags, hid_t *h5fd_hid_flags, + int_f *h5fd_flags, hid_t_f *h5fd_hid_flags, int_f *h5g_flags, int_f *h5i_flags, int_f *h5p_flags, int_f *h5r_flags, int_f *h5s_flags, int_f *h5t_flags, int_f *h5z_flags) diff --git a/fortran/src/H5f90i.h b/fortran/src/H5f90i.h index c1a390c..221e854 100644 --- a/fortran/src/H5f90i.h +++ b/fortran/src/H5f90i.h @@ -22,17 +22,17 @@ #include "H5private.h" +/* + * Include generated header. This header defines integer types, + * so this file only needs to define _fcd and real_f. + */ +#include "H5f90i_gen.h" + #if (defined (UNICOS) || (defined (_UNICOS))) #include <fortran.h> /*typedef char* _fcd;*/ -typedef long haddr_t_f; -typedef long hsize_t_f; -typedef long hssize_t_f; -typedef long size_t_f; -typedef long int_f; -typedef long hid_t_f; typedef double real_f; #endif /* UNICOS */ @@ -40,12 +40,6 @@ typedef double real_f; #if defined(IBM6000) || defined(_AIX) typedef char *_fcd; -typedef long long haddr_t_f; -typedef long long hsize_t_f; -typedef long long hssize_t_f; -typedef int size_t_f; -typedef int int_f; -typedef int hid_t_f; typedef float real_f; #define _fcdtocp(desc) (desc) #endif /*IBM6000*/ @@ -53,12 +47,6 @@ typedef float real_f; /* MAC APPLE definitions with IBM XL compiler*/ #if defined(__APPLE__) typedef char *_fcd; -typedef long long haddr_t_f; -typedef long long hsize_t_f; -typedef long long hssize_t_f; -typedef int size_t_f; -typedef int int_f; -typedef int hid_t_f; typedef float real_f; #define _fcdtocp(desc) (desc) @@ -69,47 +57,24 @@ typedef float real_f; /* Common definitions */ typedef char *_fcd; -typedef int int_f; -typedef int hid_t_f; typedef float real_f; #define _fcdtocp(desc) (desc) /* IA32 specific definitions */ #if (defined(i386) || defined(__i386) || defined(__i386__)) -typedef long long haddr_t_f; -typedef long long hsize_t_f; -typedef long long hssize_t_f; -typedef int size_t_f; - /* AMD64 specific definitions */ #elif defined __x86_64__ -typedef long long haddr_t_f; -typedef long long hsize_t_f; -typedef long long hssize_t_f; -typedef int size_t_f; - /* IA64 specific definitions */ #elif defined __ia64 -typedef long haddr_t_f; -typedef long hsize_t_f; -typedef long hssize_t_f; -typedef long size_t_f; - #endif /* IA64 */ #endif /* LINUX*/ #if defined(IRIX) || defined(IRIS4) || defined(sgi) || defined(__sgi__) || defined(__sgi) typedef char *_fcd; -typedef long haddr_t_f; -typedef long hsize_t_f; -typedef long hssize_t_f; -typedef long size_t_f; -typedef int int_f; -typedef int hid_t_f; typedef float real_f; #define _fcdtocp(desc) (desc) #endif /* IRIX */ @@ -117,12 +82,6 @@ typedef float real_f; #if (defined(SUN) || defined(sun) || defined(__sun__) || defined(__SUNPRO_C)) & !defined(__i386) typedef char *_fcd; -typedef long long haddr_t_f; -typedef long long hssize_t_f; -typedef long long hsize_t_f; -typedef int size_t_f; -typedef int int_f; -typedef int hid_t_f; typedef float real_f; #define _fcdtocp(desc) (desc) @@ -131,12 +90,6 @@ typedef float real_f; #if defined DEC_ALPHA || (defined __alpha && defined __unix__ && !defined __linux__) typedef char *_fcd; -typedef long haddr_t_f; -typedef long hsize_t_f; -typedef long hssize_t_f; -typedef long size_t_f; -typedef int int_f; -typedef int hid_t_f; typedef float real_f; #define _fcdtocp(desc) (desc) @@ -145,12 +98,6 @@ typedef float real_f; #if defined __alpha__ && defined __linux__ typedef char *_fcd; -typedef long long haddr_t_f; -typedef long long hsize_t_f; -typedef long long hssize_t_f; -typedef long long size_t_f; -typedef int int_f; -typedef int hid_t_f; typedef float real_f; #define _fcdtocp(desc) (desc) @@ -159,27 +106,14 @@ typedef float real_f; #if defined(HP9000) || (!defined(__convexc__) && (defined(hpux) || defined(__hpux))) typedef char *_fcd; -typedef long long haddr_t_f; -typedef long long hsize_t_f; -typedef long long hssize_t_f; -typedef long size_t_f; -typedef int int_f; -typedef int hid_t_f; typedef float real_f; #define _fcdtocp(desc) (desc) #endif /* HP9000 */ - #if defined _WINDOWS || defined WIN32 typedef char *_fcd; -typedef int haddr_t_f; -typedef int hsize_t_f; -typedef int hssize_t_f; -typedef int size_t_f; -typedef int int_f; -typedef int hid_t_f; typedef float real_f; #define _fcdtocp(desc) (desc) @@ -191,32 +125,9 @@ typedef float real_f; /* Common definitions */ typedef char *_fcd; -typedef int int_f; -typedef int hid_t_f; typedef float real_f; #define _fcdtocp(desc) (desc) -/* IA32 specific definitions */ -#if (defined(i386) || defined(__i386) || defined(__i386__)) -typedef long long haddr_t_f; -typedef long long hsize_t_f; -typedef long long hssize_t_f; -typedef int size_t_f; -/* AMD64 specific definitions */ -#elif defined __x86_64__ -typedef long long haddr_t_f; -typedef long long hsize_t_f; -typedef long long hssize_t_f; -typedef int size_t_f; -/* IA64 specific definitions */ -#elif defined __ia64 -typedef long haddr_t_f; -typedef long hsize_t_f; -typedef long hssize_t_f; -typedef long size_t_f; -#endif /* IA64 */ - - #endif /* FreeBSD */ #endif /* _H5f90i_H */ diff --git a/fortran/src/H5f90proto.h b/fortran/src/H5f90proto.h index 027cf1a..537ae97 100644 --- a/fortran/src/H5f90proto.h +++ b/fortran/src/H5f90proto.h @@ -650,7 +650,7 @@ H5_FCDLL int_f nh5open_c(void); H5_FCDLL int_f nh5close_c(void); H5_FCDLL int_f nh5init_types_c(hid_t_f *types, hid_t_f * floatingtypes, hid_t_f * integertypes); H5_FCDLL int_f nh5close_types_c(hid_t_f *types, int_f *lentypes, hid_t_f * floatingtypes, int_f * floatinglen, hid_t_f * integertypes, int_f * integerlen); - H5_FCDLL int_f nh5init_flags_c( int_f *h5d_flags, int_f *h5f_flags, +H5_FCDLL int_f nh5init_flags_c( int_f *h5d_flags, int_f *h5f_flags, int_f *h5fd_flags, hid_t_f *h5fd_hid_flags, int_f *h5g_flags, int_f *h5i_flags, int_f *h5p_flags, int_f *h5r_flags, int_f *h5s_flags, diff --git a/fortran/src/H5fortran_detect.f90 b/fortran/src/H5fortran_detect.f90 new file mode 100644 index 0000000..3ddcc3c --- /dev/null +++ b/fortran/src/H5fortran_detect.f90 @@ -0,0 +1,95 @@ + program int_kind + write(*,*) " /*generating header file*/ " + call i01() + call i02() + call i04() + call i08() + end program int_kind + subroutine i01() + implicit none + integer( 1 ) :: a + integer :: a_size + a_size = bit_size(a) + if (a_size .eq. 8) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_1" + endif + if (a_size .eq. 16) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_2" + endif + if (a_size .eq. 32) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_4" + endif + if (a_size .eq. 64) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_8" + endif + if (a_size .eq. 128) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_16" + endif + return + end subroutine + subroutine i02() + implicit none + integer( 2 ) :: a + integer :: a_size + a_size = bit_size(a) + if (a_size .eq. 8) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_1" + endif + if (a_size .eq. 16) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_2" + endif + if (a_size .eq. 32) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_4" + endif + if (a_size .eq. 64) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_8" + endif + if (a_size .eq. 128) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_16" + endif + return + end subroutine + subroutine i04() + implicit none + integer( 4 ) :: a + integer :: a_size + a_size = bit_size(a) + if (a_size .eq. 8) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_1" + endif + if (a_size .eq. 16) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_2" + endif + if (a_size .eq. 32) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_4" + endif + if (a_size .eq. 64) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_8" + endif + if (a_size .eq. 128) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_16" + endif + return + end subroutine + subroutine i08() + implicit none + integer( 8 ) :: a + integer :: a_size + a_size = bit_size(a) + if (a_size .eq. 8) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_1" + endif + if (a_size .eq. 16) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_2" + endif + if (a_size .eq. 32) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_4" + endif + if (a_size .eq. 64) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_8" + endif + if (a_size .eq. 128) then + write(*,*) "#define H5_FORTRAN_HAS_INTEGER_16" + endif + return + end subroutine diff --git a/fortran/src/H5fortran_detect_gen.f90 b/fortran/src/H5fortran_detect_gen.f90 new file mode 100644 index 0000000..4af696f --- /dev/null +++ b/fortran/src/H5fortran_detect_gen.f90 @@ -0,0 +1,59 @@ +! H5test_kind.f90 +! +! This fortran program generates H5fortran_detect.f90 +! + program test_kind + integer :: i, j, last, kind_numbers(10) + last = -1 + ii = 0 + j = selected_int_kind(18) +! write(*,*) j + do i = 1,100 + j = selected_int_kind(i) + if(j .ne. last) then + if(last .ne. -1) then + ii = ii + 1 + kind_numbers(ii) = last + endif + last = j + if(j .eq. -1) exit + endif + enddo +! write(*,*) kind_numbers(1:ii) +! Generate a program + write(*,*) "program int_kind" + write(*,*) "write(*,*) "" /*generating header file*/ """ + do i = 1, ii + j = kind_numbers(i) + write(*, "("" call i"", i2.2,""()"")") j + enddo + write(*,*) "end program int_kind" + do i = 1, ii + j = kind_numbers(i) + write(*, "("" subroutine i"" i2.2,""()"")") j + write(*,*)" implicit none" + write(*,*)" integer(",j,") :: a" + write(*,*)" integer :: a_size" + write(*,*)" a_size = bit_size(a)" + write(*,*)" if (a_size .eq. 8) then" + write(*,*)" write(*,*) ""#define H5_FORTRAN_HAS_INTEGER_1"" " + write(*,*)" endif" + write(*,*)" if (a_size .eq. 16) then" + write(*,*)" write(*,*) ""#define H5_FORTRAN_HAS_INTEGER_2"" " + write(*,*)" endif" + write(*,*)" if (a_size .eq. 32) then" + write(*,*)" write(*,*) ""#define H5_FORTRAN_HAS_INTEGER_4"" " + write(*,*)" endif" + write(*,*)" if (a_size .eq. 64) then" + write(*,*)" write(*,*) ""#define H5_FORTRAN_HAS_INTEGER_8"" " + write(*,*)" endif" + write(*,*)" if (a_size .eq. 128) then" + write(*,*)" write(*,*) ""#define H5_FORTRAN_HAS_INTEGER_16"" " + write(*,*)" endif" + write(*,*)" return" + write(*,*)" end subroutine" + enddo + end program + + + diff --git a/fortran/src/H5fortran_types.f90.in b/fortran/src/H5fortran_types.f90.in deleted file mode 100644 index 0aaabb6..0000000 --- a/fortran/src/H5fortran_types.f90.in +++ /dev/null @@ -1,45 +0,0 @@ - -! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -! Copyright by the Board of Trustees of the University of Illinois. * -! All rights reserved. * -! * -! This file is part of HDF5. The full HDF5 copyright notice, including * -! terms governing use, modification, and redistribution, is contained in * -! the files COPYING and Copyright.html. COPYING can be found at the root * -! of the source code distribution tree; Copyright.html can be found at the * -! root level of an installed copy of the electronic HDF5 document set and * -! is linked from the top-level documents page. It can also be found at * -! http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * -! access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * -! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -! -! -! This file contains HDF5 Fortran90 type definitions -! - MODULE H5FORTRAN_TYPES - ! - ! HDF5 integers - ! - ! Each of the arguments of SELECTED_INT_KIND function should be - ! determined by configure. - ! R_LARGE is the number of digits for the biggest integer supported. - ! R_INTEGER is the number of digits in INTEGER - ! For example: - ! On 64 bit machine ( DEC ALPHA) R_LARGE = 18 and R_INTEGER = 9 - ! On 32 bit machines ( Sparc Solaris ) R_LARGE = 9 and R_INTEGER = 9 - ! - INTEGER, PARAMETER :: R_LARGE = @R_LARGE@ - INTEGER, PARAMETER :: R_INTEGER = @R_INTEGER@ - INTEGER, PARAMETER :: HADDR_T = @HADDR_T@ - INTEGER, PARAMETER :: HSIZE_T = @HSIZE_T@ - INTEGER, PARAMETER :: HSSIZE_T = @HSSIZE_T@ - INTEGER, PARAMETER :: HID_T = @HID_T@ - INTEGER, PARAMETER :: SIZE_T = @SIZE_T@ - - ! - ! Some HDF5 FORTARN90 default values ( here for now 8/5/99 EIP ) - ! - - INTEGER(SIZE_T), PARAMETER :: OBJECT_NAMELEN_DEFAULT_F = @OBJECT_NAMELEN_DEFAULT_F@ - - END MODULE H5FORTRAN_TYPES diff --git a/fortran/src/H5match_types.c b/fortran/src/H5match_types.c new file mode 100644 index 0000000..47164c7 --- /dev/null +++ b/fortran/src/H5match_types.c @@ -0,0 +1,352 @@ +/* C Program to find type sizes */ + +#include <stdio.h> +#include <assert.h> + +#include "H5public.h" +/* Include H5Ipublic.h for hid_t type */ +#include "H5Ipublic.h" + +/* Definitions of which fortran type sizes exist */ +#include "H5fort_type_defines.h" + +/* File pointers for files */ +FILE * c_header; +FILE * fort_header; + +#define CFILE "H5f90i_gen.h" +#define FFILE "H5fortran_types.f90" + +void initCfile() +{ + fprintf(c_header, + "/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\ +* Copyright by the Board of Trustees of the University of Illinois. *\n\ + * All rights reserved. *\n\ + * *\n\ + * This file is part of HDF5. The full HDF5 copyright notice, including *\n\ + * terms governing use, modification, and redistribution, is contained in *\n\ + * the files COPYING and Copyright.html. COPYING can be found at the root *\n\ + * of the source code distribution tree; Copyright.html can be found at the *\n\ + * root level of an installed copy of the electronic HDF5 document set and *\n\ + * is linked from the top-level documents page. It can also be found at *\n\ + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *\n\ + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *\n\ + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */\n\ +\n\n\ +\#ifndef _H5f90i_gen_H\n\ +\#define _H5f90i_gen_H\n\ +\n\ +/* This file is automatically generated by H5match_types.c at build time. */\n\n"); +} + +void initFfile() +{ + fprintf(fort_header, + "! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n\ +! Copyright by the Board of Trustees of the University of Illinois. *\n\ +! All rights reserved. *\n\ +! *\n\ +! This file is part of HDF5. The full HDF5 copyright notice, including *\n\ +! terms governing use, modification, and redistribution, is contained in *\n\ +! the files COPYING and Copyright.html. COPYING can be found at the root *\n\ +! of the source code distribution tree; Copyright.html can be found at the *\n\ +! root level of an installed copy of the electronic HDF5 document set and *\n\ +! is linked from the top-level documents page. It can also be found at *\n\ +! http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *\n\ +! access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *\n\ +! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\ +!\n!\n\ +! This file is automatically generated and contains HDF5 Fortran90 type definitions.\n!\n\ + MODULE H5FORTRAN_TYPES\n\ + !\n\ + ! HDF5 integers\n\ + !\n"); + +} + +void endCfile() +{ + fprintf(c_header, "\n#endif /* _H5f90i_gen_H */\n"); +} +void endFfile() +{ + fprintf(fort_header, "\n INTEGER(SIZE_T), PARAMETER :: OBJECT_NAMELEN_DEFAULT_F = -1\n\n"); + fprintf(fort_header, " END MODULE H5FORTRAN_TYPES\n"); +} + +/* Define a c_int_x type in the C header */ +void writeTypedef(const char* c_type, unsigned int size) +{ + fprintf(c_header, "#define c_int_%d %s\n", size, c_type); +} + +/* Call this function if there is no matching C type for sizes > 1 */ +void writeTypedefDefault(unsigned int size) +{ + assert(size %2 == 0); + + fprintf(c_header, "typedef struct {c_int_%d a; c_int_%d b;} c_int_%d\n", size / 2, size / 2, size); +} + +/* Create matching Fortran and C types by writing to both files */ +void writeToFiles(const char* fortran_type, const char* c_type, unsigned int size) +{ + fprintf(fort_header, " INTEGER, PARAMETER :: %s = %d\n", fortran_type, size); + fprintf(c_header, "typedef c_int_%d %s;\n", size, c_type); +} + +/* hid_t and hssize_t don't have their sizes defined anywhere. + * Use sizeof() instead. */ +#define H5_SIZEOF_HID_T sizeof(hid_t) +#define H5_SIZEOF_HSSIZE_T sizeof(hssize_t) + +int main() +{ + /* Open target files */ + c_header = fopen(CFILE, "w"); + fort_header = fopen(FFILE, "w"); + + /* Write copyright, boilerplate to both files */ + initCfile(); + initFfile(); + + /* First, define c_int_x */ + if(sizeof(long long) == 1) + writeTypedef("long long", 1); + else if(sizeof(long) == 1) + writeTypedef("long", 1); + else if(sizeof(int) == 1) + writeTypedef("int", 1); + else if(sizeof(short) == 1) + writeTypedef("short", 1); + else + writeTypedef("char", 1); + /* Actually, char is not necessarily one byte. + * But if char isn't, then nothing is, so this + * is as close as we can get. */ + + if(sizeof(long long) == 2) + writeTypedef("long long", 2); + else if(sizeof(long) == 2) + writeTypedef("long", 2); + else if(sizeof(int) == 2) + writeTypedef("int", 2); + else if(sizeof(short) == 2) + writeTypedef("short", 2); + else + writeTypedefDefault(2); + + if(sizeof(long long) == 4) + writeTypedef("long long", 4); + else if(sizeof(long) == 4) + writeTypedef("long", 4); + else if(sizeof(int) == 4) + writeTypedef("int", 4); + else if(sizeof(short) == 4) + writeTypedef("short", 4); + else + writeTypedefDefault(4); + + if(sizeof(long long) == 8) + writeTypedef("long long", 8); + else if(sizeof(long) == 8) + writeTypedef("long", 8); + else if(sizeof(int) == 8) + writeTypedef("int", 8); + else if(sizeof(short) == 8) + writeTypedef("short", 8); + else + writeTypedefDefault(8); + + /* Now begin defining fortran types. */ + fprintf(c_header, "\n"); + + /* haddr_t */ + if( H5_SIZEOF_HADDR_T >= 8) { + #ifdef H5_FORTRAN_HAS_INTEGER_8 + writeToFiles("HADDR_T", "haddr_t_f", 8); + goto hsize_t_start; + #endif + } + if( H5_SIZEOF_HADDR_T >= 4) { + #ifdef H5_FORTRAN_HAS_INTEGER_4 + writeToFiles("HADDR_T", "haddr_t_f", 4); + goto hsize_t_start; + #endif + } + if( H5_SIZEOF_HADDR_T >= 2) { + #ifdef H5_FORTRAN_HAS_INTEGER_2 + writeToFiles("HADDR_T", "haddr_t_f", 2); + goto hsize_t_start; + #endif + } + if( H5_SIZEOF_HADDR_T >= 1) { + #ifdef H5_FORTRAN_HAS_INTEGER_1 + writeToFiles("HADDR_T", "haddr_t_f", 1); + goto hsize_t_start; + #endif + } + /* Error: couldn't find a size for haddr_t */ + return -1; + + hsize_t_start: + + /* hsize_t */ + if( H5_SIZEOF_HSIZE_T >= 8) { + #ifdef H5_FORTRAN_HAS_INTEGER_8 + writeToFiles("HSIZE_T", "hsize_t_f", 8); + goto hssize_t_start; + #endif + } + if( H5_SIZEOF_HSIZE_T >= 4) { + #ifdef H5_FORTRAN_HAS_INTEGER_4 + writeToFiles("HSIZE_T", "hsize_t_f", 4); + goto hssize_t_start; + #endif + } + if( H5_SIZEOF_HSIZE_T >= 2) { + #ifdef H5_FORTRAN_HAS_INTEGER_2 + writeToFiles("HSIZE_T", "hsize_t_f", 2); + goto hssize_t_start; + #endif + } + if( H5_SIZEOF_HSIZE_T >= 1) { + #ifdef H5_FORTRAN_HAS_INTEGER_1 + writeToFiles("HSIZE_T", "hsize_t_f", 1); + goto hssize_t_start; + #endif + } + /* Error: couldn't find a size for hsize_t */ + return -1; + + hssize_t_start: + + /* hssize_t */ + if( H5_SIZEOF_HSSIZE_T >= 8) { + #ifdef H5_FORTRAN_HAS_INTEGER_8 + writeToFiles("HSSIZE_T", "hssize_t_f", 8); + goto size_t_start; + #endif + } + if( H5_SIZEOF_HSSIZE_T >= 4) { + #ifdef H5_FORTRAN_HAS_INTEGER_4 + writeToFiles("HSSIZE_T", "hssize_t_f", 4); + goto size_t_start; + #endif + } + if( H5_SIZEOF_HSSIZE_T >= 2) { + #ifdef H5_FORTRAN_HAS_INTEGER_2 + writeToFiles("HSSIZE_T", "hssize_t_f", 2); + goto size_t_start; + #endif + } + if( H5_SIZEOF_HSSIZE_T >= 1) { + #ifdef H5_FORTRAN_HAS_INTEGER_1 + writeToFiles("HSSIZE_T", "hssize_t_f", 1); + goto size_t_start; + #endif + } + /* Error: couldn't find a size for hssize_t */ + return -1; + + + size_t_start: + /* size_t */ + if( H5_SIZEOF_SIZE_T >= 8) { + #ifdef H5_FORTRAN_HAS_INTEGER_8 + writeToFiles("SIZE_T", "size_t_f", 8); + goto int_start; + #endif + } + if( H5_SIZEOF_SIZE_T >= 4) { + #ifdef H5_FORTRAN_HAS_INTEGER_4 + writeToFiles("SIZE_T", "size_t_f", 4); + goto int_start; + #endif + } + if( H5_SIZEOF_SIZE_T >= 2) { + #ifdef H5_FORTRAN_HAS_INTEGER_2 + writeToFiles("SIZE_T", "size_t_f", 2); + goto int_start; + #endif + } + if( H5_SIZEOF_SIZE_T >= 1) { + #ifdef H5_FORTRAN_HAS_INTEGER_1 + writeToFiles("SIZE_T", "size_t_f", 1); + goto int_start; + #endif + } + /* Error: couldn't find a size for size_t */ + return -1; + + int_start: + /* int */ + if( H5_SIZEOF_INT >= 8) { + #ifdef H5_FORTRAN_HAS_INTEGER_8 + writeToFiles("INT", "int_f", 8); + goto hid_t_start; + #endif + } + if( H5_SIZEOF_INT >= 4) { + #ifdef H5_FORTRAN_HAS_INTEGER_4 + writeToFiles("INT", "int_f", 4); + goto hid_t_start; + #endif + } + if( H5_SIZEOF_INT >= 2) { + #ifdef H5_FORTRAN_HAS_INTEGER_2 + writeToFiles("INT", "int_f", 2); + goto hid_t_start; + #endif + } + if( H5_SIZEOF_INT >= 1) { + #ifdef H5_FORTRAN_HAS_INTEGER_1 + writeToFiles("INT", "int_f", 1); + goto hid_t_start; + #endif + } + /* Error: couldn't find a size for int */ + return -1; + + hid_t_start: + /* hid_t */ + if( H5_SIZEOF_HID_T >= 8) { + #ifdef H5_FORTRAN_HAS_INTEGER_8 + writeToFiles("HID_T", "hid_t_f", 8); + goto real_start; + #endif + } + if( H5_SIZEOF_HID_T >= 4) { + #ifdef H5_FORTRAN_HAS_INTEGER_4 + writeToFiles("HID_T", "hid_t_f", 4); + goto real_start; + #endif + } + if( H5_SIZEOF_HID_T >= 2) { + #ifdef H5_FORTRAN_HAS_INTEGER_2 + writeToFiles("HID_T", "hid_t_f", 2); + goto real_start; + #endif + } + if( H5_SIZEOF_HID_T >= 1) { + #ifdef H5_FORTRAN_HAS_INTEGER_1 + writeToFiles("HID_T", "hid_t_f", 1); + goto real_start; + #endif + } + /* Error: couldn't find a size for hid_t */ + return -1; + + real_start: + goto done; + done: + + /* Close files */ + endCfile(); + endFfile(); + fclose(c_header); + fclose(fort_header); + return 0; +} + diff --git a/fortran/src/Makefile.am b/fortran/src/Makefile.am index 88340a3..efc1aa2 100644 --- a/fortran/src/Makefile.am +++ b/fortran/src/Makefile.am @@ -50,7 +50,12 @@ libhdf5_fortran_la_SOURCES=H5fortran_flags.f90 H5f90global.f90 \ # h5fc and libhdf5_fortran.settings are generated during configure. # Remove them only when distclean. -DISTCLEANFILES=h5fc H5fortran_types.f90 libhdf5_fortran.settings +DISTCLEANFILES=h5fc libhdf5_fortran.settings + +# H5fortran_types.f90 and H5f90i.h are automatically generaed by +# H5match_types, and must be cleaned explicitly. H5fort_type_defines.h +# is generated by H5fortran_detect +MOSTLYCLEANFILES=H5fortran_types.f90 H5f90i_gen.h H5fort_type_defines.h # Fortran module files can have different extensions and different names # (e.g., different capitalizations) on different platforms. Write rules @@ -92,6 +97,42 @@ else H5FC_NAME = h5fc endif +# Rules for automatically detecting which fortran types are present +# and matching them to C types. This is accomplished using helper +# programs. +# It's a bit tricky to make sure that Automake builds things in the right +# order (especially when using 'gmake -j ...' +# H5fortran_detect.f90 needs to be compiled into H5fortran_detect. +# This program is run, and its output is saved in H5fort_type_defines.h +# H5match_types.c then includes this file and can be compiled into +# H5match_types. When H5match_types is run, it creates H5f90i_gen.h +# and H5fortran_types.f90, which are needed by the Fortran library. + +# These are the helper programs we need to build. +noinst_PROGRAMS = H5match_types H5fortran_detect + +# Tell Automake to create H5f90i_gen.h before it does anything else. +# When it creates H5f90i_gen.h, it will create H5fortran_types.f90 as +# a side effect. +BUILT_SOURCES = H5f90i_gen.h + +# Specify what Automake needs to create: first the H5fort_type_defines.h +# header, then H5match_types which includes that header, then +# it needs to run H5match_types. +H5fortran_types.f90 H5f90i_gen.h: H5match_types.c + $(MAKE) $(AM_MAKEFLAGS) H5fort_type_defines.h + $(MAKE) $(AM_MAKEFLAGS) H5match_types + $(RUNSERIAL) ./H5match_types + +# H5fort_type_defines.h is created by running H5fortran_detect. +# Obviously, H5fortran_detect needs to be built first. +H5fort_type_defines.h: H5fortran_detect + $(RUNSERIAL) ./H5fortran_detect > H5fort_type_defines.h + +# Automake knows how to build fortran programs if we tell it the source +# files. +H5fortran_detect_SOURCES = H5fortran_detect.f90 + # Mark this directory as part of the Fortran API HDF_FORTRAN=yes diff --git a/fortran/src/Makefile.in b/fortran/src/Makefile.in index 7b4ebea..9c828f3 100644 --- a/fortran/src/Makefile.in +++ b/fortran/src/Makefile.in @@ -31,7 +31,8 @@ # -SOURCES = $(libhdf5_fortran_la_SOURCES) + +SOURCES = $(libhdf5_fortran_la_SOURCES) $(H5fortran_detect_SOURCES) H5match_types.c srcdir = @srcdir@ top_srcdir = @top_srcdir@ @@ -55,11 +56,11 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -DIST_COMMON = README $(srcdir)/H5fortran_types.f90.in \ - $(srcdir)/Makefile.am $(srcdir)/Makefile.in $(srcdir)/h5fc.in \ - $(srcdir)/libhdf5_fortran.settings.in \ +DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(srcdir)/h5fc.in $(srcdir)/libhdf5_fortran.settings.in \ $(top_srcdir)/config/commence.am \ $(top_srcdir)/config/conclude.am +noinst_PROGRAMS = H5match_types$(EXEEXT) H5fortran_detect$(EXEEXT) subdir = fortran/src ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.in @@ -67,7 +68,7 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(SHELL) $(top_srcdir)/bin/mkinstalldirs CONFIG_HEADER = $(top_builddir)/src/H5config.h -CONFIG_CLEAN_FILES = h5fc H5fortran_types.f90 libhdf5_fortran.settings +CONFIG_CLEAN_FILES = h5fc libhdf5_fortran.settings am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -94,6 +95,13 @@ am_libhdf5_fortran_la_OBJECTS = H5fortran_flags.lo H5f90global.lo \ H5Gf.lo H5If.lo H5Pf.lo H5Rf.lo H5Sf.lo H5Tf.lo H5Zf.lo \ $(am__objects_1) libhdf5_fortran_la_OBJECTS = $(am_libhdf5_fortran_la_OBJECTS) +PROGRAMS = $(noinst_PROGRAMS) +am_H5fortran_detect_OBJECTS = H5fortran_detect.$(OBJEXT) +H5fortran_detect_OBJECTS = $(am_H5fortran_detect_OBJECTS) +H5fortran_detect_LDADD = $(LDADD) +H5match_types_SOURCES = H5match_types.c +H5match_types_OBJECTS = H5match_types.$(OBJEXT) +H5match_types_LDADD = $(LDADD) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/bin/depcomp am__depfiles_maybe = depfiles @@ -110,8 +118,10 @@ LTFCCOMPILE = $(LIBTOOL) --mode=compile $(FC) $(AM_FCFLAGS) $(FCFLAGS) FCLD = $(FC) FCLINK = $(LIBTOOL) --mode=link $(FCLD) $(AM_FCFLAGS) $(FCFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = $(libhdf5_fortran_la_SOURCES) -DIST_SOURCES = $(am__libhdf5_fortran_la_SOURCES_DIST) +SOURCES = $(libhdf5_fortran_la_SOURCES) $(H5fortran_detect_SOURCES) \ + H5match_types.c +DIST_SOURCES = $(am__libhdf5_fortran_la_SOURCES_DIST) \ + $(H5fortran_detect_SOURCES) H5match_types.c settingsDATA_INSTALL = $(INSTALL_DATA) DATA = $(settings_DATA) ETAGS = etags @@ -352,7 +362,12 @@ libhdf5_fortran_la_SOURCES = H5fortran_flags.f90 H5f90global.f90 \ # h5fc and libhdf5_fortran.settings are generated during configure. # Remove them only when distclean. -DISTCLEANFILES = h5fc H5fortran_types.f90 libhdf5_fortran.settings +DISTCLEANFILES = h5fc libhdf5_fortran.settings + +# H5fortran_types.f90 and H5f90i.h are automatically generaed by +# H5match_types, and must be cleaned explicitly. H5fort_type_defines.h +# is generated by H5fortran_detect +MOSTLYCLEANFILES = H5fortran_types.f90 H5f90i_gen.h H5fort_type_defines.h # Install libhdf5_fortran.settings in lib directory settingsdir = $(libdir) @@ -363,6 +378,15 @@ settings_DATA = libhdf5_fortran.settings # is configured for parallel mode @BUILD_PARALLEL_CONDITIONAL_TRUE@H5FC_NAME = h5pfc +# Tell Automake to create H5f90i_gen.h before it does anything else. +# When it creates H5f90i_gen.h, it will create H5fortran_types.f90 as +# a side effect. +BUILT_SOURCES = H5f90i_gen.h + +# Automake knows how to build fortran programs if we tell it the source +# files. +H5fortran_detect_SOURCES = H5fortran_detect.f90 + # Mark this directory as part of the Fortran API HDF_FORTRAN = yes @@ -378,7 +402,8 @@ PROGS = $(bin_PROGRAMS) $(bin_SCRIPTS) $(noinst_PROGRAMS) $(noinst_SCRIPTS) \ $(EXTRA_PROG) TESTS = $(check_PROGRAMS) $(check_SCRIPTS) $(EXTRA_TEST) -all: all-am +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .c .f90 .lo .o .obj @@ -413,8 +438,6 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh h5fc: $(top_builddir)/config.status $(srcdir)/h5fc.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ -H5fortran_types.f90: $(top_builddir)/config.status $(srcdir)/H5fortran_types.f90.in - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ libhdf5_fortran.settings: $(top_builddir)/config.status $(srcdir)/libhdf5_fortran.settings.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ install-libLTLIBRARIES: $(lib_LTLIBRARIES) @@ -447,6 +470,19 @@ clean-libLTLIBRARIES: libhdf5_fortran.la: $(libhdf5_fortran_la_OBJECTS) $(libhdf5_fortran_la_DEPENDENCIES) $(FCLINK) -rpath $(libdir) $(libhdf5_fortran_la_LDFLAGS) $(libhdf5_fortran_la_OBJECTS) $(libhdf5_fortran_la_LIBADD) $(LIBS) +clean-noinstPROGRAMS: + @list='$(noinst_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +H5fortran_detect$(EXEEXT): $(H5fortran_detect_OBJECTS) $(H5fortran_detect_DEPENDENCIES) + @rm -f H5fortran_detect$(EXEEXT) + $(FCLINK) $(H5fortran_detect_LDFLAGS) $(H5fortran_detect_OBJECTS) $(H5fortran_detect_LDADD) $(LIBS) +H5match_types$(EXEEXT): $(H5match_types_OBJECTS) $(H5match_types_DEPENDENCIES) + @rm -f H5match_types$(EXEEXT) + $(LINK) $(H5match_types_LDFLAGS) $(H5match_types_OBJECTS) $(H5match_types_LDADD) $(LIBS) + mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -467,6 +503,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Zf.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5_f.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5f90kit.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5match_types.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ @@ -603,13 +640,15 @@ distdir: $(DISTFILES) done check-am: all-am $(MAKE) $(AM_MAKEFLAGS) check-TESTS -check: check-am -all-am: Makefile $(LTLIBRARIES) $(DATA) all-local +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am +all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(DATA) all-local installdirs: for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(settingsdir)"; do \ test -z "$$dir" || $(mkdir_p) "$$dir"; \ done -install: install-am +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -624,6 +663,7 @@ install-strip: `test -z '$(STRIP)' || \ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: + -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) clean-generic: @@ -634,10 +674,11 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am clean-am: clean-generic clean-libLTLIBRARIES clean-libtool clean-local \ - mostlyclean-am + clean-noinstPROGRAMS mostlyclean-am distclean: distclean-am -rm -rf ./$(DEPDIR) @@ -689,10 +730,10 @@ uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES \ .PHONY: CTAGS GTAGS all all-am all-local check check-TESTS check-am \ clean clean-generic clean-libLTLIBRARIES clean-libtool \ - clean-local ctags distclean distclean-compile \ - distclean-generic distclean-libtool distclean-local \ - distclean-tags distdir dvi dvi-am html html-am info info-am \ - install install-am install-data install-data-am \ + clean-local clean-noinstPROGRAMS ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-local distclean-tags distdir dvi dvi-am html html-am \ + info info-am install install-am install-data install-data-am \ install-data-local install-exec install-exec-am \ install-exec-local install-info install-info-am \ install-libLTLIBRARIES install-man install-settingsDATA \ @@ -733,6 +774,19 @@ uninstall-local: install-exec-local: $(INSTALL) h5fc $(bindir)/$(H5FC_NAME) +# Specify what Automake needs to create: first the H5fort_type_defines.h +# header, then H5match_types which includes that header, then +# it needs to run H5match_types. +H5fortran_types.f90 H5f90i_gen.h: H5match_types.c + $(MAKE) $(AM_MAKEFLAGS) H5fort_type_defines.h + $(MAKE) $(AM_MAKEFLAGS) H5match_types + $(RUNSERIAL) ./H5match_types + +# H5fort_type_defines.h is created by running H5fortran_detect. +# Obviously, H5fortran_detect needs to be built first. +H5fort_type_defines.h: H5fortran_detect + $(RUNSERIAL) ./H5fortran_detect > H5fort_type_defines.h + # Hardcode the dependencies of these files. There isn't a known way of # determining this automagically (like we do with the C files). So, when # doing a parallel make, some modules could be made way before the |