forked from EarthSystemDiagnostics/piccr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
piccr-main.R
executable file
·99 lines (63 loc) · 2.53 KB
/
piccr-main.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env Rscript
##===================================================================================
## MAIN FUNCTION OF piccr
##
## author: Thomas Muench (tmuench@awi.de)
## last update: December 2017
##===================================================================================
cat('\n=== Starting piccr ===\n')
#====================================================================================
# SOURCE SUB ROUTINES
cat('\nSourcing piccr files...\n')
## path of folder containing piccr
package_folder=as.character(Sys.getenv()['PWD'])
## all R files in piccr folder
pck.files=list.files(package_folder,pattern='[.][R]$')
## exclude main routine (does not need to be sourced)
pck.files=pck.files[-grep('main',pck.files)]
## source files
for (f in pck.files){
cat(f,':')
source(file.path(package_folder,f))
cat(' ok.\n')
}
cat('\n')
#====================================================================================
# INPUT
cat('Reading meta input...')
## get command line arguments
args=commandArgs(TRUE)
## first command line argument is working folder where Picarro isotope data
## files are located together with INPUT.txt specifying necessary input info
working_folder=args[1]
## error handling
if (is.na(working_folder))
stop('\nSpecify folder containing the Picarro data as command-line argument.\n')
## read meta input
meta.info_folder=get.input_folder(working_folder)
cat('done.\n')
#====================================================================================
# READ RAW DATA FROM FILES
cat('Reading data...')
## call reading routine
isotope_data=wrapper.ReadDataFiles(meta.info_folder)
## store file data and meta information as list structure
folder.iso_data=list(isotope_data=isotope_data,
meta.info_folder=meta.info_folder)
cat('done.\n')
#====================================================================================
# CORRECT AND CALIBRATE RAW DATA
cat('Calibrating data...')
calibration.results=CalibratePicarroData(folder.iso_data,
meta.info_folder$flag.MemCorr,meta.info_folder$flag.Calibration)
cat('done.\n')
#====================================================================================
# OUTPUT OF CALIBRATED DATA AND ACCURACY ESTIMATES
cat('Writing output...')
WriteOutput(calibration.results,meta.info_folder)
cat('done.\n')
#====================================================================================
# END
cat('\nProgramme run successful.\n\n')
q(save="no",status=0)
#====================================================================================