221 #ifdef enable_action_msgs
222 nclayer_enable_action, nclayer_actionm, &
224 nclayer_error, nclayer_warning, nclayer_info, nclayer_check
237 use netcdf,
only: nf90_inquire, nf90_inq_dimid, &
238 nf90_inquire_dimension, nf90_inquire_variable, nf90_def_dim, &
239 nf90_def_var, nf90_get_var, nf90_put_var, &
240 nf90_def_var_deflate, nf90_def_var_chunking, &
241 nf90_byte, nf90_short, nf90_int, nf90_float, nf90_double, &
243 nf90_ebaddim, nf90_noerr, nf90_max_name, nf90_chunked
364 integer(i_long),
intent(in) :: nchans
365 #ifdef ENABLE_ACTION_MSGS 366 character(len=1000) :: action_str
368 if (nclayer_enable_action)
then 369 write(action_str,
"(A, I0, A)")
"nc_diag_chaninfo_dim_set(nchans = ", nchans,
")" 370 call nclayer_actionm(trim(action_str))
377 call nclayer_error(
"Critical error - specified a nchan < 1!")
382 call nclayer_error(
"nchans already set!")
387 call nclayer_error(
"NetCDF4 layer not initialized yet!")
431 integer(i_long),
intent(in) :: multiplier
432 #ifdef ENABLE_ACTION_MSGS 433 character(len=1000) :: action_str
435 if (nclayer_enable_action)
then 436 write(action_str,
"(A, I0, A)")
"nc_diag_chaninfo_allocmulti(multiplier = ", multiplier,
")" 437 call nclayer_actionm(trim(action_str))
491 integer(i_long) :: ndims, nvars, var_index, type_index
492 integer(i_long) :: rel_index, i, j
496 character(len=NF90_MAX_NAME) :: tmp_var_name
497 integer(i_long) :: tmp_var_type, tmp_var_ndims
499 integer(i_long),
dimension(:),
allocatable :: tmp_var_dimids, tmp_var_dim_sizes
500 character(len=NF90_MAX_NAME) ,
allocatable :: tmp_var_dim_names(:)
503 logical :: is_nchans_var
507 integer(i_byte),
dimension(:),
allocatable :: byte_buffer
508 integer(i_short),
dimension(:),
allocatable :: short_buffer
509 integer(i_long),
dimension(:),
allocatable :: long_buffer
511 real(r_single),
dimension(:),
allocatable :: rsingle_buffer
512 real(r_double),
dimension(:),
allocatable :: rdouble_buffer
514 character(1),
dimension(:,:),
allocatable :: string_buffer
517 integer(i_long) :: dim_nc_err
520 call nclayer_check(nf90_inquire(
ncid, ndimensions = ndims, &
528 if (dim_nc_err == nf90_ebaddim)
then 530 else if (dim_nc_err /= nf90_noerr)
then 533 call nclayer_check(dim_nc_err)
542 do var_index = 1, nvars
544 call nclayer_check(nf90_inquire_variable(
ncid, var_index, name = tmp_var_name, ndims = tmp_var_ndims))
547 allocate(tmp_var_dimids(tmp_var_ndims))
548 allocate(tmp_var_dim_names(tmp_var_ndims))
549 allocate(tmp_var_dim_sizes(tmp_var_ndims))
552 call nclayer_check(nf90_inquire_variable(
ncid, var_index, dimids = tmp_var_dimids, &
553 xtype = tmp_var_type))
555 if ((tmp_var_ndims == 1) .OR. &
556 ((tmp_var_ndims == 2) .AND. (tmp_var_type == nf90_char)))
then 558 is_nchans_var = .false.
565 do i = 1, tmp_var_ndims
566 call nclayer_check(nf90_inquire_dimension(
ncid, tmp_var_dimids(i), tmp_var_dim_names(i), &
567 tmp_var_dim_sizes(i)))
569 if (tmp_var_dim_names(i) ==
"nchans") is_nchans_var = .true.
572 if (is_nchans_var)
then 599 if (tmp_var_type == nf90_byte)
then 603 call nclayer_check(nf90_get_var(
ncid, var_index, byte_buffer))
613 deallocate(byte_buffer)
616 else if (tmp_var_type == nf90_short)
then 620 call nclayer_check(nf90_get_var(
ncid, var_index, short_buffer))
630 deallocate(short_buffer)
633 else if (tmp_var_type == nf90_int)
then 637 call nclayer_check(nf90_get_var(
ncid, var_index, long_buffer))
647 deallocate(long_buffer)
650 else if (tmp_var_type == nf90_float)
then 654 call nclayer_check(nf90_get_var(
ncid, var_index, rsingle_buffer))
664 deallocate(rsingle_buffer)
667 else if (tmp_var_type == nf90_double)
then 671 call nclayer_check(nf90_get_var(
ncid, var_index, rdouble_buffer))
681 deallocate(rdouble_buffer)
684 else if (tmp_var_type == nf90_char)
then 688 call nclayer_check(nf90_get_var(
ncid, var_index, string_buffer))
698 deallocate(string_buffer)
706 call nclayer_error(
"NetCDF4 type invalid!")
709 print *, trim(tmp_var_name),
"rel index", rel_index
734 deallocate(tmp_var_dimids)
735 deallocate(tmp_var_dim_names)
736 deallocate(tmp_var_dim_sizes)
835 logical,
intent(in),
optional :: internal
838 integer(i_llong) :: curdatindex
839 integer(i_byte) :: data_type
840 integer(i_long) :: data_type_index
841 character(len=100) :: data_name
842 integer(i_long) :: nc_data_type
844 integer(i_long) :: tmp_dim_id
845 character(len=120) :: data_dim_name
847 character(len=:),
allocatable :: string_arr(:)
849 #ifdef ENABLE_ACTION_MSGS 850 character(len=1000) :: action_str
852 if (nclayer_enable_action)
then 853 if (
present(internal))
then 854 write(action_str,
"(A, L, A)")
"nc_diag_chaninfo_write_def(internal = ", internal,
")" 856 write(action_str,
"(A)")
"nc_diag_chaninfo_write_def(internal = (not specified))" 858 call nclayer_actionm(trim(action_str))
884 data_type_index = 1 + &
887 call nclayer_info(
"chaninfo: defining " // trim(data_name))
890 if (data_type ==
nlayer_byte) nc_data_type = nf90_byte
891 if (data_type ==
nlayer_short) nc_data_type = nf90_short
892 if (data_type ==
nlayer_long) nc_data_type = nf90_int
893 if (data_type ==
nlayer_float) nc_data_type = nf90_float
898 print *,
"chaninfo part 1" 917 write (data_dim_name,
"(A, A)") trim(data_name),
"_maxstrlen" 922 allocate(
character(10000) :: string_arr(diag_chaninfo_store%var_usage(curdatindex)))
925 string_arr = diag_chaninfo_store%ci_string(data_type_index:(data_type_index + &
926 diag_chaninfo_store%var_usage(curdatindex) - 1))
932 diag_chaninfo_store%max_str_lens(curdatindex) = &
938 call nclayer_check(nf90_def_dim(
ncid, data_dim_name, &
939 diag_chaninfo_store%max_str_lens(curdatindex), &
942 print *,
"Defining char var type..." 946 call nclayer_check(nf90_def_var(
ncid, diag_chaninfo_store%names(curdatindex), &
947 nc_data_type, (/ tmp_dim_id, diag_chaninfo_store%nchans_dimid /), &
948 diag_chaninfo_store%var_ids(curdatindex)))
950 print *,
"Done defining char var type..." 953 deallocate(string_arr)
958 call nclayer_check(nf90_def_var(
ncid, diag_chaninfo_store%names(curdatindex), &
959 nc_data_type, diag_chaninfo_store%nchans_dimid, &
960 diag_chaninfo_store%var_ids(curdatindex)))
964 print *,
"chaninfo part 2" 969 diag_chaninfo_store%types(curdatindex), &
970 diag_chaninfo_store%var_ids(curdatindex))
979 call nclayer_check(nf90_def_var_chunking(
ncid, diag_chaninfo_store%var_ids(curdatindex), &
980 nf90_chunked, (/ diag_chaninfo_store%max_str_lens(curdatindex), diag_chaninfo_store%nchans /)))
982 call nclayer_check(nf90_def_var_chunking(
ncid, diag_chaninfo_store%var_ids(curdatindex), &
983 nf90_chunked, (/ diag_chaninfo_store%nchans /)))
987 call nclayer_check(nf90_def_var_deflate(
ncid, diag_chaninfo_store%var_ids(curdatindex), &
993 diag_chaninfo_store%def_lock = .true.
996 if(.NOT.
present(internal)) &
997 call nclayer_error(
"Can't write definitions - definitions have already been written and locked!")
1000 call nclayer_error(
"Can't write definitions - number of chans not set yet!")
1006 call nclayer_error(
"Can't write definitions - NetCDF4 layer not initialized yet!")
1111 logical,
intent(in),
optional :: flush_data_only
1113 integer(i_byte) :: data_type
1114 integer(i_long) :: data_type_index
1115 character(len=100) :: data_name
1117 character(len=1000) :: nchan_empty_msg
1119 integer(i_llong) :: curdatindex, j
1120 integer(i_long) :: string_arr_maxlen
1122 character(len=:),
allocatable :: string_arr(:)
1124 #ifdef ENABLE_ACTION_MSGS 1125 character(len=1000) :: action_str
1127 if (nclayer_enable_action)
then 1128 if (
present(flush_data_only))
then 1129 write(action_str,
"(A, L, A)")
"nc_diag_chaninfo_write_data(flush_data_only = ", flush_data_only,
")" 1131 write(action_str,
"(A)")
"nc_diag_chaninfo_write_data(flush_data_only = (not specified))" 1133 call nclayer_actionm(trim(action_str))
1154 data_type_index = 1 + &
1157 call nclayer_info(
"chaninfo: writing " // trim(data_name))
1162 if ((.NOT. (
present(flush_data_only) .AND. flush_data_only)) .AND. &
1166 write (nchan_empty_msg,
"(A, A, A, I0, A, I0, A)")
"Amount of data written in ", &
1167 trim(data_name),
" (", &
1170 ")" // char(10) // &
1176 call nclayer_error(trim(nchan_empty_msg))
1178 call nclayer_warning(trim(nchan_empty_msg))
1183 print *,
"****** Processing ******" 1184 print *,
"data_name:" 1186 print *,
"data_type:" 1188 print *,
"data_type_index:" 1189 print *, data_type_index
1190 print *,
"diag_chaninfo_store%var_ids(curdatindex):" 1192 print *,
"diag_chaninfo_store%var_usage(curdatindex):" 1194 print *,
"Upper range (data_type_index + &" 1195 print *,
" diag_chaninfo_store%var_usage(curdatindex) - 1):" 1196 print *, (data_type_index + &
1220 print *,
"Resulting data to be stored:" 1237 print *,
"Resulting data to be stored:" 1240 print *,
"start index:" 1265 allocate(
character(string_arr_maxlen) :: &
1266 string_arr(diag_chaninfo_store%var_usage(curdatindex)))
1268 do j = data_type_index, data_type_index + &
1269 diag_chaninfo_store%var_usage(curdatindex) - 1
1270 string_arr(j - data_type_index + 1) = &
1271 trim(diag_chaninfo_store%ci_string(j))
1275 do j = 1, diag_chaninfo_store%var_usage(curdatindex)
1276 write (*,
"(A, A, A)")
"String: '", string_arr(j),
"'" 1279 write (*,
"(A, I0)")
"string_arr_maxlen = ", string_arr_maxlen
1280 write (*,
"(A, I0)")
"diag_chaninfo_store%var_usage(curdatindex) = ", diag_chaninfo_store%var_usage(curdatindex)
1283 do j = data_type_index, data_type_index + &
1284 diag_chaninfo_store%var_usage(curdatindex) - 1
1285 string_arr(j - data_type_index + 1) = &
1286 diag_chaninfo_store%ci_string(j)
1290 call nclayer_check(nf90_put_var(
ncid, diag_chaninfo_store%var_ids(curdatindex), &
1292 start = (/ 1, 1 + diag_chaninfo_store%rel_indexes(curdatindex) /), &
1293 count = (/ string_arr_maxlen, &
1294 diag_chaninfo_store%var_usage(curdatindex) /) ))
1296 deallocate(string_arr)
1298 call nclayer_error(
"Critical error - unknown variable type!")
1303 if (
present(flush_data_only) .AND. flush_data_only)
then 1304 diag_chaninfo_store%rel_indexes(curdatindex) = &
1305 diag_chaninfo_store%rel_indexes(curdatindex) + &
1306 diag_chaninfo_store%var_usage(curdatindex)
1307 diag_chaninfo_store%var_usage(curdatindex) = 0
1310 print *,
"diag_chaninfo_store%rel_indexes(curdatindex) is now:" 1311 print *, diag_chaninfo_store%rel_indexes(curdatindex)
1318 if (
present(flush_data_only) .AND. flush_data_only)
then 1320 print *,
"In buffer flush mode!" 1325 diag_chaninfo_store%data_lock = .true.
1327 print *,
"In data lock mode!" 1331 call nclayer_error(
"Can't write data - data have already been written and locked!")
1334 call nclayer_error(
"Can't write data - number of chans not set yet!")
1338 call nclayer_error(
"Can't write data - NetCDF4 layer not initialized yet!")
1393 logical,
intent(in) :: enable_strict
1398 call nclayer_error(
"Can't set strictness level for chaninfo - NetCDF4 layer not initialized yet!")
1430 integer(i_llong),
intent(in) :: num_of_addl_vars
1431 #ifdef ENABLE_ACTION_MSGS 1432 character(len=1000) :: action_str
1434 if (nclayer_enable_action)
then 1435 write(action_str,
"(A, I0, A)")
"nc_diag_chaninfo_prealloc_vars(num_of_addl_vars = ", num_of_addl_vars,
")" 1436 call nclayer_actionm(trim(action_str))
1513 call nclayer_error(
"NetCDF4 layer not initialized yet!")
1568 integer(i_byte),
intent(in) :: nclayer_type
1569 integer(i_llong),
intent(in) :: num_of_addl_slots
1571 #ifdef ENABLE_ACTION_MSGS 1572 character(len=1000) :: action_str
1574 if (nclayer_enable_action)
then 1575 write(action_str,
"(A, I0, A, I0, A)")
"nc_diag_chaninfo_prealloc_vars_storage(nclayer_type = ", nclayer_type,
", num_of_addl_slots = ", num_of_addl_slots,
")" 1576 call nclayer_actionm(trim(action_str))
1597 call nclayer_error(
"Invalid type specified for variable storage preallocation!")
1632 integer(i_llong) :: addl_fields
1634 logical :: meta_realloc
1635 meta_realloc = .false.
1655 meta_realloc = .true.
1664 meta_realloc = .true.
1673 meta_realloc = .true.
1683 meta_realloc = .true.
1693 meta_realloc = .true.
1703 meta_realloc = .true.
1713 meta_realloc = .true.
1723 if (meta_realloc)
then 1727 call nclayer_error(
"Number of chans not set yet!")
1730 call nclayer_error(
"NetCDF4 layer not initialized yet!")
1785 character(len=*),
intent(in) :: chaninfo_name
1786 integer(i_byte),
intent(in) :: chaninfo_value
1788 integer(i_long) :: i, var_index, var_rel_index, type_index
1790 #ifdef ENABLE_ACTION_MSGS 1791 character(len=1000) :: action_str
1793 if (nclayer_enable_action)
then 1794 write(action_str,
"(A, I0, A)")
"nc_diag_chaninfo_byte(chaninfo_name = " // chaninfo_name //
", chaninfo_value = ", chaninfo_value,
")" 1795 call nclayer_actionm(trim(action_str))
1800 call nclayer_error(
"Can't add new data - data have already been written and locked!")
1819 if (var_index == -1)
then 1824 call nclayer_error(
"Can't add new variable - definitions have already been written and locked!")
1865 call nclayer_error(
"Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.")
1931 character(len=*),
intent(in) :: chaninfo_name
1932 integer(i_short),
intent(in) :: chaninfo_value
1934 integer(i_long) :: i, var_index, var_rel_index, type_index
1936 #ifdef ENABLE_ACTION_MSGS 1937 character(len=1000) :: action_str
1939 if (nclayer_enable_action)
then 1940 write(action_str,
"(A, I0, A)")
"nc_diag_chaninfo_short(chaninfo_name = " // chaninfo_name //
", chaninfo_value = ", chaninfo_value,
")" 1941 call nclayer_actionm(trim(action_str))
1946 call nclayer_error(
"Can't add new data - data have already been written and locked!")
1965 if (var_index == -1)
then 1970 call nclayer_error(
"Can't add new variable - definitions have already been written and locked!")
2011 call nclayer_error(
"Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.")
2077 character(len=*),
intent(in) :: chaninfo_name
2078 integer(i_long),
intent(in) :: chaninfo_value
2080 integer(i_long) :: i, var_index, var_rel_index, type_index
2082 #ifdef ENABLE_ACTION_MSGS 2083 character(len=1000) :: action_str
2085 if (nclayer_enable_action)
then 2086 write(action_str,
"(A, I0, A)")
"nc_diag_chaninfo_long(chaninfo_name = " // chaninfo_name //
", chaninfo_value = ", chaninfo_value,
")" 2087 call nclayer_actionm(trim(action_str))
2092 call nclayer_error(
"Can't add new data - data have already been written and locked!")
2112 print *,
" *** chaninfo_name" 2113 print *, chaninfo_name
2114 print *,
" *** var_index is set to:" 2118 if (var_index == -1)
then 2123 call nclayer_error(
"Can't add new variable - definitions have already been written and locked!")
2165 print *,
"!!!! diag_chaninfo_store%var_usage(var_index)" 2168 call nclayer_error(
"Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.")
2178 print *,
"====================================" 2179 print *,
"diag_chaninfo_store%total" 2181 print *,
"var_index" 2183 print *,
"diag_chaninfo_store%var_rel_pos(var_index)" 2185 print *,
"diag_chaninfo_store%nchans" 2187 print *,
"diag_chaninfo_store%var_usage(var_index)" 2189 print *,
"====================================" 2248 character(len=*),
intent(in) :: chaninfo_name
2249 real(r_single),
intent(in) :: chaninfo_value
2251 integer(i_long) :: i, var_index, var_rel_index, type_index
2253 #ifdef ENABLE_ACTION_MSGS 2254 character(len=1000) :: action_str
2256 if (nclayer_enable_action)
then 2257 write(action_str,
"(A, F0.5, A)")
"nc_diag_chaninfo_rsingle(chaninfo_name = " // chaninfo_name //
", chaninfo_value = ", chaninfo_value,
")" 2258 call nclayer_actionm(trim(action_str))
2263 call nclayer_error(
"Can't add new data - data have already been written and locked!")
2283 print *,
" *** chaninfo_name" 2284 print *, chaninfo_name
2285 print *,
" *** var_index is set to:" 2289 if (var_index == -1)
then 2294 call nclayer_error(
"Can't add new variable - definitions have already been written and locked!")
2335 call nclayer_error(
"Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.")
2344 print *,
"====================================" 2345 print *,
"diag_chaninfo_store%total" 2347 print *,
"var_index" 2349 print *,
"diag_chaninfo_store%var_rel_pos(var_index)" 2351 print *,
"diag_chaninfo_store%nchans" 2353 print *,
"diag_chaninfo_store%var_usage(var_index)" 2355 print *,
"====================================" 2415 character(len=*),
intent(in) :: chaninfo_name
2416 real(r_double),
intent(in) :: chaninfo_value
2418 integer(i_long) :: i, var_index, var_rel_index, type_index
2420 #ifdef ENABLE_ACTION_MSGS 2421 character(len=1000) :: action_str
2423 if (nclayer_enable_action)
then 2424 write(action_str,
"(A, F0.5, A)")
"nc_diag_chaninfo_rdouble(chaninfo_name = " // chaninfo_name //
", chaninfo_value = ", chaninfo_value,
")" 2425 call nclayer_actionm(trim(action_str))
2430 call nclayer_error(
"Can't add new data - data have already been written and locked!")
2449 if (var_index == -1)
then 2454 call nclayer_error(
"Can't add new variable - definitions have already been written and locked!")
2495 call nclayer_error(
"Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.")
2562 character(len=*),
intent(in) :: chaninfo_name
2563 character(len=*),
intent(in) :: chaninfo_value
2565 integer(i_long) :: i, var_index, var_rel_index, type_index
2567 #ifdef ENABLE_ACTION_MSGS 2568 character(len=1000) :: action_str
2570 if (nclayer_enable_action)
then 2571 write(action_str,
"(A)")
"nc_diag_chaninfo_string(chaninfo_name = " // chaninfo_name //
", chaninfo_value = " // trim(chaninfo_value) //
")" 2572 call nclayer_actionm(trim(action_str))
2577 call nclayer_error(
"Can't add new data - data have already been written and locked!")
2596 if (var_index == -1)
then 2601 call nclayer_error(
"Can't add new variable - definitions have already been written and locked!")
2642 call nclayer_error(
"Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.")
2648 call nclayer_error(
"Cannot expand variable string length after locking variable definitions!")
2663 call nclayer_error(
"Cannot change string size when trimming is disabled!")
subroutine nc_diag_chaninfo_resize_string(addl_num_entries, update_acount_in)
type(diag_chaninfo), allocatable diag_chaninfo_store
integer(i_long), parameter nlayer_multi_base
subroutine nc_diag_chaninfo_resize_short(addl_num_entries, update_acount_in)
integer, parameter, public i_byte
subroutine nc_diag_chaninfo_rdouble(chaninfo_name, chaninfo_value)
subroutine nc_diag_chaninfo_write_def(internal)
integer(i_byte), parameter nlayer_short
subroutine nc_diag_chaninfo_short(chaninfo_name, chaninfo_value)
integer(i_long), parameter nlayer_fill_long
integer, parameter, public i_long
integer(i_byte), parameter nlayer_fill_byte
integer(i_byte), parameter nlayer_double
subroutine nc_diag_chaninfo_expand
subroutine nc_diag_chaninfo_resize_byte(addl_num_entries, update_acount_in)
subroutine nc_diag_chaninfo_resize_long(addl_num_entries, update_acount_in)
integer function max_len_string_array(str_arr, arr_length)
integer(i_byte), parameter nlayer_string
subroutine nc_diag_chaninfo_dim_set(nchans)
integer(i_long), parameter nlayer_compression
integer(i_short), parameter nlayer_fill_short
subroutine nc_diag_chaninfo_set_strict(enable_strict)
subroutine nc_diag_chaninfo_resize_rsingle(addl_num_entries, update_acount_in)
subroutine nc_diag_chaninfo_write_data(flush_data_only)
integer, parameter, public i_short
subroutine nc_diag_chaninfo_prealloc_vars_storage(nclayer_type, num_of_addl_slots)
integer(i_byte), parameter nlayer_byte
character, parameter nlayer_fill_char
subroutine nc_diag_varattr_add_var(var_name, var_type, var_id)
integer(i_short), parameter nlayer_default_ent
subroutine nc_diag_chaninfo_resize_rdouble(addl_num_entries, update_acount_in)
subroutine nc_diag_chaninfo_rsingle(chaninfo_name, chaninfo_value)
subroutine nc_diag_chaninfo_allocmulti(multiplier)
subroutine nc_diag_chaninfo_load_def
real(r_single), parameter nlayer_fill_float
integer, parameter, public r_double
subroutine nc_diag_chaninfo_prealloc_vars(num_of_addl_vars)
integer, parameter, public r_single
integer, parameter, public i_llong
integer(i_byte), parameter nlayer_float
integer(i_byte), parameter nlayer_long
subroutine nc_diag_chaninfo_string(chaninfo_name, chaninfo_value)
real(r_double), parameter nlayer_fill_double
subroutine nc_diag_chaninfo_long(chaninfo_name, chaninfo_value)
subroutine nc_diag_chaninfo_byte(chaninfo_name, chaninfo_value)