Writes cfpd to a HDF5 file
subroutine write_cfpd_weights
!+ Writes [[libfida:cfpd]] to a HDF5 file
integer(HID_T) :: fid
integer(HSIZE_T), dimension(1) :: dim1
integer(HSIZE_T), dimension(2) :: dim2
integer(HSIZE_T), dimension(4) :: dim4
integer :: error
character(charlim) :: filename
!! write to file
filename=trim(adjustl(inputs%result_dir))//"/"//trim(adjustl(inputs%runid))//"_cfpd.h5"
!Open HDF5 interface
call h5open_f(error)
!Create file overwriting any existing file
call h5fcreate_f(filename, H5F_ACC_TRUNC_F, fid, error)
!Write variables
if(inputs%dist_type.eq.1) then
dim1(1) = 1
dim2 = [ctable%nenergy, ctable%nchan]
dim4 = [ctable%nenergy, ctable%nchan, fbm%nenergy, fbm%npitch]
call h5ltmake_compressed_dataset_double_f(fid, "/flux", 2, dim2, cfpd%flux, error)
call h5ltmake_compressed_dataset_double_f(fid, "/prob", 2, dim2, cfpd%prob, error)
call h5ltmake_compressed_dataset_double_f(fid, "/gam", 2, dim2, cfpd%gam, error)
call h5ltmake_compressed_dataset_double_f(fid, "/weight", 4, dim4, cfpd%weight, error)
call h5ltmake_dataset_int_f(fid,"/nenergy",0,dim1,[fbm%nenergy], error)
call h5ltmake_dataset_int_f(fid,"/npitch",0,dim1,[fbm%npitch], error)
call h5ltmake_compressed_dataset_double_f(fid,"/energy", 1, dim4(3:3), fbm%energy, error)
call h5ltmake_compressed_dataset_double_f(fid,"/pitch", 1, dim4(4:4), fbm%pitch, error)
call h5ltmake_compressed_dataset_double_f(fid,"/earray", 1, dim2(1:1), ctable%earray, error)
call h5ltset_attribute_string_f(fid,"/flux", "description", &
"CFPD flux: flux(energy,chan)", error)
call h5ltset_attribute_string_f(fid,"/flux", "units", &
"kHz", error)
call h5ltset_attribute_string_f(fid,"/prob", "description", &
"CFPD average nonzero probability: prob(energy,chan)", error)
call h5ltset_attribute_string_f(fid,"/gam", "description", &
"CFPD average nonzero gyroangle: gam(energy,chan)", error)
call h5ltset_attribute_string_f(fid,"/gam", "units", "rad", error)
call h5ltset_attribute_string_f(fid,"/weight", "description", &
"CFPD Weight Function: weight(Ch,E3,E,p), rate = sum(f*weight)", error)
call h5ltset_attribute_string_f(fid,"/weight", "units","products*cm^3*dE*dp/fast-ion*s", error)
call h5ltset_attribute_string_f(fid,"/nenergy", "description", &
"Number of distribution function energy values", error)
call h5ltset_attribute_string_f(fid,"/npitch", "description", &
"Number of distribution function pitch values", error)
call h5ltset_attribute_string_f(fid,"/energy","description", &
"Energy array", error)
call h5ltset_attribute_string_f(fid,"/energy", "units","keV", error)
call h5ltset_attribute_string_f(fid,"/pitch", "description", &
"Pitch array: p = v_parallel/v w.r.t. the magnetic field", error)
call h5ltset_attribute_string_f(fid,"/earray","description", &
"E3 energy array", error)
call h5ltset_attribute_string_f(fid,"/earray", "units","keV", error)
endif
call h5ltset_attribute_string_f(fid, "/", "version", version, error)
call h5ltset_attribute_string_f(fid,"/","description",&
"CFPD signals calculated by FIDASIM", error)
!Close file
call h5fclose_f(fid, error)
!Close HDF5 interface
call h5close_f(error)
if(inputs%verbose.ge.1) then
write(*,'(T4,a,a)') 'Charged fusion products written to: ', trim(filename)
endif
end subroutine write_cfpd_weights