Commit 5e95b130 authored by Marco De Lucia's avatar Marco De Lucia
Browse files

fixed RunPQC adding optional "second"

parent 17a22ea8
## Functions for dealing with simulations with kinetics
### 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
##' thereof - through \code{phreeqc}. Obviously it requires the
......@@ -17,14 +17,15 @@
##' @title Run the generated input buffer using phreeqc
##' @param input The input buffer, or list of inputs
##' @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
##' multiple parallel simulations were called. Some manipulations
##' of the colnames are also made.
##' @author MDL
##' @export
RunPQC <- function(input, procs=1) {
RunPQC <- function(input, procs=1, second=TRUE) {
.runPQC <- function(input) {
.runPQC <- function(input, second=TRUE) {
require(phreeqc)
phreeqc::phrRunString(input)
out <- phreeqc::phrGetSelectedOutput()[[1]]
......@@ -33,7 +34,8 @@ RunPQC <- function(input, procs=1) {
nso <- sub('.mol.kgw.','',nso, fixed=TRUE)
nso <- sub('^k_','',nso)
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
return(data.matrix(out))
}
......@@ -41,7 +43,7 @@ RunPQC <- function(input, procs=1) {
## is lin a list of inputs?
if (!is.list(input)) {
if(is.character(input)) { ## normal sequential run
res <- .runPQC(input)
res <- .runPQC(input, second=second)
} else {
stopmsg("something wrong with the input, dying!")
}
......@@ -51,7 +53,7 @@ RunPQC <- function(input, procs=1) {
## old one
## res <- parallel::mclapply(input, .runPQC, mc.silent=TRUE, mc.cores=procs)
## 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 <- paste("rbind(",paste("res[[",1:procs,"]]",sep="", collapse = ", "),")")
......
......@@ -4,12 +4,14 @@
\alias{RunPQC}
\title{Run the generated input buffer using phreeqc}
\usage{
RunPQC(input, procs = 1)
RunPQC(input, procs = 1, second = TRUE)
}
\arguments{
\item{input}{The input buffer, or list of inputs}
\item{procs}{the number of processes to employ}
\item{second}{logical, if TRUE skips each odd row}
}
\value{
a data.frame containing the SELECTED_OUTPUT, ordered if
......@@ -26,7 +28,7 @@ RPhreeFile("phreeqc.dat", is.db=TRUE ))}
}
\details{
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
well-formed, so this is responsibility of the user.
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment