181 use netcdf,
only: nf90_inq_libvers, nf90_open, nf90_create, &
182 nf90_enddef, nf90_close, nf90_sync, &
183 nf90_write, nf90_netcdf4, nf90_clobber
193 #ifdef enable_action_msgs
194 nclayer_enable_action, nclayer_actionm, &
196 nclayer_error, nclayer_warning, nclayer_info, nclayer_check, &
197 nc_set_info_display, nc_set_action_display
292 character(len=*),
intent(in) :: filename
293 logical,
intent(in),
optional :: append
297 integer :: bsize = 16777216;
299 #ifdef ENABLE_ACTION_MSGS 300 character(len=1000) :: action_str
302 if (nclayer_enable_action)
then 303 if (
present(append))
then 304 write(action_str,
"(A, L, A)")
"nc_diag_init(filename = " // trim(filename) // &
305 ", append = ", append,
")" 307 write(action_str,
"(A)")
"nc_diag_init(filename = " // trim(filename) // &
308 ", append = (not specified))" 310 call nclayer_actionm(trim(action_str))
315 call nclayer_info(
'Initializing netcdf layer library, version ' // trim(nf90_inq_libvers()) //
'...')
323 if (
present(append) .AND. (append .eqv. .true.))
then 325 call nclayer_check( nf90_open(filename, nf90_write,
ncid, &
326 bsize, cache_nelems = 16777216) )
342 call nclayer_check( nf90_create(filename, or(nf90_netcdf4, nf90_clobber),
ncid, &
343 0, bsize, cache_nelems = 16777216) )
350 call nclayer_error(
"BUG! diag_chaninfo_store is allocated, but init_done is not set!")
354 call nclayer_error(
"BUG! diag_metadata_store is allocated, but init_done is not set!")
358 call nclayer_error(
"BUG! diag_data2d_store is allocated, but init_done is not set!")
362 call nclayer_error(
"BUG! diag_data2d_store is allocated, but init_done is not set!")
382 if (
present(append) .AND. (append .eqv. .true.))
then 383 call nclayer_info(
"Loading chaninfo variables/dimensions from file:")
386 call nclayer_info(
"Loading metadata variables/dimensions from file:")
389 call nclayer_info(
"Loading data2d variables/dimensions from file:")
395 call nclayer_error(
"Attempted to initialize without closing previous nc_diag file!" &
399 //
" Attempted to open file: " // trim(filename) //
")")
437 #ifdef ENABLE_ACTION_MSGS 438 if (nclayer_enable_action)
then 439 call nclayer_actionm(
"nc_diag_lock_def()")
442 call nclayer_info(
"Locking all variable definitions!")
445 call nclayer_info(
"Defining chaninfo:")
448 call nclayer_info(
"Defining metadata:")
451 call nclayer_info(
"Defining data2d:")
454 call nclayer_info(
"All variable definitions locked!")
505 #ifdef ENABLE_ACTION_MSGS 506 if (nclayer_enable_action)
then 507 call nclayer_actionm(
"nc_diag_write()")
515 call nclayer_info(
"Defining chaninfo:")
518 call nclayer_info(
"Defining metadata:")
521 call nclayer_info(
"Defining data2d:")
528 call nclayer_check(nf90_enddef(
ncid))
531 call nclayer_info(
"Writing chaninfo:")
534 call nclayer_info(
"Writing metadata:")
537 call nclayer_info(
"Writing data2d:")
541 call nclayer_info(
"All done queuing in data, letting NetCDF take over!")
542 call nclayer_check(nf90_close(
ncid))
544 call nclayer_info(
"All done!")
579 #ifdef ENABLE_ACTION_MSGS 580 if (nclayer_enable_action)
then 581 call nclayer_actionm(
"nc_diag_finish()")
587 call nclayer_info(
"Cleaning up...")
591 call nclayer_error(
"BUG! diag_chaninfo_store is not allocated, but init_done is set!")
595 call nclayer_error(
"BUG! diag_metadata_store is not allocated, but init_done is set!")
599 call nclayer_error(
"BUG! diag_data2d_store is not allocated, but init_done is set!")
603 call nclayer_error(
"BUG! diag_data2d_store is not allocated, but init_done is set!")
620 call nclayer_error(
"Attempted to deallocate without initializing!")
671 #ifdef ENABLE_ACTION_MSGS 672 if (nclayer_enable_action)
then 673 call nclayer_actionm(
"nc_diag_flush_buffer()")
677 call nclayer_error(
"Attempted to flush nc_diag_write buffers without initializing!")
682 call nclayer_error(
"Definitions must be locked in order to flush the buffer!")
685 call nclayer_info(
"Flushing chaninfo:")
688 call nclayer_info(
"Flushing metadata:")
691 call nclayer_info(
"Flushing data2d:")
694 call nclayer_info(
"Flushing done!")
723 #ifdef ENABLE_ACTION_MSGS 724 if (nclayer_enable_action)
then 725 call nclayer_actionm(
"nc_diag_flush_to_file()")
730 call nclayer_error(
"Attempted to flush NetCDF buffers without initializing!")
733 call nclayer_check(nf90_sync(
ncid))
764 logical,
intent(in) :: enable_strict
773 call nclayer_error(
"Can't set strictness level - NetCDF4 layer not initialized yet!")
809 logical,
intent(in) :: do_trim
type(diag_data2d), allocatable diag_data2d_store
type(diag_chaninfo), allocatable diag_chaninfo_store
subroutine nc_diag_data2d_load_def
subroutine nc_diag_data2d_allocmulti(multiplier)
subroutine nc_diag_chaninfo_write_def(internal)
integer(i_byte), parameter nlayer_short
subroutine nc_diag_finish
type(diag_metadata), allocatable diag_metadata_store
integer(i_byte), parameter nlayer_double
subroutine nc_diag_flush_buffer
subroutine nc_diag_init(filename, append)
type(diag_varattr), allocatable diag_varattr_store
subroutine nc_diag_lock_def
integer(i_byte), parameter nlayer_string
subroutine nc_diag_data2d_write_data(flush_data_only)
subroutine nc_diag_set_trim(do_trim)
subroutine nc_diag_data2d_prealloc_vars(num_of_addl_vars)
subroutine nc_diag_flush_to_file
subroutine nc_diag_data2d_prealloc_vars_storage_all(num_of_addl_slots)
subroutine nc_diag_chaninfo_dim_set(nchans)
subroutine nc_diag_chaninfo_set_strict(enable_strict)
subroutine nc_diag_set_strict(enable_strict)
subroutine nc_diag_data2d_write_def(internal)
subroutine nc_diag_chaninfo_write_data(flush_data_only)
subroutine nc_diag_data2d_prealloc_vars_storage(nclayer_type, num_of_addl_slots)
subroutine nc_diag_chaninfo_prealloc_vars_storage(nclayer_type, num_of_addl_slots)
integer(i_byte), parameter nlayer_byte
character(len=200) cur_nc_file
subroutine nc_diag_data2d_set_strict(enable_strict)
subroutine nc_diag_chaninfo_allocmulti(multiplier)
subroutine nc_diag_chaninfo_load_def
subroutine nc_diag_chaninfo_prealloc_vars(num_of_addl_vars)
integer(i_byte), parameter nlayer_float
integer(i_byte), parameter nlayer_long