Skip to content

Commit 5583fea

Browse files
committed
some refactoring.
commented out debug lines in build.sh.
1 parent f2c0136 commit 5583fea

File tree

3 files changed

+55
-37
lines changed

3 files changed

+55
-37
lines changed

build.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
# Jacob Williams : 12/27/2014
6969
#
7070

71-
set -x
72-
set -v
71+
#set -x
72+
#set -v
7373
set -o errexit
7474

7575
FORDMD='json-fortran.md' # FORD options file for building documentation
@@ -340,20 +340,20 @@ if [[ $JF_SKIP_TESTS != [yY]* ]] ; then
340340
fi
341341
if [ -f ${SRCFILE}-unicode.gcov ] && [ -f ${SRCFILE}-no-unicode.gcov ]; then
342342

343-
##############
344-
echo ""
345-
echo "-------------------"
346-
echo "no-unicode file"
347-
echo "-------------------"
348-
cat ${SRCFILE}-no-unicode.gcov
349-
echo ""
350-
echo "-------------------"
351-
echo "unicode file"
352-
echo "-------------------"
353-
cat ${SRCFILE}-unicode.gcov
354-
echo ""
355-
./pages/development-resources/gccr.pl -n -c ${SRCFILE}-no-unicode.gcov no-unicode \
356-
${SRCFILE}-unicode.gcov unicode
343+
############## for debugging
344+
#echo ""
345+
#echo "-------------------"
346+
#echo "no-unicode file"
347+
#echo "-------------------"
348+
#cat ${SRCFILE}-no-unicode.gcov
349+
#echo ""
350+
#echo "-------------------"
351+
#echo "unicode file"
352+
#echo "-------------------"
353+
#cat ${SRCFILE}-unicode.gcov
354+
#echo ""
355+
#./pages/development-resources/gccr.pl -n -c ${SRCFILE}-no-unicode.gcov no-unicode \
356+
# ${SRCFILE}-unicode.gcov unicode
357357
##############
358358

359359
# merge them

src/json_string_utilities.F90

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ module json_string_utilities
6262
public :: integer_to_string
6363
public :: real_to_string
6464
public :: string_to_integer
65+
public :: string_to_real
6566
public :: valid_json_hex
6667
public :: to_unicode
6768
public :: escape_string
@@ -176,6 +177,35 @@ subroutine real_to_string(rval,real_fmt,compact_real,str)
176177
end subroutine real_to_string
177178
!*****************************************************************************************
178179

180+
!*****************************************************************************************
181+
!> author: Jacob Williams
182+
! date: 1/19/2014
183+
!
184+
! Convert a string into a `real(RK)`.
185+
!
186+
!# History
187+
! * Jacob Williams, 10/27/2015 : Now using `fmt=*`, rather than
188+
! `fmt=real_fmt`, since it doesn't work for some unusual cases
189+
! (e.g., when `str='1E-5'`).
190+
! * Jacob Williams : 2/6/2017 : moved core logic to this routine.
191+
192+
subroutine string_to_real(str,rval,status_ok)
193+
194+
implicit none
195+
196+
character(kind=CK,len=*),intent(in) :: str
197+
real(RK),intent(out) :: rval
198+
logical(LK),intent(out) :: status_ok !! true if there were no errors
199+
200+
integer(IK) :: ierr !! read iostat error code
201+
202+
read(str,fmt=*,iostat=ierr) rval
203+
status_ok = (ierr==0)
204+
if (.not. status_ok) rval = 0.0_RK
205+
206+
end subroutine string_to_real
207+
!*****************************************************************************************
208+
179209
!*****************************************************************************************
180210
!> author: Izaak Beekman
181211
! date: 02/24/2015

src/json_value_module.F90

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ module json_value_module
557557
procedure :: name_equal
558558
procedure :: json_value_print
559559
procedure :: string_to_int
560-
procedure :: string_to_double
560+
procedure :: string_to_dble
561561
procedure :: parse_value
562562
procedure :: parse_number
563563
procedure :: parse_string
@@ -4514,10 +4514,6 @@ end subroutine wrap_json_get_path
45144514
!>
45154515
! Convert a string into an integer.
45164516
!
4517-
!# History
4518-
! * Jacob Williams : 12/10/2013 : Rewrote routine. Added error checking.
4519-
! * Modified by Izaak Beekman
4520-
!
45214517
!@note Replacement for the `parse_integer` function in the original code.
45224518

45234519
function string_to_int(json,str) result(ival)
@@ -4550,34 +4546,26 @@ end function string_to_int
45504546
!*****************************************************************************************
45514547

45524548
!*****************************************************************************************
4553-
!> author: Jacob Williams
4554-
! date: 1/19/2014
4555-
!
4549+
!>
45564550
! Convert a string into a double.
4557-
!
4558-
!# History
4559-
! * Jacob Williams, 10/27/2015 : Now using `fmt=*`, rather than
4560-
! `fmt=real_fmt`, since it doesn't work for some unusual cases
4561-
! (e.g., when `str='1E-5'`).
45624551

4563-
function string_to_double(json,str) result(rval)
4552+
function string_to_dble(json,str) result(rval)
45644553

45654554
implicit none
45664555

45674556
class(json_core),intent(inout) :: json
45684557
character(kind=CK,len=*),intent(in) :: str
45694558
real(RK) :: rval
45704559

4571-
integer(IK) :: ierr !! read iostat error code
4560+
logical(LK) :: status_ok !! error flag
45724561

45734562
if (.not. json%exception_thrown) then
45744563

4575-
!string to double
4576-
read(str,fmt=*,iostat=ierr) rval
4564+
call string_to_real(str,rval,status_ok)
45774565

4578-
if (ierr/=0) then !if there was an error
4566+
if (.not. status_ok) then !if there was an error
45794567
rval = 0.0_RK
4580-
call json%throw_exception('Error in string_to_double: '//&
4568+
call json%throw_exception('Error in string_to_dble: '//&
45814569
'string cannot be converted to a double: '//&
45824570
trim(str))
45834571
end if
@@ -4586,7 +4574,7 @@ function string_to_double(json,str) result(rval)
45864574
rval = 0.0_RK
45874575
end if
45884576

4589-
end function string_to_double
4577+
end function string_to_dble
45904578
!*****************************************************************************************
45914579

45924580
!*****************************************************************************************
@@ -7098,7 +7086,7 @@ subroutine parse_number(json, unit, str, value)
70987086
ival = json%string_to_int(tmp)
70997087
call to_integer(value,ival)
71007088
else
7101-
rval = json%string_to_double(tmp)
7089+
rval = json%string_to_dble(tmp)
71027090
call to_double(value,rval)
71037091
end if
71047092

0 commit comments

Comments
 (0)