20190317
20190419 suivre: version mise à jour:
TourDeBabelKlimaLoggProReleve
à consommer dans une fenêtre de commande
set stampdeb et stampfin pour fixer l'étendue
programme pour fusionner un fichier créé par
AutomateMeteociel et celui exporté par
KlimaLoggpro
' 20160302 fusion meteo et .csv de klimaloggpro
' à faire: renommer fichierr en fonction de stampdeb et fin actuels
entete="timestamp meteo rdc Cave cusisine orangerie/grenier"
set wshShell = CreateObject( "WScript.Shell" )
stampdeb= wshShell.ExpandEnvironmentStrings( "%stampdeb%" )
stampfin= wshShell.ExpandEnvironmentStrings( "%stampfin%" )
if mid(stampdeb,1,1)="%" then stampdeb=""
if mid(stampfin,1,1)="%" then stampfin=""
'sgbox stampdeb & vbcrlf & stampfin
dbg=false
dim tklima(100000)
nklima=0
dim tmeteo(100000)
nmeteo=0
Set WshShell = CreateObject("WScript.Shell")
set fso=createobject("scripting.filesystemobject")
if wscript.arguments.count=0 then
msgbox "fusion klimaloggpro et meteo " & vbcrlf & "appel: and.vbs fichier_klimaloggpro_csv fichier_meteo.txt" & vbcrlf & "sortie fichier_meteo.csv" & vbcrlf & _
"éventuellement limité par %stampdeb% et %stampfin%"
wscript.quit
end if
racine=wscript.arguments(0)
if len(racine)<=4 then
msgbox "extension .csv obligatoire pour fichier klimaloggpro"
wscript.quit
end if
if mid(racine,len(racine)-3)<>".csv" then
msgbox "extension .csv obligatoire pour fichier klimaloggpro"
wscript.quit
end if
racine=mid(racine,1,len(racine)-4)
if not fso.fileexists(racine&".csv") then
msgbox racine&".csv"&" pas trouvé"
wscript.quit
end if
if wscript.arguments.count<2 then
msgbox "manque nom fichier meteo"
wscript.quit
end if
set fi=fso.opentextfile(racine&".csv")
racinemeteo=wscript.arguments(1)
if mid(racinemeteo,len(racinemeteo)-3)<>".txt" then
msgbox "extension .txt obligatoire pour fichier meteo."
wscript.quit
end if
if len(racinemeteo)<=4 then
msgbox "extension .txt obligatoire pour fichier meteo."
wscript.quit
end if
if not fso.fileexists(racinemeteo) then
msgbox racinemeteo&".txt"&" pas trouvé"
wscript.quit
end if
set fm=fso.opentextfile(racinemeteo)
' allonger de stampdeb stampfin
n1=len(racinemeteo)-4
outname=mid(racinemeteo,1,n1)
if outname<>stampdeb & "-" & stampfin then
outname=outname & "-" & stampdeb & "-" & stampfin
'sgbox "à renommer"
end if
if fso.fileexists(outname & ".csv") then
msgbox outname & ".csv existe déjà"
wscript.quit
end if
SET out=fso.createtextfile(outname & ".csv",1)
out.writeline entete
dim t
dim tot
nbliklima=0
lireklima
'sgbox "ok lu klima " & nbliklima
nblimeteo=0
liremeteo
'sgbox "ok lu meteo " & nblimeteo
'msgbox "nmeteo:" & nmeteo
merge
sub lireklima
une=fi.readline
pre=""
while not fi.atendofstream
li=fi.readline
nbliklima=nbliklima+1
ok=true
' if mid(li,1,10)<stampdeb then ok=false
' end if
' if stampfin<>"" then
' if mid(li,1,10)>stampfin then ok=false
' end if
if len(li)>3 then ' and ok then
if mid(li,1,3)="201" then
'out.writeline li
jour=mid(li,1,4) & mid(li,6,2) & mid(li,9,2)
' ignorer les lignes de même heure
hh=mid(li, 12,2)
' ajouté filtre sur variables stampdeb stampfin
' msgbox jour & hh & vbcrlf & stampdeb
ok=true
if stampdeb>"" and jour&hh<stampdeb then ok=false
if stampfin>"" and jour&hh>stampfin then ok=false
if ok and hh<>pre then
t=mid(li,21)
tI=pro
tx=pro ' RHI
tx=pro ' DEWI
t1=pro ' T1
tx=pro ' RH1
tx=pro ' DEW1
t2=pro ' T2
tx=pro ' RH2
tx=pro ' DEW2
t3=pro
tx=pro
tx=pro
' out.writeline jour & hh & " " & t & " " & t2 & " " & t3
tklima(nklima)=jour & hh & " " & trim(tI) & " " & trim(t1) & " " & trim(t2)& " " & trim(t3)
nklima=nklima+1
pre=hh
end if ' hh<>pre
end if ' 201
end if ' len >3
wend
'msgbox "nklima:" & nklima
fi.close
end sub
function pro
t=mid(t,2)
f=instr(t,"""")
pro=mid(t,1,f-1)
t=mid(t,f+2)
end function
sub liremeteo ' lire
while not fm.atendofstream
unemeteo=fm.readline
tmeteo(nmeteo)=unemeteo
nmeteo=nmeteo+1
nblimeteo=nblimeteo+1
wend
'msgbox "nmeteo:" & nmeteo & vbcrlf &"nlimima=" & nklima
end sub
sub merge
nout=0
termine=false
imeteo=0
iklima=0
liun=v(tmeteo(imeteo))
imeteo=imeteo+1
litr=v(tklima(iklima))
iklima=iklima+1
while not termine
if mid(liun,1,10)< mid(litr,1,10) then
if dbg then out.writeline "ignorer UN jusqu'à " & litr
while mid(liun,1,10)< mid(litr,1,10) and not termine
if imeteo=nmeteo then
if dbg then out.writeline "liun " & liun
termine=true
else
liun=v(tmeteo(imeteo))
imeteo=imeteo+1
if dbg then out.writeline "avance un " & liun
end if
wend
elseif mid(liun,1,10)> mid(litr,1,10) then
if dbg then out.writeline "ignorer TR jusqu'à " & liun
while mid(liun,1,10)> mid(litr,1,10) and not termine
if iklima=nklima then
termine=true
if dbg then out.writeline "kima"
else
if iklima>100000 then
msgbox "tklima deborde" & iklima
wscript.quit
end if
litr=v(tklima(iklima)):iklima=iklima+1
if dbg then out.writeline "avance TR " &litr& " est il anterieur a " & mid(liun,1,10)
end if
wend
else ' =
if dbg then out.writeline "concordance " & litr & "==" & mid(liun,1,10)
out.writeline liun & mid(litr,11)
nout=nout+1
if imeteo<nmeteo then liun=v(tmeteo(imeteo)):imeteo=imeteo+1: else termine=true
if iklima<nklima then litr=v(tklima(iklima)):iklima=iklima+1: else termine=true
end if
wend
msgbox "fin de merge nout=" & nout
end sub
function v(t)
n=""
for i=1 to len(t)
c=mid(t,i,1)
if c="." then c=","
n=n&c
next
v=n
end function