Le jeudi 20 février 2020, le service gitlab.irstea.fr sera inaccessible en raison d'une migration vers un nouveau centre de données. Merci de votre compréhension.

Commit 0364e9bf authored by Danis Pierre-Alain's avatar Danis Pierre-Alain

Delete Control_Unit.r

parent cf37c8e4
## [mg/m3]=[micro g/L]
##=======================================================================
dicCdParam <- function(param=NA, CdParam=NA)
{
## pierre-alain.danis@afbiodiversite.fr
##
## > dicCdParam('pH', NA)
## [1] 1302
## > dicCdParam(NA, 1350)
## [1] "PT"
##
dicCdParam <- data.frame('As'='1369')
dicCdParam['Argent'] <- '1368'
dicCdParam['Chlorures'] <- '1337'
dicCdParam['CN'] <- '1390'
dicCdParam['Cond25'] <- '1303'
dicCdParam['TH'] <- '1345'
dicCdParam['pH'] <- '1302'
dicCdParam['SO4'] <- '1338'
dicCdParam['TAC'] <- '1347'
dicCdParam['COD'] <- '1841'
dicCdParam['SiO2'] <- '1348'
dicCdParam['Silicates'] <- '1342'
dicCdParam['HCO3'] <- '1327'
dicCdParam['Ca'] <- '1374'
dicCdParam['MES'] <- '1305'
dicCdParam['Na'] <- '1375'
dicCdParam['Mg'] <- '1372'
dicCdParam['K'] <- '1367'
dicCdParam['CO3'] <- '1328'
dicCdParam['Hg'] <- '1387'
dicCdParam['DCO'] <- '1314'
dicCdParam['DBO5'] <- '1313'
dicCdParam['O2'] <- '1311'
dicCdParam['SatO2'] <- '1312'
dicCdParam['NO3'] <- '1340'
dicCdParam['NO2'] <- '1339'
dicCdParam['NH4'] <- '1335'
dicCdParam['NKJ'] <- '1319'
dicCdParam['AzoteGlobal'] <- '1551'
dicCdParam['PO4'] <- '1433'
dicCdParam['PT'] <- '1350'
dicCdParam['Bore'] <- '1362'
dicCdParam['TempEau'] <- '1301'
dicCdParam['Turbidite'] <- '1295'
dicCdParam['Pb'] <- '1382'
dicCdParam['Pheopigment'] <- '1436'
dicCdParam['ChloA'] <- '1439'
dicCdParam['Couleur'] <- '1309'
dicCdParam['Secchi'] <- '1332'
dicCdParam['TempAir'] <- ''
dicCdParam['Fluor'] <- '1391'
dicCdParam['FerTotal'] <- '1393'
dicCdParam['FerIIdissous'] <- '1393'
dicCdParam['Mn'] <- '1394'
dicCdParam['Al'] <- '1370'
dicCdParam['MatSec'] <- '1799'
if (is.na(param)) return (colnames((dicCdParam[which(dicCdParam == CdParam)])))
if (is.na(CdParam)) return (as.numeric(dicCdParam[which(colnames(dicCdParam) == param)]))
}
##=======================================================================
##VerifUnit('Euph','Al',25,'2782')
VerifUnit <- function(Zone, param, ResAna, CdUnit)
{
## pierre-alain.danis@afbiodiversite.fr
##
## > VerifUnit('Sed', 'Hg', 23, 158)
## [1] 23
## >
##
##
if (is.na(ResAna)) return(NA)
if (Zone %in% c('Euph', 'Fond', 'Int','Profil'))
{
if (param == 'Al' & CdUnit == '278') ResAnaOK=ResAna # [micro-g d'Al/L]
else if (param == 'As' & (CdUnit == '280' | CdUnit == '133')) ResAnaOK=ResAna # [micro-g d'As/L]
else if (param == 'As' & CdUnit == '162') ResAnaOK=ResAna*1000. # [mg/L]->[micro-g/L]
else if (param == 'AzoteGlobal' & CdUnit == '168') ResAnaOK=ResAna*1000. # [mg N/L]->[micro-g/L]
else if (param == 'Bore' & CdUnit == '162') ResAnaOK=ResAna*1000. # [mg/L]->[micro-g/L]
else if (param == 'Bore' & (CdUnit == '282' | CdUnit == '133')) ResAnaOK=ResAna# [microgramme de bore par litre]
else if (param == 'Ca' & (CdUnit == '162' | CdUnit == '292')) ResAnaOK=ResAna # [mg/L]
else if ((param == 'ChloA' | param == 'ChloAp') & (CdUnit == '133' | CdUnit == '161')) ResAnaOK=ResAna # [micro g/L] | [mg/m3]=[micro g/L]
else if (param == 'Chlorures' & (CdUnit == '162' | CdUnit == '164')) ResAnaOK=ResAna # [mg de Chlore /L]
else if (param == 'CN' & (CdUnit == '380' | CdUnit == '133')) ResAnaOK=ResAna # [micro-g de cyanures/L]
else if (param == 'CN' & CdUnit == '162') ResAnaOK=ResAna*1000. # [mg/L]->[micro-g/L]
else if (param == 'CO3' & (CdUnit == '162' | CdUnit == '167')) ResAnaOK=ResAna # [mg/L]
else if (param == 'COD' & (CdUnit == '162' | CdUnit == '163')) ResAnaOK=ResAna# [mg/L]
else if (param == 'COD' & (CdUnit == '133' | CdUnit == '161')) ResAnaOK=ResAna/1000. # [mg/m3]=[micro g/L] => [mg/L]
else if (param == 'COT' & (CdUnit == '162' | CdUnit == '163')) ResAnaOK=ResAna# [mg/L]
else if (param == 'Cond25' & CdUnit == '147') ResAnaOK=ResAna # [microS/cm a 25C]
else if (param == 'Cond20' & CdUnit == '147')ResAnaOK=ResAna/0.901 # [microS/cm a 20C] converti a 25C
## voir D:\02_PhysicoChimie\Conductivite.xls
else if (param == 'Couleur' & CdUnit == '178') ResAnaOK=ResAna # [milligramme de platine par litre]
else if (param == 'DBO5' & (CdUnit == '162' | CdUnit == '175')) ResAnaOK=ResAna # [mg/L]
else if (param == 'DCO' & (CdUnit == '162' | CdUnit == '175')) ResAnaOK=ResAna # [mg/L]
##else if (param == 'Fer' & (CdUnit == '307' | CdUnit == '133')) # [micro-g de Fer/L]
## ResAnaOK=ResAna
else if (param == 'FerTotal' & (CdUnit == '307' | CdUnit == '133')) ResAnaOK=ResAna # [micro-g de Fer/L]
else if (param == 'FerIIdissous' & (CdUnit == '307' | CdUnit == '133')) ResAnaOK=ResAna # [micro-g de Fer/L]
else if (param == 'HCO3' & (CdUnit == '162' | CdUnit == '274')) ResAnaOK=ResAna # [mg/L]
else if (param == 'K' & (CdUnit == '162' | CdUnit == '316')) ResAnaOK=ResAna # [mg/L]
else if (param == 'Fluor' & (CdUnit == '162' | CdUnit == '306')) ResAnaOK=ResAna # [mg/L]
else if (param == 'MES' & (CdUnit == '162' | CdUnit == '175')) ResAnaOK=ResAna # [mg/L]
else if (param == 'Mg' & (CdUnit == '162' | CdUnit == '320')) ResAnaOK=ResAna # [mg/L]
else if (param == 'Mn' & (CdUnit == '321')) ResAnaOK=ResAna # [microgramme de manganèse par litre]
else if (param == 'Mn' & (CdUnit == '162' )) ResAnaOK=ResAna*1000. # [mg/L]-> [micro-g/L]
else if (param == 'Na' & (CdUnit == '162' | CdUnit == '326')) ResAnaOK=ResAna # [mg/L]
else if (param == 'NO3' & (CdUnit == '162' | CdUnit == '173')) ResAnaOK=ResAna*1000. # Nitrates[mg NO3/L] -> [micro-g NO3/L]
else if (param == 'NO3' & CdUnit == '168' ) ResAnaOK=ResAna*(14.+3.*16.)/(14.)*1000. # Nitrates [mg N/L] -> [mg NO3/L] -> [micro-g NO3/L]
else if (param == 'NO2' & (CdUnit == '162' | CdUnit == '171')) ResAnaOK=ResAna*1000. # # Nitrites [mg NO2/L] -> [micro-g NO2/L]
else if (param == 'NO2' & CdUnit == '168' ) ResAnaOK=ResAna*(14.+2.*16.)/(14.)*1000. # # Nitrites[mg N/L] -> [mg NO2/L] -> [micro-g NO2/L]
else if (param == 'NH4' & (CdUnit == '162' | CdUnit == '169')) ResAnaOK=ResAna*1000. # Ammonium [mg NH4/L] -> [micro-g NH4/L]
else if (param == 'NH4' & CdUnit == '168') ResAnaOK=ResAna*(14.+4.)/(14.)*1000. # [mg N/L] -> [mg NH4/L] -> [micro-g NH4/L]
else if (param == 'NH4' & CdUnit == '327') ResAnaOK=ResAna*(14.+4.)/(14.+3.)*1000. # Ammoniac [mg NH3/L] -> [mg NH4/L] -> [micro-g NH4/L] # erreur unite ou code parametre
else if (param == 'NKJ' & (CdUnit == '162' | CdUnit == '168')) ResAnaOK=ResAna*1000. # [mg N/L] -> [micro-g N/L]
else if (param == 'AzoteGlobal' & (CdUnit == '162' | CdUnit == '168')) ResAnaOK=ResAna*1000. # [mg N/L] -> [micro-g N/L]
else if (param == 'O2' & (CdUnit == '162' | CdUnit == '175')) ResAnaOK=ResAna # [mg/L]
else if (param == 'Pb' & (CdUnit == '335' | CdUnit == '133' | CdUnit == '301' )) # [µg/L]
{
ResAnaOK=ResAna
if (CdUnit == '301') print(c('pb unite dans table '))
}
else if (param == 'pH' & (CdUnit == '264' | CdUnit == '0')) # [pH]
{
ResAnaOK=ResAna
if (CdUnit == '0') print(paste('cdunite a coriger dans base'))
}
else if (param == 'Pheopigment' & (CdUnit == '161' | CdUnit == '133')) # [mg/m3]=[micro g/L]
{
if (ResAna >= 0) ResAnaOK=ResAna
else if (ResAna < 0) ResAnaOK = NA
}
else if (param == 'Pheopigment' & CdUnit == '133')# [micro g/L]
{
if (ResAna>=0) ResAnaOK=ResAna
else if (ResAna<0) ResAnaOK=NA # D apres Christophe Laplace courriel du 26/04/2011 (NA)
}
else if (param == 'PO4' & (CdUnit == '162' | CdUnit == '176')) ResAnaOK=ResAna*1000. # [mg PO4/L] -> [micro g PO4/L]
else if (param == 'PO4' & CdUnit == '177' ) ResAnaOK=ResAna*(31.+4.*16.)/(31.)*1000. # [mg P/L] -> [mg PO4/L] -> [micro g PO4/L]
else if (param == 'PT' & (CdUnit == '162' | CdUnit == '177')) ResAnaOK=ResAna*1000. # [mg/L] -> [micro g/L]
else if (param == 'PT' & CdUnit == '133') ResAnaOK=ResAna # [micro g/L]
else if (param == 'SatO2' & CdUnit == '243') ResAnaOK=ResAna # [%]
else if (param == 'Secchi' & CdUnit == '111') ResAnaOK=ResAna # [m]
else if (param == 'Secchi' & CdUnit == '13') ResAnaOK=ResAna/100. # [cm] -> [m]
else if (param == 'SiO2' & (CdUnit == '162' | CdUnit == '273')) ResAnaOK=ResAna # [mg/L]
else if (param == 'Silicates' & CdUnit == '273') ResAnaOK=ResAna # [mg SiO2/L]
else if (param == 'Silicates' & (CdUnit == '162' | CdUnit == '337')) ResAnaOK=ResAna*(28.+2.*16.)/(28.+3.*16) # [mg SiO3/L]->[mg SiO2/ L]
#else if (param == 'TempEau' & CdUnit == '27') ResAnaOK=ResAna # [C]
else if (param == 'SO4' & (CdUnit == '162' | CdUnit == '179')) ResAnaOK=ResAna # [mg/L]
else if ((param == 'TAC' | param == 'TH') & CdUnit == '28') ResAnaOK=ResAna*0.2 # [degres fancais]->[mEq/L]
else if ((param == 'TAC' | param == 'TH') & CdUnit == '155') ResAnaOK=ResAna # [mEq/L]
else if ((param == 'TAC' | param == 'TH') & CdUnit == '192')
{
# 1 degré français correspond à [10-4 mol/L] e.i. [0.1 mmol/L]
ResAnaOK=ResAna*10.*0.2 # [mmol/L]->[degres fancais]->[mEq/L]
print(paste('Pb unite pour ',param, 'ds control unit 49'))
}
else if (param == 'Temp' & CdUnit == '27') ResAnaOK=ResAna # [degres C]
else if (param == 'Turbidite' & (CdUnit == '232' | CdUnit == '233') ) ResAnaOK=ResAna # [NTU]
else print(paste(Zone,'Manque unite ',CdUnit,' de ',param,' pour ',param,sep=''))
}
else if (Zone == 'Sed')
{
if (param == 'COD' & (CdUnit == '160' | CdUnit == '382' | CdUnit == '53' | CdUnit == '158')) ResAnaOK=ResAna # [mg/kg]
else if (param == 'COD' & (CdUnit == '409' | CdUnit == '45' | CdUnit == '401')) ResAnaOK=ResAna*1000. # [g/kg] => [mg/kg]
else if (param == 'COD' & (CdUnit == '243' | CdUnit == '246')) ResAnaOK=ResAna/100.*1000000. # [%] => [kg/kg] => [mg/kg]
else if (param == 'PT' & (CdUnit == '160' | CdUnit == '158' | CdUnit == '381' | CdUnit == '53' )) ResAnaOK=ResAna # [mg/kg]
else if (param == 'PT' & (CdUnit == '401' | CdUnit == '45' )) ResAnaOK=ResAna*1000. # [g/kg] => [mg/kg]
else if (param == 'PT' & (CdUnit == '243' | CdUnit == '246')) ResAnaOK=ResAna/100.*1000000. # [%] => [kg/kg] => [mg/kg]
else if (param == 'NKJ' & (CdUnit == '160' | CdUnit == '158' | CdUnit == '395' | CdUnit == '53')) ResAnaOK=ResAna # [mg/kg]
else if ( param == 'NKJ' & (CdUnit == '401' | CdUnit == '354')) ResAnaOK=ResAna*1000. # [g/kg] => [mg/kg]
else if ( param == 'NKJ' & (CdUnit == '243' | CdUnit == '246')) ResAnaOK=ResAna/100.*1000000. # [%] => [kg/kg] => [mg/kg]
else if (param == 'AzoteGlobal' & (CdUnit == '160' | CdUnit == '158' | CdUnit == '395' | CdUnit == '53')) ResAnaOK=ResAna # [mg/kg]
else if (param == 'AzoteGlobal' & (CdUnit == '401' | CdUnit == '354' | CdUnit == '45')) ResAnaOK=ResAna*1000. # [g/kg] => [mg/kg]
else if (param == 'AzoteGlobal' & (CdUnit == '243' | CdUnit == '246')) ResAnaOK=ResAna/100.*1000000. # [%] => [kg/kg] => [mg/kg]
else if (param == 'FerTotal' & (CdUnit == '160' | CdUnit == '158' | CdUnit == '308')) ResAnaOK=ResAna # [mg/kg]
else if (param == 'Al' & (CdUnit == '160' | CdUnit == '279')) ResAnaOK=ResAna # [mg/kg]
else if (param == 'Al' & (CdUnit == '246')) ResAnaOK=ResAna/100*1000000 # [%]=[kg/kg] => [mg/kg]
else if (param == 'Mn' & (CdUnit == '160' | CdUnit == '158' | CdUnit == '322')) ResAnaOK=ResAna # [mg/kg]
else if (param == 'Al' & (CdUnit == '160' | CdUnit == '158' | CdUnit == '279')) ResAnaOK=ResAna # [mg/kg]
else if (param == 'MatSec' & (CdUnit == '243' | CdUnit == '399' | CdUnit == '246')) ResAnaOK=ResAna # [%]
else if (param == 'Perte550' & (CdUnit == '243' | CdUnit == '246')) ResAnaOK=ResAna # [%]
else if (substr(param,1,7) == 'Granulo' & (CdUnit == '243' | CdUnit == '246')) ResAnaOK=ResAna # [%]
else if (param == 'As' & (CdUnit == '160' | CdUnit == '158' | CdUnit == '366' )) ResAnaOK=ResAna # [mg/kg]
else if (param == 'Argent' & (CdUnit == '160' | CdUnit == '158' | CdUnit == '277' )) ResAnaOK=ResAna #[mg/kg]
else if (param == 'Hg' & (CdUnit == '160' | CdUnit == '158' | CdUnit == '312')) ResAnaOK=ResAna #[mg/kg]
else if (param == 'Pb' & (CdUnit == '160' | CdUnit == '158'| CdUnit == '336')) ResAnaOK=ResAna #[mg/kg]
else if (param == 'Bore' & (CdUnit == '283' | CdUnit == '158' | CdUnit == '160' )) ResAnaOK=ResAna #[mg/kg]
else print(paste(Zone,'Manque unite :', CdUnit, param))
}
else if (Zone == 'WaterInSed')
{
if ( param == 'PT' & (CdUnit == '162' | CdUnit == '177')) ResAnaOK=ResAna*1000. # [mg/L] -> [micro g/L] #si 176 faire ResAna*31/95 ou enlever de la base si doublons avec 177
else if (param == 'PO4' & (CdUnit == '162' | CdUnit == '176')) ResAnaOK=ResAna*1000. # [mg PO4/L] -> [micro g PO4/L]
else if (param == 'PO4' & CdUnit == '177' ) ResAnaOK=ResAna*(31.+4.*16.)/(31.)*1000. # [mg P/L] -> [mg PO4/L] -> [micro g PO4/L]
else if (param == 'NH4' & (CdUnit == '162' | CdUnit == '169')) ResAnaOK=ResAna*1000. # [mg NH4/L]->[micro-g NH4/L]#Ammonium
else if (param == 'NH4' & CdUnit == '378') ResAnaOK=ResAn ## [micro-g NH4/L] #Ammonium
else if (param == 'NKJ' & (CdUnit == '168')) ResAnaOK=ResAna*1000. # [mg N/L]->[micro-g N/L] #### | CdUnit == '243')) 243 doit être une erreur !! PAD 25/03/2016
else if (param == 'AzoteGlobal' & (CdUnit == '168' | CdUnit == '45')) ResAnaOK=ResAna*1000. # [mg N/L]->[micro-g N/L]
else if (param == 'NH4' & CdUnit == '168') ResAnaOK=ResAna*(14.+4.)/(14.)*1000. # [mg N/L]->[mg NH4/L]->[micro-g NH4/L] # Ammoniac
else if (param == 'NH4' & CdUnit == '327') ResAnaOK=ResAna*(14.+4.)/(14.+3.)*1000. #[mg NH3/L]->[mg NH4/L]->[micro-g NH4/L] # Ammoniac # erreur unite ou code parametre
else if (param == 'FerIIdissous' & CdUnit == '307') ResAnaOK=ResAna #[micro-g Fer/L]
else
{
print(paste(Zone,'Manque unite:',CdUnit,param,dicCdParam(param,NA)))
ResAnaOK <- NA
}
}
else
{
print(paste('Manque Zone=',Zone,' ??? (in fct Control_Unit)'))
ResAnaOK <- NA
}
return (ResAnaOK)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment