json_file_print_2 Subroutine

private subroutine json_file_print_2(me, filename)

Arguments

Type IntentOptional AttributesName
class(json_file), intent(inout) :: me
character(kind=CDK,len=*), intent(in) :: filename

filename to print to

Description

Print the JSON structure to the specified filename. The file is opened, printed, and then closed.

Example

Example loading a JSON file, changing a value, and then printing result to a new file:

     type(json_file) :: f
     logical :: found
     call f%load_file('my_file.json')    !open the original file
     call f%update('version',4,found)    !change the value of a variable
     call f%print_file('my_file_2.json') !save file as new name

Calls

proc~~json_file_print_2~~CallsGraph proc~json_file_print_2 json_file_print_2 interface~throw_exception throw_exception proc~json_file_print_2->interface~throw_exception proc~json_throw_exception json_throw_exception interface~throw_exception->proc~json_throw_exception
Help

Variables

TypeVisibility AttributesNameInitial
integer(kind=IK), public :: iunit
integer(kind=IK), public :: istat

Source Code

    subroutine json_file_print_2(me,filename)

    implicit none

    class(json_file),intent(inout)       :: me
    character(kind=CDK,len=*),intent(in) :: filename  !! filename to print to

    integer(IK) :: iunit,istat

    open(newunit=iunit,file=filename,status='REPLACE',iostat=istat FILE_ENCODING )
    if (istat==0) then
        call me%print_file(iunit)    !call the other routine
        close(iunit,iostat=istat)
    else
        call throw_exception('Error in json_file_print_2: could not open file: '//&
                              trim(filename))
    end if

    end subroutine json_file_print_2