Skip to content

Commit

Permalink
Adapt to work with multiple concentrations
Browse files Browse the repository at this point in the history
  • Loading branch information
mrustl committed Jun 18, 2024
1 parent 88d0f82 commit 8711f6b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/convert_atmosphere_to_string.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ convert_atmosphere_to_string <- function(
do_pad_short <- function(x) stringr::str_pad(x, pad_short, "left")
do_pad_long <- function(x) stringr::str_pad(x, pad_long, "left")

headers <- get_atmosphere_headers()
#headers <- get_atmosphere_headers()
headers <- names(atm)

headers_short <- "tAtm"
headers_long <- setdiff(headers, headers_short)
Expand Down
26 changes: 26 additions & 0 deletions R/read_atmosph.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ atm[idx_start:idx_end] %>%
writeLines(a_file)

atm_dat <- readr::read_table(a_file, col_names = FALSE)

n_unnamed <- ncol(atm_dat)-length(atm_names)

if(n_unnamed > 0) {
kwb.utils::catAndRun(sprintf("Guessing 'solute concentration' column names for %d unnamed columns",
n_unnamed),
expr = {

if(n_unnamed %% 2 != 0) {
message(sprintf("and replacing '%s', with 'cTop2'", atm_names[length(atm_names)]))
n_unnamed <- n_unnamed + 1
}

atm_names_added <- lapply(seq_len(n_unnamed/2), function(i){
c(sprintf("cTop%d", i+1), sprintf("cBot%d", i+1))
}) %>% unlist()

if(ncol(atm_dat)-n_unnamed-1 < length(atm_names)) {
atm_names <- atm_names[-(ncol(atm_dat)-n_unnamed+1)]
}

atm_names <- c(atm_names, atm_names_added)

})
}

names(atm_dat)[seq_along(atm_names)] <- atm_names

list(config = atm_config,
Expand Down

0 comments on commit 8711f6b

Please sign in to comment.