diff --git a/R/NcDataReader.R b/R/NcDataReader.R index 741ffbb6d1ca54f4e1e224df04feddefef9682fb..ebc58fc27c6a6c5a379e9773de1ffe27bed2ecc3 100644 --- a/R/NcDataReader.R +++ b/R/NcDataReader.R @@ -221,6 +221,13 @@ NcDataReader <- function(file_path = NULL, file_object = NULL, # Origin year and month ori_year <- as.numeric(substr(parts[2], 1, 4)) ori_month <- as.numeric(substr(parts[2], 6, 7)) + if (is.na(ori_month)) { + ori_month <- as.numeric(substr(parts[2], 6, 6)) + } + if (!is.numeric(ori_year) | !is.numeric(ori_month)) { + stop(paste0("The time unit attribute format is not 'YYYY-MM-DD' or 'YYYY-M-D'. ", + "Check the file or contact the maintainer.")) + } if (calendar == 'gregorian') { # Find how many years + months diff --git a/R/Start.R b/R/Start.R index 3d82d57e6b711b9c3c4785b532a38d617006a37b..e8a1d7df40a55151e6329c8bb7707bde3beaf6da 100644 --- a/R/Start.R +++ b/R/Start.R @@ -3654,6 +3654,9 @@ Start <- function(..., # dim = indices/selectors, } } } + #========================================================================= + # Find the dimension to split if split_multiselected_dims = TRUE. + # If there is no dimension able to be split, change split_multiselected_dims to FALSE. all_split_dims <- NULL if (split_multiselected_dims) { for (dim_param in 1:length(dim_params)) { @@ -3692,7 +3695,13 @@ Start <- function(..., # dim = indices/selectors, } } } + if (is.null(all_split_dims)) { + split_multiselected_dims <- FALSE + .warning(paste0("Not found any dimensions able to be split. The parameter ", + "'split_multiselected_dims' is changed to FALSE.")) + } } + #====================================================================== if (merge_across_dims_narm) { # only merge_across_dims -> the 'time' dim length needs to be adjusted @@ -3746,6 +3755,7 @@ Start <- function(..., # dim = indices/selectors, if (split_multiselected_dims & merge_across_dims) { # TODO: More than one split? inner_dim_pos_in_split_dims <- which(names(all_split_dims[[1]]) == inner_dims_across_files) + # if inner_dim is not the first, change! if (inner_dim_pos_in_split_dims != 1) { split_dims <- c(split_dims[inner_dim_pos_in_split_dims], diff --git a/tests/testthat/test-Start-split-merge.R b/tests/testthat/test-Start-split-merge.R index 10e8ab671c8207acac694cc467fd22ac5a438e45..da21f9233c063f9cb4c8b334057bf3419ee12bd8 100644 --- a/tests/testthat/test-Start-split-merge.R +++ b/tests/testthat/test-Start-split-merge.R @@ -4,6 +4,7 @@ context("Start() split + merge dim and value check") var_name <- 'sfcWind' path.exp <- '/esarchive/exp/ecmwf/s2s-monthly_ensforhc/daily/$var$_f24h/$sdate$/$var$_$syear$.nc' + suppressWarnings( hcst <- Start(dat = path.exp, var = var_name,