API Reference
Unified IO
data_load
Load structured data from a file.
subroutine data_load(filename, root, error [, fmt] [, wrap_name])
character(len=*), intent(in) :: filename
type(hsd_table), intent(out) :: root
type(hsd_error_t), allocatable, intent(out) :: error
integer, optional, intent(in) :: fmt ! DATA_FMT_* constant
character(len=*), optional, intent(in) :: wrap_name ! wrap content under this name
end subroutine
Parameters:
filename— Path to the input file.root— Output: the parsed tree.error— Output: allocated on error, unallocated on success.fmt— Optional format override. Default:DATA_FMT_AUTO(detect from extension).wrap_name— Optional: wrap the loaded content under a root table with this name.
data_load_string
Load structured data from a string.
subroutine data_load_string(source, root, fmt, error [, filename])
character(len=*), intent(in) :: source
type(hsd_table), intent(out) :: root
integer, intent(in) :: fmt ! DATA_FMT_* constant (required)
type(hsd_error_t), allocatable, intent(out) :: error
character(len=*), optional, intent(in) :: filename ! for error messages
end subroutine
data_dump
Dump a tree to a file.
subroutine data_dump(root, filename, error [, fmt] [, pretty])
type(hsd_table), intent(in) :: root
character(len=*), intent(in) :: filename
type(hsd_error_t), allocatable, intent(out) :: error
integer, optional, intent(in) :: fmt ! DATA_FMT_* constant
logical, optional, intent(in) :: pretty ! default: .true.
end subroutine
data_dump_to_string
Dump a tree to a string.
subroutine data_dump_to_string(root, output, fmt [, pretty])
type(hsd_table), intent(in) :: root
character(len=:), allocatable, intent(out) :: output
integer, intent(in) :: fmt
logical, optional, intent(in) :: pretty
end subroutine
data_convert
Convert a file from one format to another.
subroutine data_convert(input_file, output_file, error [, input_fmt] [, output_fmt])
character(len=*), intent(in) :: input_file, output_file
type(hsd_error_t), allocatable, intent(out) :: error
integer, optional, intent(in) :: input_fmt, output_fmt
end subroutine
Format Constants
integer, parameter :: DATA_FMT_AUTO ! Auto-detect from file extension
integer, parameter :: DATA_FMT_HSD ! HSD format
integer, parameter :: DATA_FMT_XML ! XML format
integer, parameter :: DATA_FMT_JSON ! JSON format
integer, parameter :: DATA_FMT_YAML ! YAML format
integer, parameter :: DATA_FMT_TOML ! TOML format (requires WITH_TOML)
integer, parameter :: DATA_FMT_HDF5 ! HDF5 format (requires WITH_HDF5)
Utilities
data_detect_format
Detect format from a filename’s extension.
integer function data_detect_format(filename)
character(len=*), intent(in) :: filename
end function
Returns one of the DATA_FMT_* constants, or DATA_FMT_AUTO if the
extension is not recognized.
data_format_available
Check if a backend is available at runtime.
logical function data_format_available(fmt)
integer, intent(in) :: fmt
end function
Returns .true. for HSD, XML, JSON, and YAML (always available). Returns
.true. for TOML and HDF5 only if the library was built with the respective
option.
Backend-Specific Functions
HSD Backend
subroutine hsd_backend_load(filename, root, error)
subroutine hsd_backend_load_string(source, root, error [, filename])
subroutine hsd_backend_dump(root, filename, error)
subroutine hsd_backend_dump_to_string(root, output)
XML Backend
subroutine xml_parse_file(filename, root, error)
subroutine xml_parse_string(source, root, error [, filename])
subroutine xml_dump_file(root, filename, error [, pretty])
subroutine xml_dump_to_string(root, output [, pretty])
JSON Backend
subroutine json_parse_file(filename, root, error)
subroutine json_parse_string(source, root, error [, filename])
subroutine json_dump_file(root, filename, error [, pretty])
subroutine json_dump_to_string(root, output [, pretty])
YAML Backend
subroutine yaml_parse_file(filename, root, error)
subroutine yaml_parse_string(source, root, error [, filename])
subroutine yaml_dump_file(root, filename, error [, pretty])
subroutine yaml_dump_to_string(root, output [, pretty])
TOML Backend (optional)
Available only when built with HSD_DATA_WITH_TOML=ON.
subroutine toml_backend_load(filename, root, error)
subroutine toml_backend_load_string(source, root, error)
subroutine toml_backend_dump(root, filename, error)
subroutine toml_backend_dump_to_string(root, output)
Re-exported hsd-fortran API
The hsd_data module re-exports the entire hsd-fortran public API. This
means you only need use hsd_data to access both the multi-format IO and all
tree manipulation functions. Key re-exported symbols:
Types
Type |
Description |
|---|---|
|
Container node with named children |
|
Leaf node holding scalar/array data |
|
Abstract base class for all nodes |
|
Pointer wrapper for polymorphic node references |
|
Stateful child iterator |
|
Error type with message and status code |
Constructors
Function |
Description |
|---|---|
|
Create a new table node |
|
Create a new value node |
Accessors
Procedure |
Description |
|---|---|
|
Get typed value by path |
|
Get with fallback default |
|
Get or set default in tree |
|
Get 2-D matrix |
|
Get with unit conversion |
Mutators
Procedure |
Description |
|---|---|
|
Set a value by path |
|
Remove all children from a table |
Query
Procedure |
Description |
|---|---|
|
Check if child exists |
|
Get child node by path |
|
Get child table |
|
Remove a child |
|
Count children |
|
Get all child names |
|
Type checks |
|
Get value type constant |
|
Merge two trees |
|
Deep copy a tree |
|
Structural equality |
Validation
Procedure |
Description |
|---|---|
|
Assert a key exists |
|
Range validation |
|
Enum validation |
|
Find unprocessed nodes |
Schema
Procedure |
Description |
|---|---|
|
Initialize schema |
|
Add field definition |
|
Validate against schema |
|
Strict validation (reject unknown) |
Attributes
Procedure |
Description |
|---|---|
|
Get attribute value |
|
Check attribute existence |
|
Set attribute value |
Status Codes
Constant |
Value |
Meaning |
|---|---|---|
|
0 |
Success |
|
1 |
Parse error |
|
2 |
Block not closed |
|
3 |
Attribute bracket not closed |
|
4 |
String quote not closed |
|
5 |
Text outside any block |
|
6 |
Circular include detected |
|
7 |
Too many nested includes |
|
8 |
File not found |
|
9 |
IO operation failed |
|
10 |
Type conversion failed |
|
11 |
Key not found |
|
20 |
Schema validation failed |
Value Type Constants
Constant |
Description |
|---|---|
|
No type / table node |
|
String value |
|
Integer value |
|
Real (double precision) value |
|
Logical (boolean) value |
|
Array of values |
|
Complex number |