replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Problem in program
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem in program

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
subroutine



Joined: 02 Nov 2009
Posts: 4
Location: Aberdeen, Scotland

PostPosted: Tue Nov 03, 2009 9:36 am    Post subject: Problem in program Reply with quote

I am having a simple problem with a Fortran program I have built in Fortran. The program will run as desired in the NAG compiler but not in Silverfrost (plato). Can anybody see the problem?

The program imports external data. Using a subroutine it calculates enginnering strain and writes to an external file.
Using a second subroutine it calculates true strain and writes to an external file.


PROGRAM array_true_stress

INTEGER, PARAMETER :: MAX_SIZE = 5970
REAL, DIMENSION(MAX_SIZE) :: a
REAL, DIMENSION(MAX_SIZE) :: b
REAL, DIMENSION(MAX_SIZE) :: c

CHARACTER(len=20) :: filename
INTEGER :: i
INTEGER :: nvals = 0
INTEGER :: status
REAL :: temp

WRITE(*,1000)
1000 FORMAT(1X,'Enter the filename with the data to be manipulated: ')
READ(*,'(A20)') filename

OPEN(UNIT=9, FILE=filename, STATUS='OLD', ACTION='READ', IOSTAT=status)
fileopen: IF( STATUS == 0 ) THEN

DO
READ(9,*,IOSTAT=status) temp
IF( status /= 0) EXIT
nvals=nvals+1
a(nvals)=temp
END DO

CALL engineering_strain (i, nvals, b, a)
OPEN(UNIT=10, FILE='eng_strain.txt', STATUS='OLD', ACTION='WRITE')
WRITE(10,960) (b(i), i=1, nvals)
WRITE(*,*) 'Engineering strain data written to an external file'
960 FORMAT (4X,F16.9)

CALL true_strain (i, nvals, a, c)
OPEN(UNIT=11, FILE='true_strain.txt', STATUS='OLD', ACTION='WRITE')
WRITE(11,960) (c(i), i=1, nvals)
WRITE(*,*) 'True strain data written to an external file'

ELSE fileopen
WRITE(*,1050) status
1050 FORMAT(1X,'File open failed--status=',I6)
END IF fileopen

CONTAINS
SUBROUTINE engineering_strain (i, nvals, b, a)
REAL, INTENT(IN):: a(i)
REAL, INTENT(OUT):: b(i)
convert_eng: DO i=1, nvals
b(i)=a(i)/100
END DO convert_eng
END SUBROUTINE engineering_strain

SUBROUTINE true_strain (i, nvals, a, c)
REAL, INTENT(IN):: a(i)
REAL, INTENT(OUT):: c(i)
add: DO i=1, nvals
c(i)=LOG((a(i)/100)+1)
END DO add
END SUBROUTINE true_strain

END PROGRAM array_true_stress
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Tue Nov 03, 2009 11:47 am    Post subject: Reply with quote

I tried your program and it works fine for me. First I created a file with some data points (eng.dat) and some empty files true_strain.txt and eng_strain.txt. The program executes with the desired external files written.

I thought that CONTAINS is only used in modules: learned something new Wink
Back to top
View user's profile Send private message
subroutine



Joined: 02 Nov 2009
Posts: 4
Location: Aberdeen, Scotland

PostPosted: Tue Nov 03, 2009 3:34 pm    Post subject: Reply with quote

Hi jjgermi,

Thank you for your reply.

This is really confusing me! When I run the previous source code I receive the following error:

Runtime error from program:g:\test.exe
Run-time Error
*** Error 112, Reference to undefined variable, array element or function result (/UNDEF)

ARRAY_TRUE_STRESS~ENGINEERING_STRAIN - in file test.f95 at line 44 [+002f]

main - in file test.f95 at line 28 [+027f]


This is in reference to the CONTAINS use for the first subroutine. I reinstalled silverfrost and still receive this error message. Can you think of any reason why this program works for you and not for me? It works for me in the NAG compiler. In silverfrost it will compile and ctreate the executable file but the previous error message is generated when executed.

Any suggestions?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Tue Nov 03, 2009 4:02 pm    Post subject: Reply with quote

Reference to undefined variable means just that. You have used a value that was not previously set.

If you run the program through the debugger then it will stop at the offending value.
Back to top
View user's profile Send private message AIM Address
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Tue Nov 03, 2009 4:54 pm    Post subject: Reply with quote

Change the array declarations in the subroutines to the following:-

REAL, INTENT(IN):: a(nvals)
REAL, INTENT(OUT):: b(nvals)
Back to top
View user's profile Send private message Visit poster's website
subroutine



Joined: 02 Nov 2009
Posts: 4
Location: Aberdeen, Scotland

PostPosted: Tue Nov 03, 2009 6:26 pm    Post subject: Reply with quote

Thank you JohnHorspool. That has solved my problem.

Can you briefly explain why that worked?

Thank you for your time.
Back to top
View user's profile Send private message
Emanuele



Joined: 21 Oct 2009
Posts: 78
Location: Bologna (Italy)

PostPosted: Tue Nov 03, 2009 7:25 pm    Post subject: Reply with quote

If I read properly your code, in the first call to subroutine you pass the argument "i" without having assigned it a value yet.

This causes an exception - as Paul said - if you compile your program with the "CheckMate Win32" option (default with Plato). Instead if you compile your program in "Debug Win32" or "Release Win32" mode you will not see any error (may be this is why jjgeremis had no problem).

In any case I think that your code works better with John�s corrections.

Good luck!
Back to top
View user's profile Send private message
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Tue Nov 03, 2009 7:51 pm    Post subject: Reply with quote

Subroutine, as Emanuele has said "i" was unassigned with the call to the first subroutine, which then attempts to declare an array size using it. This is incorrect, the array contains "nvals" items, thus use "nvals" for its size declaration.
Back to top
View user's profile Send private message Visit poster's website
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Tue Nov 03, 2009 8:16 pm    Post subject: Reply with quote

Emanuele is correct: I did compile the program with "Debug Win32". One can only learn here Smile
Back to top
View user's profile Send private message
subroutine



Joined: 02 Nov 2009
Posts: 4
Location: Aberdeen, Scotland

PostPosted: Wed Nov 04, 2009 9:15 am    Post subject: Reply with quote

Thanks guys for the informed response. I know can see why my program wasn't working. I will now annotate my program for future reference!

That is an interesting point regarding the "debug win32" and "releasewin32".
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group