Skip to content
Snippets Groups Projects
Commit 5e95b130 authored by Marco De Lucia's avatar Marco De Lucia
Browse files

fixed RunPQC adding optional "second"

parent 17a22ea8
No related branches found
No related tags found
No related merge requests found
## Functions for dealing with simulations with kinetics ## Functions for dealing with simulations with kinetics
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018 ### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018
### Time-stamp: "Last modified 2018-05-17 15:52:34 delucia" ### Time-stamp: "Last modified 2018-05-24 18:01:01 delucia"
##' This function just runs the generated input buffer - or a list ##' This function just runs the generated input buffer - or a list
##' thereof - through \code{phreeqc}. Obviously it requires the ##' thereof - through \code{phreeqc}. Obviously it requires the
...@@ -17,14 +17,15 @@ ...@@ -17,14 +17,15 @@
##' @title Run the generated input buffer using phreeqc ##' @title Run the generated input buffer using phreeqc
##' @param input The input buffer, or list of inputs ##' @param input The input buffer, or list of inputs
##' @param procs the number of processes to employ ##' @param procs the number of processes to employ
##' @param second logical, if TRUE skips each odd row
##' @return a data.frame containing the SELECTED_OUTPUT, ordered if ##' @return a data.frame containing the SELECTED_OUTPUT, ordered if
##' multiple parallel simulations were called. Some manipulations ##' multiple parallel simulations were called. Some manipulations
##' of the colnames are also made. ##' of the colnames are also made.
##' @author MDL ##' @author MDL
##' @export ##' @export
RunPQC <- function(input, procs=1) { RunPQC <- function(input, procs=1, second=TRUE) {
.runPQC <- function(input) { .runPQC <- function(input, second=TRUE) {
require(phreeqc) require(phreeqc)
phreeqc::phrRunString(input) phreeqc::phrRunString(input)
out <- phreeqc::phrGetSelectedOutput()[[1]] out <- phreeqc::phrGetSelectedOutput()[[1]]
...@@ -33,7 +34,8 @@ RunPQC <- function(input, procs=1) { ...@@ -33,7 +34,8 @@ RunPQC <- function(input, procs=1) {
nso <- sub('.mol.kgw.','',nso, fixed=TRUE) nso <- sub('.mol.kgw.','',nso, fixed=TRUE)
nso <- sub('^k_','',nso) nso <- sub('^k_','',nso)
nso <- sub('.g.','(g)',nso, fixed=TRUE) nso <- sub('.g.','(g)',nso, fixed=TRUE)
out <- out[seq(2, nrow(out), by=2),] if (second)
out <- out[seq(2, nrow(out), by=2),]
colnames(out) <- nso colnames(out) <- nso
return(data.matrix(out)) return(data.matrix(out))
} }
...@@ -41,7 +43,7 @@ RunPQC <- function(input, procs=1) { ...@@ -41,7 +43,7 @@ RunPQC <- function(input, procs=1) {
## is lin a list of inputs? ## is lin a list of inputs?
if (!is.list(input)) { if (!is.list(input)) {
if(is.character(input)) { ## normal sequential run if(is.character(input)) { ## normal sequential run
res <- .runPQC(input) res <- .runPQC(input, second=second)
} else { } else {
stopmsg("something wrong with the input, dying!") stopmsg("something wrong with the input, dying!")
} }
...@@ -51,7 +53,7 @@ RunPQC <- function(input, procs=1) { ...@@ -51,7 +53,7 @@ RunPQC <- function(input, procs=1) {
## old one ## old one
## res <- parallel::mclapply(input, .runPQC, mc.silent=TRUE, mc.cores=procs) ## res <- parallel::mclapply(input, .runPQC, mc.silent=TRUE, mc.cores=procs)
## res <- parallel::parLapply(ThisRunCluster, input, .runPQC) ## res <- parallel::parLapply(ThisRunCluster, input, .runPQC)
res <- foreach(i=seq_along(input), .combine=rbind) %dopar% .runPQC(input[[i]]) res <- foreach(i=seq_along(input), .combine=rbind) %dopar% .runPQC(input[[i]], second=second)
## ## a is the string containing the rbind of each element of the list ## ## a is the string containing the rbind of each element of the list
## a <- paste("rbind(",paste("res[[",1:procs,"]]",sep="", collapse = ", "),")") ## a <- paste("rbind(",paste("res[[",1:procs,"]]",sep="", collapse = ", "),")")
......
...@@ -4,12 +4,14 @@ ...@@ -4,12 +4,14 @@
\alias{RunPQC} \alias{RunPQC}
\title{Run the generated input buffer using phreeqc} \title{Run the generated input buffer using phreeqc}
\usage{ \usage{
RunPQC(input, procs = 1) RunPQC(input, procs = 1, second = TRUE)
} }
\arguments{ \arguments{
\item{input}{The input buffer, or list of inputs} \item{input}{The input buffer, or list of inputs}
\item{procs}{the number of processes to employ} \item{procs}{the number of processes to employ}
\item{second}{logical, if TRUE skips each odd row}
} }
\value{ \value{
a data.frame containing the SELECTED_OUTPUT, ordered if a data.frame containing the SELECTED_OUTPUT, ordered if
...@@ -26,7 +28,7 @@ RPhreeFile("phreeqc.dat", is.db=TRUE ))} ...@@ -26,7 +28,7 @@ RPhreeFile("phreeqc.dat", is.db=TRUE ))}
} }
\details{ \details{
Currently parallelization is achieved using Currently parallelization is achieved using
\code{parallel::mclapply}, this can change in the future. At the \code{parallel::parLapply}, this can change in the future. At the
moment the function doesn't check that the SELCTED_OUTPUT block is moment the function doesn't check that the SELCTED_OUTPUT block is
well-formed, so this is responsibility of the user. well-formed, so this is responsibility of the user.
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment