- #1
- 3,971
- 329
Hi guys, I can't figure this one out. Here I am working with a piece of code which should read in a grid of 2 arrays, a radius array and an electron fraction array. The code looks like this:
varelecfrac has been set to 2. It reads the array without giving me any runtime error or anything, but it adds a 0 to end of all the radius values (ryegrid). The file that I fed it looks like this:
But the output looks like this:
As you can see, all the radius values are a factor of 10 larger for some reason. Anyone have any ideas why FORTRAN is doing this? I have tried writing "500.d0" in my test.dat file but it didn't change anything. It's not simply a write error either since I made it write out values for the electron fraction later (when the code is actually calculating something) and they were all wrong because the radii read from the file were all wrong. Thanks for any help!
Fortran:
subroutine varelec_init(varelecfrac,elecprofile,effilename,elecfracname)
integer :: varelecfrac,elecprofile
character*80 effilename
character*80 elecfracname
character*80 rest
character*1 first elecfracname = ''
! varelecfrac = 0 means constant elecfrac, 1 means analytic profile, 2 means read from file
! elecprofile = 1 means linear electron fraction
if(varelecfrac.eq.0) then
elecfracname = 'Constant electron fraction'
elseif(varelecfrac.eq.1) then
elecfracname = 'Analytic profile '
elseif(varelecfrac.eq.2) then
if(myid.eq.0) then
write(6,*) ' Reading electron fraction from ',effilename
write(6,*) ' Beginning of file '
icomments=1
open(unit=20,file=trim(effilename))
do while (icomments.eq.1)
read(20,'(a1,a80)')first,rest
if(elecfracname.eq.'') elecfracname=rest
if (first.eq.'#') then
write(6,'(a1,a80)') first,rest
else
icomments=0
backspace 20
endif
enddo
! read data file
iend=0
iegrid=0
do while (iend.eq.0)
iegrid=iegrid+1
read(20,*,iostat=ierr) ryegrid(iegrid), yegrid(iegrid)
if(ierr.ne.0) then
iend=1
iegrid=iegrid-1
close(20)
endif
enddo
write(6,*) ' Electron fraction grid contains ',iegrid,'values'
write(6,*) ' Beginning of Y_e grid '
do i=1,min(5,iegrid)
write(6,'(1p,f15.7,e18.9)') ryegrid(i),yegrid(i)
enddo
write(6,*) ' End of Y_e grid '
do i=max(1,iegrid-4),iegrid
write(6,'(1p,f15.7,e18.9)') ryegrid(i),yegrid(i)
enddo
! end of if for myid = 0
endif! end of if for varelecfrac=0,1,2
endif
return
end subroutine varelec_init
varelecfrac has been set to 2. It reads the array without giving me any runtime error or anything, but it adds a 0 to end of all the radius values (ryegrid). The file that I fed it looks like this:
Fortran:
# Electron fraction testing
# (0) r/km (1) Ye
#$ 13 1
500 .1
550 .105
600 .11
650 .115
700 .12
800 .13
900 .14
1000 .15
1500 .2
2000 .25
3000 .3
4000 .35
5000 .4
But the output looks like this:
Fortran:
Reading electron fraction from test.dat
Beginning of file
# Electron fraction testing
# (0) r/km (1) Ye
#$ 13 1
Electron fraction grid contains 13 values
Beginning of Y_e grid
5000.0000000 1.000000000E-01
5500.0000000 1.050000000E-01
6000.0000000 1.100000000E-01
6500.0000000 1.150000000E-01
7000.0000000 1.200000000E-01
End of Y_e grid
15000.0000000 2.000000000E-01
20000.0000000 2.500000000E-01
30000.0000000 3.000000000E-01
40000.0000000 3.500000000E-01
50000.0000000 4.000000000E-01
As you can see, all the radius values are a factor of 10 larger for some reason. Anyone have any ideas why FORTRAN is doing this? I have tried writing "500.d0" in my test.dat file but it didn't change anything. It's not simply a write error either since I made it write out values for the electron fraction later (when the code is actually calculating something) and they were all wrong because the radii read from the file were all wrong. Thanks for any help!
Last edited by a moderator: