From 4bc81d501dc3ce1ba2c4200e502c305f9b007832 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 17 Jan 2012 13:13:39 -0500 Subject: [PATCH] Started HDF5 interface. --- src/DEPENDENCIES | 5 +++ src/OBJECTS | 1 + src/global.F90 | 11 +++++++ src/hdf5_interface.F90 | 72 ++++++++++++++++++++++++++++++++++++++++++ src/initialize.F90 | 21 +++++++++--- src/main.F90 | 11 +++++++ 6 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 src/hdf5_interface.F90 diff --git a/src/DEPENDENCIES b/src/DEPENDENCIES index 5016e4278b..bdcbc62d06 100644 --- a/src/DEPENDENCIES +++ b/src/DEPENDENCIES @@ -67,6 +67,9 @@ global.o: source_header.o global.o: tally_header.o global.o: timing.o +hdf5_interface.o: constants.o +hdf5_interface.o: global.o + initialize.o: ace.o initialize.o: bank_header.o initialize.o: constants.o @@ -77,6 +80,7 @@ initialize.o: error.o initialize.o: geometry.o initialize.o: geometry_header.o initialize.o: global.o +initialize.o: hdf5_interface.o initialize.o: input_xml.o initialize.o: output.o initialize.o: random_lcg.o @@ -117,6 +121,7 @@ interpolation.o: string.o main.o: constants.o main.o: global.o +main.o: hdf5_interface.o main.o: initialize.o main.o: intercycle.o main.o: output.o diff --git a/src/OBJECTS b/src/OBJECTS index e7fc0db9bd..2cc565cf0e 100644 --- a/src/OBJECTS +++ b/src/OBJECTS @@ -14,6 +14,7 @@ fission.o \ geometry.o \ geometry_header.o \ global.o \ +hdf5_interface.o \ initialize.o \ intercycle.o \ interpolation.o \ diff --git a/src/global.F90 b/src/global.F90 index 5e8f5334d4..f7a5f482b2 100644 --- a/src/global.F90 +++ b/src/global.F90 @@ -17,6 +17,10 @@ module global use mpi #endif +#ifdef HDF5 + use hdf5 +#endif + implicit none save @@ -163,6 +167,13 @@ module global real(8) :: plot_basis(6) real(8) :: pixel + ! ============================================================================ + ! HDF5 VARIABLES + +#ifdef HDF5 + integer(HID_T) :: hdf5_output_file +#endif + ! ============================================================================ ! MISCELLANEOUS VARIABLES diff --git a/src/hdf5_interface.F90 b/src/hdf5_interface.F90 new file mode 100644 index 0000000000..d394c41973 --- /dev/null +++ b/src/hdf5_interface.F90 @@ -0,0 +1,72 @@ +module hdf5_interface + + use constants + use global + +#ifdef HDF5 + use hdf5, only: HSIZE_T, h5open_f, h5fcreate_f, h5fclose_f, h5close_f + use h5lt, only: h5ltmake_dataset_int_f +#endif + + implicit none + +contains + +#ifdef HDF5 + +!=============================================================================== +! OPEN_HDF5_OUTPUT +!=============================================================================== + + subroutine open_hdf5_output() + + character(9), parameter :: filename = "output.h5" ! File name + integer :: error ! Error flag + + ! Initialize FORTRAN interface. + call h5open_f (error) + + ! Create a new file using default properties. + call h5fcreate_f(filename, H5F_ACC_TRUNC_F, hdf5_output_file, error) + + end subroutine open_hdf5_output + +!=============================================================================== +! WRITE_HDF5_SUMMARY +!=============================================================================== + + subroutine write_hdf5_summary() + + integer :: error ! Error flag + integer :: rank = 1 + integer(HSIZE_T) :: dims(1) = (/1/) + + ! Write version information + call h5ltmake_dataset_int_f(hdf5_output_file, "/version_major", rank, & + dims, (/ VERSION_MAJOR /), error) + call h5ltmake_dataset_int_f(hdf5_output_file, "/version_minor", rank, & + dims, (/ VERSION_MINOR /), error) + call h5ltmake_dataset_int_f(hdf5_output_file, "/version_release", rank, & + dims, (/ VERSION_RELEASE /), error) + + end subroutine write_hdf5_summary + +!=============================================================================== +! CLOSE_HDF5_OUTPUT +!=============================================================================== + + subroutine close_hdf5_output() + + integer :: error ! Error flag + + ! Terminate access to the file. + call h5fclose_f(hdf5_output_file, error) + + ! Close FORTRAN interface. + call h5close_f(error) + + end subroutine close_hdf5_output + +#endif + +end module hdf5_interface diff --git a/src/initialize.F90 b/src/initialize.F90 index 1bcae2ef36..86e6b1dba4 100644 --- a/src/initialize.F90 +++ b/src/initialize.F90 @@ -25,6 +25,10 @@ module initialize use mpi #endif +#ifdef HDF5 + use hdf5_interface, only: open_hdf5_output +#endif + implicit none type(DictionaryII), pointer :: build_dict => null() @@ -50,13 +54,20 @@ contains ! Read command line arguments call read_command_line() - if (master) call create_summary_file() - ! Print the OpenMC title and version/date/time information - if (master) call title() + if (master) then + ! Create summary.out file + call create_summary_file() - ! Print initialization header block - if (master) call header("INITIALIZATION", level=1) +#ifdef HDF5 + ! Open HDF5 output file for writing + call open_hdf5_output() +#endif + + ! Display title and initialization header + call title() + call header("INITIALIZATION", level=1) + end if ! Initialize random number generator call initialize_prng() diff --git a/src/main.F90 b/src/main.F90 index 199da60dc0..7d651ace14 100644 --- a/src/main.F90 +++ b/src/main.F90 @@ -19,6 +19,10 @@ program main use mpi #endif +#ifdef HDF5 + use hdf5_interface, only: write_hdf5_summary, close_hdf5_output +#endif + implicit none ! start timer for total run time @@ -45,6 +49,13 @@ program main ! deallocate arrays call free_memory() +#ifdef HDF5 + if (master) then + call write_hdf5_summary() + call close_hdf5_output() + end if +#endif + #ifdef MPI ! If MPI is in use and enabled, terminate it call MPI_FINALIZE(mpi_err)