Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 <tadhg.moore@dkit.ie>
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
72 changes: 37 additions & 35 deletions R/run_flake.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,63 @@
#'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)
}else if(length(files) < 1){
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))

}

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()
Expand All @@ -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)
Expand All @@ -85,18 +85,18 @@ 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?
#
# if(nml){
# args <- c(args, nml_file)
# }else{
# args <- c(args,'--read_nml')
# args <- c(args,"--read_nml")
# }
#
# origin <- getwd()
Expand All @@ -121,56 +121,58 @@ 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)
}, error = function(err) {
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)
}, error = function(err) {
print(paste("FLake_ERROR: ",err))
setwd(origin)
})

}
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
17 changes: 9 additions & 8 deletions inst/extdata/feeagh.nml → inst/extdata/flake.nml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
/


Expand All @@ -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
/
8 changes: 4 additions & 4 deletions man/run_flake.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.