@@ -338,14 +338,14 @@ module json_module
338
338
!
339
339
! ```fortran
340
340
! program test
341
- ! use json_module
342
- ! implicit none
341
+ ! use json_module
342
+ ! implicit none
343
343
! type(json_file) :: json
344
344
! integer :: ival
345
345
! real(real64) :: rval
346
346
! character(len=:),allocatable :: cval
347
347
! logical :: found
348
- ! call json_initialize()
348
+ ! call json_initialize()
349
349
! call json%load_file(filename='myfile.json')
350
350
! call json%print_file() !print to the console
351
351
! call json%get('var.i',ival,found)
@@ -431,6 +431,28 @@ module json_module
431
431
end type json_file
432
432
! *********************************************************
433
433
434
+ ! *********************************************************
435
+ ! > author: Izaak Beekman
436
+ ! date: 07/23/2015
437
+ !
438
+ ! Structure constructor to initialize a [[json_file(type)]] object
439
+ ! with an existing [[json_value]] object
440
+ !
441
+ ! # Example
442
+ !
443
+ ! ```fortran
444
+ ! ...
445
+ ! type(json_file) :: my_file
446
+ ! type(json_value) :: json_object
447
+ ! ...
448
+ ! ! Construct a json_object
449
+ ! my_file = json_file(json_object)
450
+
451
+ interface json_file
452
+ module procedure initialize_json_file
453
+ end interface
454
+ ! *************************************************************************************
455
+
434
456
! *************************************************************************************
435
457
! >
436
458
! Array element callback function. Used by [[json_get_array]].
@@ -893,6 +915,22 @@ end subroutine array_callback_func
893
915
contains
894
916
! *****************************************************************************************
895
917
918
+ ! *****************************************************************************************
919
+ ! > author: Izaak Beekman
920
+ ! date: 07/23/2015
921
+ !
922
+ ! Cast a [[json_value]] object as a [[json_file(type)]] object
923
+
924
+ function initialize_json_file (p ) result(file_object)
925
+ type (json_value), pointer , optional , intent (in ) :: p
926
+ ! ! `json_value` object to cast as a `json_file` object
927
+ type (json_file) :: file_object
928
+
929
+ if (present (p)) file_object% p = > p
930
+
931
+ end function initialize_json_file
932
+ ! *****************************************************************************************
933
+
896
934
! *****************************************************************************************
897
935
! > author: Jacob Williams
898
936
!
@@ -918,7 +956,7 @@ end subroutine destroy_json_data
918
956
! > author: Jacob Williams
919
957
! date: 12/9/2013
920
958
!
921
- ! Destroy the [[json_file]].
959
+ ! Destroy the [[json_file(type) ]].
922
960
923
961
subroutine json_file_destroy (me )
924
962
@@ -935,7 +973,7 @@ end subroutine json_file_destroy
935
973
! > author: Jacob Williams
936
974
! date: 12/5/2014
937
975
!
938
- ! Move the [[json_value]] pointer from one [[json_file]] to another.
976
+ ! Move the [[json_value]] pointer from one [[json_file(type) ]] to another.
939
977
! The "from" pointer is then nullified, but not destroyed.
940
978
!
941
979
! @note If "from%p" is not associated, then an error is thrown.
@@ -1141,7 +1179,7 @@ end subroutine json_file_print_to_string
1141
1179
! > author: Jacob Williams
1142
1180
! date: 2/3/2014
1143
1181
!
1144
- ! Returns information about a variable in a [[json_file]].
1182
+ ! Returns information about a variable in a [[json_file(type) ]].
1145
1183
1146
1184
subroutine json_file_variable_info (me ,path ,found ,var_type ,n_children )
1147
1185
@@ -4720,7 +4758,7 @@ end subroutine wrap_json_get_string_with_path
4720
4758
! > author: Jacob Williams
4721
4759
! date: 5/14/2014
4722
4760
!
4723
- ! Get a string vector from a [[json_file]].
4761
+ ! Get a string vector from a [[json_file(type) ]].
4724
4762
4725
4763
subroutine json_get_string_vec (me , vec )
4726
4764
@@ -4773,7 +4811,7 @@ end subroutine json_get_string_vec
4773
4811
4774
4812
! *****************************************************************************************
4775
4813
! >
4776
- ! Get a string vector from a [[json_file]], given the path.
4814
+ ! Get a string vector from a [[json_file(type) ]], given the path.
4777
4815
4778
4816
subroutine json_get_string_vec_with_path (me , path , vec , found )
4779
4817
0 commit comments