diff --git a/DESCRIPTION b/DESCRIPTION index a2bc549..0bccdde 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,11 +1,11 @@ Package: FLakeR Type: Package Title: Work with FLake in R -Version: 0.0.9 +Version: 0.0.10 Authors@R: person("Tadhg", "Moore", email = "tadhg.moore@dkit.ie", role = c("aut", "cre")) Maintainer: The package maintainer Description: Run the FLake model within R. Comes with a compiled version of FLake and example files. License: GPL3 Encoding: UTF-8 LazyData: true -RoxygenNote: 6.1.1 +RoxygenNote: 7.1.2 diff --git a/R/run_flake.R b/R/run_flake.R index f30136f..f60c1aa 100644 --- a/R/run_flake.R +++ b/R/run_flake.R @@ -5,21 +5,21 @@ #'The specified \code{sim_folder} must contain valid NML files. #' #'@param sim_folder the directory where simulation files are contained -#'@param nml_file filepath; to file with FLake setup. Defaults to 'flake.nml' +#'@param nml_file filepath; to file with FLake setup. Defaults to "flake.nml" #'@param verbose Save output as character vector. Defaults to FALSE #' #'@keywords methods #'@author #'Tadhg Moore #'@examples -#'sim_folder <- system.file('extdata', package = 'FLakeR') -#'run_flake(sim_folder, nml_file = 'Heiligensee80-96.nml') +#'sim_folder <- system.file("extdata", package = "FLakeR") +#'run_flake(sim_folder, nml_file = "flake.nml") #'@export #'@importFrom utils packageName -run_flake <- function (sim_folder = ".", nml_file = NULL, verbose = FALSE) +run_flake <- function (sim_folder = ".", nml_file = "flake.nml", verbose = FALSE) { if (is.null(nml_file)) { - files <- list.files(sim_folder)[grep('nml', list.files(sim_folder))] + files <- list.files(sim_folder)[grep("nml", list.files(sim_folder))] if(length(files) > 1){ stop("You must select one FLake namelist file in your sim_folder: ", sim_folder) @@ -27,23 +27,23 @@ run_flake <- function (sim_folder = ".", nml_file = NULL, verbose = FALSE) stop("You must have a valid FLake namelist file in your sim_folder: ", sim_folder) }else{ - nml = files + nml <- files } }else{ - nml = nml_file + nml <- nml_file } if (.Platform$pkgType == "win.binary") { return(run_flakeWin(sim_folder, nml_file = nml, verbose = verbose)) } ### macOS ### - if (grepl('mac.binary',.Platform$pkgType)) { - # stop('No FLake executable available for your machine yet...') + if (grepl("mac.binary",.Platform$pkgType)) { + # stop("No FLake executable available for your machine yet...") maj_v_number <- as.numeric(strsplit( - Sys.info()["release"][[1]],'.', fixed = TRUE)[[1]][1]) + Sys.info()["release"][[1]],".", fixed = TRUE)[[1]][1]) if (maj_v_number < 13.0) { - stop('pre-mavericks mac OSX is not supported. Consider upgrading') + stop("pre-mavericks mac OSX is not supported. Consider upgrading") } return(run_flakeOSx(sim_folder, nml_file = nml, verbose = verbose)) @@ -51,17 +51,17 @@ run_flake <- function (sim_folder = ".", nml_file = NULL, verbose = FALSE) } if (.Platform$pkgType == "source") { - #stop('No FLake executable available for your machine yet...') + #stop("No FLake executable available for your machine yet...") return(run_flakeNIX(sim_folder, nml_file = nml, verbose = verbose)) } } run_flakeWin <- function(sim_folder, nml_file, verbose = FALSE){ - if(.Platform$r_arch == 'x64'){ - flake_path <- system.file('extbin/win/flake.exe', package = packageName()) + if(.Platform$r_arch == "x64"){ + flake_path <- system.file("extbin/win/flake.exe", package = packageName()) }else{ - stop('No FLake executable available for your machine yet...') + stop("No FLake executable available for your machine yet...") } origin <- getwd() @@ -72,8 +72,8 @@ run_flakeWin <- function(sim_folder, nml_file, verbose = FALSE){ out <- system2(flake_path, wait = TRUE, stdout = TRUE, stderr = "", args=nml_file) } else { - out <- system2(flake_path, stdout = NULL, - stderr = NULL, args=nml_file) + out <- system2(flake_path, args=nml_file, wait = TRUE, stdout = NULL, + stderr = NULL) } setwd(origin) return(out) @@ -85,10 +85,10 @@ run_flakeWin <- function(sim_folder, nml_file, verbose = FALSE){ -# run_flakeOSx <- function(sim_folder, nml = TRUE, nml_file = 'flake.nml', verbose = TRUE, args){ -# #lib_path <- system.file('extbin/macFLake/bin', package=packageName()) #Not sure if libraries needed for FLake +# run_flakeOSx <- function(sim_folder, nml = TRUE, nml_file = "flake.nml", verbose = TRUE, args){ +# #lib_path <- system.file("extbin/macFLake/bin", package=packageName()) #Not sure if libraries needed for FLake # -# flake_path <- system.file('exec/macflake', package=packageName()) +# flake_path <- system.file("exec/macflake", package=packageName()) # # # ship flake and libs to sim_folder # #Sys.setenv(DYLD_FALLBACK_LIBRARY_PATH=lib_path) #Libraries? @@ -96,7 +96,7 @@ run_flakeWin <- function(sim_folder, nml_file, verbose = FALSE){ # if(nml){ # args <- c(args, nml_file) # }else{ -# args <- c(args,'--read_nml') +# args <- c(args,"--read_nml") # } # # origin <- getwd() @@ -121,23 +121,25 @@ run_flakeWin <- function(sim_folder, nml_file, verbose = FALSE){ # }) # } -run_flakeOSx <- function(sim_folder, nml_file = 'flake.nml', verbose=FALSE){ - flake_path <- system.file('exec/macflake', package='FLakeR') +run_flakeOSx <- function(sim_folder, nml_file = "flake.nml", verbose=FALSE){ + flake_path <- system.file("exec/macflake", package="FLakeR") origin <- getwd() setwd(sim_folder) - Sys.setenv(LD_LIBRARY_PATH = paste(system.file('extbin/nix', + old_ld_path <- Sys.getenv("LD_LIBRARY_PATH") + on.exit(expr = {Sys.setenv(LD_LIBRARY_PATH = old_ld_path)}) + Sys.setenv(LD_LIBRARY_PATH = paste(system.file("extbin/nix", package = packageName()), - Sys.getenv('LD_LIBRARY_PATH'), + Sys.getenv("LD_LIBRARY_PATH"), sep = ":")) tryCatch({ if (verbose){ out <- system2(flake_path, wait = TRUE, stdout = TRUE, stderr = "", args=nml_file) } else { - out <- system2(flake_path, stdout = NULL, - stderr = NULL, args=nml_file) + out <- system2(flake_path, args=nml_file, wait = TRUE, stdout = NULL, + stderr = NULL) } setwd(origin) return(out) @@ -145,26 +147,27 @@ run_flakeOSx <- function(sim_folder, nml_file = 'flake.nml', verbose=FALSE){ print(paste("FLake_ERROR: ",err)) setwd(origin) }) - } -run_flakeNIX <- function(sim_folder, nml_file = 'flake.nml', verbose=FALSE){ - flake_path <- system.file('exec/nixflake', package=packageName()) +run_flakeNIX <- function(sim_folder, nml_file = "flake.nml", verbose=FALSE){ + flake_path <- system.file("exec/nixflake", package=packageName()) origin <- getwd() setwd(sim_folder) - Sys.setenv(LD_LIBRARY_PATH = paste(system.file('extbin/nix', + old_ld_path <- Sys.getenv("LD_LIBRARY_PATH") + on.exit(expr = {Sys.setenv(LD_LIBRARY_PATH = old_ld_path)}) + Sys.setenv(LD_LIBRARY_PATH = paste(system.file("extbin/nix", package = packageName()), - Sys.getenv('LD_LIBRARY_PATH'), + Sys.getenv("LD_LIBRARY_PATH"), sep = ":")) tryCatch({ if (verbose){ out <- system2(flake_path, wait = TRUE, stdout = TRUE, stderr = "", args=nml_file) } else { - out <- system2(flake_path, stdout = NULL, - stderr = NULL, args=nml_file) + out <- system2(flake_path, args=nml_file, wait = TRUE, stdout = NULL, + stderr = NULL) } setwd(origin) return(out) @@ -172,5 +175,4 @@ run_flakeNIX <- function(sim_folder, nml_file = 'flake.nml', verbose=FALSE){ print(paste("FLake_ERROR: ",err)) setwd(origin) }) - } diff --git a/README.md b/README.md index f0e15e9..03ebf2a 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,6 @@ devtools::install_github("aemon-j/FLakeR") ```{r example, eval=FALSE} library(FLakeR) -sim_folder <- system.file('extdata', package = 'FLakeR') -run_flake(sim_folder, nml_file = 'Heiligensee80-96.nml') +sim_folder <- system.file("extdata", package = "FLakeR") +run_flake(sim_folder, nml_file = "flake.nml") ``` - -### Output -Suite of tools for working with FLake output coming soon... diff --git a/inst/extdata/feeagh.nml b/inst/extdata/flake.nml similarity index 80% rename from inst/extdata/feeagh.nml rename to inst/extdata/flake.nml index 6a06b70..1614e3c 100644 --- a/inst/extdata/feeagh.nml +++ b/inst/extdata/flake.nml @@ -6,7 +6,7 @@ &SIMULATION_PARAMS del_time_lk = 86400,! Time step [s] -time_step_number = 210,! /LER/ The total number of time steps (17 years 1980-1996) +time_step_number = 200,! /LER/ The total number of time steps (17 years 1980-1996) save_interval_n = 1 ! Saving interval in time steps T_wML_in = 6.128,! /LER/ initial temperature of the upper mixed layer T_bot_in = 6.255,! /LER/ initial temperature at the bottom @@ -31,10 +31,11 @@ outputfile = 'output/output.dat', !------------------------------------------------------------------------------ &LAKE_PARAMS depth_w_lk = 16.05,! /LER/ Lake depth [m] -fetch_lk = 2.0E+03, ! Typical wind fetch [m] +fetch_lk = 2000, ! Typical wind fetch [m] depth_bs_lk = 5.0, ! Depth of the thermally active layer of the bottom sediments [m] T_bs_lk = 4.0, ! Temperature at the outer edge of the thermally active layer of the bottom sediments [C] latitude_lk = 53.9,! /LER/ Geographical latitude [dgr] +c_relax_C = 0.0030, ! Adjustable constant in the relaxation equation for the shape factor / @@ -49,10 +50,10 @@ extincoef_optic = 0.98,! /LER/ Extinction coefficients / &inflow -DTinflow = 0.0, ! not relevant if Qfromfile = .true. -DTfixed = .true., ! not relevant if Qfromfile = .true. -QS = 0.0, ! inflow rate per lake area [m/s], not relevant if Qfromfile = .true. -Qfromfile = .true., -Qfile='Tinflow', ! a filename with inflow data should be subsituted for 'Tinflow' -time_step_number = 209 ! number of the model time steps, should be less than or equal to the number of rows in Qfile +DTinflow = 0.0, ! not relevant if inflows are not used +DTfixed = .true., ! not relevant if inflows are not used +QS = 0.0, ! inflow rate per lake area [m/s], not relevant if inflows are not used +Qfromfile = .true.,! /LER/ +Qfile='Tinflow', ! a filename with inflow data should be substituted for 'Tinflow' +time_step_number = 200 ! number of the model time steps, should be less than or equal to the number of rows in Qfile / diff --git a/man/run_flake.Rd b/man/run_flake.Rd index c3bff6c..7595e67 100644 --- a/man/run_flake.Rd +++ b/man/run_flake.Rd @@ -4,12 +4,12 @@ \alias{run_flake} \title{Run the FLake model} \usage{ -run_flake(sim_folder = ".", nml_file = NULL, verbose = FALSE) +run_flake(sim_folder = ".", nml_file = "flake.nml", verbose = FALSE) } \arguments{ \item{sim_folder}{the directory where simulation files are contained} -\item{nml_file}{filepath; to file with FLake setup. Defaults to 'flake.nml'} +\item{nml_file}{filepath; to file with FLake setup. Defaults to "flake.nml"} \item{verbose}{Save output as character vector. Defaults to FALSE} } @@ -18,8 +18,8 @@ This runs the FLake model on the specific simulation stored in \code{sim_folder} The specified \code{sim_folder} must contain valid NML files. } \examples{ -sim_folder <- system.file('extdata', package = 'FLakeR') -run_flake(sim_folder, nml_file = 'Heiligensee80-96.nml') +sim_folder <- system.file("extdata", package = "FLakeR") +run_flake(sim_folder, nml_file = "flake.nml") } \author{ Tadhg Moore