- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am having a hard time understanding the behaviour of some FORTRAN 77 code.
The code:
INTEGER*4 FUNCTION EINAUS(IY,IK) INTEGER*4 IRE IRE = 0 EINAUS = IRE END FUNCTION SUBROUTINE STDAUS INTEGER*4 IRE IRE = 1 WRITE(*,*) 'IRE= ',IRE WRITE(*,*) 'EINAUS(1,3)= ',EINAUS(1,3) IRE = EINAUS(1,3) WRITE(*,*) 'IRE= ',IRE RETURN END
The output:
IRE= 1 EINAUS(1,3)= NaN IRE= -2147483648
I would have expected the last two lines to read 0 instead of NaN or 0x80000000.
Please point me to the obvious thing I am missing here.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try the code below. It is however much better to have your functions in a module rather than external.
SUBROUTINE STDAUS INTEGER*4 IRE integer(4), external :: EINAUS ! declare the function IRE = 1 WRITE(*,*) 'IRE= ',IRE WRITE(*,*) 'EINAUS(1,3)= ',EINAUS(1,3) IRE = EINAUS(1,3) WRITE(*,*) 'IRE= ',IRE RETURN END
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try the code below. It is however much better to have your functions in a module rather than external.
SUBROUTINE STDAUS INTEGER*4 IRE integer(4), external :: EINAUS ! declare the function IRE = 1 WRITE(*,*) 'IRE= ',IRE WRITE(*,*) 'EINAUS(1,3)= ',EINAUS(1,3) IRE = EINAUS(1,3) WRITE(*,*) 'IRE= ',IRE RETURN END
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much. That's it.
I keep all code, that I added, in modules. But since it is not mine, and I just had to make some adjustments (procedure to function) I'll add it in like that. I'll try to convince him, since it would reduce that huge amount of COMMON blocks aswell.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page