Simulation Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

json_file_module.i90 129 KiB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523
  1. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90"
  2. !*****************************************************************************************
  3. !> author: Jacob Williams
  4. ! license: BSD
  5. !
  6. ! Higher-level [[json_file]] interface for the [[json_value]] type.
  7. !
  8. !### License
  9. ! * JSON-Fortran is released under a BSD-style license.
  10. ! See the [LICENSE](https://github.com/jacobwilliams/json-fortran/blob/master/LICENSE)
  11. ! file for details.
  12. module json_file_module
  13. use,intrinsic :: iso_fortran_env
  14. use json_kinds
  15. use json_parameters, only: unit2str
  16. use json_string_utilities
  17. use json_value_module
  18. implicit none
  19. private
  20. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_macros.inc" 1
  21. ! JSON-Fortran preprocessor macros.
  22. !
  23. ! License
  24. ! JSON-Fortran is released under a BSD-style license.
  25. ! See the [LICENSE](https://github.com/jacobwilliams/json-fortran/blob/master/LICENSE)
  26. ! file for details.
  27. !*********************************************************
  28. ! File encoding preprocessor macro.
  29. !
  30. # 15
  31. ! don't ask for utf-8 file encoding unless using UCS4
  32. ! this may let us use unformatted stream io to read in files more quickly
  33. ! even with unicode support turned on `inquire( ... encoding=FL_ENCODING)`
  34. ! may be able to detect json files in which each character is exactly one
  35. ! byte
  36. !*********************************************************
  37. !*********************************************************
  38. ! This C preprocessor macro will take a procedure name as an
  39. ! input, and output either that same procedure name if the
  40. ! code is compiled without USE_UCS4 being defined or it will
  41. ! expand the procedure name to the original procedure name,
  42. ! followed by a comma and then the original procedure name
  43. ! with 'wrap_' prepended to it. This is suitable for creating
  44. ! overloaded interfaces that will accept UCS4 character actual
  45. ! arguments as well as DEFAULT/ASCII character arguments,
  46. ! based on whether or not ISO 10646 is supported and requested.
  47. !
  48. # 55
  49. !*********************************************************
  50. # 25 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  51. !*********************************************************
  52. !> author: Jacob Williams
  53. ! date: 12/9/2013
  54. !
  55. ! The `json_file` is the main public class that is
  56. ! used to open a file and get data from it.
  57. !
  58. ! A `json_file` contains only two items: an instance of a [[json_core(type)]],
  59. ! which is used for all data manipulation, and a [[json_value]] pointer,
  60. ! which is used to construct the linked-list data structure.
  61. ! Note that most methods in the `json_file` class are simply wrappers
  62. ! to the lower-level routines in the [[json_value_module]].
  63. !
  64. !### Example
  65. !
  66. !```fortran
  67. ! program test
  68. ! use json_module
  69. ! implicit none
  70. ! type(json_file) :: json
  71. ! integer :: ival
  72. ! real(real64) :: rval
  73. ! character(len=:),allocatable :: cval
  74. ! logical :: found
  75. ! call json%initialize(compact_reals=.true.)
  76. ! call json%load(filename='myfile.json')
  77. ! call json%print() !print to the console
  78. ! call json%get('var.i',ival,found)
  79. ! call json%get('var.r(3)',rval,found)
  80. ! call json%get('var.c',cval,found)
  81. ! call json%destroy()
  82. ! end program test
  83. !```
  84. !
  85. !@note The `destroy()` method may be called to free the memory if necessary.
  86. ! [[json_file(type)]] includes a finalizer that also calls
  87. ! `destroy()` when the variable goes out of scope.
  88. type,public :: json_file
  89. private
  90. type(json_core) :: core !! The instance of the [[json_core(type)]]
  91. !! factory used for this file.
  92. type(json_value),pointer :: p => null() !! the JSON structure read from the file
  93. contains
  94. generic,public :: initialize => initialize_json_core_in_file,&
  95. set_json_core_in_file
  96. procedure,public :: get_core => get_json_core_in_file
  97. !>
  98. ! Load JSON from a file.
  99. procedure,public :: load => json_file_load
  100. !>
  101. ! The same as `load`, but only here for backward compatibility
  102. procedure,public :: load_file => json_file_load
  103. !>
  104. ! Load JSON from a string.
  105. generic,public :: deserialize => json_file_load_from_string
  106. !>
  107. ! The same as `deserialize`, but only here for backward compatibility
  108. generic,public :: load_from_string => json_file_load_from_string
  109. !>
  110. ! Print the [[json_value]] structure to an allocatable string
  111. procedure,public :: serialize => json_file_print_to_string
  112. !>
  113. ! The same as `serialize`, but only here for backward compatibility
  114. procedure,public :: print_to_string => json_file_print_to_string
  115. procedure,public :: destroy => json_file_destroy
  116. procedure,public :: nullify => json_file_nullify
  117. procedure,public :: move => json_file_move_pointer
  118. generic,public :: info => json_file_variable_info
  119. generic,public :: matrix_info => json_file_variable_matrix_info
  120. !error checking:
  121. procedure,public :: failed => json_file_failed
  122. procedure,public :: print_error_message => json_file_print_error_message
  123. procedure,public :: check_for_errors => json_file_check_for_errors
  124. procedure,public :: clear_exceptions => json_file_clear_exceptions
  125. generic,public :: print => json_file_print_to_console, &
  126. json_file_print_to_unit, &
  127. json_file_print_to_filename
  128. !>
  129. ! The same as `print`, but only here for backward compatibility
  130. generic,public :: print_file => json_file_print_to_console, &
  131. json_file_print_to_unit, &
  132. json_file_print_to_filename
  133. !>
  134. ! Rename a variable, specifying it by path
  135. generic,public :: rename => json_file_rename
  136. # 131
  137. !>
  138. ! Verify that a path is valid
  139. ! (i.e., a variable with this path exists in the file).
  140. generic,public :: valid_path => json_file_valid_path
  141. !>
  142. ! Get a variable from a [[json_file(type)]], by specifying the path.
  143. generic,public :: get => json_file_get_object, &
  144. json_file_get_integer, &
  145. json_file_get_real32, &
  146. json_file_get_real, &
  147. # 148
  148. json_file_get_logical, &
  149. json_file_get_string, &
  150. json_file_get_integer_vec, &
  151. json_file_get_real32_vec, &
  152. json_file_get_real_vec, &
  153. # 158
  154. json_file_get_logical_vec, &
  155. json_file_get_string_vec, &
  156. json_file_get_alloc_string_vec, &
  157. json_file_get_root
  158. !>
  159. ! Add a variable to a [[json_file(type)]], by specifying the path.
  160. !
  161. !### Example
  162. !
  163. !```fortran
  164. ! program test
  165. ! use json_module, rk=>json_rk, ik=>json_ik
  166. ! implicit none
  167. ! type(json_file) :: f
  168. ! call f%initialize() ! specify whatever init options you want.
  169. ! call f%add('inputs.t', 0.0_rk)
  170. ! call f%add('inputs.x', [1.0_rk,2.0_rk,3.0_rk])
  171. ! call f%add('inputs.flag', .true.)
  172. ! call f%print() ! print to the console
  173. ! end program test
  174. !```
  175. generic,public :: add => json_file_add, &
  176. json_file_add_object, &
  177. json_file_add_integer, &
  178. json_file_add_real32, &
  179. json_file_add_real, &
  180. # 190
  181. json_file_add_logical, &
  182. json_file_add_string, &
  183. json_file_add_integer_vec, &
  184. json_file_add_real32_vec, &
  185. json_file_add_real_vec, &
  186. # 200
  187. json_file_add_logical_vec, &
  188. json_file_add_string_vec
  189. # 208
  190. !>
  191. ! Update a scalar variable in a [[json_file(type)]],
  192. ! by specifying the path.
  193. !
  194. !@note These have been mostly supplanted by the `add`
  195. ! methods, which do a similar thing (and can be used for
  196. ! scalars and vectors, etc.)
  197. generic,public :: update => json_file_update_integer, &
  198. json_file_update_logical, &
  199. json_file_update_real32, &
  200. json_file_update_real, &
  201. # 225
  202. json_file_update_string
  203. # 230
  204. !>
  205. ! Remove a variable from a [[json_file(type)]]
  206. ! by specifying the path.
  207. generic,public :: remove => json_file_remove
  208. !traverse
  209. procedure,public :: traverse => json_file_traverse
  210. ! ***************************************************
  211. ! operators
  212. ! ***************************************************
  213. generic,public :: operator(.in.) => json_file_valid_path_op
  214. procedure,pass(me) :: json_file_valid_path_op
  215. generic,public :: assignment(=) => assign_json_file,&
  216. assign_json_file_to_string,&
  217. assign_string_to_json_file
  218. procedure :: assign_json_file
  219. procedure,pass(me) :: assign_json_file_to_string
  220. procedure :: assign_string_to_json_file
  221. ! ***************************************************
  222. ! private routines
  223. ! ***************************************************
  224. !load from string:
  225. procedure :: json_file_load_from_string
  226. !initialize
  227. procedure :: initialize_json_core_in_file
  228. procedure :: set_json_core_in_file
  229. !get info:
  230. procedure :: json_file_variable_info
  231. procedure :: json_file_variable_matrix_info
  232. !rename:
  233. procedure :: json_file_rename
  234. # 274
  235. !validate path:
  236. procedure :: json_file_valid_path
  237. !get:
  238. procedure :: json_file_get_object
  239. procedure :: json_file_get_integer
  240. procedure :: json_file_get_real32
  241. procedure :: json_file_get_real
  242. # 288
  243. procedure :: json_file_get_logical
  244. procedure :: json_file_get_string
  245. procedure :: json_file_get_integer_vec
  246. procedure :: json_file_get_real32_vec
  247. procedure :: json_file_get_real_vec
  248. # 298
  249. procedure :: json_file_get_logical_vec
  250. procedure :: json_file_get_string_vec
  251. procedure :: json_file_get_alloc_string_vec
  252. procedure :: json_file_get_root
  253. !add:
  254. procedure :: json_file_add
  255. procedure :: json_file_add_object
  256. procedure :: json_file_add_integer
  257. procedure :: json_file_add_real32
  258. procedure :: json_file_add_real
  259. # 314
  260. procedure :: json_file_add_logical
  261. procedure :: json_file_add_string
  262. procedure :: json_file_add_integer_vec
  263. procedure :: json_file_add_real32_vec
  264. procedure :: json_file_add_real_vec
  265. # 324
  266. procedure :: json_file_add_logical_vec
  267. procedure :: json_file_add_string_vec
  268. # 332
  269. !update:
  270. procedure :: json_file_update_integer
  271. procedure :: json_file_update_logical
  272. procedure :: json_file_update_real32
  273. procedure :: json_file_update_real
  274. # 343
  275. procedure :: json_file_update_string
  276. # 348
  277. !remove:
  278. procedure :: json_file_remove
  279. !print:
  280. procedure :: json_file_print_to_console
  281. procedure :: json_file_print_to_unit
  282. procedure :: json_file_print_to_filename
  283. final :: finalize_json_file
  284. end type json_file
  285. !*********************************************************
  286. !*********************************************************
  287. !> author: Izaak Beekman
  288. ! date: 07/23/2015
  289. !
  290. ! Structure constructor to initialize a [[json_file(type)]]
  291. ! object with an existing [[json_value]] object or a JSON
  292. ! string, and either the [[json_core(type)]] settings or a
  293. ! [[json_core(type)]] instance.
  294. !
  295. !### Example
  296. !
  297. !```fortran
  298. ! ...
  299. ! type(json_file) :: my_file
  300. ! type(json_value),pointer :: json_object
  301. ! type(json_core) :: json_core_object
  302. ! ...
  303. ! ! Construct a json_object:
  304. ! !could do this:
  305. ! my_file = json_file(json_object)
  306. ! !or:
  307. ! my_file = json_file(json_object,verbose=.true.)
  308. ! !or:
  309. ! my_file = json_file('{"x": [1]}',verbose=.true.)
  310. ! !or:
  311. ! my_file = json_file(json_object,json_core_object)
  312. ! !or:
  313. ! my_file = json_file('{"x": [1]}',json_core_object)
  314. !```
  315. interface json_file
  316. module procedure initialize_json_file, &
  317. initialize_json_file_v2, &
  318. initialize_json_file_from_string, &
  319. initialize_json_file_from_string_v2
  320. end interface
  321. !*************************************************************************************
  322. contains
  323. !*****************************************************************************************
  324. !*****************************************************************************************
  325. !>
  326. ! Finalizer for [[json_file]] class.
  327. !
  328. ! Just a wrapper for [[json_file_destroy]].
  329. subroutine finalize_json_file(me)
  330. implicit none
  331. type(json_file),intent(inout) :: me
  332. call me%destroy(destroy_core=.true.)
  333. end subroutine finalize_json_file
  334. !*****************************************************************************************
  335. !*****************************************************************************************
  336. !>
  337. ! Check error status in the file.
  338. pure function json_file_failed(me) result(failed)
  339. implicit none
  340. class(json_file),intent(in) :: me
  341. logical(LK) :: failed !! will be true if there has been an error.
  342. failed = me%core%failed()
  343. end function json_file_failed
  344. !*****************************************************************************************
  345. !*****************************************************************************************
  346. !>
  347. ! Retrieve error status and message from the class.
  348. subroutine json_file_check_for_errors(me,status_ok,error_msg)
  349. implicit none
  350. class(json_file),intent(inout) :: me
  351. logical(LK),intent(out),optional :: status_ok !! true if there were no errors
  352. character(kind=CK,len=:),allocatable,intent(out),optional :: error_msg !! the error message
  353. !! (if there were errors)
  354. # 453
  355. call me%core%check_for_errors(status_ok,error_msg)
  356. end subroutine json_file_check_for_errors
  357. !*****************************************************************************************
  358. !*****************************************************************************************
  359. !>
  360. ! Clear exceptions in the class.
  361. pure subroutine json_file_clear_exceptions(me)
  362. implicit none
  363. class(json_file),intent(inout) :: me
  364. call me%core%clear_exceptions()
  365. end subroutine json_file_clear_exceptions
  366. !*****************************************************************************************
  367. !*****************************************************************************************
  368. !>
  369. ! This is a wrapper for [[json_print_error_message]].
  370. subroutine json_file_print_error_message(me,io_unit)
  371. implicit none
  372. class(json_file),intent(inout) :: me
  373. integer, intent(in), optional :: io_unit
  374. call me%core%print_error_message(io_unit)
  375. end subroutine json_file_print_error_message
  376. !*****************************************************************************************
  377. !*****************************************************************************************
  378. !>
  379. ! Initialize the [[json_core(type)]] for this [[json_file]].
  380. ! This is just a wrapper for [[json_initialize]].
  381. !
  382. !@note This does not destroy the data in the file.
  383. !
  384. !@note [[initialize_json_core]], [[json_initialize]],
  385. ! [[initialize_json_core_in_file]], [[initialize_json_file]],
  386. ! [[initialize_json_file_v2]], [[initialize_json_file_from_string]],
  387. ! and [[initialize_json_file_from_string_v2]]
  388. ! all have a similar interface.
  389. subroutine initialize_json_core_in_file(me,&
  390. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_dummy_arguments.inc" 1
  391. ! The dummy argument list for the various `initialize` subroutines.
  392. !
  393. ! See also: json_initialize_argument.inc
  394. verbose,&
  395. compact_reals,&
  396. print_signs,&
  397. real_format,&
  398. spaces_per_tab,&
  399. strict_type_checking,&
  400. trailing_spaces_significant,&
  401. case_sensitive_keys,&
  402. no_whitespace,&
  403. unescape_strings,&
  404. comment_char,&
  405. path_mode,&
  406. path_separator,&
  407. compress_vectors,&
  408. allow_duplicate_keys,&
  409. escape_solidus,&
  410. stop_on_error,&
  411. null_to_real_mode,&
  412. non_normal_mode,&
  413. use_quiet_nan, &
  414. strict_integer_type_checking &
  415. # 506 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  416. )
  417. implicit none
  418. class(json_file),intent(inout) :: me
  419. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_arguments.inc" 1
  420. ! The argument list for the various `initialize` subroutines.
  421. !
  422. ! See also: json_initialize_dummy_arguments.inc
  423. logical(LK),intent(in),optional :: verbose
  424. !! mainly useful for debugging (default is false)
  425. logical(LK),intent(in),optional :: compact_reals
  426. !! to compact the real number strings for output (default is true)
  427. logical(LK),intent(in),optional :: print_signs
  428. !! always print numeric sign (default is false)
  429. character(kind=CDK,len=*),intent(in),optional :: real_format
  430. !! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES'
  431. integer(IK),intent(in),optional :: spaces_per_tab
  432. !! number of spaces per tab for indenting (default is 2)
  433. logical(LK),intent(in),optional :: strict_type_checking
  434. !! if true, no integer, double, or logical type
  435. !! conversions are done for the `get` routines
  436. !! (default is false).
  437. logical(LK),intent(in),optional :: trailing_spaces_significant
  438. !! for name and path comparisons, is trailing
  439. !! space to be considered significant.
  440. !! (default is false)
  441. logical(LK),intent(in),optional :: case_sensitive_keys
  442. !! for name and path comparisons, are they
  443. !! case sensitive. (default is true)
  444. logical(LK),intent(in),optional :: no_whitespace
  445. !! if true, printing the JSON structure is
  446. !! done without adding any non-significant
  447. !! spaces or linebreaks (default is false)
  448. logical(LK),intent(in),optional :: unescape_strings
  449. !! If false, then the raw escaped
  450. !! string is returned from [[json_get_string]]
  451. !! and similar routines. If true [default],
  452. !! then the string is returned unescaped.
  453. character(kind=CK,len=*),intent(in),optional :: comment_char
  454. !! If present, these characters are used
  455. !! to denote comments in the JSON file,
  456. !! which will be ignored if present.
  457. !! Example: `!`, `#`, or `/!#`. Setting this
  458. !! to a blank string disables the
  459. !! ignoring of comments. (Default is `/!#`).
  460. integer(IK),intent(in),optional :: path_mode
  461. !! How the path strings are interpreted in the
  462. !! `get_by_path` routines:
  463. !!
  464. !! * 1 : Default mode (see [[json_get_by_path_default]])
  465. !! * 2 : as RFC 6901 "JSON Pointer" paths
  466. !! (see [[json_get_by_path_rfc6901]])
  467. !! * 3 : JSONPath "bracket-notation"
  468. !! see [[json_get_by_path_jsonpath_bracket]])
  469. character(kind=CK,len=1),intent(in),optional :: path_separator
  470. !! The `path` separator to use
  471. !! in the "default" mode for
  472. !! the paths in the various
  473. !! `get_by_path` routines.
  474. !! Example: `.` [default] or `%`.
  475. !! Note: if `path_mode/=1`
  476. !! then this is ignored.
  477. logical(LK),intent(in),optional :: compress_vectors
  478. !! If true, then arrays of integers,
  479. !! nulls, doubles, and logicals are
  480. !! printed all on one line.
  481. !! [Note: `no_whitespace` will
  482. !! override this option if necessary].
  483. !! (Default is False).
  484. logical(LK),intent(in),optional :: allow_duplicate_keys
  485. !! * If True [default] then no special checks
  486. !! are done to check for duplicate keys.
  487. !! * If False, then after parsing, if any duplicate
  488. !! keys are found, an error is thrown. A call to
  489. !! [[json_value_validate]] will also check for
  490. !! duplicates.
  491. logical(LK),intent(in),optional :: escape_solidus
  492. !! * If True then the solidus "`/`" is always escaped
  493. !! "`\/`" when serializing JSON
  494. !! * If False [default], then it is not escaped.
  495. !!
  496. !! Note that this option does not affect parsing
  497. !! (both escaped and unescaped are still valid in
  498. !! all cases).
  499. logical(LK),intent(in),optional :: stop_on_error
  500. !! If an exception is raised, then immediately quit.
  501. !! (Default is False).
  502. integer(IK),intent(in),optional :: null_to_real_mode
  503. !! if `strict_type_checking=false`:
  504. !!
  505. !! * 1 : an exception will be raised if
  506. !! try to retrieve a `null` as a real.
  507. !! * 2 : a `null` retrieved as a real
  508. !! will return a NaN. [default]
  509. !! * 3 : a `null` retrieved as a real
  510. !! will return 0.0.
  511. integer(IK),intent(in),optional :: non_normal_mode
  512. !! How to serialize NaN, Infinity, and
  513. !! -Infinity real values:
  514. !!
  515. !! * 1 : as strings (e.g., "NaN",
  516. !! "Infinity", "-Infinity") [default]
  517. !! * 2 : as JSON `null` values
  518. logical(LK),intent(in),optional :: use_quiet_nan
  519. !! * If true [default], `null_to_real_mode=2`
  520. !! and [[string_to_real]] will use
  521. !! `ieee_quiet_nan` for NaN values.
  522. !! * If false,
  523. !! `ieee_signaling_nan` will be used.
  524. logical(LK),intent(in),optional :: strict_integer_type_checking
  525. !! * If false, when parsing JSON, if an integer numeric value
  526. !! cannot be converted to an integer (`integer(IK)`),
  527. !! then an attempt is then make to convert it
  528. !! to a real (`real(RK)`).
  529. !! * If true, an exception will be raised if the integer
  530. !! value cannot be read.
  531. !!
  532. !! (default is true)
  533. # 512 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  534. call me%core%initialize(&
  535. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_dummy_arguments.inc" 1
  536. ! The dummy argument list for the various `initialize` subroutines.
  537. !
  538. ! See also: json_initialize_argument.inc
  539. verbose,&
  540. compact_reals,&
  541. print_signs,&
  542. real_format,&
  543. spaces_per_tab,&
  544. strict_type_checking,&
  545. trailing_spaces_significant,&
  546. case_sensitive_keys,&
  547. no_whitespace,&
  548. unescape_strings,&
  549. comment_char,&
  550. path_mode,&
  551. path_separator,&
  552. compress_vectors,&
  553. allow_duplicate_keys,&
  554. escape_solidus,&
  555. stop_on_error,&
  556. null_to_real_mode,&
  557. non_normal_mode,&
  558. use_quiet_nan, &
  559. strict_integer_type_checking &
  560. # 515 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  561. )
  562. end subroutine initialize_json_core_in_file
  563. !*****************************************************************************************
  564. !*****************************************************************************************
  565. !>
  566. ! Set the [[json_core(type)]] for this [[json_file]].
  567. !
  568. !@note This does not destroy the data in the file.
  569. !
  570. !@note This one is used if you want to initialize the file with
  571. ! an already-existing [[json_core(type)]] (presumably, this was already
  572. ! initialized by a call to [[initialize_json_core]] or similar).
  573. subroutine set_json_core_in_file(me,core)
  574. implicit none
  575. class(json_file),intent(inout) :: me
  576. type(json_core),intent(in) :: core
  577. me%core = core
  578. end subroutine set_json_core_in_file
  579. !*****************************************************************************************
  580. !*****************************************************************************************
  581. !>
  582. ! Get a copy of the [[json_core(type)]] in this [[json_file]].
  583. subroutine get_json_core_in_file(me,core)
  584. implicit none
  585. class(json_file),intent(in) :: me
  586. type(json_core),intent(out) :: core
  587. core = me%core
  588. end subroutine get_json_core_in_file
  589. !*****************************************************************************************
  590. !*****************************************************************************************
  591. !> author: Izaak Beekman
  592. ! date: 07/23/2015
  593. !
  594. ! Cast a [[json_value]] object as a [[json_file(type)]] object.
  595. ! It also calls the `initialize()` method.
  596. !
  597. !@note [[initialize_json_core]], [[json_initialize]],
  598. ! [[initialize_json_core_in_file]], [[initialize_json_file]],
  599. ! [[initialize_json_file_v2]], [[initialize_json_file_from_string]],
  600. ! and [[initialize_json_file_from_string_v2]]
  601. ! all have a similar interface.
  602. function initialize_json_file(p,&
  603. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_dummy_arguments.inc" 1
  604. ! The dummy argument list for the various `initialize` subroutines.
  605. !
  606. ! See also: json_initialize_argument.inc
  607. verbose,&
  608. compact_reals,&
  609. print_signs,&
  610. real_format,&
  611. spaces_per_tab,&
  612. strict_type_checking,&
  613. trailing_spaces_significant,&
  614. case_sensitive_keys,&
  615. no_whitespace,&
  616. unescape_strings,&
  617. comment_char,&
  618. path_mode,&
  619. path_separator,&
  620. compress_vectors,&
  621. allow_duplicate_keys,&
  622. escape_solidus,&
  623. stop_on_error,&
  624. null_to_real_mode,&
  625. non_normal_mode,&
  626. use_quiet_nan, &
  627. strict_integer_type_checking &
  628. # 572 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  629. ) result(file_object)
  630. implicit none
  631. type(json_file) :: file_object
  632. type(json_value),pointer,optional :: p !! `json_value` object to cast
  633. !! as a `json_file` object. This
  634. !! will be nullified.
  635. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_arguments.inc" 1
  636. ! The argument list for the various `initialize` subroutines.
  637. !
  638. ! See also: json_initialize_dummy_arguments.inc
  639. logical(LK),intent(in),optional :: verbose
  640. !! mainly useful for debugging (default is false)
  641. logical(LK),intent(in),optional :: compact_reals
  642. !! to compact the real number strings for output (default is true)
  643. logical(LK),intent(in),optional :: print_signs
  644. !! always print numeric sign (default is false)
  645. character(kind=CDK,len=*),intent(in),optional :: real_format
  646. !! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES'
  647. integer(IK),intent(in),optional :: spaces_per_tab
  648. !! number of spaces per tab for indenting (default is 2)
  649. logical(LK),intent(in),optional :: strict_type_checking
  650. !! if true, no integer, double, or logical type
  651. !! conversions are done for the `get` routines
  652. !! (default is false).
  653. logical(LK),intent(in),optional :: trailing_spaces_significant
  654. !! for name and path comparisons, is trailing
  655. !! space to be considered significant.
  656. !! (default is false)
  657. logical(LK),intent(in),optional :: case_sensitive_keys
  658. !! for name and path comparisons, are they
  659. !! case sensitive. (default is true)
  660. logical(LK),intent(in),optional :: no_whitespace
  661. !! if true, printing the JSON structure is
  662. !! done without adding any non-significant
  663. !! spaces or linebreaks (default is false)
  664. logical(LK),intent(in),optional :: unescape_strings
  665. !! If false, then the raw escaped
  666. !! string is returned from [[json_get_string]]
  667. !! and similar routines. If true [default],
  668. !! then the string is returned unescaped.
  669. character(kind=CK,len=*),intent(in),optional :: comment_char
  670. !! If present, these characters are used
  671. !! to denote comments in the JSON file,
  672. !! which will be ignored if present.
  673. !! Example: `!`, `#`, or `/!#`. Setting this
  674. !! to a blank string disables the
  675. !! ignoring of comments. (Default is `/!#`).
  676. integer(IK),intent(in),optional :: path_mode
  677. !! How the path strings are interpreted in the
  678. !! `get_by_path` routines:
  679. !!
  680. !! * 1 : Default mode (see [[json_get_by_path_default]])
  681. !! * 2 : as RFC 6901 "JSON Pointer" paths
  682. !! (see [[json_get_by_path_rfc6901]])
  683. !! * 3 : JSONPath "bracket-notation"
  684. !! see [[json_get_by_path_jsonpath_bracket]])
  685. character(kind=CK,len=1),intent(in),optional :: path_separator
  686. !! The `path` separator to use
  687. !! in the "default" mode for
  688. !! the paths in the various
  689. !! `get_by_path` routines.
  690. !! Example: `.` [default] or `%`.
  691. !! Note: if `path_mode/=1`
  692. !! then this is ignored.
  693. logical(LK),intent(in),optional :: compress_vectors
  694. !! If true, then arrays of integers,
  695. !! nulls, doubles, and logicals are
  696. !! printed all on one line.
  697. !! [Note: `no_whitespace` will
  698. !! override this option if necessary].
  699. !! (Default is False).
  700. logical(LK),intent(in),optional :: allow_duplicate_keys
  701. !! * If True [default] then no special checks
  702. !! are done to check for duplicate keys.
  703. !! * If False, then after parsing, if any duplicate
  704. !! keys are found, an error is thrown. A call to
  705. !! [[json_value_validate]] will also check for
  706. !! duplicates.
  707. logical(LK),intent(in),optional :: escape_solidus
  708. !! * If True then the solidus "`/`" is always escaped
  709. !! "`\/`" when serializing JSON
  710. !! * If False [default], then it is not escaped.
  711. !!
  712. !! Note that this option does not affect parsing
  713. !! (both escaped and unescaped are still valid in
  714. !! all cases).
  715. logical(LK),intent(in),optional :: stop_on_error
  716. !! If an exception is raised, then immediately quit.
  717. !! (Default is False).
  718. integer(IK),intent(in),optional :: null_to_real_mode
  719. !! if `strict_type_checking=false`:
  720. !!
  721. !! * 1 : an exception will be raised if
  722. !! try to retrieve a `null` as a real.
  723. !! * 2 : a `null` retrieved as a real
  724. !! will return a NaN. [default]
  725. !! * 3 : a `null` retrieved as a real
  726. !! will return 0.0.
  727. integer(IK),intent(in),optional :: non_normal_mode
  728. !! How to serialize NaN, Infinity, and
  729. !! -Infinity real values:
  730. !!
  731. !! * 1 : as strings (e.g., "NaN",
  732. !! "Infinity", "-Infinity") [default]
  733. !! * 2 : as JSON `null` values
  734. logical(LK),intent(in),optional :: use_quiet_nan
  735. !! * If true [default], `null_to_real_mode=2`
  736. !! and [[string_to_real]] will use
  737. !! `ieee_quiet_nan` for NaN values.
  738. !! * If false,
  739. !! `ieee_signaling_nan` will be used.
  740. logical(LK),intent(in),optional :: strict_integer_type_checking
  741. !! * If false, when parsing JSON, if an integer numeric value
  742. !! cannot be converted to an integer (`integer(IK)`),
  743. !! then an attempt is then make to convert it
  744. !! to a real (`real(RK)`).
  745. !! * If true, an exception will be raised if the integer
  746. !! value cannot be read.
  747. !!
  748. !! (default is true)
  749. # 581 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  750. call file_object%initialize(&
  751. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_dummy_arguments.inc" 1
  752. ! The dummy argument list for the various `initialize` subroutines.
  753. !
  754. ! See also: json_initialize_argument.inc
  755. verbose,&
  756. compact_reals,&
  757. print_signs,&
  758. real_format,&
  759. spaces_per_tab,&
  760. strict_type_checking,&
  761. trailing_spaces_significant,&
  762. case_sensitive_keys,&
  763. no_whitespace,&
  764. unescape_strings,&
  765. comment_char,&
  766. path_mode,&
  767. path_separator,&
  768. compress_vectors,&
  769. allow_duplicate_keys,&
  770. escape_solidus,&
  771. stop_on_error,&
  772. null_to_real_mode,&
  773. non_normal_mode,&
  774. use_quiet_nan, &
  775. strict_integer_type_checking &
  776. # 584 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  777. )
  778. if (present(p)) then
  779. file_object%p => p
  780. ! we have to nullify it to avoid
  781. ! a dangling pointer when the file
  782. ! goes out of scope
  783. nullify(p)
  784. end if
  785. end function initialize_json_file
  786. !*****************************************************************************************
  787. !*****************************************************************************************
  788. !> author: Jacob Williams
  789. ! date: 4/26/2016
  790. !
  791. ! Cast a [[json_value]] pointer and a [[json_core(type)]] object
  792. ! as a [[json_file(type)]] object.
  793. function initialize_json_file_v2(json_value_object,json_core_object) &
  794. result(file_object)
  795. implicit none
  796. type(json_file) :: file_object
  797. type(json_value),pointer,intent(in) :: json_value_object
  798. type(json_core),intent(in) :: json_core_object
  799. file_object%p => json_value_object
  800. file_object%core = json_core_object
  801. end function initialize_json_file_v2
  802. !*****************************************************************************************
  803. !*****************************************************************************************
  804. !> author: Jacob Williams
  805. ! date: 01/19/2019
  806. !
  807. ! Cast a JSON string as a [[json_file(type)]] object.
  808. ! It also calls the `initialize()` method.
  809. !
  810. !### Example
  811. !
  812. !```fortran
  813. ! type(json_file) :: f
  814. ! f = json_file('{"key ": 1}', trailing_spaces_significant=.true.)
  815. !```
  816. !
  817. !@note [[initialize_json_core]], [[json_initialize]],
  818. ! [[initialize_json_core_in_file]], [[initialize_json_file]],
  819. ! [[initialize_json_file_v2]], [[initialize_json_file_from_string]],
  820. ! and [[initialize_json_file_from_string_v2]]
  821. ! all have a similar interface.
  822. function initialize_json_file_from_string(str,&
  823. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_dummy_arguments.inc" 1
  824. ! The dummy argument list for the various `initialize` subroutines.
  825. !
  826. ! See also: json_initialize_argument.inc
  827. verbose,&
  828. compact_reals,&
  829. print_signs,&
  830. real_format,&
  831. spaces_per_tab,&
  832. strict_type_checking,&
  833. trailing_spaces_significant,&
  834. case_sensitive_keys,&
  835. no_whitespace,&
  836. unescape_strings,&
  837. comment_char,&
  838. path_mode,&
  839. path_separator,&
  840. compress_vectors,&
  841. allow_duplicate_keys,&
  842. escape_solidus,&
  843. stop_on_error,&
  844. null_to_real_mode,&
  845. non_normal_mode,&
  846. use_quiet_nan, &
  847. strict_integer_type_checking &
  848. # 641 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  849. ) result(file_object)
  850. implicit none
  851. type(json_file) :: file_object
  852. character(kind=CK,len=*),intent(in) :: str !! string to load JSON data from
  853. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_arguments.inc" 1
  854. ! The argument list for the various `initialize` subroutines.
  855. !
  856. ! See also: json_initialize_dummy_arguments.inc
  857. logical(LK),intent(in),optional :: verbose
  858. !! mainly useful for debugging (default is false)
  859. logical(LK),intent(in),optional :: compact_reals
  860. !! to compact the real number strings for output (default is true)
  861. logical(LK),intent(in),optional :: print_signs
  862. !! always print numeric sign (default is false)
  863. character(kind=CDK,len=*),intent(in),optional :: real_format
  864. !! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES'
  865. integer(IK),intent(in),optional :: spaces_per_tab
  866. !! number of spaces per tab for indenting (default is 2)
  867. logical(LK),intent(in),optional :: strict_type_checking
  868. !! if true, no integer, double, or logical type
  869. !! conversions are done for the `get` routines
  870. !! (default is false).
  871. logical(LK),intent(in),optional :: trailing_spaces_significant
  872. !! for name and path comparisons, is trailing
  873. !! space to be considered significant.
  874. !! (default is false)
  875. logical(LK),intent(in),optional :: case_sensitive_keys
  876. !! for name and path comparisons, are they
  877. !! case sensitive. (default is true)
  878. logical(LK),intent(in),optional :: no_whitespace
  879. !! if true, printing the JSON structure is
  880. !! done without adding any non-significant
  881. !! spaces or linebreaks (default is false)
  882. logical(LK),intent(in),optional :: unescape_strings
  883. !! If false, then the raw escaped
  884. !! string is returned from [[json_get_string]]
  885. !! and similar routines. If true [default],
  886. !! then the string is returned unescaped.
  887. character(kind=CK,len=*),intent(in),optional :: comment_char
  888. !! If present, these characters are used
  889. !! to denote comments in the JSON file,
  890. !! which will be ignored if present.
  891. !! Example: `!`, `#`, or `/!#`. Setting this
  892. !! to a blank string disables the
  893. !! ignoring of comments. (Default is `/!#`).
  894. integer(IK),intent(in),optional :: path_mode
  895. !! How the path strings are interpreted in the
  896. !! `get_by_path` routines:
  897. !!
  898. !! * 1 : Default mode (see [[json_get_by_path_default]])
  899. !! * 2 : as RFC 6901 "JSON Pointer" paths
  900. !! (see [[json_get_by_path_rfc6901]])
  901. !! * 3 : JSONPath "bracket-notation"
  902. !! see [[json_get_by_path_jsonpath_bracket]])
  903. character(kind=CK,len=1),intent(in),optional :: path_separator
  904. !! The `path` separator to use
  905. !! in the "default" mode for
  906. !! the paths in the various
  907. !! `get_by_path` routines.
  908. !! Example: `.` [default] or `%`.
  909. !! Note: if `path_mode/=1`
  910. !! then this is ignored.
  911. logical(LK),intent(in),optional :: compress_vectors
  912. !! If true, then arrays of integers,
  913. !! nulls, doubles, and logicals are
  914. !! printed all on one line.
  915. !! [Note: `no_whitespace` will
  916. !! override this option if necessary].
  917. !! (Default is False).
  918. logical(LK),intent(in),optional :: allow_duplicate_keys
  919. !! * If True [default] then no special checks
  920. !! are done to check for duplicate keys.
  921. !! * If False, then after parsing, if any duplicate
  922. !! keys are found, an error is thrown. A call to
  923. !! [[json_value_validate]] will also check for
  924. !! duplicates.
  925. logical(LK),intent(in),optional :: escape_solidus
  926. !! * If True then the solidus "`/`" is always escaped
  927. !! "`\/`" when serializing JSON
  928. !! * If False [default], then it is not escaped.
  929. !!
  930. !! Note that this option does not affect parsing
  931. !! (both escaped and unescaped are still valid in
  932. !! all cases).
  933. logical(LK),intent(in),optional :: stop_on_error
  934. !! If an exception is raised, then immediately quit.
  935. !! (Default is False).
  936. integer(IK),intent(in),optional :: null_to_real_mode
  937. !! if `strict_type_checking=false`:
  938. !!
  939. !! * 1 : an exception will be raised if
  940. !! try to retrieve a `null` as a real.
  941. !! * 2 : a `null` retrieved as a real
  942. !! will return a NaN. [default]
  943. !! * 3 : a `null` retrieved as a real
  944. !! will return 0.0.
  945. integer(IK),intent(in),optional :: non_normal_mode
  946. !! How to serialize NaN, Infinity, and
  947. !! -Infinity real values:
  948. !!
  949. !! * 1 : as strings (e.g., "NaN",
  950. !! "Infinity", "-Infinity") [default]
  951. !! * 2 : as JSON `null` values
  952. logical(LK),intent(in),optional :: use_quiet_nan
  953. !! * If true [default], `null_to_real_mode=2`
  954. !! and [[string_to_real]] will use
  955. !! `ieee_quiet_nan` for NaN values.
  956. !! * If false,
  957. !! `ieee_signaling_nan` will be used.
  958. logical(LK),intent(in),optional :: strict_integer_type_checking
  959. !! * If false, when parsing JSON, if an integer numeric value
  960. !! cannot be converted to an integer (`integer(IK)`),
  961. !! then an attempt is then make to convert it
  962. !! to a real (`real(RK)`).
  963. !! * If true, an exception will be raised if the integer
  964. !! value cannot be read.
  965. !!
  966. !! (default is true)
  967. # 648 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  968. call file_object%initialize(&
  969. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_dummy_arguments.inc" 1
  970. ! The dummy argument list for the various `initialize` subroutines.
  971. !
  972. ! See also: json_initialize_argument.inc
  973. verbose,&
  974. compact_reals,&
  975. print_signs,&
  976. real_format,&
  977. spaces_per_tab,&
  978. strict_type_checking,&
  979. trailing_spaces_significant,&
  980. case_sensitive_keys,&
  981. no_whitespace,&
  982. unescape_strings,&
  983. comment_char,&
  984. path_mode,&
  985. path_separator,&
  986. compress_vectors,&
  987. allow_duplicate_keys,&
  988. escape_solidus,&
  989. stop_on_error,&
  990. null_to_real_mode,&
  991. non_normal_mode,&
  992. use_quiet_nan, &
  993. strict_integer_type_checking &
  994. # 651 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  995. )
  996. call file_object%deserialize(str)
  997. end function initialize_json_file_from_string
  998. !*****************************************************************************************
  999. !*****************************************************************************************
  1000. !>
  1001. ! Alternate version of [[initialize_json_file_from_string]], where "str" is kind=CDK.
  1002. function wrap_initialize_json_file_from_string(str,&
  1003. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_dummy_arguments.inc" 1
  1004. ! The dummy argument list for the various `initialize` subroutines.
  1005. !
  1006. ! See also: json_initialize_argument.inc
  1007. verbose,&
  1008. compact_reals,&
  1009. print_signs,&
  1010. real_format,&
  1011. spaces_per_tab,&
  1012. strict_type_checking,&
  1013. trailing_spaces_significant,&
  1014. case_sensitive_keys,&
  1015. no_whitespace,&
  1016. unescape_strings,&
  1017. comment_char,&
  1018. path_mode,&
  1019. path_separator,&
  1020. compress_vectors,&
  1021. allow_duplicate_keys,&
  1022. escape_solidus,&
  1023. stop_on_error,&
  1024. null_to_real_mode,&
  1025. non_normal_mode,&
  1026. use_quiet_nan, &
  1027. strict_integer_type_checking &
  1028. # 663 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  1029. ) result(file_object)
  1030. implicit none
  1031. type(json_file) :: file_object
  1032. character(kind=CDK,len=*),intent(in) :: str !! string to load JSON data from
  1033. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_arguments.inc" 1
  1034. ! The argument list for the various `initialize` subroutines.
  1035. !
  1036. ! See also: json_initialize_dummy_arguments.inc
  1037. logical(LK),intent(in),optional :: verbose
  1038. !! mainly useful for debugging (default is false)
  1039. logical(LK),intent(in),optional :: compact_reals
  1040. !! to compact the real number strings for output (default is true)
  1041. logical(LK),intent(in),optional :: print_signs
  1042. !! always print numeric sign (default is false)
  1043. character(kind=CDK,len=*),intent(in),optional :: real_format
  1044. !! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES'
  1045. integer(IK),intent(in),optional :: spaces_per_tab
  1046. !! number of spaces per tab for indenting (default is 2)
  1047. logical(LK),intent(in),optional :: strict_type_checking
  1048. !! if true, no integer, double, or logical type
  1049. !! conversions are done for the `get` routines
  1050. !! (default is false).
  1051. logical(LK),intent(in),optional :: trailing_spaces_significant
  1052. !! for name and path comparisons, is trailing
  1053. !! space to be considered significant.
  1054. !! (default is false)
  1055. logical(LK),intent(in),optional :: case_sensitive_keys
  1056. !! for name and path comparisons, are they
  1057. !! case sensitive. (default is true)
  1058. logical(LK),intent(in),optional :: no_whitespace
  1059. !! if true, printing the JSON structure is
  1060. !! done without adding any non-significant
  1061. !! spaces or linebreaks (default is false)
  1062. logical(LK),intent(in),optional :: unescape_strings
  1063. !! If false, then the raw escaped
  1064. !! string is returned from [[json_get_string]]
  1065. !! and similar routines. If true [default],
  1066. !! then the string is returned unescaped.
  1067. character(kind=CK,len=*),intent(in),optional :: comment_char
  1068. !! If present, these characters are used
  1069. !! to denote comments in the JSON file,
  1070. !! which will be ignored if present.
  1071. !! Example: `!`, `#`, or `/!#`. Setting this
  1072. !! to a blank string disables the
  1073. !! ignoring of comments. (Default is `/!#`).
  1074. integer(IK),intent(in),optional :: path_mode
  1075. !! How the path strings are interpreted in the
  1076. !! `get_by_path` routines:
  1077. !!
  1078. !! * 1 : Default mode (see [[json_get_by_path_default]])
  1079. !! * 2 : as RFC 6901 "JSON Pointer" paths
  1080. !! (see [[json_get_by_path_rfc6901]])
  1081. !! * 3 : JSONPath "bracket-notation"
  1082. !! see [[json_get_by_path_jsonpath_bracket]])
  1083. character(kind=CK,len=1),intent(in),optional :: path_separator
  1084. !! The `path` separator to use
  1085. !! in the "default" mode for
  1086. !! the paths in the various
  1087. !! `get_by_path` routines.
  1088. !! Example: `.` [default] or `%`.
  1089. !! Note: if `path_mode/=1`
  1090. !! then this is ignored.
  1091. logical(LK),intent(in),optional :: compress_vectors
  1092. !! If true, then arrays of integers,
  1093. !! nulls, doubles, and logicals are
  1094. !! printed all on one line.
  1095. !! [Note: `no_whitespace` will
  1096. !! override this option if necessary].
  1097. !! (Default is False).
  1098. logical(LK),intent(in),optional :: allow_duplicate_keys
  1099. !! * If True [default] then no special checks
  1100. !! are done to check for duplicate keys.
  1101. !! * If False, then after parsing, if any duplicate
  1102. !! keys are found, an error is thrown. A call to
  1103. !! [[json_value_validate]] will also check for
  1104. !! duplicates.
  1105. logical(LK),intent(in),optional :: escape_solidus
  1106. !! * If True then the solidus "`/`" is always escaped
  1107. !! "`\/`" when serializing JSON
  1108. !! * If False [default], then it is not escaped.
  1109. !!
  1110. !! Note that this option does not affect parsing
  1111. !! (both escaped and unescaped are still valid in
  1112. !! all cases).
  1113. logical(LK),intent(in),optional :: stop_on_error
  1114. !! If an exception is raised, then immediately quit.
  1115. !! (Default is False).
  1116. integer(IK),intent(in),optional :: null_to_real_mode
  1117. !! if `strict_type_checking=false`:
  1118. !!
  1119. !! * 1 : an exception will be raised if
  1120. !! try to retrieve a `null` as a real.
  1121. !! * 2 : a `null` retrieved as a real
  1122. !! will return a NaN. [default]
  1123. !! * 3 : a `null` retrieved as a real
  1124. !! will return 0.0.
  1125. integer(IK),intent(in),optional :: non_normal_mode
  1126. !! How to serialize NaN, Infinity, and
  1127. !! -Infinity real values:
  1128. !!
  1129. !! * 1 : as strings (e.g., "NaN",
  1130. !! "Infinity", "-Infinity") [default]
  1131. !! * 2 : as JSON `null` values
  1132. logical(LK),intent(in),optional :: use_quiet_nan
  1133. !! * If true [default], `null_to_real_mode=2`
  1134. !! and [[string_to_real]] will use
  1135. !! `ieee_quiet_nan` for NaN values.
  1136. !! * If false,
  1137. !! `ieee_signaling_nan` will be used.
  1138. logical(LK),intent(in),optional :: strict_integer_type_checking
  1139. !! * If false, when parsing JSON, if an integer numeric value
  1140. !! cannot be converted to an integer (`integer(IK)`),
  1141. !! then an attempt is then make to convert it
  1142. !! to a real (`real(RK)`).
  1143. !! * If true, an exception will be raised if the integer
  1144. !! value cannot be read.
  1145. !!
  1146. !! (default is true)
  1147. # 670 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  1148. file_object = initialize_json_file_from_string(&
  1149. to_unicode(str),&
  1150. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_dummy_arguments.inc" 1
  1151. ! The dummy argument list for the various `initialize` subroutines.
  1152. !
  1153. ! See also: json_initialize_argument.inc
  1154. verbose,&
  1155. compact_reals,&
  1156. print_signs,&
  1157. real_format,&
  1158. spaces_per_tab,&
  1159. strict_type_checking,&
  1160. trailing_spaces_significant,&
  1161. case_sensitive_keys,&
  1162. no_whitespace,&
  1163. unescape_strings,&
  1164. comment_char,&
  1165. path_mode,&
  1166. path_separator,&
  1167. compress_vectors,&
  1168. allow_duplicate_keys,&
  1169. escape_solidus,&
  1170. stop_on_error,&
  1171. null_to_real_mode,&
  1172. non_normal_mode,&
  1173. use_quiet_nan, &
  1174. strict_integer_type_checking &
  1175. # 674 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_file_module.F90" 2
  1176. )
  1177. end function wrap_initialize_json_file_from_string
  1178. !*****************************************************************************************
  1179. !*****************************************************************************************
  1180. !> author: Jacob Williams
  1181. ! date: 1/19/2019
  1182. !
  1183. ! Cast a JSON string and a [[json_core(type)]] object
  1184. ! as a [[json_file(type)]] object.
  1185. function initialize_json_file_from_string_v2(str, json_core_object) &
  1186. result(file_object)
  1187. implicit none
  1188. type(json_file) :: file_object
  1189. character(kind=CK,len=*),intent(in) :: str !! string to load JSON data from
  1190. type(json_core),intent(in) :: json_core_object
  1191. file_object%core = json_core_object
  1192. call file_object%deserialize(str)
  1193. end function initialize_json_file_from_string_v2
  1194. !*****************************************************************************************
  1195. !*****************************************************************************************
  1196. !>
  1197. ! Alternate version of [[initialize_json_file_from_string_v2]], where "str" is kind=CDK.
  1198. function wrap_initialize_json_file_from_string_v2(str,json_core_object) &
  1199. result(file_object)
  1200. implicit none
  1201. type(json_file) :: file_object
  1202. character(kind=CDK,len=*),intent(in) :: str !! string to load JSON data from
  1203. type(json_core),intent(in) :: json_core_object
  1204. file_object = initialize_json_file_from_string_v2(to_unicode(str),json_core_object)
  1205. end function wrap_initialize_json_file_from_string_v2
  1206. !*****************************************************************************************
  1207. !*****************************************************************************************
  1208. !> author: Jacob Williams
  1209. !
  1210. ! Nullify the [[json_value]] pointer in a [[json_file(type)]],
  1211. ! but do not destroy it.
  1212. !
  1213. ! This should normally only be done if the pointer is the target of
  1214. ! another pointer outside the class that is still intended to be in
  1215. ! scope after the [[json_file(type)]] has gone out of scope.
  1216. ! Otherwise, this would result in a memory leak.
  1217. !
  1218. !### See also
  1219. ! * [[json_file_destroy]]
  1220. !
  1221. !### History
  1222. ! * 6/30/2019 : Created
  1223. subroutine json_file_nullify(me)
  1224. implicit none
  1225. class(json_file),intent(inout) :: me
  1226. nullify(me%p)
  1227. end subroutine json_file_nullify
  1228. !*****************************************************************************************
  1229. !*****************************************************************************************
  1230. !> author: Jacob Williams
  1231. !
  1232. ! Destroy the [[json_value]] data in a [[json_file(type)]].
  1233. ! This may be done when the variable is no longer needed,
  1234. ! or will be reused to open a different file.
  1235. ! Otherwise a memory leak will occur.
  1236. !
  1237. ! Optionally, also destroy the [[json_core(type)]] instance (this
  1238. ! is not necessary to prevent memory leaks, since a [[json_core(type)]]
  1239. ! does not use pointers).
  1240. !
  1241. !### See also
  1242. ! * [[json_file_nullify]]
  1243. !
  1244. !### History
  1245. ! * 12/9/2013 : Created
  1246. ! * 4/26/2016 : Added optional `destroy_core` argument
  1247. !
  1248. !@note This routine will be called automatically when the variable
  1249. ! goes out of scope.
  1250. subroutine json_file_destroy(me,destroy_core)
  1251. implicit none
  1252. class(json_file),intent(inout) :: me
  1253. logical,intent(in),optional :: destroy_core !! to also destroy the [[json_core(type)]].
  1254. !! default is to leave it as is.
  1255. if (associated(me%p)) call me%core%destroy(me%p)
  1256. if (present(destroy_core)) then
  1257. if (destroy_core) call me%core%destroy()
  1258. end if
  1259. end subroutine json_file_destroy
  1260. !*****************************************************************************************
  1261. !*****************************************************************************************
  1262. !> author: Jacob Williams
  1263. ! date: 12/5/2014
  1264. !
  1265. ! Move the [[json_value]] pointer from one [[json_file(type)]] to another.
  1266. ! The "from" pointer is then nullified, but not destroyed.
  1267. !
  1268. !@note If "from%p" is not associated, then an error is thrown.
  1269. subroutine json_file_move_pointer(to,from)
  1270. implicit none
  1271. class(json_file),intent(inout) :: to
  1272. class(json_file),intent(inout) :: from
  1273. if (associated(from%p)) then
  1274. if (from%failed()) then
  1275. !Don't get the data if the FROM file has an
  1276. !active exception, since it may not be valid.
  1277. call to%core%throw_exception('Error in json_file_move_pointer: '//&
  1278. 'error exception in FROM file.')
  1279. else
  1280. call to%initialize() !initialize and clear any exceptions that may be present
  1281. to%p => from%p
  1282. nullify(from%p)
  1283. end if
  1284. else
  1285. call to%core%throw_exception('Error in json_file_move_pointer: '//&
  1286. 'pointer is not associated.')
  1287. end if
  1288. end subroutine json_file_move_pointer
  1289. !*****************************************************************************************
  1290. !*****************************************************************************************
  1291. !> author: Jacob Williams
  1292. ! date: 12/9/2013
  1293. !
  1294. ! Load the JSON data from a file.
  1295. !
  1296. !### Example
  1297. !
  1298. !```fortran
  1299. ! program main
  1300. ! use json_module
  1301. ! implicit none
  1302. ! type(json_file) :: f
  1303. ! call f%load('my_file.json')
  1304. ! !...
  1305. ! call f%destroy()
  1306. ! end program main
  1307. !```
  1308. subroutine json_file_load(me, filename, unit)
  1309. implicit none
  1310. class(json_file),intent(inout) :: me
  1311. character(kind=CDK,len=*),intent(in) :: filename !! the filename to open
  1312. integer(IK),intent(in),optional :: unit !! the unit number to use
  1313. !! (if not present, a newunit
  1314. !! is used)
  1315. call me%core%load(file=filename, p=me%p, unit=unit)
  1316. end subroutine json_file_load
  1317. !*****************************************************************************************
  1318. !*****************************************************************************************
  1319. !> author: Jacob Williams
  1320. ! date: 1/13/2015
  1321. !
  1322. ! Load the JSON data from a string.
  1323. !
  1324. !### Example
  1325. !
  1326. ! Load JSON from a string:
  1327. !```fortran
  1328. ! type(json_file) :: f
  1329. ! call f%deserialize('{ "name": "Leonidas" }')
  1330. !```
  1331. subroutine json_file_load_from_string(me, str)
  1332. implicit none
  1333. class(json_file),intent(inout) :: me
  1334. character(kind=CK,len=*),intent(in) :: str !! string to load JSON data from
  1335. call me%core%deserialize(me%p, str)
  1336. end subroutine json_file_load_from_string
  1337. !*****************************************************************************************
  1338. !*****************************************************************************************
  1339. !>
  1340. ! Alternate version of [[json_file_load_from_string]], where "str" is kind=CDK.
  1341. subroutine wrap_json_file_load_from_string(me, str)
  1342. implicit none
  1343. class(json_file),intent(inout) :: me
  1344. character(kind=CDK,len=*),intent(in) :: str
  1345. call me%deserialize(to_unicode(str))
  1346. end subroutine wrap_json_file_load_from_string
  1347. !*****************************************************************************************
  1348. !*****************************************************************************************
  1349. !> author: Jacob Williams
  1350. ! date: 1/11/2015
  1351. !
  1352. ! Print the JSON file to the console.
  1353. subroutine json_file_print_to_console(me)
  1354. implicit none
  1355. class(json_file),intent(inout) :: me
  1356. call me%core%print(me%p,iunit=int(output_unit,IK))
  1357. end subroutine json_file_print_to_console
  1358. !*****************************************************************************************
  1359. !*****************************************************************************************
  1360. !> author: Jacob Williams
  1361. ! date: 12/9/2013
  1362. !
  1363. ! Prints the JSON file to the specified file unit number.
  1364. subroutine json_file_print_to_unit(me, iunit)
  1365. implicit none
  1366. class(json_file),intent(inout) :: me
  1367. integer(IK),intent(in) :: iunit !! file unit number (must not be -1)
  1368. if (iunit/=unit2str) then
  1369. call me%core%print(me%p,iunit=iunit)
  1370. else
  1371. call me%core%throw_exception('Error in json_file_print_to_unit: iunit must not be -1.')
  1372. end if
  1373. end subroutine json_file_print_to_unit
  1374. !*****************************************************************************************
  1375. !*****************************************************************************************
  1376. !> author: Jacob Williams
  1377. ! date: 1/11/2015
  1378. !
  1379. ! Print the JSON structure to the specified filename.
  1380. ! The file is opened, printed, and then closed.
  1381. !
  1382. !### Example
  1383. ! Example loading a JSON file, changing a value, and then printing
  1384. ! result to a new file:
  1385. !```fortran
  1386. ! type(json_file) :: f
  1387. ! logical :: found
  1388. ! call f%load('my_file.json') !open the original file
  1389. ! call f%update('version',4,found) !change the value of a variable
  1390. ! call f%print('my_file_2.json') !save file as new name
  1391. !```
  1392. subroutine json_file_print_to_filename(me,filename)
  1393. implicit none
  1394. class(json_file),intent(inout) :: me
  1395. character(kind=CDK,len=*),intent(in) :: filename !! filename to print to
  1396. call me%core%print(me%p,filename)
  1397. end subroutine json_file_print_to_filename
  1398. !*****************************************************************************************
  1399. !*****************************************************************************************
  1400. !> author: Jacob Williams
  1401. ! date: 1/11/2015
  1402. !
  1403. ! Print the JSON file to a string.
  1404. !
  1405. !### Example
  1406. !
  1407. ! Open a JSON file, and then print the contents to a string:
  1408. !```fortran
  1409. ! type(json_file) :: f
  1410. ! character(kind=CK,len=:),allocatable :: str
  1411. ! call f%load('my_file.json')
  1412. ! call f%serialize(str)
  1413. !```
  1414. subroutine json_file_print_to_string(me,str)
  1415. implicit none
  1416. class(json_file),intent(inout) :: me
  1417. character(kind=CK,len=:),allocatable,intent(out) :: str !! string to print JSON data to
  1418. call me%core%serialize(me%p,str)
  1419. end subroutine json_file_print_to_string
  1420. !*****************************************************************************************
  1421. !*****************************************************************************************
  1422. !> author: Jacob Williams
  1423. ! date: 2/3/2014
  1424. !
  1425. ! Returns information about a variable in a [[json_file(type)]].
  1426. !
  1427. !@note If `found` is present, no exceptions will be thrown if an
  1428. ! error occurs. Otherwise, an exception will be thrown if the
  1429. ! variable is not found.
  1430. subroutine json_file_variable_info(me,path,found,var_type,n_children,name)
  1431. implicit none
  1432. class(json_file),intent(inout) :: me
  1433. character(kind=CK,len=*),intent(in) :: path !! path to the variable
  1434. logical(LK),intent(out),optional :: found !! the variable exists in the structure
  1435. integer(IK),intent(out),optional :: var_type !! variable type
  1436. integer(IK),intent(out),optional :: n_children !! number of children
  1437. character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name
  1438. call me%core%info(me%p,path,found,var_type,n_children,name)
  1439. end subroutine json_file_variable_info
  1440. !*****************************************************************************************
  1441. !*****************************************************************************************
  1442. !>
  1443. ! Alternate version of [[json_file_variable_info]], where "path" is kind=CDK.
  1444. !
  1445. !@note If `found` is present, no exceptions will be thrown if an
  1446. ! error occurs. Otherwise, an exception will be thrown if the
  1447. ! variable is not found.
  1448. subroutine wrap_json_file_variable_info(me,path,found,var_type,n_children,name)
  1449. implicit none
  1450. class(json_file),intent(inout) :: me
  1451. character(kind=CDK,len=*),intent(in) :: path
  1452. logical(LK),intent(out),optional :: found
  1453. integer(IK),intent(out),optional :: var_type
  1454. integer(IK),intent(out),optional :: n_children
  1455. character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name
  1456. call me%info(to_unicode(path),found,var_type,n_children,name)
  1457. end subroutine wrap_json_file_variable_info
  1458. !*****************************************************************************************
  1459. !*****************************************************************************************
  1460. !> author: Jacob Williams
  1461. ! date: 6/26/2016
  1462. !
  1463. ! Returns matrix information about a variable in a [[json_file(type)]].
  1464. !
  1465. !@note If `found` is present, no exceptions will be thrown if an
  1466. ! error occurs. Otherwise, an exception will be thrown if the
  1467. ! variable is not found.
  1468. subroutine json_file_variable_matrix_info(me,path,is_matrix,found,&
  1469. var_type,n_sets,set_size,name)
  1470. implicit none
  1471. class(json_file),intent(inout) :: me
  1472. character(kind=CK,len=*),intent(in) :: path !! path to the variable
  1473. logical(LK),intent(out) :: is_matrix !! true if it is a valid matrix
  1474. logical(LK),intent(out),optional :: found !! true if it was found
  1475. integer(IK),intent(out),optional :: var_type !! variable type of data in
  1476. !! the matrix (if all elements have
  1477. !! the same type)
  1478. integer(IK),intent(out),optional :: n_sets !! number of data sets (i.e., matrix
  1479. !! rows if using row-major order)
  1480. integer(IK),intent(out),optional :: set_size !! size of each data set (i.e., matrix
  1481. !! cols if using row-major order)
  1482. character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name
  1483. call me%core%matrix_info(me%p,path,is_matrix,found,var_type,n_sets,set_size,name)
  1484. end subroutine json_file_variable_matrix_info
  1485. !*****************************************************************************************
  1486. !*****************************************************************************************
  1487. !>
  1488. ! Alternate version of [[json_file_variable_matrix_info]], where "path" is kind=CDK.
  1489. !
  1490. !@note If `found` is present, no exceptions will be thrown if an
  1491. ! error occurs. Otherwise, an exception will be thrown if the
  1492. ! variable is not found.
  1493. subroutine wrap_json_file_variable_matrix_info(me,path,is_matrix,found,&
  1494. var_type,n_sets,set_size,name)
  1495. implicit none
  1496. class(json_file),intent(inout) :: me
  1497. character(kind=CDK,len=*),intent(in) :: path !! path to the variable
  1498. logical(LK),intent(out) :: is_matrix !! true if it is a valid matrix
  1499. logical(LK),intent(out),optional :: found !! true if it was found
  1500. integer(IK),intent(out),optional :: var_type !! variable type of data in
  1501. !! the matrix (if all elements have
  1502. !! the same type)
  1503. integer(IK),intent(out),optional :: n_sets !! number of data sets (i.e., matrix
  1504. !! rows if using row-major order)
  1505. integer(IK),intent(out),optional :: set_size !! size of each data set (i.e., matrix
  1506. !! cols if using row-major order)
  1507. character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name
  1508. call me%matrix_info(to_unicode(path),is_matrix,found,var_type,n_sets,set_size,name)
  1509. end subroutine wrap_json_file_variable_matrix_info
  1510. !*****************************************************************************************
  1511. !*****************************************************************************************
  1512. !> author: Izaak Beekman
  1513. ! date: 7/23/2015
  1514. !
  1515. ! Get a [[json_value]] pointer to the JSON file root.
  1516. !
  1517. !@note This is equivalent to calling ```[[json_file]]%get('$',p)```
  1518. subroutine json_file_get_root(me,p)
  1519. implicit none
  1520. class(json_file),intent(inout) :: me
  1521. type(json_value),pointer,intent(out) :: p !! pointer to the variable
  1522. p => me%p
  1523. end subroutine json_file_get_root
  1524. !*****************************************************************************************
  1525. !*****************************************************************************************
  1526. !> author: Jacob Williams
  1527. !
  1528. ! Assignment operator for [[json_core(type)]] = [[json_core(type)]].
  1529. ! This will duplicate the [[json_core(type)]] and also
  1530. ! perform a deep copy of the [[json_value(type)]] data structure.
  1531. subroutine assign_json_file(me,f)
  1532. implicit none
  1533. class(json_file),intent(out) :: me
  1534. type(json_file),intent(in) :: f
  1535. me%core = f%core ! no pointers here so OK to copy
  1536. call me%core%clone(f%p,me%p)
  1537. end subroutine assign_json_file
  1538. !*****************************************************************************************
  1539. !*****************************************************************************************
  1540. !> author: Jacob Williams
  1541. !
  1542. ! Assignment operator for character = [[json_core(type)]].
  1543. ! This is just a wrapper for the [[json_value_to_string]] routine.
  1544. !
  1545. !### Note
  1546. ! * If an exception is raised or the file contains no data,
  1547. ! this will return an empty string.
  1548. subroutine assign_json_file_to_string(str,me)
  1549. implicit none
  1550. character(kind=CK,len=:),allocatable,intent(out) :: str
  1551. class(json_file),intent(in) :: me
  1552. type(json_core) :: core_copy !! a copy of `core` from `me`
  1553. if (me%core%failed() .or. .not. associated(me%p)) then
  1554. str = CK_''
  1555. else
  1556. ! This is sort of a hack. Since `me` has to have `intent(in)`
  1557. ! for the assignment to work, we need to make a copy of `me%core`
  1558. ! so we can call the low level routine (since it needs it to
  1559. ! be `intent(inout)`) because it's possible for this
  1560. ! function to raise an exception.
  1561. core_copy = me%core ! copy the parser settings
  1562. call core_copy%serialize(me%p,str)
  1563. if (me%core%failed()) str = CK_''
  1564. end if
  1565. end subroutine assign_json_file_to_string
  1566. !*****************************************************************************************
  1567. !*****************************************************************************************
  1568. !> author: Jacob Williams
  1569. !
  1570. ! Assignment operator for [[json_core(type)]] = character.
  1571. ! This is just a wrapper for the [[json_file_load_from_string]] routine.
  1572. subroutine assign_string_to_json_file(me,str)
  1573. implicit none
  1574. class(json_file),intent(inout) :: me
  1575. character(kind=CK,len=*),intent(in) :: str
  1576. if (associated(me%p)) call me%destroy()
  1577. if (me%core%failed()) call me%core%clear_exceptions()
  1578. call me%deserialize(str)
  1579. end subroutine assign_string_to_json_file
  1580. !*****************************************************************************************
  1581. !*****************************************************************************************
  1582. !> author: Jacob Williams
  1583. !
  1584. ! Alternate version of [[assign_string_to_json_file]], where "str" is kind=CDK.
  1585. subroutine wrap_assign_string_to_json_file(me,str)
  1586. implicit none
  1587. class(json_file),intent(inout) :: me
  1588. character(kind=CDK,len=*),intent(in) :: str
  1589. call me%assign_string_to_json_file(to_unicode(str))
  1590. end subroutine wrap_assign_string_to_json_file
  1591. !*****************************************************************************************
  1592. !*****************************************************************************************
  1593. !> author: Jacob Williams
  1594. !
  1595. ! A wrapper for [[json_file_valid_path]] for the `.in.` operator
  1596. function json_file_valid_path_op(path,me) result(found)
  1597. implicit none
  1598. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1599. class(json_file),intent(in) :: me !! the JSON file
  1600. logical(LK) :: found !! if the variable was found
  1601. type(json_core) :: core_copy !! a copy of `core` from `me`
  1602. ! This is sort of a hack. Since `me` has to have `intent(in)`
  1603. ! for the operator to work, we need to make a copy of `me%core`
  1604. ! so we can call the low level routine (since it needs it to
  1605. ! be `intent(inout)`) because it's technically possible for this
  1606. ! function to raise an exception. This normally should never
  1607. ! happen here unless the JSON structure is malformed.
  1608. core_copy = me%core ! copy the settings (need them to know
  1609. ! how to interpret the path)
  1610. found = core_copy%valid_path(me%p, path) ! call the low-level routine
  1611. call core_copy%destroy() ! just in case (but not really necessary)
  1612. end function json_file_valid_path_op
  1613. !*****************************************************************************************
  1614. !*****************************************************************************************
  1615. !> author: Jacob Williams
  1616. !
  1617. ! Alternate version of [[json_file_valid_path_op]], where "path" is kind=CDK.
  1618. function wrap_json_file_valid_path_op(path,me) result(found)
  1619. implicit none
  1620. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1621. class(json_file),intent(in) :: me !! the JSON file
  1622. logical(LK) :: found !! if the variable was found
  1623. found = to_unicode(path) .in. me
  1624. end function wrap_json_file_valid_path_op
  1625. !*****************************************************************************************
  1626. !*****************************************************************************************
  1627. !> author: Jacob Williams
  1628. !
  1629. ! Returns true if the `path` is present in the JSON file.
  1630. function json_file_valid_path(me,path) result(found)
  1631. implicit none
  1632. class(json_file),intent(inout) :: me
  1633. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1634. logical(LK) :: found !! if the variable was found
  1635. found = me%core%valid_path(me%p, path)
  1636. end function json_file_valid_path
  1637. !*****************************************************************************************
  1638. !*****************************************************************************************
  1639. !> author: Jacob Williams
  1640. !
  1641. ! Alternate version of [[json_file_valid_path]], where "path" is kind=CDK.
  1642. function wrap_json_file_valid_path(me,path) result(found)
  1643. implicit none
  1644. class(json_file),intent(inout) :: me
  1645. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1646. logical(LK) :: found !! if the variable was found
  1647. found = me%valid_path(to_unicode(path))
  1648. end function wrap_json_file_valid_path
  1649. !*****************************************************************************************
  1650. !*****************************************************************************************
  1651. !> author: Jacob Williams
  1652. !
  1653. ! Rename a variable in a JSON file.
  1654. subroutine json_file_rename(me,path,name,found)
  1655. implicit none
  1656. class(json_file),intent(inout) :: me
  1657. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1658. character(kind=CK,len=*),intent(in) :: name !! the new name
  1659. logical(LK),intent(out),optional :: found !! if the variable was found
  1660. call me%core%rename(me%p, path, name, found)
  1661. end subroutine json_file_rename
  1662. !*****************************************************************************************
  1663. !*****************************************************************************************
  1664. !> author: Jacob Williams
  1665. !
  1666. ! Alternate version of [[json_file_rename]], where "path" and "name" are kind=CDK.
  1667. subroutine wrap_json_file_rename(me,path,name,found)
  1668. implicit none
  1669. class(json_file),intent(inout) :: me
  1670. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1671. character(kind=CDK,len=*),intent(in) :: name !! the new name
  1672. logical(LK),intent(out),optional :: found !! if the variable was found
  1673. call me%json_file_rename(to_unicode(path),to_unicode(name),found)
  1674. end subroutine wrap_json_file_rename
  1675. !*****************************************************************************************
  1676. !*****************************************************************************************
  1677. !> author: Jacob Williams
  1678. !
  1679. ! Wrapper for [[json_file_rename]] where "path" is kind=CDK).
  1680. subroutine json_file_rename_path_ascii(me,path,name,found)
  1681. implicit none
  1682. class(json_file),intent(inout) :: me
  1683. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1684. character(kind=CK,len=*),intent(in) :: name !! the new name
  1685. logical(LK),intent(out),optional :: found !! if the variable was found
  1686. call me%json_file_rename(to_unicode(path),name,found)
  1687. end subroutine json_file_rename_path_ascii
  1688. !*****************************************************************************************
  1689. !*****************************************************************************************
  1690. !> author: Jacob Williams
  1691. !
  1692. ! Wrapper for [[json_file_rename]] where "name" is kind=CDK).
  1693. subroutine json_file_rename_name_ascii(me,path,name,found)
  1694. implicit none
  1695. class(json_file),intent(inout) :: me
  1696. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1697. character(kind=CDK,len=*),intent(in) :: name !! the new name
  1698. logical(LK),intent(out),optional :: found !! if the variable was found
  1699. call me%json_file_rename(path,to_unicode(name),found)
  1700. end subroutine json_file_rename_name_ascii
  1701. !*****************************************************************************************
  1702. !*****************************************************************************************
  1703. !> author: Jacob Williams
  1704. ! date: 2/3/2014
  1705. !
  1706. ! Get a [[json_value]] pointer to an object from a JSON file.
  1707. subroutine json_file_get_object(me, path, p, found)
  1708. implicit none
  1709. class(json_file),intent(inout) :: me
  1710. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1711. type(json_value),pointer,intent(out) :: p !! pointer to the variable
  1712. logical(LK),intent(out),optional :: found !! if it was really found
  1713. call me%core%get(me%p, path, p, found)
  1714. end subroutine json_file_get_object
  1715. !*****************************************************************************************
  1716. !*****************************************************************************************
  1717. !>
  1718. ! Alternate version of [[json_file_get_object]], where "path" is kind=CDK.
  1719. subroutine wrap_json_file_get_object(me, path, p, found)
  1720. implicit none
  1721. class(json_file),intent(inout) :: me
  1722. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1723. type(json_value),pointer,intent(out) :: p !! pointer to the variable
  1724. logical(LK),intent(out),optional :: found !! if it was really found
  1725. call me%get(to_unicode(path), p, found)
  1726. end subroutine wrap_json_file_get_object
  1727. !*****************************************************************************************
  1728. !*****************************************************************************************
  1729. !> author: Jacob Williams
  1730. ! date: 12/9/2013
  1731. !
  1732. ! Get an integer value from a JSON file.
  1733. subroutine json_file_get_integer(me, path, val, found, default)
  1734. implicit none
  1735. class(json_file),intent(inout) :: me
  1736. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1737. integer(IK),intent(out) :: val !! value
  1738. logical(LK),intent(out),optional :: found !! if it was really found
  1739. integer(IK),intent(in),optional :: default
  1740. call me%core%get(me%p, path, val, found, default)
  1741. end subroutine json_file_get_integer
  1742. !*****************************************************************************************
  1743. !*****************************************************************************************
  1744. !>
  1745. ! Alternate version of [[json_file_get_integer]], where "path" is kind=CDK.
  1746. subroutine wrap_json_file_get_integer(me, path, val, found, default)
  1747. implicit none
  1748. class(json_file),intent(inout) :: me
  1749. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1750. integer(IK),intent(out) :: val !! value
  1751. logical(LK),intent(out),optional :: found !! if it was really found
  1752. integer(IK),intent(in),optional :: default
  1753. call me%get(to_unicode(path), val, found, default)
  1754. end subroutine wrap_json_file_get_integer
  1755. !*****************************************************************************************
  1756. !*****************************************************************************************
  1757. !> author: Jacob Williams
  1758. ! date: 1/20/2014
  1759. !
  1760. ! Get an integer vector from a JSON file.
  1761. subroutine json_file_get_integer_vec(me, path, vec, found, default)
  1762. implicit none
  1763. class(json_file),intent(inout) :: me
  1764. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1765. integer(IK),dimension(:),allocatable,intent(out) :: vec !! the value vector
  1766. logical(LK),intent(out),optional :: found !! if it was really found
  1767. integer(IK),dimension(:),intent(in),optional :: default
  1768. call me%core%get(me%p, path, vec, found, default)
  1769. end subroutine json_file_get_integer_vec
  1770. !*****************************************************************************************
  1771. !*****************************************************************************************
  1772. !>
  1773. ! Alternate version of [[json_file_get_integer_vec]], where "path" is kind=CDK.
  1774. subroutine wrap_json_file_get_integer_vec(me, path, vec, found, default)
  1775. implicit none
  1776. class(json_file),intent(inout) :: me
  1777. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1778. integer(IK),dimension(:),allocatable,intent(out) :: vec !! the value vector
  1779. logical(LK),intent(out),optional :: found !! if it was really found
  1780. integer(IK),dimension(:),intent(in),optional :: default
  1781. call me%get(to_unicode(path), vec, found, default)
  1782. end subroutine wrap_json_file_get_integer_vec
  1783. !*****************************************************************************************
  1784. !*****************************************************************************************
  1785. !> author: Jacob Williams
  1786. ! date: 12/9/2013
  1787. !
  1788. ! Get a real(RK) variable value from a JSON file.
  1789. subroutine json_file_get_real (me, path, val, found, default)
  1790. implicit none
  1791. class(json_file),intent(inout) :: me
  1792. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1793. real(RK),intent(out) :: val !! value
  1794. logical(LK),intent(out),optional :: found !! if it was really found
  1795. real(RK),intent(in),optional :: default
  1796. call me%core%get(me%p, path, val, found, default)
  1797. end subroutine json_file_get_real
  1798. !*****************************************************************************************
  1799. !*****************************************************************************************
  1800. !>
  1801. ! Alternate version of [[json_file_get_real]], where "path" is kind=CDK.
  1802. subroutine wrap_json_file_get_real (me, path, val, found, default)
  1803. implicit none
  1804. class(json_file),intent(inout) :: me
  1805. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1806. real(RK),intent(out) :: val !! value
  1807. logical(LK),intent(out),optional :: found !! if it was really found
  1808. real(RK),intent(in),optional :: default
  1809. call me%get(to_unicode(path), val, found, default)
  1810. end subroutine wrap_json_file_get_real
  1811. !*****************************************************************************************
  1812. !*****************************************************************************************
  1813. !> author: Jacob Williams
  1814. ! date: 1/19/2014
  1815. !
  1816. ! Get a real(RK) vector from a JSON file.
  1817. subroutine json_file_get_real_vec(me, path, vec, found, default)
  1818. implicit none
  1819. class(json_file),intent(inout) :: me
  1820. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1821. real(RK),dimension(:),allocatable,intent(out) :: vec !! the value vector
  1822. logical(LK),intent(out),optional :: found !! if it was really found
  1823. real(RK),dimension(:),intent(in),optional :: default
  1824. call me%core%get(me%p, path, vec, found, default)
  1825. end subroutine json_file_get_real_vec
  1826. !*****************************************************************************************
  1827. !*****************************************************************************************
  1828. !>
  1829. ! Alternate version of [[json_file_get_real_vec]], where "path" is kind=CDK.
  1830. subroutine wrap_json_file_get_real_vec(me, path, vec, found, default)
  1831. implicit none
  1832. class(json_file),intent(inout) :: me
  1833. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1834. real(RK),dimension(:),allocatable,intent(out) :: vec !! the value vector
  1835. logical(LK),intent(out),optional :: found !! if it was really found
  1836. real(RK),dimension(:),intent(in),optional :: default
  1837. call me%get(to_unicode(path), vec, found, default)
  1838. end subroutine wrap_json_file_get_real_vec
  1839. !*****************************************************************************************
  1840. !*****************************************************************************************
  1841. !> author: Jacob Williams
  1842. ! date: 1/21/2019
  1843. !
  1844. ! Alternate version of [[json_file_get_real]] where `val` is `real32`.
  1845. subroutine json_file_get_real32 (me, path, val, found, default)
  1846. implicit none
  1847. class(json_file),intent(inout) :: me
  1848. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1849. real(real32),intent(out) :: val !! value
  1850. logical(LK),intent(out),optional :: found !! if it was really found
  1851. real(real32),intent(in),optional :: default
  1852. call me%core%get(me%p, path, val, found, default)
  1853. end subroutine json_file_get_real32
  1854. !*****************************************************************************************
  1855. !*****************************************************************************************
  1856. !>
  1857. ! Alternate version of [[json_file_get_real32]], where "path" is kind=CDK.
  1858. subroutine wrap_json_file_get_real32 (me, path, val, found, default)
  1859. implicit none
  1860. class(json_file),intent(inout) :: me
  1861. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1862. real(real32),intent(out) :: val !! value
  1863. logical(LK),intent(out),optional :: found !! if it was really found
  1864. real(real32),intent(in),optional :: default
  1865. call me%get(to_unicode(path), val, found, default)
  1866. end subroutine wrap_json_file_get_real32
  1867. !*****************************************************************************************
  1868. !*****************************************************************************************
  1869. !> author: Jacob Williams
  1870. ! date: 1/21/2019
  1871. !
  1872. ! Alternate version of [[json_file_get_real_vec]] where `vec` is `real32`.
  1873. subroutine json_file_get_real32_vec(me, path, vec, found, default)
  1874. implicit none
  1875. class(json_file),intent(inout) :: me
  1876. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1877. real(real32),dimension(:),allocatable,intent(out) :: vec !! the value vector
  1878. logical(LK),intent(out),optional :: found !! if it was really found
  1879. real(real32),dimension(:),intent(in),optional :: default
  1880. call me%core%get(me%p, path, vec, found, default)
  1881. end subroutine json_file_get_real32_vec
  1882. !*****************************************************************************************
  1883. !*****************************************************************************************
  1884. !>
  1885. ! Alternate version of [[json_file_get_real32_vec]], where "path" is kind=CDK.
  1886. subroutine wrap_json_file_get_real32_vec(me, path, vec, found, default)
  1887. implicit none
  1888. class(json_file),intent(inout) :: me
  1889. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1890. real(real32),dimension(:),allocatable,intent(out) :: vec !! the value vector
  1891. logical(LK),intent(out),optional :: found !! if it was really found
  1892. real(real32),dimension(:),intent(in),optional :: default
  1893. call me%get(to_unicode(path), vec, found, default)
  1894. end subroutine wrap_json_file_get_real32_vec
  1895. !*****************************************************************************************
  1896. # 1748
  1897. !*****************************************************************************************
  1898. !> author: Jacob Williams
  1899. ! date: 12/9/2013
  1900. !
  1901. ! Get a logical(LK) value from a JSON file.
  1902. subroutine json_file_get_logical(me,path,val,found,default)
  1903. implicit none
  1904. class(json_file),intent(inout) :: me
  1905. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1906. logical(LK),intent(out) :: val !! value
  1907. logical(LK),intent(out),optional :: found !! if it was really found
  1908. logical(LK),intent(in),optional :: default
  1909. call me%core%get(me%p, path, val, found, default)
  1910. end subroutine json_file_get_logical
  1911. !*****************************************************************************************
  1912. !*****************************************************************************************
  1913. !>
  1914. ! Alternate version of [[json_file_get_logical]], where "path" is kind=CDK.
  1915. subroutine wrap_json_file_get_logical(me,path,val,found,default)
  1916. implicit none
  1917. class(json_file),intent(inout) :: me
  1918. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1919. logical(LK),intent(out) :: val !! value
  1920. logical(LK),intent(out),optional :: found !! if it was really found
  1921. logical(LK),intent(in),optional :: default
  1922. call me%get(to_unicode(path), val, found, default)
  1923. end subroutine wrap_json_file_get_logical
  1924. !*****************************************************************************************
  1925. !*****************************************************************************************
  1926. !> author: Jacob Williams
  1927. ! date: 1/20/2014
  1928. !
  1929. ! Get a logical(LK) vector from a JSON file.
  1930. subroutine json_file_get_logical_vec(me, path, vec, found, default)
  1931. implicit none
  1932. class(json_file),intent(inout) :: me
  1933. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1934. logical(LK),dimension(:),allocatable,intent(out) :: vec !! the value vector
  1935. logical(LK),intent(out),optional :: found !! if it was really found
  1936. logical(LK),dimension(:),intent(in),optional :: default
  1937. call me%core%get(me%p, path, vec, found, default)
  1938. end subroutine json_file_get_logical_vec
  1939. !*****************************************************************************************
  1940. !*****************************************************************************************
  1941. !>
  1942. ! Alternate version of [[json_file_get_logical_vec]], where "path" is kind=CDK.
  1943. subroutine wrap_json_file_get_logical_vec(me, path, vec, found, default)
  1944. implicit none
  1945. class(json_file),intent(inout) :: me
  1946. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1947. logical(LK),dimension(:),allocatable,intent(out) :: vec !! the value vector
  1948. logical(LK),intent(out),optional :: found !! if it was really found
  1949. logical(LK),dimension(:),intent(in),optional :: default
  1950. call me%get(to_unicode(path), vec, found, default)
  1951. end subroutine wrap_json_file_get_logical_vec
  1952. !*****************************************************************************************
  1953. !*****************************************************************************************
  1954. !> author: Jacob Williams
  1955. ! date: 12/9/2013
  1956. !
  1957. ! Get a character string from a json file.
  1958. ! The output val is an allocatable character string.
  1959. subroutine json_file_get_string(me, path, val, found, default)
  1960. implicit none
  1961. class(json_file),intent(inout) :: me
  1962. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1963. character(kind=CK,len=:),allocatable,intent(out) :: val !! value
  1964. logical(LK),intent(out),optional :: found !! if it was really found
  1965. character(kind=CK,len=*),intent(in),optional :: default
  1966. call me%core%get(me%p, path, val, found, default)
  1967. end subroutine json_file_get_string
  1968. !*****************************************************************************************
  1969. !*****************************************************************************************
  1970. !>
  1971. ! Alternate version of [[json_file_get_string]], where "path" is kind=CDK.
  1972. subroutine wrap_json_file_get_string(me, path, val, found, default)
  1973. implicit none
  1974. class(json_file),intent(inout) :: me
  1975. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  1976. character(kind=CK,len=:),allocatable,intent(out) :: val !! value
  1977. logical(LK),intent(out),optional :: found !! if it was really found
  1978. character(kind=CK,len=*),intent(in),optional :: default
  1979. call me%get(to_unicode(path), val, found, default)
  1980. end subroutine wrap_json_file_get_string
  1981. !*****************************************************************************************
  1982. !*****************************************************************************************
  1983. !> author: Jacob Williams
  1984. ! date: 1/19/2014
  1985. !
  1986. ! Get a string vector from a JSON file.
  1987. subroutine json_file_get_string_vec(me, path, vec, found, default)
  1988. implicit none
  1989. class(json_file),intent(inout) :: me
  1990. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  1991. character(kind=CK,len=*),dimension(:),allocatable,intent(out) :: vec !! value vector
  1992. logical(LK),intent(out),optional :: found !! if it was really found
  1993. character(kind=CK,len=*),dimension(:),intent(in),optional :: default
  1994. call me%core%get(me%p, path, vec, found, default)
  1995. end subroutine json_file_get_string_vec
  1996. !*****************************************************************************************
  1997. !*****************************************************************************************
  1998. !>
  1999. ! Alternate version of [[json_file_get_string_vec]], where "path" is kind=CDK.
  2000. subroutine wrap_json_file_get_string_vec(me, path, vec, found, default)
  2001. implicit none
  2002. class(json_file),intent(inout) :: me
  2003. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2004. character(kind=CK,len=*),dimension(:),allocatable,intent(out) :: vec !! value vector
  2005. logical(LK),intent(out),optional :: found !! if it was really found
  2006. character(kind=CK,len=*),dimension(:),intent(in),optional :: default
  2007. call me%get(to_unicode(path), vec, found, default)
  2008. end subroutine wrap_json_file_get_string_vec
  2009. !*****************************************************************************************
  2010. !*****************************************************************************************
  2011. !> author: Jacob Williams
  2012. ! date: 12/17/2016
  2013. !
  2014. ! Get an (allocatable length) string vector from a JSON file.
  2015. ! This is just a wrapper for [[json_get_alloc_string_vec_by_path]].
  2016. subroutine json_file_get_alloc_string_vec(me, path, vec, ilen, found, default, default_ilen)
  2017. implicit none
  2018. class(json_file),intent(inout) :: me
  2019. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2020. character(kind=CK,len=:),dimension(:),allocatable,intent(out) :: vec !! value vector
  2021. integer(IK),dimension(:),allocatable,intent(out) :: ilen !! the actual length
  2022. !! of each character
  2023. !! string in the array
  2024. logical(LK),intent(out),optional :: found
  2025. character(kind=CK,len=*),dimension(:),intent(in),optional :: default
  2026. integer(IK),dimension(:),intent(in),optional :: default_ilen !! the actual
  2027. !! length of `default`
  2028. call me%core%get(me%p, path, vec, ilen, found, default, default_ilen)
  2029. end subroutine json_file_get_alloc_string_vec
  2030. !*****************************************************************************************
  2031. !*****************************************************************************************
  2032. !>
  2033. ! Alternate version of [[json_file_get_alloc_string_vec]], where "path" is kind=CDK.
  2034. ! This is just a wrapper for [[wrap_json_get_alloc_string_vec_by_path]].
  2035. subroutine wrap_json_file_get_alloc_string_vec(me, path, vec, ilen, found, default, default_ilen)
  2036. implicit none
  2037. class(json_file),intent(inout) :: me
  2038. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2039. character(kind=CK,len=:),dimension(:),allocatable,intent(out) :: vec !! value vector
  2040. integer(IK),dimension(:),allocatable,intent(out) :: ilen !! the actual length
  2041. !! of each character
  2042. !! string in the array
  2043. logical(LK),intent(out),optional :: found
  2044. character(kind=CK,len=*),dimension(:),intent(in),optional :: default
  2045. integer(IK),dimension(:),intent(in),optional :: default_ilen !! the actual
  2046. !! length of `default`
  2047. call me%get(to_unicode(path), vec, ilen, found, default, default_ilen)
  2048. end subroutine wrap_json_file_get_alloc_string_vec
  2049. !*****************************************************************************************
  2050. !*****************************************************************************************
  2051. !> author: Jacob Williams
  2052. !
  2053. ! Add a [[json_value]] pointer as the root object to a JSON file.
  2054. !
  2055. !### Note
  2056. !
  2057. ! This is mostly equivalent to:
  2058. !```fortran
  2059. ! f = [[json_file]](p)
  2060. !```
  2061. ! But without the finalization calls.
  2062. !
  2063. ! And:
  2064. !```fortran
  2065. ! if (destroy_original) call [[json_file]]%destroy()
  2066. ! call [[json_file]]%add('$',p)
  2067. !```
  2068. subroutine json_file_add(me,p,destroy_original)
  2069. implicit none
  2070. class(json_file),intent(inout) :: me
  2071. type(json_value),pointer,intent(in) :: p !! pointer to the variable to add
  2072. logical(LK),intent(in),optional :: destroy_original !! if the file currently contains
  2073. !! an associated pointer, it is
  2074. !! destroyed. [Default is True]
  2075. logical(LK) :: destroy !! if `me%p` is to be destroyed
  2076. if (present(destroy_original)) then
  2077. destroy = destroy_original
  2078. else
  2079. destroy = .true. ! default
  2080. end if
  2081. if (destroy) call me%core%destroy(me%p)
  2082. me%p => p
  2083. end subroutine json_file_add
  2084. !*****************************************************************************************
  2085. !*****************************************************************************************
  2086. !> author: Jacob Williams
  2087. !
  2088. ! Add a [[json_value]] pointer to an object to a JSON file.
  2089. subroutine json_file_add_object(me,path,p,found,was_created)
  2090. implicit none
  2091. class(json_file),intent(inout) :: me
  2092. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2093. type(json_value),pointer,intent(in) :: p !! pointer to the variable to add
  2094. logical(LK),intent(out),optional :: found !! if the variable was found
  2095. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2096. if (.not. associated(me%p)) call me%core%create_object(me%p,ck_'') ! create root
  2097. call me%core%add_by_path(me%p,path,p,found,was_created)
  2098. end subroutine json_file_add_object
  2099. !*****************************************************************************************
  2100. !*****************************************************************************************
  2101. !> author: Jacob Williams
  2102. !
  2103. ! Alternate version of [[json_file_add_object]], where "path" is kind=CDK.
  2104. subroutine wrap_json_file_add_object(me,path,p,found,was_created)
  2105. implicit none
  2106. class(json_file),intent(inout) :: me
  2107. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2108. type(json_value),pointer,intent(in) :: p !! pointer to the variable to add
  2109. logical(LK),intent(out),optional :: found !! if the variable was found
  2110. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2111. call me%json_file_add_object(to_unicode(path),p,found,was_created)
  2112. end subroutine wrap_json_file_add_object
  2113. !*****************************************************************************************
  2114. !*****************************************************************************************
  2115. !> author: Jacob Williams
  2116. !
  2117. ! Add an integer value to a JSON file.
  2118. subroutine json_file_add_integer(me,path,val,found,was_created)
  2119. implicit none
  2120. class(json_file),intent(inout) :: me
  2121. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2122. integer(IK),intent(in) :: val !! value
  2123. logical(LK),intent(out),optional :: found !! if the variable was found
  2124. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2125. if (.not. associated(me%p)) call me%core%create_object(me%p,ck_'') ! create root
  2126. call me%core%add_by_path(me%p,path,val,found,was_created)
  2127. end subroutine json_file_add_integer
  2128. !*****************************************************************************************
  2129. !*****************************************************************************************
  2130. !> author: Jacob Williams
  2131. !
  2132. ! Alternate version of [[json_file_add_integer]], where "path" is kind=CDK.
  2133. subroutine wrap_json_file_add_integer(me,path,val,found,was_created)
  2134. implicit none
  2135. class(json_file),intent(inout) :: me
  2136. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2137. integer(IK),intent(in) :: val !! value
  2138. logical(LK),intent(out),optional :: found !! if the variable was found
  2139. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2140. call me%json_file_add_integer(to_unicode(path),val,found,was_created)
  2141. end subroutine wrap_json_file_add_integer
  2142. !*****************************************************************************************
  2143. !*****************************************************************************************
  2144. !> author: Jacob Williams
  2145. !
  2146. ! Add an integer vector to a JSON file.
  2147. subroutine json_file_add_integer_vec(me,path,vec,found,was_created)
  2148. implicit none
  2149. class(json_file),intent(inout) :: me
  2150. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2151. integer(IK),dimension(:),intent(in) :: vec !! the value vector
  2152. logical(LK),intent(out),optional :: found !! if the variable was found
  2153. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2154. if (.not. associated(me%p)) call me%core%create_object(me%p,ck_'') ! create root
  2155. call me%core%add_by_path(me%p,path,vec,found,was_created)
  2156. end subroutine json_file_add_integer_vec
  2157. !*****************************************************************************************
  2158. !*****************************************************************************************
  2159. !> author: Jacob Williams
  2160. !
  2161. ! Alternate version of [[json_file_add_integer_vec]], where "path" is kind=CDK.
  2162. subroutine wrap_json_file_add_integer_vec(me,path,vec,found,was_created)
  2163. implicit none
  2164. class(json_file),intent(inout) :: me
  2165. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2166. integer(IK),dimension(:),intent(in) :: vec !! the value vector
  2167. logical(LK),intent(out),optional :: found !! if the variable was found
  2168. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2169. call me%json_file_add_integer_vec(to_unicode(path),vec,found,was_created)
  2170. end subroutine wrap_json_file_add_integer_vec
  2171. !*****************************************************************************************
  2172. !*****************************************************************************************
  2173. !> author: Jacob Williams
  2174. !
  2175. ! Add a real(RK) variable value to a JSON file.
  2176. subroutine json_file_add_real(me,path,val,found,was_created)
  2177. implicit none
  2178. class(json_file),intent(inout) :: me
  2179. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2180. real(RK),intent(in) :: val !! value
  2181. logical(LK),intent(out),optional :: found !! if the variable was found
  2182. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2183. if (.not. associated(me%p)) call me%core%create_object(me%p,ck_'') ! create root
  2184. call me%core%add_by_path(me%p,path,val,found,was_created)
  2185. end subroutine json_file_add_real
  2186. !*****************************************************************************************
  2187. !*****************************************************************************************
  2188. !> author: Jacob Williams
  2189. !
  2190. ! Alternate version of [[json_file_add_real]], where "path" is kind=CDK.
  2191. subroutine wrap_json_file_add_real(me,path,val,found,was_created)
  2192. implicit none
  2193. class(json_file),intent(inout) :: me
  2194. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2195. real(RK),intent(in) :: val !! value
  2196. logical(LK),intent(out),optional :: found !! if the variable was found
  2197. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2198. call me%json_file_add_real(to_unicode(path),val,found,was_created)
  2199. end subroutine wrap_json_file_add_real
  2200. !*****************************************************************************************
  2201. !*****************************************************************************************
  2202. !> author: Jacob Williams
  2203. !
  2204. ! Add a real(RK) vector to a JSON file.
  2205. subroutine json_file_add_real_vec(me,path,vec,found,was_created)
  2206. implicit none
  2207. class(json_file),intent(inout) :: me
  2208. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2209. real(RK),dimension(:),intent(in) :: vec !! the value vector
  2210. logical(LK),intent(out),optional :: found !! if the variable was found
  2211. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2212. if (.not. associated(me%p)) call me%core%create_object(me%p,ck_'') ! create root
  2213. call me%core%add_by_path(me%p,path,vec,found,was_created)
  2214. end subroutine json_file_add_real_vec
  2215. !*****************************************************************************************
  2216. !*****************************************************************************************
  2217. !> author: Jacob Williams
  2218. !
  2219. ! Alternate version of [[json_file_add_real_vec]], where "path" is kind=CDK.
  2220. subroutine wrap_json_file_add_real_vec(me,path,vec,found,was_created)
  2221. implicit none
  2222. class(json_file),intent(inout) :: me
  2223. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2224. real(RK),dimension(:),intent(in) :: vec !! the value vector
  2225. logical(LK),intent(out),optional :: found !! if the variable was found
  2226. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2227. call me%json_file_add_real_vec(to_unicode(path),vec,found,was_created)
  2228. end subroutine wrap_json_file_add_real_vec
  2229. !*****************************************************************************************
  2230. !*****************************************************************************************
  2231. !> author: Jacob Williams
  2232. !
  2233. ! Alternate version of [[json_file_add_real]] where `val` is `real32`.
  2234. subroutine json_file_add_real32(me,path,val,found,was_created)
  2235. implicit none
  2236. class(json_file),intent(inout) :: me
  2237. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2238. real(real32),intent(in) :: val !! value
  2239. logical(LK),intent(out),optional :: found !! if the variable was found
  2240. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2241. call me%core%add_by_path(me%p,path,val,found,was_created)
  2242. end subroutine json_file_add_real32
  2243. !*****************************************************************************************
  2244. !*****************************************************************************************
  2245. !> author: Jacob Williams
  2246. !
  2247. ! Alternate version of [[json_file_add_real32]], where "path" is kind=CDK.
  2248. subroutine wrap_json_file_add_real32(me,path,val,found,was_created)
  2249. implicit none
  2250. class(json_file),intent(inout) :: me
  2251. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2252. real(real32),intent(in) :: val !! value
  2253. logical(LK),intent(out),optional :: found !! if the variable was found
  2254. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2255. call me%json_file_add_real32(to_unicode(path),val,found,was_created)
  2256. end subroutine wrap_json_file_add_real32
  2257. !*****************************************************************************************
  2258. !*****************************************************************************************
  2259. !> author: Jacob Williams
  2260. !
  2261. ! Alternate version of [[json_file_add_real_vec]] where `vec` is `real32`.
  2262. subroutine json_file_add_real32_vec(me,path,vec,found,was_created)
  2263. implicit none
  2264. class(json_file),intent(inout) :: me
  2265. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2266. real(real32),dimension(:),intent(in) :: vec !! the value vector
  2267. logical(LK),intent(out),optional :: found !! if the variable was found
  2268. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2269. call me%core%add_by_path(me%p,path,vec,found,was_created)
  2270. end subroutine json_file_add_real32_vec
  2271. !*****************************************************************************************
  2272. !*****************************************************************************************
  2273. !> author: Jacob Williams
  2274. !
  2275. ! Alternate version of [[json_file_add_real32_vec]], where "path" is kind=CDK.
  2276. subroutine wrap_json_file_add_real32_vec(me,path,vec,found,was_created)
  2277. implicit none
  2278. class(json_file),intent(inout) :: me
  2279. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2280. real(real32),dimension(:),intent(in) :: vec !! the value vector
  2281. logical(LK),intent(out),optional :: found !! if the variable was found
  2282. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2283. call me%json_file_add_real32_vec(to_unicode(path),vec,found,was_created)
  2284. end subroutine wrap_json_file_add_real32_vec
  2285. !*****************************************************************************************
  2286. # 2379
  2287. !*****************************************************************************************
  2288. !> author: Jacob Williams
  2289. !
  2290. ! Add a logical(LK) value to a JSON file.
  2291. subroutine json_file_add_logical(me,path,val,found,was_created)
  2292. implicit none
  2293. class(json_file),intent(inout) :: me
  2294. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2295. logical(LK),intent(in) :: val !! value
  2296. logical(LK),intent(out),optional :: found !! if the variable was found
  2297. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2298. if (.not. associated(me%p)) call me%core%create_object(me%p,ck_'') ! create root
  2299. call me%core%add_by_path(me%p,path,val,found,was_created)
  2300. end subroutine json_file_add_logical
  2301. !*****************************************************************************************
  2302. !*****************************************************************************************
  2303. !> author: Jacob Williams
  2304. !
  2305. ! Alternate version of [[json_file_add_logical]], where "path" is kind=CDK.
  2306. subroutine wrap_json_file_add_logical(me,path,val,found,was_created)
  2307. implicit none
  2308. class(json_file),intent(inout) :: me
  2309. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2310. logical(LK),intent(in) :: val !! value
  2311. logical(LK),intent(out),optional :: found !! if the variable was found
  2312. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2313. call me%json_file_add_logical(to_unicode(path),val,found,was_created)
  2314. end subroutine wrap_json_file_add_logical
  2315. !*****************************************************************************************
  2316. !*****************************************************************************************
  2317. !> author: Jacob Williams
  2318. !
  2319. ! Add a logical(LK) vector to a JSON file.
  2320. subroutine json_file_add_logical_vec(me,path,vec,found,was_created)
  2321. implicit none
  2322. class(json_file),intent(inout) :: me
  2323. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2324. logical(LK),dimension(:),intent(in) :: vec !! the value vector
  2325. logical(LK),intent(out),optional :: found !! if the variable was found
  2326. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2327. if (.not. associated(me%p)) call me%core%create_object(me%p,ck_'') ! create root
  2328. call me%core%add_by_path(me%p,path,vec,found,was_created)
  2329. end subroutine json_file_add_logical_vec
  2330. !*****************************************************************************************
  2331. !*****************************************************************************************
  2332. !> author: Jacob Williams
  2333. !
  2334. ! Alternate version of [[json_file_add_logical_vec]], where "path" is kind=CDK.
  2335. subroutine wrap_json_file_add_logical_vec(me,path,vec,found,was_created)
  2336. implicit none
  2337. class(json_file),intent(inout) :: me
  2338. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2339. logical(LK),dimension(:),intent(in) :: vec !! the value vector
  2340. logical(LK),intent(out),optional :: found !! if the variable was found
  2341. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2342. call me%json_file_add_logical_vec(to_unicode(path),vec,found,was_created)
  2343. end subroutine wrap_json_file_add_logical_vec
  2344. !*****************************************************************************************
  2345. !*****************************************************************************************
  2346. !> author: Jacob Williams
  2347. !
  2348. ! Add a character string to a json file.
  2349. subroutine json_file_add_string(me,path,val,found,was_created,trim_str,adjustl_str)
  2350. implicit none
  2351. class(json_file),intent(inout) :: me
  2352. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2353. character(kind=CK,len=*),intent(in) :: val !! value
  2354. logical(LK),intent(out),optional :: found !! if the variable was found
  2355. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2356. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val`
  2357. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val`
  2358. !! (note that ADJUSTL is done before TRIM)
  2359. if (.not. associated(me%p)) call me%core%create_object(me%p,ck_'') ! create root
  2360. call me%core%add_by_path(me%p,path,val,found,was_created,trim_str,adjustl_str)
  2361. end subroutine json_file_add_string
  2362. !*****************************************************************************************
  2363. !*****************************************************************************************
  2364. !> author: Jacob Williams
  2365. !
  2366. ! Alternate version of [[json_file_add_string]], where "path" and "val" are kind=CDK.
  2367. subroutine wrap_json_file_add_string(me,path,val,found,was_created,trim_str,adjustl_str)
  2368. implicit none
  2369. class(json_file),intent(inout) :: me
  2370. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2371. character(kind=CDK,len=*),intent(in) :: val !! value
  2372. logical(LK),intent(out),optional :: found !! if the variable was found
  2373. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2374. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val`
  2375. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val`
  2376. !! (note that ADJUSTL is done before TRIM)
  2377. call me%json_file_add_string(to_unicode(path),to_unicode(val),found,&
  2378. was_created,trim_str,adjustl_str)
  2379. end subroutine wrap_json_file_add_string
  2380. !*****************************************************************************************
  2381. !*****************************************************************************************
  2382. !> author: Jacob Williams
  2383. !
  2384. ! Wrapper for [[json_file_add_string]] where "path" is kind=CDK).
  2385. subroutine json_file_add_string_path_ascii(me,path,val,found,&
  2386. was_created,trim_str,adjustl_str)
  2387. implicit none
  2388. class(json_file),intent(inout) :: me
  2389. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2390. character(kind=CK,len=*),intent(in) :: val !! value
  2391. logical(LK),intent(out),optional :: found !! if the variable was found
  2392. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2393. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val`
  2394. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val`
  2395. !! (note that ADJUSTL is done before TRIM)
  2396. if (.not. associated(me%p)) call me%core%create_object(me%p,ck_'') ! create root
  2397. call me%json_file_add_string(to_unicode(path),val,found,&
  2398. was_created,trim_str,adjustl_str)
  2399. end subroutine json_file_add_string_path_ascii
  2400. !*****************************************************************************************
  2401. !*****************************************************************************************
  2402. !> author: Jacob Williams
  2403. !
  2404. ! Wrapper for [[json_file_add_string]] where "val" is kind=CDK).
  2405. subroutine json_file_add_string_value_ascii(me,path,val,found,&
  2406. was_created,trim_str,adjustl_str)
  2407. implicit none
  2408. class(json_file),intent(inout) :: me
  2409. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2410. character(kind=CDK,len=*),intent(in) :: val !! value
  2411. logical(LK),intent(out),optional :: found !! if the variable was found
  2412. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2413. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val`
  2414. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val`
  2415. !! (note that ADJUSTL is done before TRIM)
  2416. if (.not. associated(me%p)) call me%core%create_object(me%p,ck_'') ! create root
  2417. call me%json_file_add_string(path,to_unicode(val),found,&
  2418. was_created,trim_str,adjustl_str)
  2419. end subroutine json_file_add_string_value_ascii
  2420. !*****************************************************************************************
  2421. !*****************************************************************************************
  2422. !> author: Jacob Williams
  2423. !
  2424. ! Add a string vector to a JSON file.
  2425. subroutine json_file_add_string_vec(me,path,vec,found,&
  2426. was_created,ilen,trim_str,adjustl_str)
  2427. implicit none
  2428. class(json_file),intent(inout) :: me
  2429. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2430. character(kind=CK,len=*),dimension(:),intent(in) :: vec !! the value vector
  2431. logical(LK),intent(out),optional :: found !! if the variable was found
  2432. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2433. integer(IK),dimension(:),intent(in),optional :: ilen !! the string lengths of each
  2434. !! element in `value`. If not present,
  2435. !! the full `len(value)` string is added
  2436. !! for each element.
  2437. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element
  2438. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element
  2439. !! (note that ADJUSTL is done before TRIM)
  2440. if (.not. associated(me%p)) call me%core%create_object(me%p,ck_'') ! create root
  2441. call me%core%add_by_path(me%p,path,vec,found,was_created,ilen,trim_str,adjustl_str)
  2442. end subroutine json_file_add_string_vec
  2443. !*****************************************************************************************
  2444. !*****************************************************************************************
  2445. !> author: Jacob Williams
  2446. !
  2447. ! Alternate version of [[json_file_add_string_vec]], where "path" and "vec" are kind=CDK.
  2448. subroutine wrap_json_file_add_string_vec(me,path,vec,found,&
  2449. was_created,ilen,trim_str,adjustl_str)
  2450. implicit none
  2451. class(json_file),intent(inout) :: me
  2452. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2453. character(kind=CDK,len=*),dimension(:),intent(in):: vec !! the value vector
  2454. logical(LK),intent(out),optional :: found !! if the variable was found
  2455. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2456. integer(IK),dimension(:),intent(in),optional :: ilen !! the string lengths of each
  2457. !! element in `value`. If not present,
  2458. !! the full `len(value)` string is added
  2459. !! for each element.
  2460. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element
  2461. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element
  2462. !! (note that ADJUSTL is done before TRIM)
  2463. call me%json_file_add_string_vec(to_unicode(path),to_unicode(vec),found,&
  2464. was_created,ilen,trim_str,adjustl_str)
  2465. end subroutine wrap_json_file_add_string_vec
  2466. !*****************************************************************************************
  2467. !*****************************************************************************************
  2468. !> author: Jacob Williams
  2469. !
  2470. ! Alternate version of [[json_file_add_string_vec]], where "path" is kind=CDK.
  2471. subroutine json_file_add_string_vec_path_ascii(me,path,vec,found,&
  2472. was_created,ilen,trim_str,adjustl_str)
  2473. implicit none
  2474. class(json_file),intent(inout) :: me
  2475. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2476. character(kind=CK,len=*),dimension(:),intent(in) :: vec !! the value vector
  2477. logical(LK),intent(out),optional :: found !! if the variable was found
  2478. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2479. integer(IK),dimension(:),intent(in),optional :: ilen !! the string lengths of each
  2480. !! element in `value`. If not present,
  2481. !! the full `len(value)` string is added
  2482. !! for each element.
  2483. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element
  2484. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element
  2485. !! (note that ADJUSTL is done before TRIM)
  2486. call me%json_file_add_string_vec(to_unicode(path),vec,found,&
  2487. was_created,ilen,trim_str,adjustl_str)
  2488. end subroutine json_file_add_string_vec_path_ascii
  2489. !*****************************************************************************************
  2490. !*****************************************************************************************
  2491. !> author: Jacob Williams
  2492. !
  2493. ! Alternate version of [[json_file_add_string_vec]], where "vec" is kind=CDK.
  2494. subroutine json_file_add_string_vec_vec_ascii(me,path,vec,found,&
  2495. was_created,ilen,trim_str,adjustl_str)
  2496. implicit none
  2497. class(json_file),intent(inout) :: me
  2498. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2499. character(kind=CDK,len=*),dimension(:),intent(in) :: vec !! the value vector
  2500. logical(LK),intent(out),optional :: found !! if the variable was found
  2501. logical(LK),intent(out),optional :: was_created !! if the variable had to be created
  2502. integer(IK),dimension(:),intent(in),optional :: ilen !! the string lengths of each
  2503. !! element in `value`. If not present,
  2504. !! the full `len(value)` string is added
  2505. !! for each element.
  2506. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element
  2507. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element
  2508. !! (note that ADJUSTL is done before TRIM)
  2509. call me%json_file_add_string_vec(path,to_unicode(vec),found,&
  2510. was_created,ilen,trim_str,adjustl_str)
  2511. end subroutine json_file_add_string_vec_vec_ascii
  2512. !*****************************************************************************************
  2513. !*****************************************************************************************
  2514. !> author: Jacob Williams
  2515. ! date: 1/10/2015
  2516. !
  2517. ! Given the path string, if the variable is present in the file,
  2518. ! and is a scalar, then update its value.
  2519. ! If it is not present, then create it and set its value.
  2520. !
  2521. !### See also
  2522. ! * [[json_update_integer]]
  2523. subroutine json_file_update_integer(me,path,val,found)
  2524. implicit none
  2525. class(json_file),intent(inout) :: me
  2526. character(kind=CK,len=*),intent(in) :: path
  2527. integer(IK),intent(in) :: val
  2528. logical(LK),intent(out) :: found
  2529. if (.not. me%core%failed()) call me%core%update(me%p,path,val,found)
  2530. end subroutine json_file_update_integer
  2531. !*****************************************************************************************
  2532. !*****************************************************************************************
  2533. !>
  2534. ! Alternate version of [[json_file_update_integer]], where "path" is kind=CDK.
  2535. subroutine wrap_json_file_update_integer(me,path,val,found)
  2536. implicit none
  2537. class(json_file),intent(inout) :: me
  2538. character(kind=CDK,len=*),intent(in) :: path
  2539. integer(IK),intent(in) :: val
  2540. logical(LK),intent(out) :: found
  2541. call me%update(to_unicode(path),val,found)
  2542. end subroutine wrap_json_file_update_integer
  2543. !*****************************************************************************************
  2544. !*****************************************************************************************
  2545. !> author: Jacob Williams
  2546. ! date: 1/10/2015
  2547. !
  2548. ! Given the path string, if the variable is present in the file,
  2549. ! and is a scalar, then update its value.
  2550. ! If it is not present, then create it and set its value.
  2551. !
  2552. !### See also
  2553. ! * [[json_update_logical]]
  2554. subroutine json_file_update_logical(me,path,val,found)
  2555. implicit none
  2556. class(json_file),intent(inout) :: me
  2557. character(kind=CK,len=*),intent(in) :: path
  2558. logical(LK),intent(in) :: val
  2559. logical(LK),intent(out) :: found
  2560. if (.not. me%core%failed()) call me%core%update(me%p,path,val,found)
  2561. end subroutine json_file_update_logical
  2562. !*****************************************************************************************
  2563. !*****************************************************************************************
  2564. !>
  2565. ! Alternate version of [[json_file_update_logical]], where "path" is kind=CDK.
  2566. subroutine wrap_json_file_update_logical(me,path,val,found)
  2567. implicit none
  2568. class(json_file),intent(inout) :: me
  2569. character(kind=CDK,len=*),intent(in) :: path
  2570. logical(LK),intent(in) :: val
  2571. logical(LK),intent(out) :: found
  2572. call me%update(to_unicode(path),val,found)
  2573. end subroutine wrap_json_file_update_logical
  2574. !*****************************************************************************************
  2575. !*****************************************************************************************
  2576. !> author: Jacob Williams
  2577. ! date: 1/10/2015
  2578. !
  2579. ! Given the path string, if the variable is present in the file,
  2580. ! and is a scalar, then update its value.
  2581. ! If it is not present, then create it and set its value.
  2582. subroutine json_file_update_real(me,path,val,found)
  2583. implicit none
  2584. class(json_file),intent(inout) :: me
  2585. character(kind=CK,len=*),intent(in) :: path
  2586. real(RK),intent(in) :: val
  2587. logical(LK),intent(out) :: found
  2588. if (.not. me%core%failed()) call me%core%update(me%p,path,val,found)
  2589. end subroutine json_file_update_real
  2590. !*****************************************************************************************
  2591. !*****************************************************************************************
  2592. !>
  2593. ! Alternate version of [[json_file_update_real]], where "path" is kind=CDK.
  2594. subroutine wrap_json_file_update_real(me,path,val,found)
  2595. implicit none
  2596. class(json_file),intent(inout) :: me
  2597. character(kind=CDK,len=*),intent(in) :: path
  2598. real(RK),intent(in) :: val
  2599. logical(LK),intent(out) :: found
  2600. call me%update(to_unicode(path),val,found)
  2601. end subroutine wrap_json_file_update_real
  2602. !*****************************************************************************************
  2603. !*****************************************************************************************
  2604. !> author: Jacob Williams
  2605. ! date: 1/21/2019
  2606. !
  2607. ! Alternate version of [[json_file_update_real]] where `val` is `real32`.
  2608. subroutine json_file_update_real32(me,path,val,found)
  2609. implicit none
  2610. class(json_file),intent(inout) :: me
  2611. character(kind=CK,len=*),intent(in) :: path
  2612. real(real32),intent(in) :: val
  2613. logical(LK),intent(out) :: found
  2614. call me%update(path,real(val,RK),found)
  2615. end subroutine json_file_update_real32
  2616. !*****************************************************************************************
  2617. !*****************************************************************************************
  2618. !>
  2619. ! Alternate version of [[json_file_update_real32]], where "path" is kind=CDK.
  2620. subroutine wrap_json_file_update_real32(me,path,val,found)
  2621. implicit none
  2622. class(json_file),intent(inout) :: me
  2623. character(kind=CDK,len=*),intent(in) :: path
  2624. real(real32),intent(in) :: val
  2625. logical(LK),intent(out) :: found
  2626. call me%update(to_unicode(path),val,found)
  2627. end subroutine wrap_json_file_update_real32
  2628. !*****************************************************************************************
  2629. # 2889
  2630. !*****************************************************************************************
  2631. !> author: Jacob Williams
  2632. ! date: 1/10/2015
  2633. !
  2634. ! Given the path string, if the variable is present in the file,
  2635. ! and is a scalar, then update its value.
  2636. ! If it is not present, then create it and set its value.
  2637. !
  2638. !### See also
  2639. ! * [[json_update_string]]
  2640. subroutine json_file_update_string(me,path,val,found,trim_str,adjustl_str)
  2641. implicit none
  2642. class(json_file),intent(inout) :: me
  2643. character(kind=CK,len=*),intent(in) :: path
  2644. character(kind=CK,len=*),intent(in) :: val
  2645. logical(LK),intent(out) :: found
  2646. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val`
  2647. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val`
  2648. !! (note that ADJUSTL is done before TRIM)
  2649. if (.not. me%core%failed()) call me%core%update(me%p,path,val,found,trim_str,adjustl_str)
  2650. end subroutine json_file_update_string
  2651. !*****************************************************************************************
  2652. !*****************************************************************************************
  2653. !>
  2654. ! Alternate version of [[json_file_update_string]], where "path" and "val" are kind=CDK.
  2655. subroutine wrap_json_file_update_string(me,path,val,found,trim_str,adjustl_str)
  2656. implicit none
  2657. class(json_file),intent(inout) :: me
  2658. character(kind=CDK,len=*),intent(in) :: path
  2659. character(kind=CDK,len=*),intent(in) :: val
  2660. logical(LK),intent(out) :: found
  2661. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val`
  2662. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val`
  2663. !! (note that ADJUSTL is done before TRIM)
  2664. call me%update(to_unicode(path),to_unicode(val),found,trim_str,adjustl_str)
  2665. end subroutine wrap_json_file_update_string
  2666. !*****************************************************************************************
  2667. !*****************************************************************************************
  2668. !>
  2669. ! Alternate version of [[json_file_update_string]], where "path" is kind=CDK.
  2670. subroutine json_file_update_string_name_ascii(me,path,val,found,trim_str,adjustl_str)
  2671. implicit none
  2672. class(json_file),intent(inout) :: me
  2673. character(kind=CDK,len=*),intent(in) :: path
  2674. character(kind=CK, len=*),intent(in) :: val
  2675. logical(LK),intent(out) :: found
  2676. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val`
  2677. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val`
  2678. !! (note that ADJUSTL is done before TRIM)
  2679. call me%update(to_unicode(path),val,found,trim_str,adjustl_str)
  2680. end subroutine json_file_update_string_name_ascii
  2681. !*****************************************************************************************
  2682. !*****************************************************************************************
  2683. !>
  2684. ! Alternate version of [[json_file_update_string]], where "val" is kind=CDK.
  2685. subroutine json_file_update_string_val_ascii(me,path,val,found,trim_str,adjustl_str)
  2686. implicit none
  2687. class(json_file),intent(inout) :: me
  2688. character(kind=CK, len=*),intent(in) :: path
  2689. character(kind=CDK,len=*),intent(in) :: val
  2690. logical(LK),intent(out) :: found
  2691. logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val`
  2692. logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val`
  2693. !! (note that ADJUSTL is done before TRIM)
  2694. call me%update(path,to_unicode(val),found,trim_str,adjustl_str)
  2695. end subroutine json_file_update_string_val_ascii
  2696. !*****************************************************************************************
  2697. !*****************************************************************************************
  2698. !> author: Jacob Williams
  2699. ! date: 6/11/2016
  2700. !
  2701. ! Traverse the JSON structure in the file.
  2702. ! This routine calls the user-specified [[json_traverse_callback_func]]
  2703. ! for each element of the structure.
  2704. subroutine json_file_traverse(me,traverse_callback)
  2705. implicit none
  2706. class(json_file),intent(inout) :: me
  2707. procedure(json_traverse_callback_func) :: traverse_callback
  2708. call me%core%traverse(me%p,traverse_callback)
  2709. end subroutine json_file_traverse
  2710. !*****************************************************************************************
  2711. !*****************************************************************************************
  2712. !> author: Jacob Williams
  2713. ! date: 7/7/2018
  2714. !
  2715. ! Remove a variable from a JSON file.
  2716. !
  2717. !@note This is just a wrapper to [[remove_if_present]].
  2718. subroutine json_file_remove(me,path)
  2719. implicit none
  2720. class(json_file),intent(inout) :: me
  2721. character(kind=CK,len=*),intent(in) :: path !! the path to the variable
  2722. call me%core%remove_if_present(me%p,path)
  2723. end subroutine json_file_remove
  2724. !*****************************************************************************************
  2725. !*****************************************************************************************
  2726. !>
  2727. ! Alternate version of [[json_file_remove]], where "path" is kind=CDK.
  2728. subroutine wrap_json_file_remove(me,path)
  2729. implicit none
  2730. class(json_file),intent(inout) :: me
  2731. character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
  2732. call me%remove(to_unicode(path))
  2733. end subroutine wrap_json_file_remove
  2734. !*****************************************************************************************
  2735. !*****************************************************************************************
  2736. end module json_file_module
  2737. !*****************************************************************************************