Metadata labels for simulation data

All yaml node types (type_list, type_dictionary, etc.) have the dump procedure, which will dump all yaml to a given output unit. So, for example, this program reads test.yaml, then emits it to emitted.yaml

program test
  use fortran_yaml_c, only: parse, error_length
  use yaml_types, only: type_node
  
  class(type_node), pointer :: root
  character(len=error_length) :: error
  
  root => parse("test.yaml", error = error)
  if (error/='') then
    print*,trim(error)
    stop 1
  endif
  
  open(unit=1,file="emitted.yaml")
  
  call root%dump(unit=1,indent=0)
  close(1)
  call root%finalize()
  deallocate(root)
end program

You can also put together some yaml using the various yaml_types, then dump it. example:

program test
  use yaml_types, only: type_node, type_dictionary, type_error, real_kind, &
                        type_list, type_list_item, type_scalar, type_key_value_pair
  
  class(type_node), pointer :: root
  
  class(type_node), pointer :: val1, val2, val3
  character(len=1024) :: key1, key2, key3
  
  key1 = "pi"
  allocate(type_scalar::val1)
  select type (val1)
  class is(type_scalar)
    val1%string = "3.14159"
  end select
  
  key2 = "happy-today"
  allocate(type_scalar::val2)
  select type (val2)
  class is(type_scalar)
    val2%string = "true"
  end select
  
  key3 = "to-do"
  allocate(type_scalar::val3)
  select type (val3)
  class is(type_scalar)
    val3%string = "run a mile"
  end select
  
  allocate(type_dictionary::root)
  select type (root)
  class is (type_dictionary)
    call root%set(key1, val1)
    call root%set(key2, val2)
    call root%set(key3, val3)
  end select
  
  open(unit=1,file="emitted.yaml")
  call root%dump(unit=1,indent=0)
  close(1)

  call root%finalize()
  deallocate(root)

end program
2 Likes