Read a spectrum instance from a JSON file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(spectrum_type), | intent(inout) | :: | self |
|
||
character(len=*), | intent(in) | :: | filename | JSON file name |
subroutine readJSON(self,filename)
!! Read a spectrum instance from a JSON file.
class(spectrum_type),intent(inout) :: self !! `spectrum` instance
character(len=*),intent(in) :: filename !! JSON file name
type(json_file) :: json
logical :: found
integer(kind=ik) :: nfreqs
integer(kind=ik) :: ndirs
real(kind=rk),dimension(:),allocatable :: arr
call json % initialize()
call json % load_file(trim(filename))
call json % get('frequency',self % f,found)
call json % get('wavenumber',self % k,found)
call json % get('directions',self % th,found)
call json % get('spectrum',arr,found)
nfreqs = size(self % f)
ndirs = size(self % th)
self % spec = reshape(arr,[nfreqs,ndirs])
call json % get('depth',self % depth,found)
call json % get('elevation',self % elevation,found)
call json % get('gravity',self % grav,found)
call json % get('air_density',self % air_density,found)
call json % get('water_density',self % water_density,found)
call json % get('surface_tension',self % surface_tension,found)
call json % get('u-velocity',self % u,found)
call json % get('v-velocity',self % v,found)
call json % get('z',self % z,found)
call json % destroy()
self % df = diff(self % f)
self % dk = diff(self % k)
if(ndirs > 1)then
self % dth = diff_periodic(self % th)
else
self % dth = [1]
endif
self % cp = twopi * self % f / self % k
self % cg = twopi * self % df / self % dk
endsubroutine readJSON