Newer
Older
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
# General information on station
iStatut = c('0'='inconnu',
'1'='station avec signification hydrologique',
'2'='station sans signification hydrologique',
'3'="station d'essai")
iFinalite = c('0'='inconnue',
'1'="hydrométrie générale",
'2'='alerte de crue',
'3'="hydrométrie générale et alerte de crue",
'4'="gestion d'ouvrage",
'5'='police des eaux',
'6'="suivi d'étiage",
'7'='bassin expérimental',
'8'='drainage')
iType = c('0'='inconnu',
'1'='une échelle',
'2'='deux échelles, station mère',
'3'='deux échelles, station fille',
'4'='débits mesurés',
'5'='virtuelle')
iInfluence = c('0'='inconnue',
'1'='nulle ou faible',
'2'='en étiage seulement',
'3'='forte en toute saison')
iDebit = c('0'='reconstitué',
'1'="réel (prise en compte de l'eau rajoutée ou retirée du bassin selon aménagements)",
'2'='naturel')
iQBE = c('0'='qualité basses eaux inconnue',
'1'='qualité basses eaux bonne',
'2'='qualité basses eaux douteuse')
iQME = c('0'='qualité moyennes eaux inconnue',
'1'='qualité moyennes eaux bonne',
'2'='qualité moyennes eaux douteuse')
iQHE = c('0'='qualité hautes eaux inconnue',
'1'='qualité hautes eaux bonne',
'2'='qualité hautes eaux douteuse')
extract_info = function (data_path, filedir, filename, verbose=TRUE) {
# Convert the filename in vector
# If the filename is 'all' or regroup more than one filename
# Create a filelist to store all the filename
# Get all the filename in the data directory selected
# For all the filename in the directory selected
# If the filename extention is 'txt'
# Store the filename in the filelist
# If the filename regroup more than one filename
# The filelist correspond to the filename
}
# Create a blank data frame
# For all the file in the filelist
# Concatenate by raw data frames created by this function when filename correspond to only one filename
df_info = rbind(df_info,
extract_info(data_path,
filedir,
# Set the rownames by default (to avoid strange numbering)
# Get the filename from the vector
filename = filename[1]
# Print information if asked
if (verbose) {
print(paste("extraction of info for file :", filename))
}
# Create a tibble with all the information needed
df_info =
tibble(code=trimws(substr(infotxt[11], 38, nchar(infotxt[11]))),
nom=trimws(substr(infotxt[12], 39, nchar(infotxt[12]))),
territoire=trimws(substr(infotxt[13], 39, nchar(infotxt[13]))),
L93X=as.numeric(substr(infotxt[16], 38, 50)),
L93Y=as.numeric(substr(infotxt[16], 52, 63)),
surface=as.numeric(substr(infotxt[19], 38, 50)),
statut=iStatut[trimws(substr(infotxt[26], 38, 50))],
finalite=iFinalite[trimws(substr(infotxt[26], 52, 56))],
type=iType[trimws(substr(infotxt[26], 58, 58))],
influence=iInfluence[trimws(substr(infotxt[26], 60, 60))],
debit=iDebit[trimws(substr(infotxt[26], 62, 62))],
QBE=iQBE[trimws(substr(infotxt[26], 72, 72))],
QME=iQME[trimws(substr(infotxt[26], 74, 74))],
QHE=iQHE[trimws(substr(infotxt[26], 76, 76))],
file_path=file_path
)
# "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data",
# '',
# c('H5920011_HYDRO_QJM.txt', 'K4470010_HYDRO_QJM.txt'))
extract_data = function (data_path, filedir, filename, verbose=TRUE) {
# If the filename is 'all' or regroup more than one filename
# Create a filelist to store all the filename
# Get all the filename in the data directory selected
filelist_tmp = list.files(file.path(data_path,
filedir))
# For all the filename in the directory selected
# If the filename extention is 'txt'
# Store the filename in the filelist
# If the filename regroup more than one filename
# The filelist correspond to the filename
# For all the file in the filelist
# Concatenate by raw data frames created by this function when filename correspond to only one filename
df_data = rbind(df_data,
extract_data(data_path,
filedir,
# Set the rownames by default (to avoid strange numbering)
# Get the filename from the vector
# Print information if asked
if (verbose) {
print(paste("extraction of data for file :", filename))
}
# Extract all the information for the station
df_info = extract_info(data_path, filedir, filename, verbose=FALSE)
# Get the code of the station
# Create a tibble with the date as Date class and the code of the station
df_data = tibble(Date=as.Date(as.character(df_data$Date),
format="%Y%m%d"),
df_data[-1],
code=code)
# "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data",
# '',
# c('H5920011_HYDRO_QJM.txt', 'K4470010_HYDRO_QJM.txt'))