Commit 3734ed2e authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

merged changes from branches/cdi_fileDrivenInput

parents e1b4fdc2 247f3a60
......@@ -238,12 +238,22 @@ src/gaussgrid.h -text
src/getline.c -text
src/gribapi.c -text
src/gribapi.h -text
src/gribapi_utilities.c -text
src/gribapi_utilities.h -text
src/grid.c -text
src/grid.h -text
src/ieg.h -text
src/ieglib.c -text
src/input_file.c -text
src/input_file.h -text
src/institution.c -text
src/institution.h -text
src/iterator.c -text
src/iterator.h -text
src/iterator_fallback.c -text
src/iterator_fallback.h -text
src/iterator_grib.c -text
src/iterator_grib.h -text
src/make_cdilib -text
src/make_fint.c -text
src/mo_cdi.f90 -text
......@@ -278,6 +288,10 @@ src/pio_util.c -text
src/pio_util.h -text
src/pkgconfig/cdi.pc.in -text
src/pkgconfig/cdipio.pc.in -text
src/proprietarySystemWorkarounds.c -text
src/proprietarySystemWorkarounds.h -text
src/referenceCounting.c -text
src/referenceCounting.h -text
src/resource_handle.c -text
src/resource_handle.h -text
src/resource_unpack.c -text
......
2015-03-26 Uwe Schulzweida
* merged changes from branches/cdi_fileDrivenInput
2015-03-26 Uwe Schulzweida
* Version 1.6.8 released
......
......@@ -258,6 +258,7 @@ ENABLE_CGRIBEX = @ENABLE_CGRIBEX@
ENABLE_EXTRA = @ENABLE_EXTRA@
ENABLE_GRIB = @ENABLE_GRIB@
ENABLE_IEG = @ENABLE_IEG@
ENABLE_MPI = @ENABLE_MPI@
ENABLE_NC2 = @ENABLE_NC2@
ENABLE_NC4 = @ENABLE_NC4@
ENABLE_NETCDF = @ENABLE_NETCDF@
......
......@@ -231,6 +231,7 @@ ENABLE_CGRIBEX = @ENABLE_CGRIBEX@
ENABLE_EXTRA = @ENABLE_EXTRA@
ENABLE_GRIB = @ENABLE_GRIB@
ENABLE_IEG = @ENABLE_IEG@
ENABLE_MPI = @ENABLE_MPI@
ENABLE_NC2 = @ENABLE_NC2@
ENABLE_NC4 = @ENABLE_NC4@
ENABLE_NETCDF = @ENABLE_NETCDF@
......
......@@ -141,7 +141,7 @@ void version(void)
static
void usage(void)
{
char *name;
const char *name;
int id;
fprintf(stderr, "usage : %s [Option] [ifile] [ofile]\n", Progname);
......
......@@ -279,6 +279,7 @@ ENABLE_CGRIBEX = @ENABLE_CGRIBEX@
ENABLE_EXTRA = @ENABLE_EXTRA@
ENABLE_GRIB = @ENABLE_GRIB@
ENABLE_IEG = @ENABLE_IEG@
ENABLE_MPI = @ENABLE_MPI@
ENABLE_NC2 = @ENABLE_NC2@
ENABLE_NC4 = @ENABLE_NC4@
ENABLE_NETCDF = @ENABLE_NETCDF@
......
......@@ -11,7 +11,7 @@ PROGRAM CDIREADF2003
DOUBLE PRECISION, ALLOCATABLE :: field(:,:)
CHARACTER(kind=c_char), POINTER, DIMENSION(:) :: &
msg, cdi_version
CHARACTER(kind=c_char), DIMENSION(cdi_max_name + 1) :: &
CHARACTER(kind=c_char, LEN = cdi_max_name + 1) :: &
name, longname, units
INTEGER :: name_c_len, longname_c_len, units_c_len
......
......@@ -273,6 +273,7 @@ ENABLE_CGRIBEX = @ENABLE_CGRIBEX@
ENABLE_EXTRA = @ENABLE_EXTRA@
ENABLE_GRIB = @ENABLE_GRIB@
ENABLE_IEG = @ENABLE_IEG@
ENABLE_MPI = @ENABLE_MPI@
ENABLE_NC2 = @ENABLE_NC2@
ENABLE_NC4 = @ENABLE_NC4@
ENABLE_NETCDF = @ENABLE_NETCDF@
......
......@@ -257,6 +257,7 @@ ENABLE_CGRIBEX = @ENABLE_CGRIBEX@
ENABLE_EXTRA = @ENABLE_EXTRA@
ENABLE_GRIB = @ENABLE_GRIB@
ENABLE_IEG = @ENABLE_IEG@
ENABLE_MPI = @ENABLE_MPI@
ENABLE_NC2 = @ENABLE_NC2@
ENABLE_NC4 = @ENABLE_NC4@
ENABLE_NETCDF = @ENABLE_NETCDF@
......
......@@ -40,7 +40,8 @@ class CdiTaxis {
int ntsteps, unit;
int rdate, rtime, vdate, vtime;
int type, calendar, hasBounds;
char name[CHARSIZE], *unitname;
char name[CHARSIZE];
const char *unitname;
};
class CdiZaxis {
......
#!/usr/bin/env ruby
require 'optparse'
################################################################
# CONFIGURATION:
CFTypeInfo = {
'int' => {:namedConst => 'c_int' , :ftype => 'integer'},
'short int' => {:namedConst => 'c_short' , :ftype => 'integer'},
'long int' => {:namedConst => 'c_long' , :ftype => 'integer'},
'long long int' => {:namedConst => 'c_long_long' , :ftype => 'integer'},
'signed char' => {:namedConst => 'c_signed_char' , :ftype => 'integer'},
'unsigned char' => {:namedConst => 'c_signed_char' , :ftype => 'integer'},
'size_t' => {:namedConst => 'c_size_t' , :ftype => 'integer'},
'int8_t' => {:namedConst => 'c_int8_t' , :ftype => 'integer'},
'int16_t' => {:namedConst => 'c_int16_t' , :ftype => 'integer'},
'int32_t' => {:namedConst => 'c_int32_t' , :ftype => 'integer'},
'int64_t' => {:namedConst => 'c_int64_t' , :ftype => 'integer'},
'int_fast8_t' => {:namedConst => 'c_int_fast8_t' , :ftype => 'integer'},
'int_fast16_t' => {:namedConst => 'c_int_fast16_t' , :ftype => 'integer'},
'int_fast32_t' => {:namedConst => 'c_int_fast32_t' , :ftype => 'integer'},
'int_fast64_t' => {:namedConst => 'c_int_fast64_t' , :ftype => 'integer'},
'int_least8_t' => {:namedConst => 'c_int_least8_t' , :ftype => 'integer'},
'int_least16_t' => {:namedConst => 'c_int_least16_t' , :ftype => 'integer'},
'int_least32_t' => {:namedConst => 'c_int_least32_t' , :ftype => 'integer'},
'int_least64_t' => {:namedConst => 'c_int_least64_t' , :ftype => 'integer'},
'intmax_t' => {:namedConst => 'c_intmax_t' , :ftype => 'integer'},
'intptr_t' => {:namedConst => 'c_intptr_t' , :ftype => 'integer'},
'float' => {:namedConst => 'c_float' , :ftype => 'real'},
'double' => {:namedConst => 'c_double' , :ftype => 'real'},
'long double' => {:namedConst => 'c_long_double' , :ftype => 'real'},
'float _Complex' => {:namedConst => 'c_float_complex' , :ftype => 'complex'},
'double _Complex' => {:namedConst => 'c_double_complex' , :ftype => 'complex'},
'long double _Complex' => {:namedConst => 'c_long_double_complex', :ftype => 'complex'},
'_Bool' => {:namedConst => 'c_bool' , :ftype => 'logical'},
'char' => {:namedConst => 'c_char' , :ftype => 'character'}
}
# how the module should be invoked from fortran
ModuleName = 'mo_cdi'
# which conversion is to use generating the fortran routine names, this could
# be any ruby String method.
FNameMethod = :noop
# FNameMethod = :downcase
# FNameMethod = :noop
# FNameMethod = :upcase
class String;def noop;self;end;end
# fortran subroutines are not allowed to have a parameters with the same name,
# so in case of a match, these parameters have to get an new name
FParamExtension = 'v'
# Naming convention from above:
# all non scalar variables should have the postfix '_vec' in there name
Vectors = /_vec$/i
################################################################################
FortranMaxLineLength = 132
# read the c header file and grep out name, return type and paramterlist of
# each function
def getFuncInfo(filename)
typelist = %w[char int float double void]
cppflags = ENV['CPPFLAGS'].nil? ? '' : ENV['CPPFLAGS']
funclist = IO.popen("cpp #{cppflags} #{filename} | cpp -fpreprocessed").readlines.delete_if {|line| line.include?('#')}.collect {|line| line.chomp}
# delete everything, that do not look like a function prototype
typeRegexp = /^.*(#{typelist.join('|')}) \**\w+\s*\(.*\)/
funclist.delete_if {|line|
not typeRegexp.match(line.lstrip)
}
funclist.collect! {|line|
md = /(\w+)+ +(\**)(\w+)\s*\((.*)\)/.match(line)
returnType, returnPointer, funcName, paramList = md[1,4]
paramList = paramList.split(',').collect {|p| p.split(' ').each {|_p| _p.strip}}
[funcName, returnType, returnPointer, paramList]
}
funclist
end
# grep the #define C-Constants, which should be available within the fortran CDI API
def getDefines(filename)
defines = File.open(filename,'r').readlines.grep(/^#define/).collect {|line|
md = / +(\w+) +(-*\d+)/.match(line)
}.select {|item| not item.nil?}.collect {|match| match[1..2]}
# This script generates a fortran source file that uses the ISO_C_BINDINGS to interface to the functions defined in the given C header file.
# The basic approach is, that every C function is wrapped in a fortran function/subroutine, which internally uses a bind(c) interface to the C code.
# This wrapper based approach has the advantage that the wrapper is free to provide a true fortran interface
# that enables full type checking of its arguments; the pure bind(c) interface would not be able to distinguish
# between different opaque pointer types, for instance, nor would it be able to infer the size of a static string returned by a C function.
#
# Within this header file, the following constructs are recognized:
#
# * #define FOO 123
# * typedef struct foo foo;
# * typedef struct foo { ... } foo;
# * ... foo(...);
#
# These constructs are used to divide a source line into parts that are recognizable by the templates defined below.
# A function definition, for instance, is divided into a return type, a function name, and a number of argument definitions,
# the return type and argument descriptions are matched against templates which define the translation of these parts into fortran code.
# Note that all these constructs must be one-liners since processing in this script is line based.
#
# Every template is a hash that contains an entry :regex, which is used to match it against the corresponding C declaration.
# There are a couple of placeholders that may be used within these regex strings, they are expanded by matchTemplate() before a Regexp object is constructed from the string in :regex.
# These placeholders are:
# <integerTypes> matches the C integer types that can be used within Fortran by prefixing 'c_' to the type
# <floatTypes> matches the C floating point types that can be used within Fortran by prefixing 'c_' to the type
# <opaqueTypes> matches all the opaque types defined within the header
# <publicTypes> matches all the public types defined within the header
#
# In the case of argument and type templates, this :regex may contain one or more named subexpressions /(?<name>...)/,
# which can be included in the other fields by means of a corresponding placeholder "<name>".
# The names of the subexpressions that are to be substituted in this way need to be listed in the :placeholders key.
# This is usually used to capture the variable name, and then use "<name>_foo" to derive fortran variable names from the argument name,
# but it may also be used to capture the size of an array declaration.
# Since fortran uses so many keywords that can easily conflict with C argument names, it is a good idea not to use a naked "<name>";
# always append something to it as in "<name>_dummy"
#
# Argument templates must provide the following fields:
# :regex A regex that matches the whole definition of a C argument. Make sure it only matches the cases that the template can actually handle!
# :placeholders An array of the name of the named subexpressions used in the regex. For the :regex => /(?<foo>.),(?<bar>.)/ you would use :placeholders => %w[foo bar]
# :dummyName The name of the fortran dummy argument. Both the wrapper function and the `bind(c)` interface use the same name.
# :acceptAs The declaration of the dummy argument in the fortran wrapper.
# :helperVars Declarations of additional variables needed to provide the desired functionality in the wrapper function.
# :precallStatements Code that needs to be executed before the C function is called.
# :callExpression The actual argument that the wrapper passes to the C function.
# :passAs The declaration of the dummy argument in the `bind(c)` interface.
# :postcallStatements Code that needs to be executed after the C function returns.
#
#
#
# Return type templates are similar to argument templates, but they have to deal with the fact that fortran differentiates between subroutines and functions. Because of this, return type templates add the :isVoid key which is only true if the C function returns `void`.
#
# Return type templates must provide the following fields:
# :regex A regex that matches the whole definition of a C return type. Make sure it only matches the cases that the template can actually handle!
# :isVoid Always false, except for the template for `void`.
# :returnAs The type of the fortran wrapper function.
# :helperVars Declarations of additional variables needed to provide the desired functionality in the wrapper function.
# :precallStatements Code that needs to be executed before the C function is called.
# :recieveAs The type of the `bind(c)` interface function.
# :assignVariable The expression that the result of the C function is assigned to.
# :postcallStatements Code that needs to be executed after the C function returns.
#
#
#
# Type templates are used for the variables in public `struct` definitions. These are much simpler as they only have to translate a C variable declaration into an interoperable fortran variable declaration.
#
# Type templates must provide the following fields:
# :regex A regex that matches the whole C variable definition. Make sure it only matches the cases that the template can actually handle!
# :placeholders An array of the name of the named subexpressions used in the regex. Same semantics as in an argument template.
# :declareAs The declaration of the corresponding fortran derived type member.
#
#
#
# The wrapper that is generated for a non-void C function looks like this:
#
# function fname(:dummyName...) result(result)
# :returnAs :: result
# :acceptAs...
# :helperVars...
# interface
# :recieveAs function lib_fname(:dummyName...) bind(c, name = 'fname')
# import <importConstants>
# :passAs...
# end function lib_fname
# end interface
# :precallStatements
# :assignVariable = lib_fname(:callExpression)
# :postcallStatements
# end function fname
#
#
#
# The wrapper that is generated for a void C function looks like this:
#
# subroutine fname(:dummyName...)
# :acceptAs...
# :helperVars...
# interface
# subroutine lib_fname(:dummyName...) bind(c, name = 'fname')
# import <importConstants>
# :passAs...
# end subroutine lib_fname
# end interface
# :precallStatements
# call lib_fname(:callExpression)
# :postcallStatements
# end subroutine fname
####################################################################################################
# Template definitions #############################################################################
####################################################################################################
$argumentTemplates = [
{ #Dummy for declarations using foo(void).
:regex => '^\s*void\s*$',
:placeholders => %w[],
:dummyName => '',
:acceptAs => '',
:helperVars => '',
:precallStatements => '',
:callExpression => '',
:passAs => '',
:postcallStatements => ''
}, { #<integerTypes>
:regex => '^\s*(?<type><integerTypes>)\s+(?<name>\w+)\s*$',
:placeholders => %w[name type],
:dummyName => '<name>_dummy',
:acceptAs => 'integer(c_<type>), value :: <name>_dummy',
:helperVars => '',
:precallStatements => '',
:callExpression => '<name>_dummy',
:passAs => 'integer(c_<type>), value :: <name>_dummy',
:postcallStatements => ''
}, { #<floatTypes>
:regex => '^\s*(?<type><floatTypes>)\s+(?<name>\w+)\s*$',
:placeholders => %w[name type],
:dummyName => '<name>_dummy',
:acceptAs => 'real(c_<type>), value :: <name>_dummy',
:helperVars => '',
:precallStatements => '',
:callExpression => '<name>_dummy',
:passAs => 'real(c_<type>), value :: <name>_dummy',
:postcallStatements => ''
},
#Array arguments. These are marked by a `_vec` suffix by convention.
#Since it's near impossible to write regexs that only match names that do *not* end in a given suffix,
#these templates must precede the more general templates for pointer arguments.
#That way, we can override the more general template with the more special one if both match.
{ #<integerTypes>* <name>_vec
:regex => '^\s*(?<type><integerTypes>)\s*\*\s*(?<name>\w+_vec)\s*$',
:placeholders => %w[name type],
:dummyName => '<name>_dummy',
:acceptAs => 'integer(c_<type>), intent(inout) :: <name>_dummy(*)',
:helperVars => "",
:precallStatements => "",
:callExpression => '<name>_dummy',
:passAs => 'integer(c_<type>), intent(inout) :: <name>_dummy(*)',
:postcallStatements => ""
}, { #<floatTypes>* <name>_vec
:regex => '^\s*(?<type><floatTypes>)\s*\*\s*(?<name>\w+_vec)\s*$',
:placeholders => %w[name type],
:dummyName => '<name>_dummy',
:acceptAs => 'real(c_<type>), intent(inout) :: <name>_dummy(*)',
:helperVars => "",
:precallStatements => "",
:callExpression => '<name>_dummy',
:passAs => 'real(c_<type>), intent(inout) :: <name>_dummy(*)',
:postcallStatements => ""
}, { #unsigned char <name>[<size>]
:regex => '^\s*unsigned\s+char\s+(?<name>\w+)\s*\[\s*(?<size>[^\]]+)\s*\]\s*$',
:placeholders => %w[name size],
:dummyName => '<name>_dummy',
:acceptAs => 'character(kind = c_char), intent(inout) :: <name>_dummy(<size>)',
:helperVars => "",
:precallStatements => "",
:callExpression => '<name>_dummy',
:passAs => 'character(kind = c_char), intent(inout) :: <name>_dummy(*)',
:postcallStatements => ""
}, { #const <integerTypes>* <name>_vec
:regex => '^\s*const\s+(?<type><integerTypes>)\s*\*\s*(?<name>\w+_vec)\s*$',
:placeholders => %w[name type],
:dummyName => '<name>_dummy',
:acceptAs => 'integer(c_<type>), intent(in) :: <name>_dummy(*)',
:helperVars => "",
:precallStatements => "",
:callExpression => '<name>_dummy',
:passAs => 'integer(c_<type>), intent(in) :: <name>_dummy(*)',
:postcallStatements => ""
}, { #const <floatTypes>* <name>_vec
:regex => '^\s*const\s+(?<type><floatTypes>)\s*\*\s*(?<name>\w+_vec)\s*$',
:placeholders => %w[name type],
:dummyName => '<name>_dummy',
:acceptAs => 'real(c_<type>), intent(in) :: <name>_dummy(*)',
:helperVars => "",
:precallStatements => "",
:callExpression => '<name>_dummy',
:passAs => 'real(c_<type>), intent(in) :: <name>_dummy(*)',
:postcallStatements => ""
}, { #const unsigned char <name>[<size>]
:regex => '^\s*(const\s+unsigned\s+char|unsigned\s+char\s+const)\s+(?<name>\w+)\s*\[\s*(?<size>[^\]]+)\s*\]\s*$',
:placeholders => %w[name size],
:dummyName => '<name>_dummy',
:acceptAs => 'character(kind = c_char), intent(in) :: <name>_dummy(<size>)',
:helperVars => "",
:precallStatements => "",
:callExpression => '<name>_dummy',
:passAs => 'character(kind = c_char), intent(in) :: <name>_dummy(*)',
:postcallStatements => ""
}, { #const <integerTypes> <name>[<lineCount>][<lineSize>]
:regex => '^\s*const\s+(?<type><integerTypes>)\s+(?<name>\w+)\s*\[\s*(?<lineCount>[^\]]+)\s*\]\s*\[\s*(?<lineSize>[^\]]+)\s*\]\s*$',
:placeholders => %w[name type lineCount lineSize],
:dummyName => '<name>_dummy',
:acceptAs => 'integer(c_<type>), intent(in) :: <name>_dummy(<lineSize>, <lineCount>)',
:helperVars => "",
:precallStatements => "",
:callExpression => '<name>_dummy',
:passAs => 'integer(c_<type>), intent(in) :: <name>_dummy(*)',
:postcallStatements => ""
},
#Pointer arguments. These match both pointers and arrays, so they must appear after the more special array templates.
#Most of these are wrapped by optional arguments which have to be named in calling code, which is why we don't use the _dummy suffix for them.
{ #<integerTypes>*
:regex => '^\s*(?<type><integerTypes>)\s*\*\s*(?<name>\w+)\s*$',
:placeholders => %w[name type],
:dummyName => '<name>',
:acceptAs => 'integer(c_<type>), optional, intent(inout) :: <name>',
:helperVars => "integer(c_<type>), target :: <name>_temp\ntype(c_ptr) :: <name>_ptr",
:precallStatements => "<name>_ptr = c_null_ptr\nif(present(<name>)) <name>_ptr = c_loc(<name>_temp)",
:callExpression => '<name>_ptr',
:passAs => 'type(c_ptr), value :: <name>',
:postcallStatements => "if(present(<name>)) <name> = <name>_temp"
}, { #<floatTypes>*
:regex => '^\s*(?<type><floatTypes>)\s*\*\s*(?<name>\w+)\s*$',
:placeholders => %w[name type],
:dummyName => '<name>',
:acceptAs => 'real(c_<type>), optional, intent(inout) :: <name>',
:helperVars => "real(c_<type>), target :: <name>_temp\ntype(c_ptr) :: <name>_ptr",
:precallStatements => "<name>_ptr = c_null_ptr\nif(present(<name>)) <name>_ptr = c_loc(<name>_temp)",
:callExpression => '<name>_ptr',
:passAs => 'type(c_ptr), value :: <name>',
:postcallStatements => "if(present(<name>)) <name> = <name>_temp"
}, { #unsigned char (*<name>)[<size>]
:regex => '^\s*unsigned\s+char\s*\(\s*\*\s*(?<name>\w+)\s*\)\s*\[\s*(?<size>[^\]]+)\s*\]\s*$',
:placeholders => %w[name size],
:dummyName => '<name>',
:acceptAs => 'character(kind = c_char), optional, intent(inout) :: <name>(<size>)',
:helperVars => "character(kind = c_char), target :: <name>_temp(<size>)\ntype(c_ptr) :: <name>_ptr",
:precallStatements => "<name>_ptr = c_null_ptr\nif(present(<name>)) <name>_ptr = c_loc(<name>_temp)",
:callExpression => '<name>_ptr',
:passAs => 'type(c_ptr), value :: <name>',
:postcallStatements => "if(present(<name>)) <name> = <name>_temp"
},
#String arguments.
{ #char* Unsafe buffer passing
:regex => '^\s*char\s*\*\s*(?<name>\w+)\s*$',
:placeholders => %w[name],
:dummyName => '<name>_dummy',
:acceptAs => 'character(kind = c_char, len = *), intent(inout) :: <name>_dummy',
:helperVars => "character(kind = c_char) :: <name>_temp(len(<name>_dummy))\n" +
"integer :: <name>_i\n" +
"logical :: <name>_padding = .true.",
:precallStatements => "do <name>_i = len(<name>_dummy), 1, -1\n" +
"\tif(<name>_dummy(<name>_i:<name>_i) /= ' ') <name>_padding = .false.\n" +
"\tif(<name>_padding) then\n" +
"\t\t<name>_temp(<name>_i) = c_null_char\n" +
"\telse\n" +
"\t\t<name>_temp(<name>_i) = <name>_dummy(<name>_i:<name>_i)\n" +
"\tend if\n" +
"end do",
:callExpression => '<name>_temp',
:passAs => 'character(kind = c_char) :: <name>_dummy(*)',
:postcallStatements => "<name>_padding = .false.\n" +
"do <name>_i = 1, len(<name>_dummy)\n" +
"\tif(<name>_temp(<name>_i) == c_null_char) <name>_padding = .true.\n" +
"\tif(<name>_padding) then\n" +
"\t\t<name>_dummy(<name>_i:<name>_i) = ' '\n" +
"\telse\n" +
"\t\t<name>_dummy(<name>_i:<name>_i) = <name>_temp(<name>_i)\n" +
"\tend if\n" +
"end do"
}, { #const char* Safe passing of an input string.
:regex => '^\s*(const\s+char|char\sconst)\s*\*\s*(?<name>\w+)\s*$',
:placeholders => %w[name],
:dummyName => '<name>_dummy',
:acceptAs => 'character(kind = c_char, len = *), intent(in) :: <name>_dummy',
:helperVars => "character(kind = c_char) :: <name>_temp(len(<name>_dummy) + 1)\ninteger :: <name>_i",
:precallStatements => "do <name>_i = 1, len(<name>_dummy)\n<name>_temp(<name>_i) = <name>_dummy(<name>_i:<name>_i)\nend do\n<name>_temp(len(<name>_dummy) + 1) = c_null_char",
:callExpression => '<name>_temp',
:passAs => 'character(kind = c_char) :: <name>_dummy(*)',
:postcallStatements => ''
}, { #char** Safe returning of an output string.
:regex => '^\s*char\s*\*\s*\*\s*(?<name>\w+)\s*$',
:placeholders => %w[name],
:dummyName => '<name>',
:acceptAs => 'character(kind = c_char), pointer, optional, intent(inout) :: <name>(:)',
:helperVars => "type(c_ptr), target :: <name>_ptr\n" +
"type(c_ptr) :: <name>_handle\n" +
"integer :: <name>_shape(1)\n" +
"character(kind = c_char), pointer :: <name>_fptr(:)",
:precallStatements => "<name>_handle = c_null_ptr\n" +
"if(present(<name>)) <name>_handle = c_loc(<name>_ptr)",
:callExpression => '<name>_handle',
:passAs => 'type(c_ptr), value :: <name>',
:postcallStatements => "if(present(<name>)) then\n" +
"\tif(c_associated(<name>_ptr)) then\n" +
"\t\t<name>_shape(1) = int(lib_strlen(<name>_ptr))\n" +
"\t\tcall c_f_pointer(<name>_ptr, <name>_fptr, <name>_shape)\n" +
"\t\tallocate(<name>(<name>_shape(1)))\n" +
"\t\t<name> = <name>_fptr\n" +
"\t\tcall lib_free(<name>_ptr)\n" +
"\telse\n" +
"\t\t<name> => null()\n" +
"\tend if\n" +
"end if"
},
#Public and opaque types
{ #[const] <opaqueTypes>*
:regex => '^\s*(const\s+|)(?<type><opaqueTypes>)(\s+const|)\s*\*\s*(?<name>\w+)\s*$',
:placeholders => %w[name type],
:dummyName => '<name>_dummy',
:acceptAs => 'type(t_<type>), intent(in) :: <name>_dummy',
:helperVars => '',
:precallStatements => '',
:callExpression => '<name>_dummy%ptr',
:passAs => 'type(c_ptr), value :: <name>_dummy',
:postcallStatements => ''
}
]
$returnTypeTemplates = [
{ #void
:regex => '^\s*void\s*$',
:placeholders => %w[],
:isVoid => true
}, { #<integerTypes>
:regex => '^\s*(?<type><integerTypes>)\s*$',
:placeholders => %w[type],
:isVoid => false,
:returnAs => 'integer(c_<type>)',
:helperVars => '',
:precallStatements => '',
:recieveAs => 'integer(c_<type>)',
:assignVariable => 'result',
:postcallStatements => ''
}, { #<floatTypes>
:regex => '^\s*(?<type><floatTypes>)\s*$',
:placeholders => %w[type],
:isVoid => false,
:returnAs => 'real(c_<type>)',
:helperVars => '',
:precallStatements => '',
:recieveAs => 'real(c_<type>)',
:assignVariable => 'result',
:postcallStatements => ''
}, { #char*
:regex => '^\s*char\s*\*\s*$',
:placeholders => %w[],
:isVoid => false,
:returnAs => 'character(kind = c_char), dimension(:), pointer',
:helperVars => "type(c_ptr) :: cString\n" +
"integer :: shape(1)\n" +
"character(kind = c_char), dimension(:), pointer :: temp",
:precallStatements => '',
:recieveAs => 'type(c_ptr)',
:assignVariable => 'cString',
:postcallStatements => "if(c_associated(cString)) then\n" +
"\tshape(1) = int(lib_strlen(cString))\n" +
"\tcall c_f_pointer(cString, temp, shape)\n" +
"\tallocate(result(shape(1)))\n" +
"\tresult = temp\n" +
"\tcall lib_free(cString)\n" +
"else\n" +
"\tresult => null()\n" +
"end if"
}, { #const char*
:regex => '^\s*const\s+char\s*\*\s*$',
:placeholders => %w[],
:isVoid => false,
:returnAs => 'character(kind = c_char), dimension(:), pointer',
:helperVars => "type(c_ptr) :: ptr\ninteger :: shape(1)",
:precallStatements => 'result => null()',
:recieveAs => 'type(c_ptr)',
:assignVariable => 'ptr',
:postcallStatements => "if(c_associated(ptr)) then\n" +
"\tshape(1) = int(lib_strlen(ptr))\n" +
"\tcall c_f_pointer(ptr, result, shape)\n" +
"end if"
}, { #const int* This returns the naked pointer because we can't know the length of the returned array within the wrapper. The user has to call c_f_pointer() himself.
:regex => '^\s*const\s+(?<type><integerTypes>)\s*\*\s*$',
:placeholders => %w[type],
:isVoid => false,
:returnAs => 'type(c_ptr)',
:helperVars => '',
:precallStatements => '',
:recieveAs => 'type(c_ptr)',
:assignVariable => 'result',
:postcallStatements => ''
}, { #const double* This returns the naked pointer because we can't know the length of the returned array within the wrapper. The user has to call c_f_pointer() himself.
:regex => '^\s*const\s+(?<type><floatTypes>)\s*\*\s*$',
:placeholders => %w[type],
:isVoid => false,
:returnAs => 'type(c_ptr)',
:helperVars => '',
:precallStatements => '',
:recieveAs => 'type(c_ptr)',