write_3d_r4_nrrd Subroutine

private subroutine write_3d_r4_nrrd(array, filename, overwrite, dict)

Uses

write 3D array of float32's to .nrrd fileformat

Arguments

Type IntentOptional Attributes Name
real(kind=sp), intent(in) :: array(:,:,:)

array to be written to disk

character(len=*), intent(in) :: filename

filename

logical, intent(in) :: overwrite

overwrite flag

type(toml_table), intent(inout), optional :: dict

dictionary of metadata


Source Code

        subroutine write_3d_r4_nrrd(array, filename, overwrite, dict)
            !! write 3D array of float32's to .nrrd fileformat

            use tomlf,           only : toml_table, toml_dump, toml_error
            use iso_fortran_env, only : int32, int64, real32, real64
            use utils,           only : str
            use constants,       only : sp
            
            !> filename
            character(*),               intent(IN)    :: filename
            !> array to be written to disk
            real(kind=sp),              intent(IN)    :: array(:, :, :)
            !> dictionary of metadata
            type(toml_table), optional, intent(INOUT) :: dict
            !> overwrite flag
            logical,                    intent(IN)    :: overwrite

            type(toml_error), allocatable :: error
            character(len=:), allocatable :: file
            integer :: u

            if(check_file(filename) .and. .not. overwrite)then
                file = get_new_file_name(filename)
            else
                file = filename
            end if

            open(newunit=u,file=file,form="formatted")
            !to do fix precision
            call write_hdr(u, [size(array, 1), size(array, 2), size(array, 3)], "float")

            if(present(dict))then
                call toml_dump(dict, u, error)
            end if
            write(u,"(A)")new_line("C")
            close(u)
            open(newunit=u,file=file,access="stream",form="unformatted",position="append")
            write(u)array
            close(u)
        
        end subroutine write_3d_r4_nrrd