summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2015-11-18 14:56:44 +0100
committerErich Eckner <git@eckner.net>2015-11-19 11:46:44 +0100
commitc42d9c90f212cf3a23844421b07a77154f604e7f (patch)
tree207bb8196040ba0abf876d6ae79560d91f33f6c9
parenta83b351ed71b1b1ce1aaa2c5685241c9e5cde214 (diff)
downloadFH-Wetter-c42d9c90f212cf3a23844421b07a77154f604e7f.tar.xz
pegelunit.pas schreibt jetzt auch binär
-rw-r--r--pegelunit.pas212
-rw-r--r--wetter.konf2
-rw-r--r--wetter.lps167
3 files changed, 260 insertions, 121 deletions
diff --git a/pegelunit.pas b/pegelunit.pas
index e63a799..d5fd5a5 100644
--- a/pegelunit.pas
+++ b/pegelunit.pas
@@ -31,6 +31,9 @@ type
procedure lade(s: string);
property zeit: extended read _uzeit;
property hoehe: longint read _hoehe;
+ procedure dump(p: pointer);
+ procedure pmud(p: pointer);
+ function size: longint;
end;
tPegelListe = class
@@ -47,6 +50,9 @@ type
property items[i: longint]: tPegelStand
read rItem; default;
function minMaxY(startZeit,stopZeit: extended): tPoint;
+ procedure dump(p: pointer);
+ procedure pmud(p: pointer; version,len: longint);
+ function size: longint;
end;
tPegelUpdateThread = class(tThread)
@@ -83,7 +89,7 @@ type
implementation
-uses math, unit1, myStringListUnit;
+uses math, unit1, myStringListUnit, fileUnit;
const
pegelStationsNamen: array[tPegelstation] of array[0..1] of string =
@@ -172,6 +178,24 @@ begin
end;
end;
+procedure tPegelStand.dump(p: pointer);
+begin
+ pExtended(p)^:=_uZeit;
+ pLongint(p+sizeof(extended))^:=_hoehe;
+end;
+
+procedure tPegelStand.pmud(p: pointer);
+begin
+ _uZeit:=pExtended(p)^;
+ _hoehe:=pLongint(p+sizeof(extended))^;
+ setzeZeit;
+end;
+
+function tPegelStand.size: longint;
+begin
+ result:=sizeof(extended)+sizeof(longint);
+end;
+
// tPegelListe *****************************************************************
constructor tPegelListe.create;
@@ -252,6 +276,60 @@ begin
end;
end;
+procedure tPegelListe.dump(p: pointer);
+var
+ i,siz: longint;
+begin
+ if count=0 then exit;
+ siz:=items[0].size;
+ for i:=0 to count-1 do begin
+ items[i].dump(p);
+ p:=p+siz;
+ end;
+end;
+
+procedure tPegelListe.pmud(p: pointer; version,len: longint);
+var
+ i,siz: longint;
+ np: tPegelStand;
+begin
+ case version of
+ 0: begin
+ inhalt.clear;
+
+ np:=tPegelStand.create;
+ siz:=np.size;
+
+ if len mod siz <> 0 then begin
+ writeln('Datenlänge ('+inttostr(len)+' Byte) ist kein Vielfaches der Länge eines Datums ('+inttostr(siz)+' Byte)!');
+ raise exception.create('Datenlänge ('+inttostr(len)+' Byte) ist kein Vielfaches der Länge eines Datums ('+inttostr(siz)+' Byte)!');
+ end;
+
+ np.pmud(p);
+ p:=p+siz;
+ inhalt.add(np);
+
+ for i:=1 to (len div siz)-1 do begin
+ np:=tPegelStand.create;
+ np.pmud(p);
+ p:=p+siz;
+ inhalt.add(np);
+ end;
+ end;
+ else begin
+ writeln('Zu neue Dateiversion: Ich verstehe nur bis Version 0, es liegt aber Version '+inttostr(version)+' vor!');
+ raise exception.create('Zu neue Dateiversion: Ich verstehe nur bis Version 0, es liegt aber Version '+inttostr(version)+' vor!');
+ end;
+ end{of case};
+end;
+
+function tPegelListe.size: longint;
+begin
+ result:=count;
+ if result>0 then
+ result:=result*items[0].size;
+end;
+
// tPegelUpdateThread **********************************************************
constructor tPegelUpdateThread.create(besitzer: tPegelStaende);
@@ -434,72 +512,118 @@ end;
procedure tPegelStaende.laden(von: string);
var
- f: tMyStringList;
+ sl: tMyStringList;
s: string;
ps: tPegelstation;
psda,gefunden: boolean;
- i: longint;
+ i,len: longint;
+ pt: pointer;
begin
if not fileexists(von) then begin
writeln('Pegeldatei '''+von+''' existiert nicht!');
raise exception.create('Pegeldatei '''+von+''' existiert nicht!');
exit;
end;
- f:=tMyStringList.create;
+
if rightStr(von,3)='.gz' then
- f.loadFromGz(von)
+ loadFromGz(von,pt,len)
else
- f.loadFromFile(von);
- psda:=false;
- ps:=low(TPegelstation);
- while f.readln(s) do begin
- if pos('Station: ',s)=1 then begin
- delete(s,1,pos(' ',s));
- ps:=low(TPegelstation);
- gefunden:=false;
- while ps<=high(TPegelstation) do begin
- for i:=0 to length(Pegelstationsnamen[psBlankenstein])-1 do
- gefunden:=gefunden or ((Pegelstationsnamen[ps,i]<>'') and (Pegelstationsnamen[ps,i]=s));
- if gefunden then break;
- inc(ps);
+ loadFromFile(von,pt,len);
+
+ if pLongint(pt)^ <> 314159265 then begin // magische Zahl nicht gefunden -> Rückfallebene: Text!
+ sl:=tMyStringList.create;
+ setlength(s,len);
+ move(pt^,s[1],length(s));
+ sl.text:=s;
+
+ psda:=false;
+ ps:=low(TPegelstation);
+ while sl.readln(s) do begin
+ if pos('Station: ',s)=1 then begin
+ delete(s,1,pos(' ',s));
+ ps:=low(TPegelstation);
+ gefunden:=false;
+ while ps<=high(TPegelstation) do begin
+ for i:=0 to length(Pegelstationsnamen[psBlankenstein])-1 do
+ gefunden:=gefunden or ((Pegelstationsnamen[ps,i]<>'') and (Pegelstationsnamen[ps,i]=s));
+ if gefunden then break;
+ inc(ps);
+ end;
+ if not gefunden then begin
+ sl.free;
+ writeln('Pegelstation '''+s+''' nicht gefunden '''+Pegelstationsnamen[psSaalfeld,0]+'''!');
+ raise exception.create('Pegelstation '''+s+''' nicht gefunden '''+Pegelstationsnamen[psSaalfeld,0]+'''!');
+ end;
+ psda:=true;
+ continue;
end;
- if not gefunden then begin
- f.free;
- writeln('Pegelstation '''+s+''' nicht gefunden '''+Pegelstationsnamen[psSaalfeld,0]+'''!');
- raise exception.create('Pegelstation '''+s+''' nicht gefunden '''+Pegelstationsnamen[psSaalfeld,0]+'''!');
+ if not psda then begin
+ sl.free;
+ writeln('Es wurde noch keine Pegelstation erwähnt!');
+ raise exception.create('Es wurde noch keine Pegelstation erwähnt!');
end;
- psda:=true;
- continue;
- end;
- if not psda then begin
- f.free;
- writeln('Es wurde noch keine Pegelstation erwähnt!');
- raise exception.create('Es wurde noch keine Pegelstation erwähnt!');
+ werte[ps].add(s);
end;
- werte[ps].add(s);
+ sl.free;
+ end
+ else begin
+ case (pLongint(pt)+1)^ of
+ 0: begin
+ i:=2*sizeof(longint);
+ for ps:=low(tPegelStation) to high(tPegelStation) do begin
+ werte[ps].pmud(pt+i+sizeof(longint),(pLongint(pt)+1)^,pLongint(pt+i)^);
+ i:=i+werte[ps].size+sizeof(longint);
+ end;
+ end;
+ else begin
+ writeln('Zu neue Dateiversion: Ich verstehe nur bis Version 0, es liegt aber Version '+inttostr((pLongint(pt)+1)^)+' vor!');
+ raise exception.create('Zu neue Dateiversion: Ich verstehe nur bis Version 0, es liegt aber Version '+inttostr((pLongint(pt)+1)^)+' vor!');
+ end;
+ end{of case};
end;
- f.free;
+ freemem(pt);
+
if not assigned(put) then
put:=tPegelUpdateThread.create(self);
end;
procedure tPegelStaende.speichern(nach: string);
var
- f: tMyStringList;
- ps: tPegelStation;
- i: longint;
+ sl: tMyStringList;
+ ps: tPegelStation;
+ pt: pointer;
+ i,len: longint;
begin
- f:=tMyStringList.create;
- for ps:=low(tPegelStation) to high(tPegelStation) do begin
- f.add('Station: '+Pegelstationsnamen[ps,0]);
- for i:=0 to werte[ps].Count-1 do
- f.add(werte[ps][i].schreibe);
+ if rightStr(nach,4)='.txt' then begin // Rückfallebene: Text
+ sl:=tMyStringList.create;
+ for ps:=low(tPegelStation) to high(tPegelStation) do begin
+ sl.add('Station: '+Pegelstationsnamen[ps,0]);
+ for i:=0 to werte[ps].Count-1 do
+ sl.add(werte[ps][i].schreibe);
+ end;
+ sl.saveToFile(nach);
+ sl.free;
+ end
+ else begin
+ len:=2*sizeof(longint);
+ for ps:=low(tPegelStation) to high(tPegelStation) do
+ len:=len+werte[ps].size+sizeof(longint);
+ getmem(pt,len);
+ pLongint(pt)^:=314159265; // magische Zahl
+ (pLongint(pt)+1)^:=0; // Version
+ i:=2*sizeof(longint);
+ for ps:=low(tPegelStation) to high(tPegelStation) do begin
+ pLongint(pt+i)^:=werte[ps].size;
+ i:=i+sizeof(longint);
+ werte[ps].dump(pt+i);
+ i:=i+werte[ps].size;
+ end;
+ if rightStr(nach,3)='.gz' then
+ saveToGz(nach,pt,len)
+ else
+ saveToFile(nach,pt,len);
+ freemem(pt);
end;
- if rightStr(nach,3)='.gz' then
- f.saveToGz(nach)
- else
- f.saveToFile(nach);
- f.free;
end;
procedure tPegelStaende.achsenZeichnen(zuZeichnen: tPegelStationsSet; startZeit,stopZeit: extended);
diff --git a/wetter.konf b/wetter.konf
index dd0e27a..4a6d73a 100644
--- a/wetter.konf
+++ b/wetter.konf
@@ -1,4 +1,4 @@
pidDatei: /tmp/wetter.pid
wetterDatei: letztes_Wetter.dat.gz
-pegelDatei: letzte_Pegel.txt.gz
+pegelDatei: letzte_Pegel.dat.gz
datenZeitRaum: 7*4
diff --git a/wetter.lps b/wetter.lps
index 7a0d7ad..cd04c8e 100644
--- a/wetter.lps
+++ b/wetter.lps
@@ -3,13 +3,13 @@
<ProjectSession>
<Version Value="9"/>
<BuildModes Active="Default"/>
- <Units Count="14">
+ <Units Count="16">
<Unit0>
<Filename Value="wetter.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="12" Y="6"/>
- <UsageCount Value="53"/>
+ <UsageCount Value="55"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
@@ -18,9 +18,9 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
- <TopLine Value="184"/>
- <CursorPos X="13" Y="213"/>
- <UsageCount Value="53"/>
+ <TopLine Value="86"/>
+ <CursorPos Y="91"/>
+ <UsageCount Value="55"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
@@ -28,212 +28,227 @@
<Filename Value="original/pegelunit.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
- <UsageCount Value="53"/>
+ <UsageCount Value="55"/>
</Unit2>
<Unit3>
<Filename Value="fhunit.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="2"/>
- <TopLine Value="539"/>
- <CursorPos X="41" Y="554"/>
- <UsageCount Value="53"/>
+ <TopLine Value="513"/>
+ <CursorPos X="8" Y="574"/>
+ <UsageCount Value="55"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
+ <Filename Value="../units/fileunit.pas"/>
+ <IsPartOfProject Value="True"/>
+ <EditorIndex Value="-1"/>
+ <TopLine Value="106"/>
+ <CursorPos X="20" Y="110"/>
+ <UsageCount Value="24"/>
+ </Unit4>
+ <Unit5>
<Filename Value="original/Unit1.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="1043"/>
<CursorPos X="5" Y="1083"/>
<UsageCount Value="21"/>
- </Unit4>
- <Unit5>
+ </Unit5>
+ <Unit6>
<Filename Value="pegelunit.pas"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="3"/>
- <TopLine Value="16"/>
- <CursorPos Y="56"/>
- <UsageCount Value="26"/>
+ <TopLine Value="286"/>
+ <CursorPos Y="323"/>
+ <UsageCount Value="27"/>
<Loaded Value="True"/>
- </Unit5>
- <Unit6>
+ </Unit6>
+ <Unit7>
<Filename Value="../units/systemunit.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="116"/>
<CursorPos Y="159"/>
<UsageCount Value="7"/>
- </Unit6>
- <Unit7>
+ </Unit7>
+ <Unit8>
<Filename Value="wetter.konf"/>
<EditorIndex Value="1"/>
- <CursorPos Y="3"/>
- <UsageCount Value="26"/>
+ <CursorPos X="38" Y="2"/>
+ <UsageCount Value="27"/>
<Loaded Value="True"/>
<DefaultSyntaxHighlighter Value="None"/>
- </Unit7>
- <Unit8>
+ </Unit8>
+ <Unit9>
<Filename Value="/usr/lib/fpc/src/packages/fcl-process/src/process.pp"/>
<EditorIndex Value="-1"/>
<TopLine Value="157"/>
<CursorPos X="73" Y="178"/>
<UsageCount Value="7"/>
- </Unit8>
- <Unit9>
+ </Unit9>
+ <Unit10>
<Filename Value="/usr/lib/lazarus/components/lazutils/lazutf8.pas"/>
<UnitName Value="LazUTF8"/>
<EditorIndex Value="-1"/>
<TopLine Value="150"/>
<CursorPos X="3" Y="171"/>
<UsageCount Value="7"/>
- </Unit9>
- <Unit10>
- <Filename Value="../units/mystringlistunit.pas"/>
- <EditorIndex Value="-1"/>
- <TopLine Value="35"/>
- <CursorPos X="3" Y="22"/>
- <UsageCount Value="10"/>
</Unit10>
<Unit11>
+ <Filename Value="../units/mystringlistunit.pas"/>
+ <EditorIndex Value="-1"/>
+ <TopLine Value="15"/>
+ <CursorPos X="6" Y="36"/>
+ <UsageCount Value="11"/>
+ </Unit11>
+ <Unit12>
<Filename Value="../units/lowlevelunit.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="58"/>
<CursorPos X="19" Y="77"/>
<UsageCount Value="10"/>
- </Unit11>
- <Unit12>
+ </Unit12>
+ <Unit13>
<Filename Value="letzte_Pegel.txt"/>
<EditorIndex Value="-1"/>
<TopLine Value="949303"/>
<CursorPos X="17" Y="949336"/>
<UsageCount Value="7"/>
<DefaultSyntaxHighlighter Value="None"/>
- </Unit12>
- <Unit13>
+ </Unit13>
+ <Unit14>
<Filename Value="/usr/lib/fpc/src/rtl/objpas/classes/classesh.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="720"/>
<CursorPos X="67" Y="737"/>
<UsageCount Value="10"/>
- </Unit13>
+ </Unit14>
+ <Unit15>
+ <Filename Value="/usr/lib/fpc/src/rtl/inc/systemh.inc"/>
+ <EditorIndex Value="-1"/>
+ <TopLine Value="513"/>
+ <CursorPos Y="535"/>
+ <UsageCount Value="10"/>
+ </Unit15>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="fhunit.pas"/>
- <Caret Line="545" Column="10" TopLine="527"/>
+ <Caret Line="469" Column="21" TopLine="444"/>
</Position1>
<Position2>
<Filename Value="fhunit.pas"/>
- <Caret Line="269" Column="11" TopLine="252"/>
+ <Caret Line="59" Column="30" TopLine="39"/>
</Position2>
<Position3>
<Filename Value="fhunit.pas"/>
- <Caret Line="613" Column="8" TopLine="590"/>
+ <Caret Line="60" Column="18" TopLine="39"/>
</Position3>
<Position4>
<Filename Value="fhunit.pas"/>
- <Caret Line="244" Column="16" TopLine="206"/>
+ <Caret Line="246" Column="25" TopLine="213"/>
</Position4>
<Position5>
<Filename Value="fhunit.pas"/>
- <Caret Line="584" Column="3" TopLine="558"/>
+ <Caret Line="469" Column="21" TopLine="436"/>
</Position5>
<Position6>
<Filename Value="fhunit.pas"/>
- <Caret Line="244" Column="17" TopLine="228"/>
+ <Caret Line="486" Column="19" TopLine="453"/>
</Position6>
<Position7>
<Filename Value="fhunit.pas"/>
- <Caret Line="493" Column="3" TopLine="464"/>
+ <Caret Line="505" Column="31" TopLine="472"/>
</Position7>
<Position8>
<Filename Value="fhunit.pas"/>
- <Caret Line="548" Column="16" TopLine="541"/>
+ <Caret Line="509" Column="33" TopLine="476"/>
</Position8>
<Position9>
<Filename Value="fhunit.pas"/>
- <Caret Line="553" Column="36" TopLine="512"/>
+ <Caret Line="568" TopLine="542"/>
</Position9>
<Position10>
<Filename Value="fhunit.pas"/>
- <Caret Line="239" Column="83" TopLine="214"/>
</Position10>
<Position11>
<Filename Value="fhunit.pas"/>
- <Caret Line="555" Column="39" TopLine="549"/>
+ <Caret Line="39" Column="19" TopLine="6"/>
</Position11>
<Position12>
<Filename Value="fhunit.pas"/>
- <Caret Line="236" TopLine="220"/>
+ <Caret Line="59" Column="19" TopLine="26"/>
</Position12>
<Position13>
<Filename Value="fhunit.pas"/>
- <Caret Line="582" Column="25" TopLine="559"/>
+ <Caret Line="239" Column="26" TopLine="206"/>
</Position13>
<Position14>
<Filename Value="fhunit.pas"/>
- <Caret Line="548" Column="30" TopLine="571"/>
+ <Caret Line="490" Column="140" TopLine="464"/>
</Position14>
<Position15>
<Filename Value="fhunit.pas"/>
- <Caret Line="60" Column="14" TopLine="40"/>
+ <Caret Line="476" Column="28" TopLine="456"/>
</Position15>
<Position16>
<Filename Value="fhunit.pas"/>
- <Caret Line="40" Column="18" TopLine="19"/>
+ <Caret Line="58" Column="28" TopLine="50"/>
</Position16>
<Position17>
<Filename Value="fhunit.pas"/>
- <Caret Line="60" Column="18" TopLine="27"/>
+ <Caret Line="464" Column="41" TopLine="445"/>
</Position17>
<Position18>
<Filename Value="fhunit.pas"/>
- <Caret Line="247" Column="25" TopLine="223"/>
+ <Caret Line="59" Column="24" TopLine="58"/>
</Position18>
<Position19>
- <Filename Value="fhunit.pas"/>
- <Caret Line="470" Column="21" TopLine="455"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="56" TopLine="19"/>
</Position19>
<Position20>
- <Filename Value="fhunit.pas"/>
- <Caret Line="485" Column="15" TopLine="470"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="191" Column="8" TopLine="153"/>
</Position20>
<Position21>
- <Filename Value="fhunit.pas"/>
- <Caret Line="498" Column="31" TopLine="470"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="56" TopLine="33"/>
</Position21>
<Position22>
- <Filename Value="fhunit.pas"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="284" Column="60" TopLine="260"/>
</Position22>
<Position23>
- <Filename Value="fhunit.pas"/>
- <Caret Line="40" Column="18" TopLine="7"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="54" Column="52" TopLine="38"/>
</Position23>
<Position24>
- <Filename Value="fhunit.pas"/>
- <Caret Line="60" Column="18" TopLine="27"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="62" Column="52" TopLine="33"/>
</Position24>
<Position25>
- <Filename Value="fhunit.pas"/>
- <Caret Line="247" Column="25" TopLine="229"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="515" Column="6" TopLine="509"/>
</Position25>
<Position26>
- <Filename Value="fhunit.pas"/>
- <Caret Line="470" Column="21" TopLine="455"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="584" Column="45" TopLine="560"/>
</Position26>
<Position27>
- <Filename Value="fhunit.pas"/>
- <Caret Line="485" Column="15" TopLine="455"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="590" Column="39" TopLine="564"/>
</Position27>
<Position28>
- <Filename Value="fhunit.pas"/>
- <Caret Line="498" Column="31" TopLine="477"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="599" Column="17" TopLine="571"/>
</Position28>
<Position29>
- <Filename Value="fhunit.pas"/>
- <Caret Line="502" Column="33" TopLine="477"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="596" Column="7" TopLine="576"/>
</Position29>
<Position30>
<Filename Value="pegelunit.pas"/>
- <Caret Line="222" Column="35" TopLine="215"/>
+ <Caret Line="92" Column="45" TopLine="77"/>
</Position30>
</JumpHistory>
</ProjectSession>