Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Erratic behavior

Status
Not open for further replies.

Pfor

Technical User
Aug 11, 2010
22
IT
hallo all,

My code at first reads a input file.
It seemed that the last two parameters of the first row of the
input file had some problem.
I changed the code not to read these two parameters.

The numerical results from the code depend on how
I delete these two parameters from the input file.

Specifically if I delete them using the "left delete button" on the keyboard there is a result, while using the "right delete button"
another output is given. (actually I think it also depends
on the number of spaces I delete in the input file).

I suspected there was a not detected syntax problem, however gfortran finds none (using "-fbounds-check ").

Also compiling with ifort -C no errors are found,
however the numerical results of the codes are different
(significantly).

Actually an error was found by Ifort, I forgot to write the "::" in the declaration of a variable in a subroutine and to initialize it, however after correcting these errors the situation didn't change.

As a summary:
the code compiled with gfortran code works correctly only if I don't read
some parameters and I cancel them in the "correct way" from the
input file (exactly the same parameters are entered directly in the code
since they are not declared as "parameters" no problems should arise).

The ifort code gives the correct result even reading the "problematic"
parameters from the input.

Does anybody have an idea of what kind of error can lead to such unpredictable behavior?
I suspect that wrongly allocated memory could do it, but the compilers find nothing.

Why the gfortran does not detect the missing "::" ?

thank you
cheers,
Paolo






 
show us the head of the data file and the first corresponding read statements, as well as the declaration of variables used in the read statement.

Describing something you don't understand has no chance to help us to find the origin of your problem !

François Jacq
 
Have a look at the data file in debug, hexedit or vi. Your datafile may have an odd combination of carriage returns and line feeds. When you delete one way, it may be removing some but not all of them.

Apologies if you are not using a windows environment. The alternative is to open your datafile in visual studio, cut everything, paste it in word, cut everything, paste it back in visual studio, then save it. This will give you consistent line terminations.

Most compilers accept both the old and new way of declaring variables. You will need the colon if you're adding attributes to the declaration
Code:
integer:: withcolon
integer nocolon
 
Hallo all,
I post here a short version of the code so to understand
If I interfaced correctly the subroutines.

I included the problematic lines from the input.
If I do not read these lines the code gives the correct
values. If I read them it is wrong.

There is a little change respect to my first post; at that time it
was enough to delete the last two input values of the first row
(using the right delete button),
now I have to delete the all the first 3 rows.

Notice that implemented also sub printing the value of the
parameters and these values are the same whether I read the
old input file or not, however the calculations are different.

Thank you for your suggestions.
cheers
Paolo
!----------------------------------------------------
module parametri
integer :: nrobox
real(kind = 8) :: dro
real(kind = 8) :: emin
real(kind = 8) :: emax
real(kind = 8) :: de
integer :: lzcut
real (kind = 8) :: dkz
integer :: ikzcut

real(kind = 8) :: v0
real(kind = 8) :: rn
real(kind = 8) :: adiff
integer :: lzout

integer :: nroboxp
real(kind = 8) :: drop
real(kind = 8) :: eminp
real(kind = 8) :: emaxp
real(kind = 8) :: dep
integer :: lzcutp

end module parametri

program vortex
use parametri
implicit none

!----------------------------------------
nrobox = 15
dro = 2.00
emin = -5.0
emax = 35.0
de = 0.005
lzcut = 5
dkz = 0.128
ikzcut = 5

v0 = 0.0
rn = 52.0
adiff = 0.6 !?
ibound = 0
lzout =1000

nroboxp = 16
drop = 0.5
eminp = -85.0
emaxp = 0.0
dep = 0.0005
lzcutp = 3
!-----------------------------------------
call Old_input_read


end program vortex


!-----------------------------------------
subroutine Old_input_read
use parametri
implicit none
open(unit=5,file='pinned_restart.in')

read(5,*) nrobox, dro,emin,emax,de,lzcut, dkz ,ikzcut
read(5,*) v0,rn,adiff ,ibound ,lzout
read(5,*) nroboxp,drop,eminp,emaxp,dep,lzcutp

close(5)

end subroutine Old_input_read

!---------------------------------------------
INPUT FILE:

15,2.00,-5.0,35.0,0.005,5,0.128,5, nrobox, dro,emin,emax,de,lzcut,dkz,ikzcut
0.,52,0.6,0,1000, v0,rn,adiff,ibound,lzout
16,0.5,-85.0,0.0,0.0005,3, nroboxp, drop,eminp,emaxp,dep,lzcutp








 
Hallo all,
I solved the problem, however I still
cannot understand it.

In the case I delete the commentaries in the
inpunt file(I posted previously), everything works fine
(notice that the values of the parameters
of the input file were read correctly even
before).

Does anybody have an idea why keeping the
commentaries creates the problem?
cheers,
Paolo
P.S.
notice that the problem is present only if compiling with gfortran
(while it disappeared with ifort)
 
It may depend on your compiler, how it handles your file.
I tried it with g95 and gfortran and here are the results:
Code:
$ g95 pfor.f95 -o pfor

$ pfor
 15 2. -5. 35. 0.005 5 0.128 5
 0. 52. 0.6 0 1000
 16 0.5 -85. 0. 0.0005 3

$ gfortran pfor.f95 -o pfor

$ pfor
At line 40 of file pfor.f95 (unit = 5, file = 'pinned_restart.in')
Fortran runtime error: End of file
Then I added CRLF at end of the file and it runs now fine with gfortran too
Code:
$ pfor
          15   2.0000000000000000       -5.0000000000000000        35.000000000000000       5.00000000000000010E-003           5  0.12800000000000000                5
   0.0000000000000000        52.000000000000000       0.59999999999999998                0        1000
          16  0.50000000000000000       -85.000000000000000        0.0000000000000000       5.00000000000000010E-004           3
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top