@@ -92,14 +92,14 @@ module json_module
92
92
! DEALINGS IN THE SOFTWARE.
93
93
!
94
94
! *****************************************************************************************
95
+ use ,intrinsic :: iso_fortran_env, only: wp = > real64 ! double precision reals
95
96
96
97
implicit none
97
98
98
99
private
99
100
100
101
! parameters:
101
- integer ,parameter ,public :: wp = selected_real_kind (15 ,307 ) ! double precision reals
102
- character (len=* ),parameter ,public :: json_ext = ' .json' ! JSON file extension
102
+ character (len=* ),parameter ,public :: json_ext = ' .json' ! JSON file extension
103
103
104
104
character (len= 1 ),parameter :: space = ' ' ! special characters
105
105
character (len= 1 ),parameter :: bspace = achar (8 )
@@ -295,12 +295,25 @@ end subroutine array_callback_func
295
295
! *************************************************************************************
296
296
297
297
! *************************************************************************************
298
- interface json_value_update
298
+ ! ****f* json_module/json_update
299
+ !
300
+ ! NAME
301
+ ! json_update
302
+ !
303
+ ! DESCRIPTION
304
+ ! These are like json_value_add, except if a child with the same name is
305
+ ! already present, then its value is simply updated.
306
+ ! Note that currently, these only work for scalar variables.
307
+ ! These routines can also change the variable's type (but an error will be
308
+ ! thrown if the existing variable is not a scalar).
309
+ !
310
+ ! SOURCE
311
+ interface json_update
299
312
module procedure :: json_update_logical,&
300
313
json_update_real,&
301
314
json_update_integer,&
302
315
json_update_chars
303
- end interface json_value_update
316
+ end interface json_update
304
317
! *************************************************************************************
305
318
306
319
! *************************************************************************************
@@ -351,7 +364,7 @@ end subroutine array_callback_func
351
364
public :: json_value_get ! use either a 1 based index or member
352
365
! name to get a json_value.
353
366
public :: json_value_add ! add data to a JSON structure
354
- public :: json_value_update ! update a value in a JSON structure
367
+ public :: json_update ! update a value in a JSON structure
355
368
public :: json_get ! get data from the JSON structure
356
369
public :: json_print ! print the JSON structure to a file
357
370
public :: json_print_to_string ! write the JSON structure to a string
@@ -1282,8 +1295,8 @@ subroutine json_update_logical(p,name,val,found)
1282
1295
call to_logical(p_var,val) ! update the value
1283
1296
case default
1284
1297
found = .false.
1285
- write ( * , * ) ' Error in json_update_logical: ' // &
1286
- ' the variable is not a scalar value'
1298
+ call throw_exception( ' Error in json_update_logical: ' // &
1299
+ ' the variable is not a scalar value' )
1287
1300
end select
1288
1301
1289
1302
else
@@ -1329,8 +1342,8 @@ subroutine json_update_real(p,name,val,found)
1329
1342
call to_real(p_var,val) ! update the value
1330
1343
case default
1331
1344
found = .false.
1332
- write ( * , * ) ' Error in json_update_real: ' // &
1333
- ' the variable is not a scalar value'
1345
+ call throw_exception( ' Error in json_update_real: ' // &
1346
+ ' the variable is not a scalar value' )
1334
1347
end select
1335
1348
1336
1349
else
@@ -1376,8 +1389,8 @@ subroutine json_update_integer(p,name,val,found)
1376
1389
call to_integer(p_var,val) ! update the value
1377
1390
case default
1378
1391
found = .false.
1379
- write ( * , * ) ' Error in json_update_integer: ' // &
1380
- ' the variable is not a scalar value'
1392
+ call throw_exception( ' Error in json_update_integer: ' // &
1393
+ ' the variable is not a scalar value' )
1381
1394
end select
1382
1395
1383
1396
else
@@ -1423,8 +1436,8 @@ subroutine json_update_chars(p,name,val,found)
1423
1436
call to_string(p_var,val) ! update the value
1424
1437
case default
1425
1438
found = .false.
1426
- write ( * , * ) ' Error in json_update_chars: ' // &
1427
- ' the variable is not a scalar value'
1439
+ call throw_exception( ' Error in json_update_chars: ' // &
1440
+ ' the variable is not a scalar value' )
1428
1441
end select
1429
1442
1430
1443
else
0 commit comments