usgs-coupled / iphreeqc

5 stars 4 forks source link

GetErrorString and GetErrorStringLineCount/GetErrorStringLine are inconsistent when loading database #5

Open scharlton2 opened 1 year ago

scharlton2 commented 1 year ago

When calling LoadDatabase or LoadDatabaseString with a missing database, GetErrorString and OutputErrorString behave as expected but GetErrorStringLineCount and GetErrorStringLine do not.

ie

id = CreateIphreeqc()

if (id .LT. 0) stop

res = SetErrorOn(id, .TRUE.)

res = LoadDatabase(id, 'phreeqcxx.dat')

if (res .NE. 0) then
   call OutputErrorString(id)
endif

write (*,'("Returned LoadDatabase with ",I0," errors."/)') res

Outputs:

ERROR: LoadDatabase: Unable to open:"phreeqcxx.dat".

Returned LoadDatabase with 1 errors.

and

id = CreateIphreeqc()

if (id .LT. 0) stop

res = SetErrorStringOn (id, .TRUE.)

res = LoadDatabase(id, 'phreeqcxx.dat')

if (res .NE. 0) then
   do i = 1, GetErrorStringLineCount(id)
      CALL GetErrorStringLine(id,i,Line)
      write (*,'(A)') trim(line)
   enddo
endif

write (*,'("Returned LoadDatabase with ",I0," errors."/)') res

Outputs:

Returned LoadDatabase with 1 errors.

Proposed fix

Call IPhreeqc::update_errors at the end of LoadDatabase and LoadDatabaseString