|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
mali28
Joined: 09 Feb 2017 Posts: 11
|
Posted: Thu Apr 27, 2017 1:58 pm Post subject: Error reading data from a text file |
|
|
I am having the following error while reading data from a text file:
nrerror: Error reading data from Options.txt
**** STOP: program terminated by nrerror
Part of the code that reads the data is below and some of the variables are real in the text file and some are logical like .false. I am declaring the logical variables as:
LOGICAL(LGT) :: variable_name
and real variables as
REAL(DP) :: variable_name
OPEN(UNIT=8,FILE='Options.txt',STATUS='OLD',iostat=SuccessFlag, &
ERR=100)
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) system
IF(system.eq.1) &
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) IntNaRatio
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) varopt
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) screen_write
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) NAGTimerOn
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) TimerOn
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) Filament
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) VapCalc
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) TempCalc
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) r_init
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) t_end
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) t_split
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) dataout_tstep
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) npts_in
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) npts_shell
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) npts_out
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) InitialA
IF(InitialA.ge.one)THEN
InitialA=one-small
WRITE(6,*) '***-------PURE WATER DROPLET CALLED-------***'
WRITE(6,*) 'In order to simulate a pure water droplet it'
WRITE(6,*) ' is necessary to introduce a very small'
WRITE(6,*) 'quantity of solute to initialise the equation'
WRITE(6,*) ' system. Therefore the initial water mass'
WRITE(6,*) ' fraction will be set to',InitialA
WRITE(6,*) '***---------------------------------------***'
PAUSE
END IF
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) pure_A_den
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) pure_B_den
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) pure_A_Cp
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) pure_B_Cp
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) Tdrop_init
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) SatSolMassFrac
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) UniformGrid
bubble=.true.
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) b_init
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) b_min
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) Solids
IF(.not.Solids) InitialSolids=.false.
IF(Solids)THEN
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) InitialD
READ(8,*,iostat=SuccessFlag, ERR=100, END=200)&
InitialParticleSize
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) Lmin
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) pure_D_den
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) pure_D_Cp
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) Stokes
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) ShellDiff
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) ShellR
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) MaxSolVolFrac
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) IntWetShell
RunWetShell=IntWetShell
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) IntDryShell
RunDryShell=IntDryShell
IF(IntWetShell.and.IntDryShell) THEN
WRITE(6,*) '!*! Error - WetShell and DryShell options selected'
WRITE(6,*) '!*! Check options in Options.txt'
WRITE(6,*) '!*! Program will now terminate'
STOP
END IF
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) MinShellT
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) &
MinShellThcknss
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) &
ThckndShellThcknss
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) SinkDiff
READ(8,*,iostat=SuccessFlag, ERR=100, END=200) Tort
READ(8,*,iostat=SuccessFlag, ERR=100, END=20 |
|
Back to top |
|
|
mali28
Joined: 09 Feb 2017 Posts: 11
|
Posted: Thu Apr 27, 2017 1:59 pm Post subject: |
|
|
I am using windows compiler with 64 bit operating system. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Thu Apr 27, 2017 3:42 pm Post subject: |
|
|
The error message is printed by one the routines (nrerror) that you compiled and linked to produce your program.
You have to see your own source code to see what condition was checked before deciding to print that error message.
You cannot expect us to tell you what to fix before you have shown us either the data or the program source. |
|
Back to top |
|
|
mali28
Joined: 09 Feb 2017 Posts: 11
|
Posted: Thu Apr 27, 2017 4:32 pm Post subject: |
|
|
I think this is:
! READ OPTIONS
ReadSuccessFlag=.false.
!io_status = 0
!CALL ReadOptions(io_status)
CALL ReadOptions(ReadSuccessFlag)
! IF(.not.ReadSuccessFlag .ne. 0) &
IF(.not.ReadSuccessFlag) &
!IF(io_status .ne. 0) &
CALL nrerror('Error reading data from Options.txt')
CALL TimerDriver(opt=-2,subtitle='Read Options',t=zero) |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Thu Apr 27, 2017 7:52 pm Post subject: |
|
|
Since ReadSuccessFlag is set to .FALSE. before calling ReadOptions, which is the routine that reads OPTIONS.TXT, if ReadOptions executes all the READs correctly but does not set ReadSuccessFlag to .TRUE. after doing so, the caller will incorrectly conclude that there were errors in reading the file. |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2816 Location: South Pole, Antarctica
|
Posted: Thu Apr 27, 2017 11:50 pm Post subject: |
|
|
I am curious if SDBG64 or currently better 32bit SDBG was used for step by step analysis of reading process |
|
Back to top |
|
|
mali28
Joined: 09 Feb 2017 Posts: 11
|
Posted: Fri Apr 28, 2017 8:59 am Post subject: |
|
|
mecej4, I think you are right. The file is being read correctly, but for some reason, CALL ReadOptions(ReadSuccessFlag) is not working. I am not sure what is causing the error.
Is that a compiler version issue?
I am using Fortran95. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Fri Apr 28, 2017 10:20 am Post subject: Re: |
|
|
mali28 wrote: | mecej4, I think you are right. The file is being read correctly, but for some reason, CALL ReadOptions(ReadSuccessFlag) is not working. I am not sure what is causing the error.
Is that a compiler version issue? |
No, it is a programmer issue.
If the READ statements were simple and had no IOSTAT= and ERR= clauses, the Fortran runtime would have aborted the program and printed out information on which source line caused the crash and a traceback report. With those clauses present, if the programmer does nothing by way of testing the IOSTAT values and taking appropriate remedial action, it is the programmer who deserves the blame for the mess that is created.
You can run the program in the debugger and put hawk eyes on ReadSuccessFlags as you step through the lines of code, or you can remove all the IOSTAT= and ERR= clauses and let the Fortran runtime tell you where, if any, the read error occurred.
Last edited by mecej4 on Fri Apr 28, 2017 11:21 pm; edited 1 time in total |
|
Back to top |
|
|
wahorger
Joined: 13 Oct 2014 Posts: 1217 Location: Morrison, CO, USA
|
Posted: Fri Apr 28, 2017 8:31 pm Post subject: |
|
|
If you need to be able to handle an arbitrary data set (and not just this one), you can create a line counter. Start at 1 and increment after each read statement. I do this in my product to let the user know when they have encountered an error (my users will occasionally muck with the data on their own, much to their ultimate grief).
You have some conditional reads, and this will necessarily require a bit more code to be put in place to handle these occurrences.
That said, mecej4's suggestion to remove all the error traps and let the system tell you which line is in error will certainly work. For this data set. |
|
Back to top |
|
|
|
|
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
|