INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

passing bit patterns

passing bit patterns

(OP)
Hi

I have a simple question, is there a way to prevent the F90 compiler to check if the actual and formal arguments to a subroutine are different?

Before telling me that it is criminal to pass the wrong kind of variable please read my reason for the question.

The reason for this question is that I am trying to convert an old F77 package to F90 and one feature of this package was the use an integer workspace to store records with all kinds of variables, (integers, pointers to other records (which were integers), characters and reals). This F77 package was written long before typing become available with F90. The problem I have is that the package goes via subroutine calls to transfer such variables of different types into the integer wrkspace and in the old F77 compilers there were never any check that the actual and formal arguments were of the same type. Thus it was possible to write

integer iws(10000)
double precision xx,yy
...
call storr(iws(77),xx)
...

where the subroutine was

subroutine storr(x1,x2)
double precision x1,x2
x1=x2
return
end

which would transfer the bit pattern representing the real value of xx to (two) integer words, iws(77) and iws(78).
One could then get the value back by reversing the arguments

call storr(yy,iws(77))

and yy would have the value of xx

Apart from giving a very primitive way of having record structures a unique feature of this integer workspace was that one could easily write all that was stored in this integer workspce on an unformatted file and then read it back and continue working with the data stored.

It will be extremely difficult to do this with the datastructure I have in my current F90 code using typed records because the records can vary greatly in size and number.

So after this long introduction, is there a way to prevent the F90 compiler to generate an error if the actual and formal arguments to a subroutine are different?

Maybe I can ask a C programmer for help?

Bosse

RE: passing bit patterns

If you use your F90 compiler to build F77 source, does it still check?

RE: passing bit patterns

(OP)
My new code is F90 and quite large, I wanted to add this F77 feature as I cannot figure out any other way to save/read results stored in the F90 typed records. I made some simple conversion of the F77 code (! instead of C etc) and compiled it with F90 and of course got error as it does not like that real and formal arguments are different.

I have no experience programming in C but I guess it would be possible to write STORR in C and compile and link it. I assume F77 has a separate runtime library so compiling it with F77 and try to link it with F90 would be more problematic.

RE: passing bit patterns

Please read up on intrinsic function "transfer" and see if you can use it to achieve what you need.

RE: passing bit patterns

I've just tried it on gfortran. Doesn't seem to be a problem

CODE --> F77

subroutine converter(src, dst)
      double precision src, dst
      dst = src
      return
      end 

CODE --> F95

program main
   implicit none
   external converter
   integer twowords(2)
   double precision dp
   ! Convert the number the F95 way
   dp = 20.5
   twowords = transfer(dp, twowords, 2)
   ! Set to some other value
   dp = 192.4
   ! Try the transfer routine
   call converter(twowords, dp)
   write(*,*) "Converted ", dp
   stop
end 
To build

gfortran -Wall -g converter.for main.f95

Doesn't come up with any warnings but instead of using the converter, you could use the transfer function in F90/F95

RE: passing bit patterns

(OP)
Thanks a lot, I assumed there must be some simple way inside F08/F90 and I am grateful not to have to browse 300 pages of documentation to find it.

RE: passing bit patterns

Unlike languages like C/C++, external functions do not need a prototype. They just need the word external, which makes it highly error prone but if you are doing bit twiddling, they're brilliant. It is like having a void* in C/C++.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close