Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
west-public
West
Commits
6e13d0ca
Commit
6e13d0ca
authored
May 22, 2021
by
Marco Govoni
Browse files
Merge branch 'json_update' into 'develop'
Update Json-Fortran to 8.2.1 See merge request west-devel/West!37
parents
9cdb9297
92d35881
Changes
24
Hide whitespace changes
Inline
Side-by-side
IO_kernel/pdep_db.f90
View file @
6e13d0ca
...
...
@@ -160,7 +160,7 @@ MODULE pdep_db
CALL
json
%
add
(
"dielectric_matrix.pdep"
,
jval
)
!
OPEN
(
NEWUNIT
=
iunit
,
FILE
=
summary_file
)
CALL
json
%
print
_file
(
iunit
)
CALL
json
%
print
(
iunit
)
CLOSE
(
iunit
)
!
CALL
json
%
destroy
()
...
...
@@ -173,7 +173,7 @@ MODULE pdep_db
IF
(
mpime
==
root
)
THEN
!
CALL
json
%
initialize
()
CALL
json
%
load
_file
(
filename
=
summary_file
)
CALL
json
%
load
(
filename
=
summary_file
)
!
CALL
json
%
info
(
'dielectric_matrix.pdep'
,
n_children
=
n_elements
)
write_element
=
n_elements
+
1
...
...
@@ -193,7 +193,7 @@ MODULE pdep_db
CALL
json
%
add
(
'dielectric_matrix.pdep('
//
TRIM
(
ADJUSTL
(
label_i
))//
').eigenvec'
,
eigenpot_filename
(
1
:
n_pdep_eigen
))
!
OPEN
(
NEWUNIT
=
iunit
,
FILE
=
summary_file
)
CALL
json
%
print
_file
(
iunit
)
CALL
json
%
print
(
iunit
)
CLOSE
(
iunit
)
CALL
json
%
destroy
()
!
...
...
@@ -321,7 +321,7 @@ MODULE pdep_db
IF
(
mpime
==
root
)
THEN
!
CALL
json
%
initialize
()
CALL
json
%
load
_file
(
filename
=
TRIM
(
ADJUSTL
(
wstat_save_dir
))
//
"/summary.json"
)
CALL
json
%
load
(
filename
=
TRIM
(
ADJUSTL
(
wstat_save_dir
))
//
"/summary.json"
)
IF
(
json
%
failed
()
)
THEN
CALL
errore
(
""
,
"Cannot open: "
//
TRIM
(
ADJUSTL
(
wstat_save_dir
))
//
"/summary.json"
,
1
)
ENDIF
...
...
IO_kernel/wfreq_db.f90
View file @
6e13d0ca
...
...
@@ -72,7 +72,7 @@ MODULE wfreq_db
!
CALL
json
%
initialize
()
!
CALL
json
%
load
_file
(
filename
=
TRIM
(
logfile
))
CALL
json
%
load
(
filename
=
TRIM
(
logfile
))
!
l_generate_plot
=
.FALSE.
l_optics
=
.FALSE.
...
...
@@ -157,7 +157,7 @@ MODULE wfreq_db
ENDDO
!
OPEN
(
NEWUNIT
=
iunit
,
FILE
=
TRIM
(
logfile
)
)
CALL
json
%
print
_file
(
iunit
)
CALL
json
%
print
(
iunit
)
CLOSE
(
iunit
)
CALL
json
%
destroy
()
!
...
...
Libraries/Json/README
View file @
6e13d0ca
==========================================
Based on the library: json-fortran v
6.3.0
Based on the library: json-fortran v
8.2.1
==========================================
JSON-Fortran: A Fortran 2008 JSON API
<https://github.com/jacobwilliams/json-fortran>
Copyright (c) 2014-20
18
, Jacob Williams
Copyright (c) 2014-20
20
, Jacob Williams
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
...
...
Libraries/Json/json_file_module.f90
View file @
6e13d0ca
...
...
@@ -31,7 +31,7 @@
! used to open a file and get data from it.
!
! A `json_file` contains only two items: an instance of a [[json_core(type)]],
! which
use
used for all data manipulation, and a [[json_value]],
! which
is
used for all data manipulation, and a [[json_value]]
pointer
,
! which is used to construct the linked-list data structure.
! Note that most methods in the `json_file` class are simply wrappers
! to the lower-level routines in the [[json_value_module]].
...
...
@@ -48,20 +48,25 @@
! character(len=:),allocatable :: cval
! logical :: found
! call json%initialize(compact_reals=.true.)
! call json%load
_file
(filename='myfile.json')
! call json%print
_file
() !print to the console
! call json%load(filename='myfile.json')
! call json%print() !print to the console
! call json%get('var.i',ival,found)
! call json%get('var.r(3)',rval,found)
! call json%get('var.c',cval,found)
! call json%destroy()
! end program test
!```
!
!@note The `destroy()` method may be called to free the memory if necessary.
! [[json_file(type)]] includes a finalizer that also calls
! `destroy()` when the variable goes out of scope.
type
,
public
::
json_file
private
type
(
json_core
)
::
core
!! The instance of the [[json_core(type)]] factory used for this file.
type
(
json_core
)
::
core
!! The instance of the [[json_core(type)]]
!! factory used for this file.
type
(
json_value
),
pointer
::
p
=>
null
()
!! the JSON structure read from the file
contains
...
...
@@ -71,11 +76,32 @@
procedure
,
public
::
get_core
=>
get_json_core_in_file
!>
! Load JSON from a file.
procedure
,
public
::
load
=>
json_file_load
!>
! The same as `load`, but only here for backward compatibility
procedure
,
public
::
load_file
=>
json_file_load
!>
! Load JSON from a string.
generic
,
public
::
deserialize
=>
MAYBEWRAP
(
json_file_load_from_string
)
!>
! The same as `deserialize`, but only here for backward compatibility
generic
,
public
::
load_from_string
=>
MAYBEWRAP
(
json_file_load_from_string
)
!>
! Print the [[json_value]] structure to an allocatable string
procedure
,
public
::
serialize
=>
json_file_print_to_string
!>
! The same as `serialize`, but only here for backward compatibility
procedure
,
public
::
print_to_string
=>
json_file_print_to_string
procedure
,
public
::
destroy
=>
json_file_destroy
procedure
,
public
::
nullify
=>
json_file_nullify
procedure
,
public
::
move
=>
json_file_move_pointer
generic
,
public
::
info
=>
MAYBEWRAP
(
json_file_variable_info
)
generic
,
public
::
matrix_info
=>
MAYBEWRAP
(
json_file_variable_matrix_info
)
...
...
@@ -86,12 +112,15 @@
procedure
,
public
::
check_for_errors
=>
json_file_check_for_errors
procedure
,
public
::
clear_exceptions
=>
json_file_clear_exceptions
procedure
,
public
::
print_to_string
=>
json_file_print_to_string
generic
,
public
::
print
=>
json_file_print_to_console
,
&
json_file_print_to_unit
,
&
json_file_print_to_filename
!>
! The same as `print`, but only here for backward compatibility
generic
,
public
::
print_file
=>
json_file_print_to_console
,
&
json_file_print_1
,
&
json_file_print_2
json_file_print_to_unit
,
&
json_file_print_to_filename
!>
! Rename a variable, specifying it by path
...
...
@@ -110,11 +139,23 @@
! Get a variable from a [[json_file(type)]], by specifying the path.
generic
,
public
::
get
=>
MAYBEWRAP
(
json_file_get_object
),
&
MAYBEWRAP
(
json_file_get_integer
),
&
MAYBEWRAP
(
json_file_get_double
),
&
#ifndef REAL32
MAYBEWRAP
(
json_file_get_real32
),
&
#endif
MAYBEWRAP
(
json_file_get_real
),
&
#ifdef REAL128
MAYBEWRAP
(
json_file_get_real64
),
&
#endif
MAYBEWRAP
(
json_file_get_logical
),
&
MAYBEWRAP
(
json_file_get_string
),
&
MAYBEWRAP
(
json_file_get_integer_vec
),
&
MAYBEWRAP
(
json_file_get_double_vec
),
&
#ifndef REAL32
MAYBEWRAP
(
json_file_get_real32_vec
),
&
#endif
MAYBEWRAP
(
json_file_get_real_vec
),
&
#ifdef REAL128
MAYBEWRAP
(
json_file_get_real64_vec
),
&
#endif
MAYBEWRAP
(
json_file_get_logical_vec
),
&
MAYBEWRAP
(
json_file_get_string_vec
),
&
MAYBEWRAP
(
json_file_get_alloc_string_vec
),
&
...
...
@@ -134,16 +175,29 @@
! call f%add('inputs.t', 0.0_rk)
! call f%add('inputs.x', [1.0_rk,2.0_rk,3.0_rk])
! call f%add('inputs.flag', .true.)
! call f%print
_file()
! call f%print
() ! print to the console
! end program test
!```
generic
,
public
::
add
=>
MAYBEWRAP
(
json_file_add_object
),
&
generic
,
public
::
add
=>
json_file_add
,
&
MAYBEWRAP
(
json_file_add_object
),
&
MAYBEWRAP
(
json_file_add_integer
),
&
MAYBEWRAP
(
json_file_add_double
),
&
#ifndef REAL32
MAYBEWRAP
(
json_file_add_real32
),
&
#endif
MAYBEWRAP
(
json_file_add_real
),
&
#ifdef REAL128
MAYBEWRAP
(
json_file_add_real64
),
&
#endif
MAYBEWRAP
(
json_file_add_logical
),
&
MAYBEWRAP
(
json_file_add_string
),
&
MAYBEWRAP
(
json_file_add_integer_vec
),
&
MAYBEWRAP
(
json_file_add_double_vec
),
&
#ifndef REAL32
MAYBEWRAP
(
json_file_add_real32_vec
),
&
#endif
MAYBEWRAP
(
json_file_add_real_vec
),
&
#ifdef REAL128
MAYBEWRAP
(
json_file_add_real64_vec
),
&
#endif
MAYBEWRAP
(
json_file_add_logical_vec
),
&
MAYBEWRAP
(
json_file_add_string_vec
)
#ifdef USE_UCS4
...
...
@@ -162,7 +216,13 @@
! scalars and vectors, etc.)
generic
,
public
::
update
=>
MAYBEWRAP
(
json_file_update_integer
),
&
MAYBEWRAP
(
json_file_update_logical
),
&
#ifndef REAL32
MAYBEWRAP
(
json_file_update_real32
),
&
#endif
MAYBEWRAP
(
json_file_update_real
),
&
#ifdef REAL128
MAYBEWRAP
(
json_file_update_real64
),
&
#endif
MAYBEWRAP
(
json_file_update_string
)
#ifdef USE_UCS4
generic
,
public
::
update
=>
json_file_update_string_name_ascii
,
&
...
...
@@ -184,6 +244,13 @@
generic
,
public
::
operator
(
.in.
)
=>
MAYBEWRAP
(
json_file_valid_path_op
)
procedure
,
pass
(
me
)
::
MAYBEWRAP
(
json_file_valid_path_op
)
generic
,
public
::
assignment
(
=
)
=>
assign_json_file
,&
assign_json_file_to_string
,&
MAYBEWRAP
(
assign_string_to_json_file
)
procedure
::
assign_json_file
procedure
,
pass
(
me
)
::
assign_json_file_to_string
procedure
::
MAYBEWRAP
(
assign_string_to_json_file
)
! ***************************************************
! private routines
! ***************************************************
...
...
@@ -212,24 +279,49 @@
!get:
procedure
::
MAYBEWRAP
(
json_file_get_object
)
procedure
::
MAYBEWRAP
(
json_file_get_integer
)
procedure
::
MAYBEWRAP
(
json_file_get_double
)
#ifndef REAL32
procedure
::
MAYBEWRAP
(
json_file_get_real32
)
#endif
procedure
::
MAYBEWRAP
(
json_file_get_real
)
#ifdef REAL128
procedure
::
MAYBEWRAP
(
json_file_get_real64
)
#endif
procedure
::
MAYBEWRAP
(
json_file_get_logical
)
procedure
::
MAYBEWRAP
(
json_file_get_string
)
procedure
::
MAYBEWRAP
(
json_file_get_integer_vec
)
procedure
::
MAYBEWRAP
(
json_file_get_double_vec
)
#ifndef REAL32
procedure
::
MAYBEWRAP
(
json_file_get_real32_vec
)
#endif
procedure
::
MAYBEWRAP
(
json_file_get_real_vec
)
#ifdef REAL128
procedure
::
MAYBEWRAP
(
json_file_get_real64_vec
)
#endif
procedure
::
MAYBEWRAP
(
json_file_get_logical_vec
)
procedure
::
MAYBEWRAP
(
json_file_get_string_vec
)
procedure
::
MAYBEWRAP
(
json_file_get_alloc_string_vec
)
procedure
::
json_file_get_root
!add:
procedure
::
json_file_add
procedure
::
MAYBEWRAP
(
json_file_add_object
)
procedure
::
MAYBEWRAP
(
json_file_add_integer
)
procedure
::
MAYBEWRAP
(
json_file_add_double
)
#ifndef REAL32
procedure
::
MAYBEWRAP
(
json_file_add_real32
)
#endif
procedure
::
MAYBEWRAP
(
json_file_add_real
)
#ifdef REAL128
procedure
::
MAYBEWRAP
(
json_file_add_real64
)
#endif
procedure
::
MAYBEWRAP
(
json_file_add_logical
)
procedure
::
MAYBEWRAP
(
json_file_add_string
)
procedure
::
MAYBEWRAP
(
json_file_add_integer_vec
)
procedure
::
MAYBEWRAP
(
json_file_add_double_vec
)
#ifndef REAL32
procedure
::
MAYBEWRAP
(
json_file_add_real32_vec
)
#endif
procedure
::
MAYBEWRAP
(
json_file_add_real_vec
)
#ifdef REAL128
procedure
::
MAYBEWRAP
(
json_file_add_real64_vec
)
#endif
procedure
::
MAYBEWRAP
(
json_file_add_logical_vec
)
procedure
::
MAYBEWRAP
(
json_file_add_string_vec
)
#ifdef USE_UCS4
...
...
@@ -242,7 +334,13 @@
!update:
procedure
::
MAYBEWRAP
(
json_file_update_integer
)
procedure
::
MAYBEWRAP
(
json_file_update_logical
)
#ifndef REAL32
procedure
::
MAYBEWRAP
(
json_file_update_real32
)
#endif
procedure
::
MAYBEWRAP
(
json_file_update_real
)
#ifdef REAL128
procedure
::
MAYBEWRAP
(
json_file_update_real64
)
#endif
procedure
::
MAYBEWRAP
(
json_file_update_string
)
#ifdef USE_UCS4
procedure
::
json_file_update_string_name_ascii
...
...
@@ -252,10 +350,12 @@
!remove:
procedure
::
MAYBEWRAP
(
json_file_remove
)
!print
_file
:
!print:
procedure
::
json_file_print_to_console
procedure
::
json_file_print_1
procedure
::
json_file_print_2
procedure
::
json_file_print_to_unit
procedure
::
json_file_print_to_filename
final
::
finalize_json_file
end
type
json_file
!*********************************************************
...
...
@@ -264,15 +364,16 @@
!> author: Izaak Beekman
! date: 07/23/2015
!
! Structure constructor to initialize a [[json_file(type)]] object
! with an existing [[json_value]] object, and either the [[json_core(type)]]
! settings or a [[json_core(type)]] instance.
! Structure constructor to initialize a [[json_file(type)]]
! object with an existing [[json_value]] object or a JSON
! string, and either the [[json_core(type)]] settings or a
! [[json_core(type)]] instance.
!
!### Example
!
!```fortran
! ...
! type(json_file)
:: my_file
! type(json_file) :: my_file
! type(json_value),pointer :: json_object
! type(json_core) :: json_core_object
! ...
...
...
@@ -282,16 +383,40 @@
! !or:
! my_file = json_file(json_object,verbose=.true.)
! !or:
! my_file = json_file('{"x": [1]}',verbose=.true.)
! !or:
! my_file = json_file(json_object,json_core_object)
! !or:
! my_file = json_file('{"x": [1]}',json_core_object)
!```
interface
json_file
module
procedure
initialize_json_file
,
initialize_json_file_v2
module
procedure
initialize_json_file
,
&
initialize_json_file_v2
,
&
MAYBEWRAP
(
initialize_json_file_from_string
),
&
MAYBEWRAP
(
initialize_json_file_from_string_v2
)
end
interface
!*************************************************************************************
contains
!*****************************************************************************************
!*****************************************************************************************
!>
! Finalizer for [[json_file]] class.
!
! Just a wrapper for [[json_file_destroy]].
subroutine
finalize_json_file
(
me
)
implicit
none
type
(
json_file
),
intent
(
inout
)
::
me
call
me
%
destroy
(
destroy_core
=
.true.
)
end
subroutine
finalize_json_file
!*****************************************************************************************
!*****************************************************************************************
!>
! Check error status in the file.
...
...
@@ -317,10 +442,17 @@
implicit
none
class
(
json_file
),
intent
(
inout
)
::
me
logical
(
LK
),
intent
(
out
)
::
status_ok
!! true if there were no errors
character
(
kind
=
CK
,
len
=
:),
allocatable
,
intent
(
out
)
::
error_msg
!! the error message (if there were errors)
logical
(
LK
),
intent
(
out
),
optional
::
status_ok
!! true if there were no errors
character
(
kind
=
CK
,
len
=
:),
allocatable
,
intent
(
out
),
optional
::
error_msg
!! the error message
!! (if there were errors)
#if defined __GFORTRAN__
character
(
kind
=
CK
,
len
=
:),
allocatable
::
tmp
!! workaround for gfortran bugs
call
me
%
core
%
check_for_errors
(
status_ok
,
tmp
)
if
(
present
(
error_msg
))
error_msg
=
tmp
#else
call
me
%
core
%
check_for_errors
(
status_ok
,
error_msg
)
#endif
end
subroutine
json_file_check_for_errors
!*****************************************************************************************
...
...
@@ -364,44 +496,23 @@
!@note This does not destroy the data in the file.
!
!@note [[initialize_json_core]], [[json_initialize]],
! [[initialize_json_core_in_file]], and [[initialize_json_file]]
! [[initialize_json_core_in_file]], [[initialize_json_file]],
! [[initialize_json_file_v2]], [[initialize_json_file_from_string]],
! and [[initialize_json_file_from_string_v2]]
! all have a similar interface.
subroutine
initialize_json_core_in_file
(
me
,
verbose
,
compact_reals
,&
print_signs
,
real_format
,
spaces_per_tab
,&
strict_type_checking
,&
trailing_spaces_significant
,&
case_sensitive_keys
,&
no_whitespace
,&
unescape_strings
,&
comment_char
,&
path_mode
,&
path_separator
,&
compress_vectors
,&
allow_duplicate_keys
,&
escape_solidus
,&
stop_on_error
)
subroutine
initialize_json_core_in_file
(
me
,&
#include "json_initialize_dummy_arguments.inc"
)
implicit
none
class
(
json_file
),
intent
(
inout
)
::
me
#include "json_initialize_arguments.inc"
call
me
%
core
%
initialize
(
verbose
,
compact_reals
,&
print_signs
,
real_format
,
spaces_per_tab
,&
strict_type_checking
,&
trailing_spaces_significant
,&
case_sensitive_keys
,&
no_whitespace
,&
unescape_strings
,&
comment_char
,&
path_mode
,&
path_separator
,&
compress_vectors
,&
allow_duplicate_keys
,&
escape_solidus
,&
stop_on_error
)
call
me
%
core
%
initialize
(&
#include "json_initialize_dummy_arguments.inc"
)
end
subroutine
initialize_json_core_in_file
!*****************************************************************************************
...
...
@@ -451,47 +562,34 @@
! It also calls the `initialize()` method.
!
!@note [[initialize_json_core]], [[json_initialize]],
! [[initialize_json_core_in_file]], and [[initialize_json_file]]
! [[initialize_json_core_in_file]], [[initialize_json_file]],
! [[initialize_json_file_v2]], [[initialize_json_file_from_string]],
! and [[initialize_json_file_from_string_v2]]
! all have a similar interface.
function
initialize_json_file
(
p
,
verbose
,
compact_reals
,&
print_signs
,
real_format
,
spaces_per_tab
,&
strict_type_checking
,&
trailing_spaces_significant
,&
case_sensitive_keys
,&
no_whitespace
,&
unescape_strings
,&
comment_char
,&
path_mode
,&
path_separator
,&
compress_vectors
,&
allow_duplicate_keys
,&
escape_solidus
,&
stop_on_error
)
result
(
file_object
)
function
initialize_json_file
(
p
,&
#include "json_initialize_dummy_arguments.inc"
)
result
(
file_object
)
implicit
none
type
(
json_file
)
::
file_object
type
(
json_value
),
pointer
,
optional
,
intent
(
in
)
::
p
!! `json_value` object to cast
!! as a `json_file` object
type
(
json_value
),
pointer
,
optional
::
p
!! `json_value` object to cast
!! as a `json_file` object. This
!! will be nullified.
#include "json_initialize_arguments.inc"
call
file_object
%
initialize
(
verbose
,
compact_reals
,&
print_signs
,
real_format
,
spaces_per_tab
,&
strict_type_checking
,&
trailing_spaces_significant
,&
case_sensitive_keys
,&
no_whitespace
,&
unescape_strings
,&
comment_char
,&
path_mode
,&
path_separator
,&
compress_vectors
,&
allow_duplicate_keys
,&
escape_solidus
,&
stop_on_error
)
if
(
present
(
p
))
file_object
%
p
=>
p
call
file_object
%
initialize
(&
#include "json_initialize_dummy_arguments.inc"
)
if
(
present
(
p
))
then
file_object
%
p
=>
p
! we have to nullify it to avoid
! a dangling pointer when the file
! goes out of scope
nullify
(
p
)
end
if
end
function
initialize_json_file
!*****************************************************************************************
...
...
@@ -503,7 +601,7 @@
! Cast a [[json_value]] pointer and a [[json_core(type)]] object
! as a [[json_file(type)]] object.
function
initialize_json_file_v2
(
json_value_object
,
json_core_object
)
&
function
initialize_json_file_v2
(
json_value_object
,
json_core_object
)
&
result
(
file_object
)
implicit
none
...
...
@@ -518,11 +616,139 @@
end
function
initialize_json_file_v2
!*****************************************************************************************
!*****************************************************************************************
!> author: Jacob Williams
! date: 01/19/2019
!
! Cast a JSON string as a [[json_file(type)]] object.
! It also calls the `initialize()` method.
!
!### Example
!
!```fortran
! type(json_file) :: f
! f = json_file('{"key ": 1}', trailing_spaces_significant=.true.)
!```
!
!@note [[initialize_json_core]], [[json_initialize]],
! [[initialize_json_core_in_file]], [[initialize_json_file]],
! [[initialize_json_file_v2]], [[initialize_json_file_from_string]],
! and [[initialize_json_file_from_string_v2]]
! all have a similar interface.
function
initialize_json_file_from_string
(
str
,&
#include "json_initialize_dummy_arguments.inc"
)
result
(
file_object
)
implicit
none
type
(
json_file
)
::
file_object
character
(
kind
=
CK
,
len
=*
),
intent
(
in
)
::
str
!! string to load JSON data from
#include "json_initialize_arguments.inc"
call
file_object
%
initialize
(&
#include "json_initialize_dummy_arguments.inc"
)
call
file_object
%
deserialize
(
str
)
end
function
initialize_json_file_from_string
!*****************************************************************************************
!*****************************************************************************************
!>
! Alternate version of [[initialize_json_file_from_string]], where "str" is kind=CDK.
function
wrap_initialize_json_file_from_string
(
str
,&
#include "json_initialize_dummy_arguments.inc"
)
result
(
file_object
)
implicit
none
type
(
json_file
)
::
file_object
character
(
kind
=
CDK
,
len
=*
),
intent
(
in
)
::
str
!! string to load JSON data from
#include "json_initialize_arguments.inc"
file_object
=
initialize_json_file_from_string
(&
to_unicode
(
str
),&
#include "json_initialize_dummy_arguments.inc"
)
end
function
wrap_initialize_json_file_from_string
!*****************************************************************************************
!*****************************************************************************************
!> author: Jacob Williams
! date: 1/19/2019
!
! Cast a JSON string and a [[json_core(type)]] object
! as a [[json_file(type)]] object.