Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Intel Fortran Compiler

SreeKS
Beginner
1,840 Views

I was trying to create a User defined model in PLAXIS2D which includes the 2 files to be read using Fortran code and the code is attached below. At that time the command end of line is shown the figure of which is attached below. Please help me so that I can run this to get the results.

0 Kudos
6 Replies
mecej4
Honored Contributor III
1,827 Views

"At that time the command end of line is shown " is not a correct report of what happened.

What the error message from the RTL shows is end-of-file on file "RfRFs.dat". Note end-of-file rather than end-of-line

Have you checked what that file and "RfIps.dat" contain? The program reads the integer n_rf from "RfIps.dat". It then attempts to read n_rf lines from "RfRFs.dat", with each line containing three real numbers. Do both files exist in the directory C:\Sree? Do the data files contain sufficient lines and correctly formatted data?

I do not know Plaxis2D at all, and how it interacts with the Fortran subroutine that you posted. We do not know if the program had previously performed I/O on the files. Try adding position='rewind' and status = 'old' to the OPEN statements, if there is some likelihood of the files having been connected earlier to the same program. 

Ron_Green
Moderator
1,783 Views

As @mecej4 says, make sure both files exist in C:\Sree.  Open them in Wordpad or something to make sure they contain ASCII data. 

 

For debug, just drop in some easy print statements right before you read 

RfRFs.dat

 

       print*, "reading n_rf lines where n_rf is ", n_rf

       do i = 1 ,n_rf 

            read (593, *) (StVarTemp(i,j), j = 1,3)

            print*, "line ', i, " is ", (StVarTemp(i,j), j = 1,3)

        end do              

        close (unit = 593) 

SreeKS
Beginner
1,696 Views

Thank you everyone for the overwhelming response. I identified the mistake as I was providing nrf as 3 where the number of variables that I defined at that time was 2.

0 Kudos
SreeKS
Beginner
1,587 Views

I have again provided a little bit of modification to my code and got another error 151, which is allocatable array is already allocated. Can someone help me to figure out what can be the probable reason for this error? I have attached the image of the error and the code below.

0 Kudos
mecej4
Honored Contributor III
1,570 Views

The error message contains the answer, and its wording is quite clear.

If your subroutine MyMod_MC is called more than once with IDTask = 1, that error will occur during the second call.

When the subroutine is first called with IDTask = 1, the allocatable array StVarTemp gets allocated when the ALLOCATE ... statement is executed. Because that variable has been declared with the SAVE attribute, if the subroutine is called a second time with IDTask = 1, that array is already allocated and the contents preserved, so it is an error to attempt to allocate it again.

The remedy depends on what the programmer wishes to do. We do not want to guess what the programmer intended to do. If the old contents are not to be preserved, remove the SAVE declaration for the array; however, only do this if you consider and accept the consequences of doing so.

JohnNichols
Valued Contributor III
1,548 Views

You should read the manual for allocate.

You should using the manual method, provide an error code

You should check the return code and add code to your Fortran file to handle the current set up properly, it is a trivial exercise

An error is merely a sign that you do did not handle the paths in the Fortran code properly

If Fortran is new to you, then I suggest you read a good Fortran book one night - that is how most of the people on this forum learnt Fortran and if it is not new to you then leaving out an error check is poor programming.  @mecej4 has kindly said, pick a path.  

Computer programming is all about side effects, a side effects merely has to be handled.  

You need to handle all potential paths if someone else is going to use the code, this why 10 lines of code has 100 lines of checking code. 

0 Kudos
Reply