.check_coords <- function(lat1, lon1, lat2, lon2) {
  if (identical(as.numeric(lat1), as.numeric(lat2)) & identical(as.numeric(lon1), as.numeric(lon2))) {
    match <- TRUE
  } else {
    match <- FALSE
  }
  return(match)
}

# reorder dims to a reference array. If they do not exist, they are created
# example
#arr_ref <- array(NA, c(dataset = 1, sdate = 8, member = 3, ftime = 1, lon = 269, lat = 181))
#arr_to_reorder <- array(NA, c(dataset = 1, member = 3, sdate = 8, lat = 181, lon = 269, pp = 1))

.reorder_dims <- function(arr_ref, arr_to_reorder) {
   
  miss_dims <- names(dim(arr_ref))[!(names(dim(arr_ref)) %in% names(dim(arr_to_reorder)))]
 
  if (length(miss_dims) != 0) { 
    for (m in seq(miss_dims)) {
      arr_to_reorder <- InsertDim(data = arr_to_reorder, posdim = length(dim(arr_to_reorder)) + 1, lendim = 1,
                                  name = miss_dims[m])
    }
  }

  # TODO: add code to reorder dimensions and put the non-common dimensions at the end

  orddim <- match(names(dim(arr_ref)),names(dim(arr_to_reorder)))
  return(Reorder(data = arr_to_reorder, order = orddim))
}

#.check_coords <- function(lat1, lon1, lat2, lon2) {
#  match <- TRUE
#  if (!((length(lat1) == length(lat2)) & (length(lon1) == length(lon2)))) {
#    match <- FALSE
#  }
#  return(match)
#}

