HSD-Fortran Documentation

License

HSD-Fortran is a lightweight, dependency-free Human-friendly Structured Data (HSD) parser for Fortran.

HSD is a data format similar to JSON and YAML, but designed to minimize the effort for humans to read and write it. It was originally developed as the input format for DFTB+.

Features

  • Parsing HSD files into a tree structure with comprehensive error reporting

  • Serialization of data structures back to HSD format

  • Include support with cycle detection (<<+ for HSD, <<< for text)

  • Path-based accessors for convenient data retrieval (e.g., "section/subsection/value")

  • Type introspection to query node types before access

  • Tree operations including merge, clone, and recursive traversal

Quick Start

program example
  use hsd
  implicit none

  type(hsd_node_t), target :: root
  type(hsd_access_t) :: access
  type(hsd_error_t), allocatable :: error
  integer :: max_steps
  real(dp) :: temperature

  ! Load HSD file
  call hsd_load_file("input.hsd", root, error)
  if (allocated(error)) then
    call error%print()
    stop 1
  end if

  ! Access values via the access object
  call access%init(root)
  call access%get("Driver/MaxSteps", max_steps)
  call access%get("Hamiltonian/DFTB/Temperature", temperature)

  ! Modify and save
  call access%set("Driver/MaxSteps", 200)
  call hsd_dump(root, "output.hsd")

  if (access%has_errors()) call access%print_errors()

end program example

Example HSD input:

Driver = ConjugateGradient {
  MaxSteps = 100
}

Hamiltonian = DFTB {
  SCC = Yes
  Temperature [Kelvin] = 300.0
}

Contents

Indices and tables