1
#' Parse a Risoe SEQ-file to a sequence neccessary for simulating quartz luminescence
2
#'
3
#' A SEQ-file created by the Risoe Sequence Editor can be imported to simulate the sequence written
4
#' in the sequence editor.
5
#'
6
#' \bold{Supported versions}: Supppored and tested: version 4.36.
7
#'
8
#' @param file \code{\link{character}} (\bold{required}): a *.seq file created by the Risoe Sequence Editor
9
#'
10
#' @param lab.dose_rate \code{\link{character}} (with default): set the dose rate of the radiation source
11
#' in the laboratory Gy/s. Default: 1 Gy/s
12
#'
13
#' @param txtProgressBar \code{\link{logical}} (with default): enables or disables the txtProgressBar for a visuell
14
#' control of the progress. Default: txtProgressBar = TRUE
15
#'
16
#' @return This function returns a \code{\link{list}} with the parsed *.seq file and the required steps for
17
#' \code{\link{model_LuminescenceSignals}}.
18
#'
19
#' @section Function version: 0.1.0 
20
#' 
21
#' @author Johannes Friedrich, University of Bayreuth (Germany),
22
#'
23
#' @references
24
#'
25
#' Riso: Sequence Editor User Manual.
26
#' Available at: http://www.nutech.dtu.dk/english/-/media/Andre_Universitetsenheder/Nutech/Produkter
27
#' %20og%20services/Dosimetri/radiation_measurement_instruments/tl_osl_reader/Manuals/
28
#' SequenceEditor.ashx?la=da
29
#'
30
#' @seealso \code{\link{model_LuminescenceSignals}}, \code{\link{readLines}}
31
#'
32
#' @examples
33
#' ##search "example_SAR_cycle.SEQ" in "extdata" in package "RLumModel"
34
#' path <- system.file("extdata", "example_SAR_cycle.SEQ", package="RLumModel")
35
#'
36
#' sequence <- read_SEQ2R(file = path, txtProgressBar = FALSE)
37
#'
38
#' @export
39
read_SEQ2R <- function(
40
  file,
41
  lab.dose_rate = 1,
42
  txtProgressBar = TRUE
43
){
44

45
# Integrity tests and conversion --------------------------------------------------------------
46

47 5
if(class(file)!= "character")
48 5
  stop("[read_SEQ2R()] class of file has to be a character.")
49
  
50 5
if(!file.exists(file))
51 5
  stop("[read_SEQ2R()] file name doesn't seem to exist.")
52

53 5
if(lab.dose_rate < 0)
54 5
  stop("[read_SEQ2R()] Argument 'lab.dose_rate' has to be positiv.")
55

56
# parse *.SEQ file --------------------------------------------------------
57

58 5
file2read <- readLines(file, encoding = "UTF-8")
59

60

61
##(1)
62
##get all rows with the term "[Cell(...)]" - that's what we are interested in and it defines
63
##the number of elements we need
64 5
records.row_number <- grep(pattern = "\\[Cell\\(", x = file2read)
65

66
##(2)
67
##make a list with data of each sequence step
68 5
data.list <- lapply(1:length(records.row_number), function(x) {
69

70
  ##grep each element
71 5
  if (!is.na(records.row_number[x + 1])) {
72 5
    return(file2read[records.row_number[x]:(records.row_number[x + 1] - 1)])
73
  }
74
  else{
75 5
    return(file2read[records.row_number[x]:length(file2read)])
76

77
  }
78

79
})
80

81
##PROGRESS BAR
82 5
if(txtProgressBar){
83 5
  cat("\n [read_SEQ2R()] \n\t Parse *.seq file to sequence for RLumModel\n")
84 5
  pb <- txtProgressBar(min=0,max=length(data.list), char = "=", style=3)
85
}
86

87 5
sequence <- list()
88 5
names <- character()
89 5
for(x in 1:length(data.list)){
90

91
  ##get length of record
92 5
  sequence.ID <- as.numeric(gsub("Command=", "", data.list[[x]][2]))
93

94
  #identify ID with sequence step
95 5
  if(sequence.ID >= 1 && sequence.ID <=5){
96

97 0
    stop(paste("[read_SEQ2R()] Step ",x," of your sequence is not supported!", sep = ""))
98
  }
99

100 5
  if(sequence.ID == 6){#TL
101

102 5
    temp_begin <- as.numeric(gsub("Low=", "", data.list[[x]][grep(pattern = "^Low=",x = data.list[[x]])]))
103 5
    temp_end <- as.numeric(gsub("High=", "", data.list[[x]][grep(pattern = "^High=",x = data.list[[x]])]))
104 5
    b <- as.numeric(gsub("Rate=", "", data.list[[x]][grep(pattern = "^Rate",x = data.list[[x]])]))
105 5
    PH_time <- as.numeric(gsub("PhTime=", "", data.list[[x]][grep(pattern = "^PhTime",x = data.list[[x]])]))
106 5
    PH_temp <- as.numeric(gsub("PhTemp=", "", data.list[[x]][grep(pattern = "^PhTemp",x = data.list[[x]])]))
107

108 5
    names[x] <- "TL"
109 5
    sequence[[x]] <- c(temp_begin,temp_end,b,PH_time,PH_temp)
110

111

112
  }
113

114 5
  if(sequence.ID == 7){#OSL
115

116 5
    temp <- as.numeric(gsub("Temperature=", "", data.list[[x]][grep(pattern = "^Temperature=",x = data.list[[x]])]))
117 5
    duration <- as.numeric(gsub("High=", "", data.list[[x]][grep(pattern = "^High=",x = data.list[[x]])]))
118 5
    optical_power <- as.numeric(gsub("Current=", "", data.list[[x]][grep(pattern = "^Current=",x = data.list[[x]])]))
119 5
    b <- as.numeric(gsub("Rate=", "", data.list[[x]][grep(pattern = "^Rate=",x = data.list[[x]])]))
120 5
    lightsource <- as.numeric(gsub("Lightsource=", "", data.list[[x]][grep(pattern = "^Lightsource=",x = data.list[[x]])]))
121

122 5
    if(lightsource == 2){
123 0
      names[x] <- "IR_OSL"
124
    }
125 5
    if(lightsource == 4){
126 5
      names[x] <- "OSL"
127

128
    }
129 5
    sequence[[x]] <- c(temp,duration,optical_power,b)
130

131

132
  }
133 5
  if(sequence.ID == 8){#TOL
134

135 0
    stop(paste("[read_SEQ2R()] Step ",x," \"TOL\" of your sequence is not supported!", sep = ""))
136

137
  }
138 5
  if(sequence.ID == 9){#TR-POSL
139

140 0
    stop(paste("[read_SEQ2R()] Step ",x," \"TR-POSL\" of your sequence is not supportel!", sep = ""))
141
  }
142

143 5
  if(sequence.ID == 10){# Irradiation
144

145

146 5
    temp <- as.numeric(gsub("An_Temp=", "", data.list[[x]][grep(pattern = "^An_Temp=",x = data.list[[x]])]))
147 5
    duration <- as.numeric(gsub("Irr_Time=", "", data.list[[x]][grep(pattern = "^Irr_Time",x = data.list[[x]])]))
148 5
    if(duration == 0){
149

150 0
      duration <- 1e-13
151
    }
152

153 5
    dose <- duration*lab.dose_rate
154

155 5
    b <- as.numeric(gsub("Rate=", "", data.list[[x]][grep(pattern = "^Rate",x = data.list[[x]])]))
156 5
    PH_time <- as.numeric(gsub("An_Time=", "", data.list[[x]][grep(pattern = "^An_Time",x = data.list[[x]])]))
157

158 5
    names[x] <- "IRR"
159 5
    sequence[[x]] <- c(temp,dose,lab.dose_rate,b,PH_time)
160

161
  }
162

163 5
  if(sequence.ID == 11){# illumination
164

165 0
    temp <- as.numeric(gsub("Temperature=", "", data.list[[x]][grep(pattern = "^Temperature=",x = data.list[[x]])]))
166 0
    duration <- as.numeric(gsub("^Bl_Time=", "", data.list[[x]][grep(pattern = "^Bl_Time",x = data.list[[x]])]))
167 0
    optical_power <- as.numeric(gsub("Power=", "", data.list[[x]][grep(pattern = "^Power",x = data.list[[x]])]))
168

169 0
    b <- as.numeric(gsub("Rate=", "", data.list[[x]][grep(pattern = "^Rate",x = data.list[[x]])]))
170 0
    PH_time <- as.numeric(gsub("An_Time=", "", data.list[[x]][grep(pattern = "^An_Time",x = data.list[[x]])]))
171

172 0
    names[x] <- "ILL"
173 0
    sequence[[x]] <- c(temp,duration,optical_power,b,PH_time)
174

175

176
  }
177

178 5
  if(sequence.ID == 12){# PH
179

180 5
    PH_temp <- as.numeric(gsub("An_Temp=", "", data.list[[x]][grep(pattern = "^An_Temp",x = data.list[[x]])]))
181 5
    PH_time <- as.numeric(gsub("An_Time=", "", data.list[[x]][grep(pattern = "^An_Time",x = data.list[[x]])]))
182 5
    b <- as.numeric(gsub("Rate=", "", data.list[[x]][grep(pattern = "^Rate",x = data.list[[x]])]))
183

184 5
    names[x] <- "PH"
185 5
    sequence[[x]] <- c(PH_temp,PH_time,b)
186

187
  }
188

189 5
  if(sequence.ID == 13){# set temp
190

191 0
    PH_temp <- as.numeric(gsub("An_Temp=", "", data.list[[x]][grep(pattern = "^An_Temp",x = data.list[[x]])]))
192

193 0
    names[x] <- "PH"
194 0
    sequence[[x]] <- c(PH_temp)
195

196
  }
197

198 5
  if(sequence.ID == 14){# Pause
199

200 0
    Pause_time <- as.numeric(gsub("An_Time=", "", data.list[[x]][grep(pattern = "^An_Time",x = data.list[[x]])]))
201

202 0
    names[x] <- "PAUSE"
203 0
    sequence[[x]] <- c(Pause_time)
204

205
  }
206

207 5
  if(sequence.ID == 15){
208

209 0
    stop(paste("[read_SEQ2R()] Step ",x," of your sequence is not supported!", sep = ""))
210
  }
211

212 5
  if(sequence.ID == 16){
213

214 0
    stop(paste("[read_SEQ2R()] Step ",x," of your sequence is not supported!", sep = ""))
215
  }
216

217 5
  if(sequence.ID == 17){
218

219 0
    stop("[read_seq2R()] Low-Level: Not supported!")
220
  }
221

222 5
  if(sequence.ID == 18){# LM-OSL
223

224 0
    temp <- as.numeric(gsub("Temperature=", "", data.list[[x]][grep(pattern = "^Temperature=",x = data.list[[x]])]))
225 0
    duration <- as.numeric(gsub("Rate=", "", data.list[[x]][grep(pattern = "^Rate",x = data.list[[x]])]))
226 0
    start_power <- as.numeric(gsub("Low=", "", data.list[[x]][grep(pattern = "^Low",x = data.list[[x]])]))
227 0
    end_power <- as.numeric(gsub("High=", "", data.list[[x]][grep(pattern = "^High",x = data.list[[x]])]))
228

229 0
    b <- as.numeric(gsub("HeatRate=", "", data.list[[x]][grep(pattern = "^HeatRate",x = data.list[[x]])]))
230 0
    PH_time <- as.numeric(gsub("PreHeatTime=", "", data.list[[x]][grep(pattern = "^PreHeatTime",x = data.list[[x]])]))
231

232 0
    names[x] <- "LM_OSL"
233 0
    sequence[[x]] <- c(temp,duration,start_power,end_power,b,PH_time)
234

235

236
  }
237

238 5
  if(sequence.ID == 19){
239

240 0
    stop(paste("[read_SEQ2R()] Step ",x," \"SG OSL\" of your sequence is not supported!", sep = ""))
241

242
  }
243

244 5
  if(sequence.ID == 20){
245

246 0
    stop(paste("[read_SEQ2R()] Step ",x," \"User defined\" of your sequence is not supported!", sep = ""))
247

248
  }
249

250

251 5
  if(sequence.ID == 21){
252

253 0
    stop(paste("[read_SEQ2R()] Step ",x," \"SG LM-OSL\" of your sequence is not supported!", sep = ""))
254

255
  }
256

257 5
  if(sequence.ID == 22){
258

259 0
    stop(paste("[read_SEQ2R()] Step ",x," of your sequence is not supported!", sep = ""))
260

261
  }
262

263 5
  if(sequence.ID == 23){
264

265 0
    stop(paste("[read_SEQ2R()] Step ",x," \"POSL\" of your sequence is not supported!", sep = ""))
266

267
  }
268

269

270 5
  if(sequence.ID == 28){#RL
271

272 0
    temp <- as.numeric(gsub("Temperature=", "", data.list[[x]][grep(pattern = "^Temperature=",x = data.list[[x]])]))
273 0
    duration <- as.numeric(gsub("High=", "", data.list[[x]][grep(pattern = "^High",x = data.list[[x]])]))
274 0
    lab.dose_rate <- lab.dose_rate
275

276 0
    dose <- duration*lab.dose_rate
277 0
    b <- as.numeric(gsub("Rate=", "", data.list[[x]][grep(pattern = "^Rate",x = data.list[[x]])]))
278

279 0
    names[x] <- "RL"
280 0
    sequence[[x]] <- c(temp,dose,lab.dose_rate,b)
281
  }
282

283 5
  if(sequence.ID == 29){
284

285 0
    stop(paste("[read_SEQ2R()] Step ",x," \"XRF\" of your sequence is not supported!", sep = ""))
286

287
  }
288

289 5
  if(sequence.ID == 30){
290

291 0
    stop(paste("[read_SEQ2R()] Step ",x," \"Photo\" of your sequence is not supported!", sep = ""))
292

293
  }
294

295

296

297
  ##update progress bar
298 5
  if (txtProgressBar) {
299 5
    setTxtProgressBar(pb, x)
300
  }
301

302

303
  }
304
  ##close ProgressBar
305 5
  if(txtProgressBar){close(pb)}
306

307 5
  return(sequence <- setNames(object = sequence, nm = names))
308
}

Read our documentation on viewing source code .

Loading