@@ -61,7 +61,10 @@ module json_file_module
61
61
62
62
private
63
63
64
- type (json_core) :: json ! ! the instance of the [[json_core]] factory used for this file
64
+ type (json_core),public :: core ! ! The instance of the [[json_core]]
65
+ ! ! factory used for this file.
66
+ ! ! Note that this is public, so it can
67
+ ! ! also be used by the user.
65
68
66
69
type (json_value),pointer :: p = > null () ! ! the JSON structure read from the file
67
70
@@ -142,6 +145,9 @@ module json_file_module
142
145
procedure :: json_file_print_1
143
146
procedure :: json_file_print_2
144
147
148
+ ! traverse
149
+ procedure ,public :: traverse = > json_file_traverse
150
+
145
151
end type json_file
146
152
! *********************************************************
147
153
@@ -188,7 +194,7 @@ pure function json_file_failed(me) result(failed)
188
194
class(json_file),intent (in ) :: me
189
195
logical (LK) :: failed ! ! will be true if there has been an error.
190
196
191
- failed = me% json % failed()
197
+ failed = me% core % failed()
192
198
193
199
end function json_file_failed
194
200
! *****************************************************************************************
@@ -205,7 +211,7 @@ subroutine json_file_check_for_errors(me,status_ok,error_msg)
205
211
logical (LK),intent (out ) :: status_ok ! ! true if there were no errors
206
212
character (kind= CK,len= :),allocatable ,intent (out ) :: error_msg ! ! the error message (if there were errors)
207
213
208
- call me% json % check_for_errors(status_ok,error_msg)
214
+ call me% core % check_for_errors(status_ok,error_msg)
209
215
210
216
end subroutine json_file_check_for_errors
211
217
! *****************************************************************************************
@@ -220,7 +226,7 @@ pure subroutine json_file_clear_exceptions(me)
220
226
221
227
class(json_file),intent (inout ) :: me
222
228
223
- call me% json % clear_exceptions()
229
+ call me% core % clear_exceptions()
224
230
225
231
end subroutine json_file_clear_exceptions
226
232
! *****************************************************************************************
@@ -236,7 +242,7 @@ subroutine json_file_print_error_message(me,io_unit)
236
242
class(json_file),intent (inout ) :: me
237
243
integer , intent (in ), optional :: io_unit
238
244
239
- call me% json % print_error_message(io_unit)
245
+ call me% core % print_error_message(io_unit)
240
246
241
247
end subroutine json_file_print_error_message
242
248
! *****************************************************************************************
@@ -274,7 +280,7 @@ subroutine initialize_json_core_in_file(me,verbose,compact_reals,&
274
280
logical (LK),intent (in ),optional :: case_sensitive_keys ! ! for name and path comparisons, are they
275
281
! ! case sensitive.
276
282
277
- call me% json % initialize(verbose,compact_reals,&
283
+ call me% core % initialize(verbose,compact_reals,&
278
284
print_signs,real_format,spaces_per_tab,&
279
285
strict_type_checking,&
280
286
trailing_spaces_significant,&
@@ -346,7 +352,7 @@ function initialize_json_file_v2(json_value_object, json_core_object) &
346
352
type (json_core),intent (in ) :: json_core_object
347
353
348
354
file_object% p = > json_value_object
349
- file_object% json = json_core_object
355
+ file_object% core = json_core_object
350
356
351
357
end function initialize_json_file_v2
352
358
! *****************************************************************************************
@@ -375,10 +381,10 @@ subroutine json_file_destroy(me,destroy_core)
375
381
logical ,intent (in ),optional :: destroy_core ! ! to also destroy the [[json_core]].
376
382
! ! default is to leave it as is.
377
383
378
- if (associated (me% p)) call me% json % destroy(me% p)
384
+ if (associated (me% p)) call me% core % destroy(me% p)
379
385
380
386
if (present (destroy_core)) then
381
- if (destroy_core) call me% json % destroy()
387
+ if (destroy_core) call me% core % destroy()
382
388
end if
383
389
384
390
end subroutine json_file_destroy
@@ -405,7 +411,7 @@ subroutine json_file_move_pointer(to,from)
405
411
if (from% failed()) then
406
412
! Don't get the data if the FROM file has an
407
413
! active exception, since it may not be valid.
408
- call to % json % throw_exception(' Error in json_file_move_pointer: ' // &
414
+ call to % core % throw_exception(' Error in json_file_move_pointer: ' // &
409
415
' error exception in FROM file.' )
410
416
else
411
417
call to % initialize() ! initialize and clear any exceptions that may be present
@@ -414,7 +420,7 @@ subroutine json_file_move_pointer(to,from)
414
420
end if
415
421
416
422
else
417
- call to % json % throw_exception(' Error in json_file_move_pointer: ' // &
423
+ call to % core % throw_exception(' Error in json_file_move_pointer: ' // &
418
424
' pointer is not associated.' )
419
425
end if
420
426
@@ -448,7 +454,7 @@ subroutine json_file_load(me, filename, unit)
448
454
character (kind= CDK,len=* ),intent (in ) :: filename ! ! the filename to open
449
455
integer (IK),intent (in ),optional :: unit ! ! the unit number to use (if not present, a newunit is used)
450
456
451
- call me% json % parse(file= filename, p= me% p, unit= unit)
457
+ call me% core % parse(file= filename, p= me% p, unit= unit)
452
458
453
459
end subroutine json_file_load
454
460
! *****************************************************************************************
@@ -474,7 +480,7 @@ subroutine json_file_load_from_string(me, str)
474
480
class(json_file),intent (inout ) :: me
475
481
character (kind= CK,len=* ),intent (in ) :: str ! ! string to load JSON data from
476
482
477
- call me% json % parse(str= str, p= me% p)
483
+ call me% core % parse(str= str, p= me% p)
478
484
479
485
end subroutine json_file_load_from_string
480
486
! *****************************************************************************************
@@ -507,7 +513,7 @@ subroutine json_file_print_to_console(me)
507
513
508
514
class(json_file),intent (inout ) :: me
509
515
510
- call me% json % print (me% p,iunit= output_unit)
516
+ call me% core % print (me% p,iunit= output_unit)
511
517
512
518
end subroutine json_file_print_to_console
513
519
! *****************************************************************************************
@@ -526,9 +532,9 @@ subroutine json_file_print_1(me, iunit)
526
532
integer (IK),intent (in ) :: iunit ! ! file unit number (must not be -1)
527
533
528
534
if (iunit/= unit2str) then
529
- call me% json % print (me% p,iunit= iunit)
535
+ call me% core % print (me% p,iunit= iunit)
530
536
else
531
- call me% json % throw_exception(' Error in json_file_print_1: iunit must not be -1.' )
537
+ call me% core % throw_exception(' Error in json_file_print_1: iunit must not be -1.' )
532
538
end if
533
539
534
540
end subroutine json_file_print_1
@@ -559,7 +565,7 @@ subroutine json_file_print_2(me,filename)
559
565
class(json_file),intent (inout ) :: me
560
566
character (kind= CDK,len=* ),intent (in ) :: filename ! ! filename to print to
561
567
562
- call me% json % print (me% p,filename)
568
+ call me% core % print (me% p,filename)
563
569
564
570
end subroutine json_file_print_2
565
571
! *****************************************************************************************
@@ -587,7 +593,7 @@ subroutine json_file_print_to_string(me,str)
587
593
class(json_file),intent (inout ) :: me
588
594
character (kind= CK,len= :),allocatable ,intent (out ) :: str ! ! string to print JSON data to
589
595
590
- call me% json % print_to_string(me% p,str)
596
+ call me% core % print_to_string(me% p,str)
591
597
592
598
end subroutine json_file_print_to_string
593
599
! *****************************************************************************************
@@ -619,7 +625,7 @@ subroutine json_file_variable_info(me,path,found,var_type,n_children)
619
625
if (found) then
620
626
621
627
! get info:
622
- call me% json % info(p,var_type,n_children)
628
+ call me% core % info(p,var_type,n_children)
623
629
624
630
else
625
631
@@ -689,7 +695,7 @@ subroutine json_file_get_object(me, path, p, found)
689
695
type (json_value),pointer ,intent (out ) :: p ! ! pointer to the variable
690
696
logical (LK),intent (out ),optional :: found ! ! if it was really found
691
697
692
- call me% json % get(me% p, path= path, p= p, found= found)
698
+ call me% core % get(me% p, path= path, p= p, found= found)
693
699
694
700
end subroutine json_file_get_object
695
701
! *****************************************************************************************
@@ -727,7 +733,7 @@ subroutine json_file_get_integer(me, path, val, found)
727
733
integer (IK),intent (out ) :: val ! ! value
728
734
logical (LK),intent (out ),optional :: found ! ! if it was really found
729
735
730
- call me% json % get(me% p, path= path, value= val, found= found)
736
+ call me% core % get(me% p, path= path, value= val, found= found)
731
737
732
738
end subroutine json_file_get_integer
733
739
! *****************************************************************************************
@@ -765,7 +771,7 @@ subroutine json_file_get_integer_vec(me, path, vec, found)
765
771
integer (IK),dimension (:),allocatable ,intent (out ) :: vec ! ! the value vector
766
772
logical (LK),intent (out ),optional :: found ! ! if it was really found
767
773
768
- call me% json % get(me% p, path, vec, found)
774
+ call me% core % get(me% p, path, vec, found)
769
775
770
776
end subroutine json_file_get_integer_vec
771
777
! *****************************************************************************************
@@ -803,7 +809,7 @@ subroutine json_file_get_double (me, path, val, found)
803
809
real (RK),intent (out ) :: val
804
810
logical (LK),intent (out ),optional :: found
805
811
806
- call me% json % get(me% p, path= path, value= val, found= found)
812
+ call me% core % get(me% p, path= path, value= val, found= found)
807
813
808
814
end subroutine json_file_get_double
809
815
! *****************************************************************************************
@@ -841,7 +847,7 @@ subroutine json_file_get_double_vec(me, path, vec, found)
841
847
real (RK),dimension (:),allocatable ,intent (out ) :: vec
842
848
logical (LK),intent (out ),optional :: found
843
849
844
- call me% json % get(me% p, path, vec, found)
850
+ call me% core % get(me% p, path, vec, found)
845
851
846
852
end subroutine json_file_get_double_vec
847
853
! *****************************************************************************************
@@ -879,7 +885,7 @@ subroutine json_file_get_logical(me,path,val,found)
879
885
logical (LK),intent (out ) :: val
880
886
logical (LK),intent (out ),optional :: found
881
887
882
- call me% json % get(me% p, path= path, value= val, found= found)
888
+ call me% core % get(me% p, path= path, value= val, found= found)
883
889
884
890
end subroutine json_file_get_logical
885
891
! *****************************************************************************************
@@ -917,7 +923,7 @@ subroutine json_file_get_logical_vec(me, path, vec, found)
917
923
logical (LK),dimension (:),allocatable ,intent (out ) :: vec
918
924
logical (LK),intent (out ),optional :: found
919
925
920
- call me% json % get(me% p, path, vec, found)
926
+ call me% core % get(me% p, path, vec, found)
921
927
922
928
end subroutine json_file_get_logical_vec
923
929
! *****************************************************************************************
@@ -956,7 +962,7 @@ subroutine json_file_get_string(me, path, val, found)
956
962
character (kind= CK,len= :),allocatable ,intent (out ) :: val
957
963
logical (LK),intent (out ),optional :: found
958
964
959
- call me% json % get(me% p, path= path, value= val, found= found)
965
+ call me% core % get(me% p, path= path, value= val, found= found)
960
966
961
967
end subroutine json_file_get_string
962
968
! *****************************************************************************************
@@ -994,7 +1000,7 @@ subroutine json_file_get_string_vec(me, path, vec, found)
994
1000
character (kind= CK,len=* ),dimension (:),allocatable ,intent (out ) :: vec
995
1001
logical (LK),intent (out ),optional :: found
996
1002
997
- call me% json % get(me% p, path, vec, found)
1003
+ call me% core % get(me% p, path, vec, found)
998
1004
999
1005
end subroutine json_file_get_string_vec
1000
1006
! *****************************************************************************************
@@ -1037,7 +1043,7 @@ subroutine json_file_update_integer(me,name,val,found)
1037
1043
integer (IK),intent (in ) :: val
1038
1044
logical (LK),intent (out ) :: found
1039
1045
1040
- if (.not. me% json % failed()) call me% json % update(me% p,name,val,found)
1046
+ if (.not. me% core % failed()) call me% core % update(me% p,name,val,found)
1041
1047
1042
1048
end subroutine json_file_update_integer
1043
1049
! *****************************************************************************************
@@ -1080,7 +1086,7 @@ subroutine json_file_update_logical(me,name,val,found)
1080
1086
logical (LK),intent (in ) :: val
1081
1087
logical (LK),intent (out ) :: found
1082
1088
1083
- if (.not. me% json % failed()) call me% json % update(me% p,name,val,found)
1089
+ if (.not. me% core % failed()) call me% core % update(me% p,name,val,found)
1084
1090
1085
1091
end subroutine json_file_update_logical
1086
1092
! *****************************************************************************************
@@ -1123,7 +1129,7 @@ subroutine json_file_update_real(me,name,val,found)
1123
1129
real (RK),intent (in ) :: val
1124
1130
logical (LK),intent (out ) :: found
1125
1131
1126
- if (.not. me% json % failed()) call me% json % update(me% p,name,val,found)
1132
+ if (.not. me% core % failed()) call me% core % update(me% p,name,val,found)
1127
1133
1128
1134
end subroutine json_file_update_real
1129
1135
! *****************************************************************************************
@@ -1166,7 +1172,7 @@ subroutine json_file_update_string(me,name,val,found)
1166
1172
character (kind= CK,len=* ),intent (in ) :: val
1167
1173
logical (LK),intent (out ) :: found
1168
1174
1169
- if (.not. me% json % failed()) call me% json % update(me% p,name,val,found)
1175
+ if (.not. me% core % failed()) call me% core % update(me% p,name,val,found)
1170
1176
1171
1177
end subroutine json_file_update_string
1172
1178
! *****************************************************************************************
@@ -1225,6 +1231,26 @@ subroutine json_file_update_string_val_ascii(me,name,val,found)
1225
1231
end subroutine json_file_update_string_val_ascii
1226
1232
! *****************************************************************************************
1227
1233
1234
+ ! *****************************************************************************************
1235
+ ! > author: Jacob Williams
1236
+ ! date: 6/11/2016
1237
+ !
1238
+ ! Traverse the JSON structure in the file.
1239
+ ! This routine calls the user-specified [[json_traverse_callback_func]]
1240
+ ! for each element of the structure.
1241
+
1242
+ subroutine json_file_traverse (me ,traverse_callback )
1243
+
1244
+ implicit none
1245
+
1246
+ class(json_file),intent (inout ) :: me
1247
+ procedure (json_traverse_callback_func) :: traverse_callback
1248
+
1249
+ call me% core% traverse(me% p,traverse_callback)
1250
+
1251
+ end subroutine json_file_traverse
1252
+ ! *****************************************************************************************
1253
+
1228
1254
! *****************************************************************************************
1229
1255
end module json_file_module
1230
1256
! *****************************************************************************************
0 commit comments