Updated ocp2df() in CHI.R to put attributes in the dataframe columns.

master
Taha Ahmed 14 years ago
parent bd2b1731fc
commit 0f936f1e62

50
CHI.R

@ -18,10 +18,36 @@ source("/home/taha/chepec/chetex/common/R/common.R")
################### ocp2df ####################### ################### ocp2df #######################
################################################## ##################################################
ocp2df <- function(datafilename) { ocp2df <- function(datafilename) {
# Function description: for recorded amperometric i-T curves ## Description:
# CH Instruments potentiostat records all data using standard SI units, ## Reads potential-time data (from CHI 760 potentiostat)
# so all potential values are in volts, currents are in amperes, ## and returns a dataframe with the data and
# charges in Coulombs, time in seconds, etc. ## the data attributes (experimental conditions).
## Usage:
## ocp2df(datafilename)
## Arguments:
## datafilename: text string with full path to experimental file
## Value:
## Dataframe with the following columns (and no extra attributes):
## $ sampleid : chr
## $ time : num
## $ current : num
## $ currentdensity : num
## $ timediff : num
## $ dIdt : num
## $ didt : num
## $ charge : num
## $ chargedensity : num
## $ InitE : num
## $ SampleInterval : num
## $ RunTime : num
## $ QuietTime : num
## $ Sensitivity : num
## Note:
## The CH Instruments 760 potentiostat records all data
## using standard SI units, therefore this function
## assumes all potential values to be in volts,
## currents to be in amperes, charges in Coulombs,
## time in seconds, and so on.
# #
datafile <- file(datafilename, "r") datafile <- file(datafilename, "r")
chifile <- readLines(datafile, n = -1) #read all lines of input file chifile <- readLines(datafile, n = -1) #read all lines of input file
@ -63,18 +89,10 @@ ocp2df <- function(datafilename) {
names(ff) <- c("sampleid", "time", "potential") names(ff) <- c("sampleid", "time", "potential")
# #
### Collect attributes of this experiment ### Collect attributes of this experiment
# These attributes are specific for each kind of experiment, # RunTime (sec)
# be careful when adapting to other electrochemical data position.RunTime <- regexpr("^Run\\sTime\\s\\(sec\\)", chifile)
rgxp.attr <- c("^Run\\sTime\\s\\(sec\\)") RunTime <- as.numeric(strsplit(chifile[which(position.RunTime == 1)], "\\s=\\s")[[1]][2])
names.attr <- c("RunTime") ff$RunTime <- RunTime
for (n in 1:length(rgxp.attr)) {
attrow.idx <- regexpr(rgxp.attr[n], chifile)
attrow.len <- attr(attrow.idx, "match.length")
attr(attrow.idx, "match.length") <- NULL
# attrow.idx should now contain only one matching row
attr(ff, names.attr[n]) <- strsplit(chifile[which(attrow.idx == 1)],
"\\s=\\s")[[1]][2]
}
# #
return(ff) return(ff)
} }

@ -5,7 +5,7 @@
# CONTENTS # CONTENTS
# >>>> LinearBaseline (deprecated) # >>>> LinearBaseline (deprecated)
# >>>> int2padstr # >>>> int2padstr
# >>>> It2charge # >>>> It2charge **** STOP USING THIS FUNCTION ***
# >>>> ProvideSampleId # >>>> ProvideSampleId
# >>>> ConvertRefPot # >>>> ConvertRefPot
# >>>> Celsius2Kelvin # >>>> Celsius2Kelvin

Loading…
Cancel
Save