Commit 6568c03e authored by Roy Fabrice's avatar Roy Fabrice
Browse files

read routines and examples implementation

more metadata are written in hdf5 amr cubes
the reading procedure are finished
an example of reading program is given
everything should be tested
parent c9671aaa
......@@ -16,12 +16,12 @@ SRC = char_utils_m.f90 \
index_m.f90 \
ramses_info_m.f90 \
amr2cell_hdf5_parameters_m.f90 \
ramses_hydro_descriptor_m.f90 \
cell_m.f90 \
cells_array_m.f90 \
cube_m.f90 \
cubes_array_m.f90 \
ramses_hydro_header_m.f90 \
ramses_hydro_descriptor_m.f90 \
ramses_hydro_data_m.f90 \
ramses_amr_header_m.f90 \
ramses_amr_data_m.f90 \
......
include ../../Make.inc
EXE = read_cell_hdf5.exe
COMMONDIR = ../../common/src/
OBJDIR=../../obj/
MODDIR=../../mod/
VPATH= $(COMMONDIR):.
SRC = char_utils_m.f90 \
error_handling_m.f90 \
constants_m.f90 \
mpi_process_m.f90 \
timer_m.f90 \
mpi_utils_m.f90 \
shared_variables_m.f90 \
index_m.f90 \
ramses_info_m.f90 \
ramses_hydro_descriptor_m.f90 \
amr2cell_hdf5_parameters_m.f90 \
cell_m.f90 \
cells_array_m.f90 \
cube_m.f90 \
cubes_array_m.f90 \
ramses_hydro_header_m.f90 \
ramses_hydro_data_m.f90 \
ramses_amr_header_m.f90 \
ramses_amr_data_m.f90 \
ramses_output_m.f90 \
ramses_output_to_cells_m.f90 \
read_cell_hdf5.f90
OBJS_NOPREFIX=$(SRC:%.f90=%.o)
OBJS=$(addprefix $(OBJDIR), $(OBJS_NOPREFIX))
# variable containing if git is used or not
ifeq ($(wildcard ../../.git/HEAD ../../.git/index),)
OBJ_GIT =
USE_GIT =
else
USE_GIT = $(shell which git)
OBJ_GIT = ../../.git/HEAD ../../.git/index
endif
$(OBJDIR)%.o:%.f90
@echo "--------------------------------"
@echo building $*.o with parameters \
FC=$(FC), FCFLAGS=$(FCFLAGS)
$(FC) -c $(FCFLAGS) $< -o $@
$(MODDIR)%.mod:%.f90
@echo "--------------------------------"
@echo building $*.mod with parameters \
FC=$(FC), FCFLAGS=$(FCFLAGS)
$(FC) -c $(FCFLAGS) $<
all: directories release
release: $(EXE)
debug: FCFLAGS = $(DEBUGFLAGS)
debug: $(EXE)
$(EXE) : gitversion $(OBJS)
@echo "--------------------------------"
@echo $(ROOT_PFOF)
@echo building $(EXE) with parameters \
FC=$(FC), LDFLAGS=$(LDFLAGS)
$(FC) -g -o $(EXE) $(OBJS) $(LDFLAGS)
cleanall :
@echo "--------------------------------"
@echo cleaning compiled objects, modules and executable
rm -f $(OBJDIR)*.o $(MODDIR)*.mod *~ $(EXE) $(COMMONDIR)/gitversion.h
clean:
@echo "--------------------------------"
@echo cleaning executable
rm -f $(EXE)
# create file for git version
gitversion: $(OBJ_GIT)
ifneq ($(USE_GIT), )
@cd $(COMMONDIR) ;\
echo "#define GITVERSION \"$(shell git rev-parse HEAD)\"" > gitversion.h
else
@cd $(COMMONDIR) ;\
echo "#define GITVERSION \"no_version_found\"" > gitversion.h
endif
directories: ${MODDIR} ${OBJDIR}
${OBJDIR}:
${MKDIR_P} $@
${MODDIR}:
${MKDIR_P} $@
.PHONY: gitversion clean cleanall directories all
......@@ -56,7 +56,7 @@ program amr2cell_hdf5
type(ramses_output_t) :: ramses_output
call mpi_init(mpierr)
call Hdf5_init()
call hdf5_init()
call timer%Init()
......@@ -90,14 +90,14 @@ program amr2cell_hdf5
call cubes_array%Associate(cells_array, global_cells_per_cube)
call cubes_array%Write(amr2cell_hdf5_parameters)
call cubes_array%Write(amr2cell_hdf5_parameters, ramses_output%hydro_descriptor)
call timer%Finalize()
if ( mpi_process%rank == 0 ) then
call timer%Print(OUTPUT_UNIT)
end if
call Hdf5_finalize()
call hdf5_finalize()
call mpi_finalize(mpierr)
end program amr2cell_hdf5
......@@ -321,7 +321,7 @@ contains
subroutine Read_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_manage_groups_m, only : Hdf5_close_group, Hdf5_open_group
use fortran_hdf5_read_attribute_m, only : Hdf5_read_attr
use hdf5, only : HID_T
use mpi_process_m, only : mpi_process_t
......
......@@ -40,8 +40,8 @@ module cell_m
public :: cell_t, Init_cell_mpi_type
type cell_t(n_non_thermal_pressures, n_passive_scalars)
integer, len :: n_non_thermal_pressures
integer, len :: n_passive_scalars
integer(kind=4), len :: n_non_thermal_pressures
integer(kind=4), len :: n_passive_scalars
integer(kind=4) :: level
integer(kind=4) :: process_id
integer(kind=4) :: cube_id
......@@ -56,7 +56,8 @@ module cell_m
procedure :: Is_eq
procedure :: Is_sup
procedure :: Print => Print_cell
procedure :: Write => Write_hdf5_cell
procedure :: Read_hdf5 => Read_hdf5_cell
procedure :: Write_hdf5 => Write_hdf5_cell
end type cell_t
contains
......@@ -250,6 +251,56 @@ contains
end subroutine Print_cell
!------------------------------------------------------------------------------------------------------------------------------------
subroutine Read_hdf5_cell(this, hdf5_id)
use char_utils_m, only : Int_to_char12, Int_to_char5
use fortran_hdf5_constants_m
use fortran_hdf5_manage_groups_m
use fortran_hdf5_read_attribute_m
use fortran_hdf5_read_data_m
use hdf5
class(cell_t(*,*)),intent(inout) :: this
integer(kind=hid_t),intent(in) :: hdf5_id
character(len=H5_STR_LEN) :: attr_name
character(len=H5_STR_LEN) :: groupname
integer(kind=hid_t) :: cell_gr_id
integer :: idim
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_cell begins on process', mpi_process%rank
#endif
call timer%Set_ref()
attr_name = 'identity'
call Hdf5_Read_data(hdf5_id, attr_name, this%identity)
attr_name = 'level'
call Hdf5_Read_attr(hdf5_id, attr_name, this%level)
attr_name = 'position'
call Hdf5_Read_attr(hdf5_id, attr_name, 3, this%position)
attr_name = 'velocity field'
call Hdf5_Read_attr(hdf5_id, attr_name, 3, this%velocity_field)
attr_name = 'density'
call Hdf5_Read_attr(hdf5_id, attr_name, this%density)
attr_name = 'thermal pressure'
call Hdf5_Read_attr(hdf5_id, attr_name, this%thermal_pressure)
if ( this%n_non_thermal_pressures /= 0 ) then
attr_name = 'non thermal pressures'
! call Hdf5_Read_attr(hdf5_id, attr_name, this%n_non_thermal_pressures, this%non_thermal_pressures)
end if
if( this%n_passive_scalars /= 0 ) then
attr_name = 'passive scalars'
call Hdf5_Read_attr(hdf5_id, attr_name, this%n_passive_scalars, this%passive_scalars)
end if
call timer%Inc_inp()
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_cell ends on process', mpi_process%rank
#endif
end subroutine Read_hdf5_cell
!------------------------------------------------------------------------------------------------------------------------------------
subroutine Write_hdf5_cell(this, hdf5_id)
......
......@@ -327,7 +327,7 @@ contains
end subroutine Distribute_cells_array
!------------------------------------------------------------------------------------------------------------------------------------
subroutine Read_hdf5_cells_array(this, hdf5_id)
subroutine Read_hdf5_cells_array(this, hdf5_id, ramses_hydro_descriptor)
use char_utils_m, only : int_to_char12
use fortran_hdf5_constants_m
......@@ -335,23 +335,28 @@ contains
use fortran_hdf5_read_attribute_m
use fortran_hdf5_read_data_m
use hdf5
use ramses_hydro_descriptor_m, only : ramses_hydro_descriptor_t
class(cells_array_t),intent(out) :: this
integer(kind=hid_t),intent(in) :: hdf5_id
type(ramses_hydro_descriptor_t), intent(in) :: ramses_hydro_descriptor
character(len=H5_STR_LEN) :: attr_name
character(len=H5_STR_LEN) :: groupname
integer(kind=hid_t) :: cell_gr_id
integer :: icell
integer(IDKIND) :: ncells
integer(kind=4) :: nps
integer(kind=4) :: nthp
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_cells_array begins on process', mpi_process%rank
#endif
! read number of cells in this array
attr_name = 'ncells'
call Hdf5_read_data(hdf5_id,attr_name,ncells)
call Hdf5_read_data(hdf5_id,attr_name, ncells)
call this%Allocate(nthp,nps,ncells)
call this%Allocate(ramses_hydro_descriptor%n_non_thermal_pressures,ramses_hydro_descriptor%n_passive_scalars,ncells)
do icell = 1, this%ncells
groupname = 'cell_'//int_to_char12(icell)
......@@ -676,7 +681,7 @@ contains
do icell = 1, this%ncells
groupname = 'cell_'//int_to_char12(icell)
call Hdf5_create_group(hdf5_id, groupname, cell_gr_id)
call this%elts(icell)%Write(cell_gr_id)
call this%elts(icell)%Write_hdf5(cell_gr_id)
call Hdf5_close_group(cell_gr_id)
end do
......@@ -684,7 +689,6 @@ contains
write(ERROR_UNIT,'(a,i0)') 'Write_hdf5_cells_array ends on process', mpi_process%rank
#endif
end subroutine Write_hdf5_cells_array
end module cells_array_m
......@@ -140,18 +140,23 @@ contains
use fortran_hdf5_manage_groups_m
use fortran_hdf5_read_attribute_m
use hdf5
use ramses_hydro_descriptor_m, only : ramses_hydro_descriptor_t
class(cube_t), intent(out) :: this
character(len=H5_FILENAME_LEN), intent(in) :: filename
type(amr2cell_hdf5_parameters_t), intent(out) :: amr2cell_hdf5_parameters
integer :: alloc_stat
integer(kind=hid_t) :: cells_group_id
integer(kind=hid_t) :: cube_file_id
integer(kind=hid_t) :: cube_info_id
character(len=ERR_MSG_LEN) :: error_message
character(len=H5_STR_LEN) :: groupname
integer :: icell
integer(HID_T) :: metadata_id
character(len=H5_STR_LEN) :: metadata_name
type(ramses_hydro_descriptor_t) :: ramses_hydro_descriptor
character(len=H5_FILENAME_LEN) :: tmpchar
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_cube begins on process', mpi_process%rank
......@@ -164,6 +169,12 @@ contains
call Hdf5_open_group(cube_file_id, groupname, metadata_id)
call this%ramses_info%Read_hdf5(metadata_id,mpi_process)
call amr2cell_hdf5_parameters%Read_hdf5(metadata_id,mpi_process)
call ramses_hydro_descriptor%Read_hdf5(metadata_id)
allocate(this%center_position(this%ramses_info%ndim), stat=alloc_stat, errmsg=error_message)
if(alloc_stat /= 0) then
call Allocate_error('this%center_position','Init_cube', error_message, alloc_stat, mpi_process%rank)
end if
! write metadata
groupname = 'cube_info'
......@@ -172,7 +183,8 @@ contains
metadata_name = 'level'
call Hdf5_read_attr(cube_info_id, metadata_name, this%level)
metadata_name = 'filename'
call Hdf5_read_attr(cube_info_id, metadata_name, H5_FILENAME_LEN, this%filename)
call Hdf5_read_attr(cube_info_id, metadata_name, H5_FILENAME_LEN, tmpchar)
this%filename = tmpchar
metadata_name = 'size'
call Hdf5_read_attr(cube_info_id, metadata_name, this%size)
metadata_name = 'center_position'
......@@ -189,7 +201,7 @@ contains
groupname = 'cells'
call Hdf5_open_group(cube_file_id, groupname, cells_group_id)
call this%cells_array%Read(cells_group_id)
call this%cells_array%Read_hdf5(cells_group_id, ramses_hydro_descriptor)
call Hdf5_close_group(cells_group_id)
call Hdf5_close_file(cube_file_id)
......@@ -202,7 +214,7 @@ contains
end subroutine Read_hdf5_cube
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Write_hdf5_cube(this, amr2cell_hdf5_parameters)
subroutine Write_hdf5_cube(this, amr2cell_hdf5_parameters, ramses_hydro_descriptor)
use amr2cell_hdf5_parameters_m, only : amr2cell_hdf5_parameters_t
use fortran_hdf5_constants_m
......@@ -210,8 +222,10 @@ contains
use fortran_hdf5_manage_groups_m
use fortran_hdf5_write_attribute_m
use hdf5
use ramses_hydro_descriptor_m, only : ramses_hydro_descriptor_t
type(amr2cell_hdf5_parameters_t), intent(in) :: amr2cell_hdf5_parameters
type(ramses_hydro_descriptor_t), intent(in) :: ramses_hydro_descriptor
class(cube_t), intent(in) :: this
integer(kind=hid_t) :: cells_group_id
......@@ -235,6 +249,7 @@ contains
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_hdf5(metadata_id,mpi_process)
call ramses_hydro_descriptor%Write_hdf5(metadata_id)
! write metadata
groupname = 'cube_info'
......@@ -260,7 +275,7 @@ contains
groupname = 'cells'
call Hdf5_create_group(cube_file_id, groupname, cells_group_id)
call this%cells_array%Write(cells_group_id)
call this%cells_array%Write_hdf5(cells_group_id)
call Hdf5_close_group(cells_group_id)
call Hdf5_close_file(cube_file_id)
......
......@@ -195,11 +195,13 @@ contains
end subroutine Init_cubes_array
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Write_cubes_array(this,amr2cell_hdf5_parameters)
subroutine Write_cubes_array(this,amr2cell_hdf5_parameters, ramses_hydro_descriptor)
use amr2cell_hdf5_parameters_m, only : amr2cell_hdf5_parameters_t
use ramses_hydro_descriptor_m, only : ramses_hydro_descriptor_t
type(amr2cell_hdf5_parameters_t), intent(in) :: amr2cell_hdf5_parameters
type(ramses_hydro_descriptor_t), intent(in) :: ramses_hydro_descriptor
class(cubes_array_t), intent(in) :: this
integer :: icube
......@@ -212,7 +214,7 @@ contains
do icube = 1, this%ncubes
if ( this%elts(icube)%process_rank == mpi_process%rank ) then
call this%elts(icube)%Write_hdf5(amr2cell_hdf5_parameters)
call this%elts(icube)%Write_hdf5(amr2cell_hdf5_parameters, ramses_hydro_descriptor)
end if
end do
......
......@@ -146,13 +146,57 @@ contains
end subroutine Read_ramses_hydro_descriptor
!------------------------------------------------------------------------------------------------------------------------------------
subroutine Read_hdf5_ramses_hydro_descriptor
subroutine Read_hdf5_ramses_hydro_descriptor(this, hdf5_id)
use error_handling_m, only : Allocate_error, IO_error, ERR_MSG_LEN
use fortran_hdf5_constants_m, only : H5_STR_LEN
use fortran_hdf5_manage_groups_m, only : Hdf5_close_group, Hdf5_open_group
use fortran_hdf5_read_attribute_m, only : Hdf5_read_attr
use hdf5, only : HID_T
integer(HID_T), intent(in) :: hdf5_id
class(ramses_hydro_descriptor_t), intent(out) :: this
integer :: alloc_stat
character(len=H5_STR_LEN) :: aname
character(len=ERR_MSG_LEN) :: error_message
integer(kind=HID_T) :: gr_id
character(len=H5_STR_LEN) :: groupname
integer(kind=4) :: iname
character(len=H5_STR_LEN), allocatable, dimension(:) :: tmpchar
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_ramses_hydro_descriptor begins on process', mpi_process%rank
#endif
call timer%Set_ref()
call timer%Set_ref()
groupname = 'ramses_hydro_descriptor_info'
call Hdf5_open_group(hdf5_id,groupname,gr_id)
aname = 'nvar'
call Hdf5_read_attr(gr_id, aname, this%nvar)
aname = 'n_non_thermal_pressures'
call Hdf5_read_attr(gr_id, aname, this%n_non_thermal_pressures)
aname = 'n_passive_scalars'
call Hdf5_read_attr(gr_id, aname, this%n_passive_scalars)
aname = 'variable_names'
allocate(tmpchar(this%nvar), stat=alloc_stat, errmsg=error_message)
if(alloc_stat /= 0) then
call Allocate_error('tmpchar','Read_hdf5_ramses_hydro_descriptor', &
error_message, alloc_stat, mpi_process%rank)
end if
allocate(this%variable_names(this%nvar), stat=alloc_stat, errmsg=error_message)
if(alloc_stat /= 0) then
call Allocate_error('this%variable_names','Read_hdf5_ramses_hydro_descriptor', &
error_message, alloc_stat, mpi_process%rank)
end if
call Hdf5_read_attr(gr_id, aname, H5_STR_LEN, this%nvar, tmpchar)
do iname = 1, this%nvar
this%variable_names(iname)%string = tmpchar(iname)
end do
call Hdf5_close_group(gr_id)
call timer%Inc_inp()
#ifdef DEBUG
......@@ -164,6 +208,7 @@ call timer%Inc_inp()
!------------------------------------------------------------------------------------------------------------------------------------
subroutine Write_hdf5_ramses_hydro_descriptor(this, hdf5_id)
use error_handling_m, only : Allocate_error, IO_error, ERR_MSG_LEN
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
......@@ -172,9 +217,13 @@ call timer%Inc_inp()
class(ramses_hydro_descriptor_t), intent(in) :: this
integer(HID_T), intent(in) :: hdf5_id
character(len=H5_STR_LEN) :: groupname
integer :: alloc_stat
character(len=H5_STR_LEN) :: aname
character(len=ERR_MSG_LEN) :: error_message
integer(kind=HID_T) :: gr_id
character(len=H5_STR_LEN) :: groupname
integer(kind=4) :: iname
character(len=H5_STR_LEN), allocatable, dimension(:) :: tmpchar
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Write_hdf5_ramses_hydro_descriptor begins on process', mpi_process%rank
......@@ -192,7 +241,15 @@ call timer%Inc_inp()
aname = 'n_passive_scalars'
call Hdf5_write_attr(gr_id, aname, this%n_passive_scalars)
aname = 'variable_names'
call Hdf5_write_attr(gr_id, aname, nvar, this%variable_names)
allocate(tmpchar(this%nvar), stat=alloc_stat, errmsg=error_message)
if(alloc_stat /= 0) then
call Allocate_error('tmpchar','Write_hdf5_ramses_hydro_descriptor', &
error_message, alloc_stat, mpi_process%rank)
end if
do iname = 1, this%nvar
tmpchar(iname) = this%variable_names(iname)%string
end do
call Hdf5_write_attr(gr_id, aname, this%nvar, tmpchar)
call Hdf5_close_group(gr_id)
......
!------------------------------------------------------------------------------------------------------------------------------------
! Copyright 2018 Fabrice Roy
!
! Contact: fabrice.roy@obspm.fr
!
! This file is part of pFoF.
!
! pFoF is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! pFoF is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with pFoF. If not, see <http://www.gnu.org/licenses/>.
!> @file
!! Program that reads HDF5 'amr_cube' files
!! @brief
!!
!! @author Fabrice Roy
!> Program that reads HDF5 'amr_cube' files
!------------------------------------------------------------------------------------------------------------------------------------
program read_cell_hdf5
use amr2cell_hdf5_parameters_m, only : amr2cell_hdf5_parameters_t
use error_handling_m, only : Allocate_error, ERR_MSG_LEN
use cell_m, only : cell_t
use cells_array_m, only : cells_array_t
use char_utils_m
use constants_m, only : IDKIND
use cube_m, only : cube_t
use fortran_hdf5_manage_interface_m
use fortran_hdf5_constants_m
use iso_fortran_env, only : OUTPUT_UNIT
use mpi
use mpi_utils_m
use ramses_info_m, only : ramses_info_t
use ramses_output_m, only : ramses_output_t
use ramses_output_to_cells_m, only : ramses_output_to_cells
use shared_variables_m
implicit none
type(amr2cell_hdf5_parameters_t) :: amr2cell_hdf5_parameters
type(cells_array_t) :: cells_array
type(cube_t) :: cube
character(H5_FILENAME_LEN) :: filename
integer(4) :: first_file, last_file, nfile
integer :: ifile
integer :: mpierr
call mpi_init(mpierr)
call hdf5_init()
call timer%Init()
call mpi_process%Init()
nfile = 8
call Mpi_distribution(first_file, last_file, nfile, mpi_process)
do ifile = first_file, last_file
filename = 'cube_amr_hydro'//Int_to_char5(ifile)//'.h5'
call cube%Read_hdf5(filename, amr2cell_hdf5_parameters)
end do
call timer%Finalize()
call timer%Print(OUTPUT_UNIT)
call hdf5_finalize()
call mpi_finalize(mpierr)
end program read_cell_hdf5
\ No newline at end of file
This diff is collapsed.
!------------------------------------------------------------------------------------------------------------------------------------
! Copyright 2018 Fabrice Roy
!
! Contact: fabrice.roy@obspm.fr
!
! This file is part of pFoF.
!
! pFoF is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.