Commit 8f391d95 authored by Roy Fabrice's avatar Roy Fabrice
Browse files

add level min and max and write parameters as metadata

add 2 parameters: cell_level_min and cell_level_max
write amr2cell_hdf5_parameters in each hdf5 files
parent 7f8c50ba
......@@ -66,10 +66,10 @@ program amr2cell_hdf5
call amr2cell_hdf5_parameters%Read()
call amr2cell_hdf5_parameters%Check()
call ramses_info%Read(trim(amr2cell_hdf5_parameters%data_dir)//trim(amr2cell_hdf5_parameters%info_filename), mpi_process)
call amr2cell_hdf5_parameters%Check(ramses_info)
call ramses_output%Init(amr2cell_hdf5_parameters)
call ramses_output%Read()
......@@ -90,7 +90,7 @@ program amr2cell_hdf5
call cubes_array%Associate(cells_array, global_cells_per_cube)
call cubes_array%Write()
call cubes_array%Write(amr2cell_hdf5_parameters)
call timer%Finalize()
if ( mpi_process%rank == 0 ) then
......
......@@ -51,20 +51,25 @@ module amr2cell_hdf5_parameters_m
character(len=LEN_STRING) :: info_filename
character(len=LEN_STRING) :: cube_filename
integer :: cube_level
integer :: cell_level_min
integer :: cell_level_max
contains
procedure :: Check => Check_amr2cell_hdf5_parameters
procedure :: Print => Print_amr2cell_hdf5_parameters
procedure :: Read => Read_amr2cell_hdf5_parameters
procedure :: Write => Write_hdf5_amr2cell_hdf5_parameters
end type amr2cell_hdf5_parameters_t
contains
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Check_amr2cell_hdf5_parameters(this)
subroutine Check_amr2cell_hdf5_parameters(this, ramses_info)
use char_utils_m, only : Int_to_char5
use constants_m, only : FILENAME_LEN
use ramses_info_m, only : ramses_info_t
class(amr2cell_hdf5_parameters_t), intent(in) :: this
class(amr2cell_hdf5_parameters_t), intent(inout) :: this
type(ramses_info_t), intent(in) :: ramses_info
character(len=FILENAME_LEN) :: filename
integer :: ncubes
......@@ -85,6 +90,17 @@ contains
call Algorithmic_error('Check_amr2cell_hdf5_parameters', 'Number of processes used should be <= number of cubes written.', 1000, mpi_process%rank)
end if
! check cell_level_min and cell_level_max
if( this%cell_level_min == 0 .or. this%cell_level_min < ramses_info%levelmin ) then
this%cell_level_min = ramses_info%levelmin
write(OUTPUT_UNIT,'(a,i0)') 'cell_level_min was undefined or < Ramses level_min ; its value has been adjusted to Ramses level_min = ', ramses_info%levelmin
end if
if( this%cell_level_max == 0 .or. this%cell_level_max > ramses_info%levelmax ) then
this%cell_level_max = ramses_info%levelmax
write(OUTPUT_UNIT,'(a,i0)') 'cell_level_max was undefined or > Ramses level_max ; its value has been adjusted to Ramses level_max = ', ramses_info%levelmax
end if
! test the existance of the files
inquire(directory=this%data_dir, exist=data_dir_exists )
if(.not. data_dir_exists) then
......@@ -136,7 +152,7 @@ contains
integer(kind=MPI_ADDRESS_KIND), allocatable, dimension(:) :: disp
integer(kind=MPI_ADDRESS_KIND) :: base
integer(kind=4) :: mpierr
integer(kind=4), parameter :: TYPESIZE = 7
integer(kind=4), parameter :: TYPESIZE = 9
integer(kind=4) :: alloc_stat
character(len=ERR_MSG_LEN) :: error_message
......@@ -165,13 +181,15 @@ contains
call mpi_get_address(parameters%info_filename, disp(5), mpierr)
call mpi_get_address(parameters%cube_filename, disp(6), mpierr)
call mpi_get_address(parameters%cube_level, disp(7), mpierr)
call mpi_get_address(parameters%cell_level_min, disp(8), mpierr)
call mpi_get_address(parameters%cell_level_max, disp(9), mpierr)
base = disp(1)
disp(:) = disp(:) - base
blocklen(1:6) = LEN_STRING
blocklen(7:7) = 1
blocklen(7:9) = 1
type(1:6) = MPI_CHARACTER
type(7:7) = MPI_INTEGER
type(7:9) = MPI_INTEGER
call mpi_type_create_struct(typesize, blocklen, disp, type, mpi_type_a2cp, mpierr)
call mpi_type_commit(mpi_type_a2cp, mpierr)
......@@ -205,6 +223,8 @@ contains
write(unit_number,'(a)') 'Output parameters:'
write(unit_number,'(a,a)') ' - cube filename: ', trim(this%cube_filename)
write(unit_number,'(a,i0)') ' - cube level: ', this%cube_level
write(unit_number,'(a,i0)') ' - minimum cell level: ', this%cell_level_min
write(unit_number,'(a,i0)') ' - maximum cell level: ', this%cell_level_max
write(unit_number,'(a,a)') '---------------------------------------------------------------------------------'
#ifdef DEBUG
......@@ -221,6 +241,8 @@ contains
character(len=LEN_STRING) :: data_directory, amr_filename, hydro_filename, info_filename, &
hydro_descriptor_filename
character(len=LEN_STRING) :: cube_filename
integer :: cell_level_max = 0
integer :: cell_level_min = 0
integer :: cube_level
character(ERR_MSG_LEN) :: error_message
integer :: ioerr
......@@ -233,7 +255,7 @@ contains
namelist / input_parameters / data_directory, amr_filename, hydro_filename, info_filename, &
hydro_descriptor_filename
namelist / output_parameters / cube_level, cube_filename
namelist / output_parameters / cube_level, cell_level_min, cell_level_max, cube_filename
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_amr2cell_hdf5_parameters begins on process', mpi_process%rank
......@@ -275,7 +297,9 @@ contains
this%hydro_descriptor_filename = hydro_descriptor_filename
this%info_filename = info_filename
this%cube_filename = cube_filename
this%cube_level = cube_level
this%cube_level = cube_level
this%cell_level_min = cell_level_min
this%cell_level_max = cell_level_max
end if
call timer%Inc_inp()
......@@ -287,11 +311,62 @@ contains
call timer%Inc_out()
#ifdef DEBUG
! check parameters on process 1:
write(ERROR_UNIT,'(a,i0)') 'Read_amr2cell_hdf5_parameter ends on process', mpi_process%rank
#endif
end subroutine Read_amr2cell_hdf5_parameters
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Write_hdf5_amr2cell_hdf5_parameters(this, hdf5_id, mpi_process)
use fortran_hdf5_constants_m, only : H5_STR_LEN
use fortran_hdf5_manage_groups_m, only : Hdf5_close_group, Hdf5_create_group
use fortran_hdf5_write_attribute_m, only : Hdf5_write_attr
use hdf5, only : HID_T
use mpi_process_m, only : mpi_process_t
integer(HID_T), intent(in) :: hdf5_id
type(mpi_process_t), intent(in) :: mpi_process
class(amr2cell_hdf5_parameters_t), intent(in) :: this
character(len=H5_STR_LEN) :: groupname
character(len=H5_STR_LEN) :: aname
integer(kind=HID_T) :: gr_id
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Write_hdf5_amr2cell_hdf5_parameters begins on process', mpi_process%rank
#endif
groupname = 'amr2cell_hdf5_parameters'
call Hdf5_create_group(hdf5_id,groupname,gr_id)
aname = 'data_dir'
call Hdf5_write_attr(gr_id,aname,this%data_dir)
aname = 'amr_filename'
call Hdf5_write_attr(gr_id,aname,this%amr_filename)
aname = 'hydro_filename'
call Hdf5_write_attr(gr_id,aname,this%hydro_filename)
aname = 'hydro_descriptor_filename'
call Hdf5_write_attr(gr_id,aname,this%hydro_descriptor_filename)
aname = 'info_filename'
call Hdf5_write_attr(gr_id,aname,this%info_filename)
aname = 'cube_filename'
call Hdf5_write_attr(gr_id,aname,this%cube_filename)
aname = 'cube_level'
call Hdf5_write_attr(gr_id,aname,this%cube_level)
aname = 'cell_level_min'
call Hdf5_write_attr(gr_id,aname,this%cell_level_min)
aname = 'cell_level_max'
call Hdf5_write_attr(gr_id,aname,this%cell_level_max)
call Hdf5_close_group(gr_id)
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Write_hdf5_amr2cell_hdf5_parameters ends on process', mpi_process%rank
#endif
end subroutine Write_hdf5_amr2cell_hdf5_parameters
end module amr2cell_hdf5_parameters_m
......@@ -131,13 +131,15 @@ contains
end subroutine Print_info_cube
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Write_hdf5_cube(this)
subroutine Write_hdf5_cube(this, amr2cell_hdf5_parameters)
use amr2cell_hdf5_parameters_m, only : amr2cell_hdf5_parameters_t
use fortran_hdf5_constants_m
use fortran_hdf5_manage_files_m
use fortran_hdf5_manage_groups_m
use hdf5
type(amr2cell_hdf5_parameters_t), intent(in) :: amr2cell_hdf5_parameters
class(cube_t), intent(in) :: this
character(len=H5_FILENAME_LEN) :: filename
......@@ -158,6 +160,7 @@ contains
groupname = 'metadata'
call Hdf5_open_group(cube_file_id, groupname, metadata_id)
call this%ramses_info%Write_hdf5(metadata_id,mpi_process)
call amr2cell_hdf5_parameters%Write(metadata_id,mpi_process)
groupname = 'cells'
call Hdf5_create_group(cube_file_id, groupname, cells_group_id)
......
......@@ -195,8 +195,11 @@ contains
end subroutine Init_cubes_array
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Write_cubes_array(this)
subroutine Write_cubes_array(this,amr2cell_hdf5_parameters)
use amr2cell_hdf5_parameters_m, only : amr2cell_hdf5_parameters_t
type(amr2cell_hdf5_parameters_t), intent(in) :: amr2cell_hdf5_parameters
class(cubes_array_t), intent(in) :: this
integer :: icube
......@@ -209,7 +212,7 @@ contains
do icube = 1, this%ncubes
if ( this%elts(icube)%process_rank == mpi_process%rank ) then
call this%elts(icube)%Write()
call this%elts(icube)%Write(amr2cell_hdf5_parameters)
end if
end do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment