## TODO: remove paths to personal scratchs 
source("/esarchive/scratch/vagudets/repos/csoperational/R/get_regrid_params.R")


adiabatic_correction <- function(recipe) {

  ## Load exp and obs data
  source("modules/Loading/R/load_seasonal.R")
  data <- load_seasonal(recipe)
  
  ref.name <- recipe$Analysis$Datasets$Reference$name
  exp.name <- recipe$Analysis$Datasets$System$name
  
  archive <- read_yaml("conf/archive.yml")$esarchive
  

  ## load orographies in requested grid
  
  # Define regrid parameters:
  regrid_params <- get_regrid_params(recipe, archive)
  
  ## Exp orography
  orography_exp <- Start(dat = archive$System[[exp.name]]$orography, 
                         var = 'orography',  
                         lon = 'all',
                         lat = 'all',
                         transform = regrid_params$fcst.transform,
                         transform_params = list(grid = regrid_params$fcst.gridtype,
                                                 method = regrid_params$fcst.gridmethod), 
                         transform_vars = c('lat','lon'),
                         return_vars = list(lat = NULL, lon = NULL), 
                         synonims = list(lon = c('lon','longitude'),
                                         lat = c('lat','latitude')),
                         lat_reorder = Sort(decreasing = FALSE),
                         lon_reorder = CircularSort(0,359.9),
                         num_procs = 1, retrieve = TRUE)
  
  ## Obs orography
  
  ## calculate difference between orographies
  
  ## Apply lapse rate factor to correct temperature

  ## Save data

}