@ -369,44 +369,53 @@ cv2df <- function(datafilename, wearea = 1) {
for ( s in 1 : length ( starts ) ) {
for ( s in 1 : length ( starts ) ) {
zz <- textConnection ( chifile [starts [s ] : ends [s ] ] , " r" )
zz <- textConnection ( chifile [starts [s ] : ends [s ] ] , " r" )
ff <- rbind ( ff ,
ff <- rbind ( ff ,
data.frame ( sampleid , segment = factor ( s ) , cycle = facto r( ceiling ( s / 2 ) ) ,
data.frame ( sampleid , segment = s , cycle = as.intege r( ceiling ( s / 2 ) ) ,
matrix ( scan ( zz , what = numeric ( ) , sep = " ," ) ,
matrix ( scan ( zz , what = numeric ( ) , sep = " ," ) ,
ncol = 3 , byrow = T ) ) )
ncol = 3 , byrow = T ) ) )
close ( zz )
close ( zz )
}
}
# Column names after initial assignment
names ( ff ) <- c ( " sampleid" , " segment" , " cycle" , " potential" , " current" , " charge" )
names ( ff ) <- c ( " sampleid" , " segment" , " cycle" , " potential" , " current" , " charge" )
# Calculate current density
# Calculate current density
currentdensity <- ff $ current / wearea
currentdensity <- ff $ current / wearea
ff <- cbind ( ff [ , 1 : 5 ] , currentdensity = currentdensity , charge = ff [ , 6 ] )
ff <- cbind ( ff [ , 1 : 5 ] , currentdensity = currentdensity , charge = ff [ , 6 ] )
#
## Collect attributes of this experiment
### Collect attributes of this experiment
# InitE (volt)
# These attributes are specific for each kind of experiment,
position.InitE <- regexpr ( " ^Init\\sE\\s\\(V\\)" , chifile )
# be careful when adapting to other electrochemical data
InitE <- as.numeric ( strsplit ( chifile [which ( position.InitE == 1 ) ] , " \\s=\\s" ) [ [1 ] ] [2 ] )
rgxp.attr <- c ( " ^Init\\sE\\s\\(V\\)" ,
ff $ InitE <- InitE
" ^High\\sE\\s\\(V\\)" ,
# HighE (volt)
" ^Low\\sE\\s\\(V\\)" ,
position.HighE <- regexpr ( " ^High\\sE\\s\\(V\\)" , chifile )
" ^Init\\sP/N" ,
HighE <- as.numeric ( strsplit ( chifile [which ( position.HighE == 1 ) ] , " \\s=\\s" ) [ [1 ] ] [2 ] )
" ^Scan\\sRate\\s\\(V/s\\)" ,
ff $ HighE <- HighE
" ^Segment\\s=" ,
# LowE (volt)
" ^Sample\\sInterval\\s\\(V\\)" ,
position.LowE <- regexpr ( " ^Low\\sE\\s\\(V\\)" , chifile )
" ^Quiet\\sTime\\s\\(sec\\)" ,
LowE <- as.numeric ( strsplit ( chifile [which ( position.LowE == 1 ) ] , " \\s=\\s" ) [ [1 ] ] [2 ] )
" ^Sensitivity\\s\\(A/V\\)" )
ff $ LowE <- LowE
names.attr <- c ( " InitE" ,
# InitPN (positive or negative)
" HighE" ,
position.InitPN <- regexpr ( " ^Init\\sP/N" , chifile )
" LowE" ,
InitPN <- strsplit ( chifile [which ( position.InitPN == 1 ) ] , " \\s=\\s" ) [ [1 ] ] [2 ]
" InitPN" ,
ff $ InitPN <- InitPN
" ScanRate" ,
# ScanRate (volt per second)
" Segments" ,
position.ScanRate <- regexpr ( " ^Scan\\sRate\\s\\(V/s\\)" , chifile )
" SamplingInterval" ,
ScanRate <- as.numeric ( strsplit ( chifile [which ( position.ScanRate == 1 ) ] , " \\s=\\s" ) [ [1 ] ] [2 ] )
" QuietTime" ,
ff $ ScanRate <- ScanRate
" Sensitivity" )
# Segments, number of
for ( n in 1 : length ( rgxp.attr ) ) {
position.Segment <- regexpr ( " ^Segment\\s=" , chifile )
attrow.idx <- regexpr ( rgxp.attr [n ] , chifile )
Segment <- as.numeric ( strsplit ( chifile [which ( position.Segment == 1 ) ] , " \\s=\\s" ) [ [1 ] ] [2 ] )
attrow.len <- attr ( attrow.idx , " match.length" )
ff $ Segment <- Segment
attr ( attrow.idx , " match.length" ) <- NULL
# SampleInterval (volt)
attr ( ff , names.attr [n ] ) <- strsplit ( chifile [which ( attrow.idx == 1 ) ] ,
position.SampleInterval <- regexpr ( " ^Sample\\sInterval\\s\\(V\\)" , chifile )
" \\s=\\s" ) [ [1 ] ] [2 ]
SampleInterval <- as.numeric ( strsplit ( chifile [which ( position.SampleInterval == 1 ) ] , " \\s=\\s" ) [ [1 ] ] [2 ] )
}
ff $ SampleInterval <- SampleInterval
# Quiet time (seconds)
position.QuietTime <- regexpr ( " ^Quiet\\sTime\\s\\(sec\\)" , chifile )
QuietTime <- as.numeric ( strsplit ( chifile [which ( position.QuietTime == 1 ) ] , " \\s=\\s" ) [ [1 ] ] [2 ] )
ff $ QuietTime <- QuietTime
# Sensitivity (ampere per volt)
position.Sensitivity <- regexpr ( " ^Sensitivity\\s\\(A/V\\)" , chifile )
Sensitivity <- as.numeric ( strsplit ( chifile [which ( position.Sensitivity == 1 ) ] , " \\s=\\s" ) [ [1 ] ] [2 ] )
ff $ Sensitivity <- Sensitivity
#
#
return ( ff )
return ( ff )
}
}