Print

Print


Hello Neil! Hello Malcolm! Hello Van!

It took me quite a while to respond. Sorry for that. 

On Tue, 2012-10-09 at 20:03 -0600, Neil Carlson wrote:
> If you're going to approach a statically-typed language (polymorphism
> aside) like Fortran with the expectations of a dynamically-typed
> language like python you're bound to be disappointed.  You've got to
> take Fortran for what it is and design your solutions around its
> idioms.  I've no doubt that the dynamic typing of python has its
> advantages, but it most certainly has its disadvantages.
It wasn't my intention to complain about Fortran, at all. I just wanted
to give you some idea why I am having such things in mind as a functions
whose return type isn't fixed but explicit. 


On Wed, 2012-10-10 at 09:31 +0900, Malcolm Cohen wrote:
> Perhaps it is worth taking a step back and asking why it is that you want to 
> architect your solution in that way.  It might well be easier to take a slightly 
> different approach to solving the "real" problem.
Sure! It is a pretty simple task. There is a binary file header I want
to parse. Words 1:70 are 32bit floats, words 71:105 are 32bit ints,
106:110 are 32bit booleans and so on ... 
Reading the Header using stream access works just perfect. 

real(4) :: floats(1:70)
integer(4) :: ints(71:105)
...
read( unit ) floats
read( unit ) ints 
...

So, I wanted to have a function which returns a real, integer or logical
accordingly to the word/position which is passed as an argument. 

I was able to find a solution using a generic interface combined with a
auxiliary passed variable 'type'. The actual code's structure looks more
or less like that:

interface get_header 
    procedure get_header_real
    procedure get_header_int
    ....
end interface 

function get_header_real( word, type ) result( value )
    real :: type, value 
    ....

function get_header_int( word, type ) result( value )
    integer :: type, value 
    ....

I am not in favor for this solution but it works very well. 
(I played around with the TRANSFER statement. However, doing so the code
becomes very hard to understand. )


All of your hints are pointing me into a direction understanding Fortran
in a better way. Just wanted to say that I am deeply grateful for all of
your help! 

Cheers, Stefan