jacobwilliams / json-fortran

A Modern Fortran JSON API
https://jacobwilliams.github.io/json-fortran/
Other
332 stars 83 forks source link

Writing to stdout #514

Closed jaxxstorm closed 2 years ago

jaxxstorm commented 2 years ago

Is there an easy way to write to stdout? I tried modifying the example:

program example2

   use,intrinsic :: iso_fortran_env, only: wp => real64
   use json_module

   implicit none

   type(json_core) :: json
   type(json_value),pointer :: p, inp

   ! initialize the class
   call json%initialize()

   ! initialize the structure:
   call json%create_object(p,'')

   ! add an "inputs" object to the structure:
   call json%create_object(inp,'inputs')
   call json%add(p, inp) !add it to the root

   ! add some data to inputs:
   call json%add(inp, 't0', 0.1_wp)
   call json%add(inp, 'tf', 1.1_wp)
   call json%add(inp, 'x0', 9999.0000d0)
   call json%add(inp, 'integer_scalar', 787)
   call json%add(inp, 'integer_array', [2,4,99])
   call json%add(inp, 'names', ['aaa','bbb','ccc'])
   call json%add(inp, 'logical_scalar', .true.)
   call json%add(inp, 'logical_vector', [.true., .false., .true.])

   ! write the file:
   call json%print()

end program example2

And get:

gfortran example.f90 -o hello -I /usr/local/Cellar/json-fortran/8.2.5/include/ /usr/local/Cellar/json-fortran/8.2.5/lib/libjsonfortran.a
example.f90:32:12:

   32 |    call json%print()
      |            1
Error: Found no matching specific binding for the call to the GENERIC 'print' at (1)
jaxxstorm commented 2 years ago

Never mind, I need to learn more fortean. Answer:

call json%print(inp)