Write unfragmented calculation results to output JSON file
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(json_output_data_t), | intent(in) | :: | data |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=256), | private | :: | basename | ||||
| type(json_value), | private, | pointer | :: | dipole_obj | |||
| integer, | private | :: | io_stat | ||||
| integer, | private | :: | iunit | ||||
| type(json_core), | private | :: | json | ||||
| type(json_value), | private, | pointer | :: | main_obj | |||
| character(len=256), | private | :: | output_file | ||||
| type(json_value), | private, | pointer | :: | root |
subroutine write_unfragmented_json_impl(data) !! Write unfragmented calculation results to output JSON file type(json_output_data_t), intent(in) :: data type(json_core) :: json type(json_value), pointer :: root, main_obj, dipole_obj integer :: iunit, io_stat character(len=256) :: output_file, basename output_file = get_output_json_filename() basename = get_basename() call json%initialize(real_format=JSON_REAL_FORMAT) call json%create_object(root, '') call json%create_object(main_obj, trim(basename)) call json%add(root, main_obj) if (data%has_energy) call json%add(main_obj, 'total_energy', data%total_energy) if (data%has_dipole .and. allocated(data%dipole)) then call json%create_object(dipole_obj, 'dipole') call json%add(main_obj, dipole_obj) call json%add(dipole_obj, 'x', data%dipole(1)) call json%add(dipole_obj, 'y', data%dipole(2)) call json%add(dipole_obj, 'z', data%dipole(3)) call json%add(dipole_obj, 'magnitude_debye', norm2(data%dipole)*AU_TO_DEBYE) end if if (data%has_gradient .and. allocated(data%gradient)) then call json%add(main_obj, 'gradient_norm', sqrt(sum(data%gradient**2))) end if if (data%has_hessian .and. allocated(data%hessian)) then call json%add(main_obj, 'hessian_frobenius_norm', sqrt(sum(data%hessian**2))) end if call logger%info("Writing JSON output to "//trim(output_file)) open (newunit=iunit, file=trim(output_file), status='replace', action='write', iostat=io_stat) if (io_stat /= 0) then call logger%error("Failed to open "//trim(output_file)//" for writing") call json%destroy(root) return end if call json%print(root, iunit) close (iunit) call json%destroy(root) call logger%info("JSON output written successfully to "//trim(output_file)) end subroutine write_unfragmented_json_impl