# https://earth.bsc.es/gitlab/es/ClimProjDiags/issues/1
library(ClimProjDiags)
data <- 1:(359 * 3)
dim(data) <- c(lon = 359, lat = 3) 
lats <- -1:1
lons <- -179:179
region = c(lonmin = 100, lonmax = -90, latmin = -1, latmax = 1)
lat_regd <- SelBox(data, lons, lats, region)$lat
lon_regd <- SelBox(data, lons, lats, region)$lon

data_new <- SelBox(data, lons, lats, region)$data

lon_regd[c(which(lon_regd > 0), which(lon_regd < 0))]
data_ordered <-data_new[c(which(lon_regd > 0), which(lon_regd < 0)),]
latmin <- lat_regd[length(lat_regd)]
latmax <- lat_regd[1]
lonmin <- lon_regd[1]
lonmax <- lon_regd[length(lon_regd)]

print(latmin)
print(latmax)
print(lonmin)
print(lonmax)

