Skip to content

Commit

Permalink
Merge pull request #266 from NCAR/obs_seq_to_netcdf-fix
Browse files Browse the repository at this point in the history
bug-fix: Obs_seq_to_netcdf appending files
  • Loading branch information
hkershaw-brown committed Aug 5, 2021
2 parents d246183 + 18e283a commit c813533
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
16 changes: 14 additions & 2 deletions assimilation_code/programs/obs_seq_to_netcdf/obs_seq_to_netcdf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ program obs_seq_to_netcdf

integer :: i, io, obsindex, ncunit
integer :: Nepochs
! Keep track of epoch files created during this run of obs_seq_to_netcdf
logical, allocatable, dimension(:) :: epoch_file_created

type(schedule_type) :: schedule
type(time_type) :: TimeMin, TimeMax ! of the entire period of interest
Expand Down Expand Up @@ -198,6 +200,8 @@ program obs_seq_to_netcdf

allocate(total_obs_in_epoch(Nepochs))
total_obs_in_epoch = 0
allocate(epoch_file_created(Nepochs))
epoch_file_created(:) = .false.

call get_time_from_schedule(TimeMin, schedule, 1, 1)
call get_time_from_schedule(TimeMax, schedule, Nepochs, 2)
Expand Down Expand Up @@ -444,8 +448,15 @@ program obs_seq_to_netcdf

if ( file_exist(ncName) .and. append_to_netcdf ) then
ncunit = NC_Compatibility_Check(ncName, iepoch)
else
ncunit = InitNetCDF(ncName, iepoch)
else
if (.not. epoch_file_created(iepoch)) then
write(string1,*) 'creating file ', ncName
call error_handler(E_MSG,'obs_seq_to_netcdf',string1,source)
ncunit = InitNetCDF(ncName, iepoch)
epoch_file_created(iepoch) = .true.
else
ncunit = NC_Compatibility_Check(ncName, iepoch)
endif
endif

ngood = 0
Expand Down Expand Up @@ -576,6 +587,7 @@ program obs_seq_to_netcdf
deallocate(module_obs_copy_names, module_qc_copy_names)

deallocate(obs_seq_filenames)
deallocate(epoch_file_created)

call error_handler(E_MSG,'obs_seq_to_netcdf','Finished successfully.',source)
call finalize_utilities()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ program obs_seq_to_netcdf

integer :: i, io, obsindex, ncunit
integer :: Nepochs
! Keep track of epoch files created during this run of obs_seq_to_netcdf
logical, allocatable, dimension(:) :: epoch_file_created

type(schedule_type) :: schedule
type(time_type) :: TimeMin, TimeMax ! of the entire period of interest
Expand Down Expand Up @@ -216,6 +218,8 @@ program obs_seq_to_netcdf

allocate(total_obs_in_epoch(Nepochs))
total_obs_in_epoch = 0
allocate(epoch_file_created(Nepochs))
epoch_file_created(:) = .false.

call get_time_from_schedule(TimeMin, schedule, 1, 1)
call get_time_from_schedule(TimeMax, schedule, Nepochs, 2)
Expand Down Expand Up @@ -464,8 +468,14 @@ program obs_seq_to_netcdf
if ( file_exist(ncName) .and. append_to_netcdf ) then
ncunit = NC_Compatibility_Check(ncName, iepoch)
else
ncunit = InitNetCDF(ncName, iepoch)
append_to_netcdf = .true.
if (.not. epoch_file_created(iepoch)) then
write(string1,*) 'creating file ', ncName
call error_handler(E_MSG,'obs_seq_to_netcdf',string1,source)
ncunit = InitNetCDF(ncName, iepoch)
epoch_file_created(iepoch) = .true.
else
ncunit = NC_Compatibility_Check(ncName, iepoch)
endif
endif

ngood = 0
Expand Down Expand Up @@ -604,6 +614,7 @@ program obs_seq_to_netcdf
deallocate(module_obs_copy_names, module_qc_copy_names)

deallocate(obs_seq_filenames)
deallocate(epoch_file_created)

call error_handler(E_MSG,'obs_seq_to_netcdf','Finished successfully.',source)
call finalize_utilities()
Expand Down

0 comments on commit c813533

Please sign in to comment.