summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2015-11-18 14:53:22 +0100
committerErich Eckner <git@eckner.net>2015-11-19 09:24:48 +0100
commita83b351ed71b1b1ce1aaa2c5685241c9e5cde214 (patch)
tree037b69bf59f3aec8fca7a1b0473f8e7387b320f7
parentc84a57a879a389ee3d1c3d736463eacece7f6dc5 (diff)
downloadFH-Wetter-a83b351ed71b1b1ce1aaa2c5685241c9e5cde214.tar.xz
fhunit.pas speichert nun binär statt in Ascii
-rw-r--r--.gitignore4
-rw-r--r--fhunit.pas145
-rw-r--r--unit1.lfm4
-rw-r--r--wetter.konf2
-rw-r--r--wetter.lpi6
-rw-r--r--wetter.lpr2
-rw-r--r--wetter.lps147
7 files changed, 213 insertions, 97 deletions
diff --git a/.gitignore b/.gitignore
index 18c24c9..bd7ecb9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,7 @@ socket
*.txt.save
*.txt.gz
*.txt.gz.save
+*.dat
+*.dat.save
+*.dat.gz
+*.dat.gz.save
diff --git a/fhunit.pas b/fhunit.pas
index 8b3f1b0..51edb6a 100644
--- a/fhunit.pas
+++ b/fhunit.pas
@@ -35,6 +35,9 @@ type
read _uZeit;
property mW[mG: tMessGroesze]: extended
read rMW;
+ procedure dump(p: pExtended); inline;
+ procedure pmud(p: pExtended); inline;
+ function size: longint; inline;
end;
tMessPunkteListe = class
@@ -52,6 +55,9 @@ type
property items[i: longint]: tMessPunkt
read rItem; default;
function minMaxY(startZeit,stopZeit: extended): tMessWerteExtPoints;
+ procedure dump(p: pointer); inline;
+ procedure pmud(p: pointer; version,len: longint); inline;
+ function size: longint; inline;
end;
tMessPunkteUpdateThread = class(tThread)
@@ -111,7 +117,7 @@ const
implementation
-uses unit1, math, myStringListUnit;
+uses unit1, math, myStringListUnit, fileUnit;
// tMessPunkt ******************************************************************
@@ -182,7 +188,6 @@ begin
setzeUZeit;
end
else begin // Format wie im Netz
-
delete(s,1,pos('<BODY',uppercase(s))-1);
s:=copy(s,1,pos('</BODY>',uppercase(s)));
delete(s,1,pos('<CENTER>',uppercase(s)));
@@ -225,6 +230,24 @@ begin
result:=trim(result);
end;
+procedure tMessPunkt.dump(p: pExtended);
+begin
+ move(_uZeit,p^,sizeof(extended));
+ move(_mW[low(tMessGroesze)],(p+1)^,length(_mW)*sizeof(_mW[low(tMessGroesze)]));
+end;
+
+procedure tMessPunkt.pmud(p: pExtended);
+begin
+ move(p^,_uZeit,sizeof(_uZeit));
+ move((p+1)^,_mW[low(tMessGroesze)],length(_mW)*sizeof(_mW[low(tMessGroesze)]));
+ setzeZeit;
+end;
+
+function tMessPunkt.size: longint;
+begin
+ result:=(1+length(_mW))*sizeof(extended);
+end;
+
// tMessPunkteListe ************************************************************
constructor tMessPunkteListe.create;
@@ -241,6 +264,8 @@ end;
function tMessPunkteListe.rItem(i: longint): tMessPunkt;
begin
+ if i>=count then
+ raise exception.create('i zu groß! ('+inttostr(i)+' von '+inttostr(count)+')');
result:=tMessPunkt(inhalt[i]);
end;
@@ -436,6 +461,60 @@ begin
beendet:=true;
end;
+procedure tMessPunkteListe.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 tMessPunkteListe.pmud(p: pointer; version,len: longint);
+var
+ i,siz: longint;
+ np: tMessPunkt;
+begin
+ case version of
+ 0: begin
+ inhalt.clear;
+
+ np:=tMessPunkt.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:=tMessPunkt.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 tMessPunkteListe.size: longint;
+begin
+ result:=count;
+ if result>0 then
+ result:=result*items[0].size;
+end;
+
// tMessPunkte *****************************************************************
constructor tMessPunkte.create(zeichenFlaeche: tImage);
@@ -465,23 +544,35 @@ end;
procedure tMessPunkte.laden(von: string);
var
- f: tMyStringList;
- s: string;
- i: longint;
+ sl: tMyStringList;
+ pt: pointer;
+ len: longint;
+ s: string;
+ i: longint;
begin
if not fileexists(von) then begin
writeln('Messwertedatei '''+von+''' existiert nicht!');
raise exception.create('Messwertedatei '''+von+''' existiert nicht!');
exit;
end;
- f:=tMyStringList.create;
+
if rightStr(von,3)='.gz' then
- f.loadFromGz(von)
+ loadFromGz(von,pt,len)
+ else
+ 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;
+ while sl.readln(s) do
+ werte.append(s);
+ sl.free;
+ end
else
- f.loadFromFile(von);
- while f.readln(s) do
- werte.append(s);
- f.free;
+ werte.pmud(pt+2*sizeof(longint),(pLongint(pt)+1)^,len-2*sizeof(longint));
+ freemem(pt);
if length(muts)=0 then begin
setlength(muts,20);
@@ -492,17 +583,29 @@ end;
procedure tMessPunkte.speichern(nach: string);
var
- f: tMyStringList;
- i: longint;
+ sl: tMyStringList;
+ pt: pointer;
+ i: longint;
begin
- f:=tMyStringList.create;
- for i:=0 to werte.count-1 do
- f.add(werte[i].schreibe);
- if rightStr(nach,3)='.gz' then
- f.saveToGz(nach)
- else
- f.saveToFile(nach);
- f.free;
+ if rightstr(nach,4)='.txt' then begin // Rückfallebene: Text
+ sl:=tMyStringList.create;
+ for i:=0 to werte.count-1 do
+ sl.add(werte[i].schreibe);
+ sl.saveToFile(nach);
+ sl.free;
+ end
+ else begin
+ i:=werte.size;
+ getmem(pt,i+2*sizeof(longint));
+ pLongint(pt)^:=314159265; // magische Zahl
+ (pLongint(pt)+1)^:=0; // Version
+ werte.dump(pt+2*sizeof(longint));
+ if rightStr(nach,3)='.gz' then
+ saveToGz(nach,pt,i+2*sizeof(longint))
+ else
+ saveToFile(nach,pt,i+2*sizeof(longint));
+ freemem(pt);
+ end;
end;
procedure tMessPunkte.achsenZeichnen(zuZeichnen: tMessGroeszenSet; startZeit,stopZeit: extended);
diff --git a/unit1.lfm b/unit1.lfm
index 5262e06..b155d6a 100644
--- a/unit1.lfm
+++ b/unit1.lfm
@@ -1,7 +1,7 @@
object Form1: TForm1
- Left = 649
+ Left = 725
Height = 204
- Top = 256
+ Top = 826
Width = 713
BorderStyle = bsNone
Caption = 'Form1'
diff --git a/wetter.konf b/wetter.konf
index 36c71f9..dd0e27a 100644
--- a/wetter.konf
+++ b/wetter.konf
@@ -1,4 +1,4 @@
pidDatei: /tmp/wetter.pid
-wetterDatei: letztes_Wetter.txt.gz
+wetterDatei: letztes_Wetter.dat.gz
pegelDatei: letzte_Pegel.txt.gz
datenZeitRaum: 7*4
diff --git a/wetter.lpi b/wetter.lpi
index 5eebeb5..94e0207 100644
--- a/wetter.lpi
+++ b/wetter.lpi
@@ -32,7 +32,7 @@
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
- <Units Count="4">
+ <Units Count="5">
<Unit0>
<Filename Value="wetter.lpr"/>
<IsPartOfProject Value="True"/>
@@ -53,6 +53,10 @@
<Filename Value="fhunit.pas"/>
<IsPartOfProject Value="True"/>
</Unit3>
+ <Unit4>
+ <Filename Value="../units/fileunit.pas"/>
+ <IsPartOfProject Value="True"/>
+ </Unit4>
</Units>
</ProjectOptions>
<CompilerOptions>
diff --git a/wetter.lpr b/wetter.lpr
index e83a0c9..7cd3f23 100644
--- a/wetter.lpr
+++ b/wetter.lpr
@@ -5,7 +5,7 @@ program wetter;
uses
cthreads,
Interfaces, // this includes the LCL widgetset
- Forms, Unit1, pegelunit, fhunit;
+ Forms, Unit1, pegelunit, fhunit, fileunit;
{$R *.res}
diff --git a/wetter.lps b/wetter.lps
index a710c84..7a0d7ad 100644
--- a/wetter.lps
+++ b/wetter.lps
@@ -3,13 +3,13 @@
<ProjectSession>
<Version Value="9"/>
<BuildModes Active="Default"/>
- <Units Count="13">
+ <Units Count="14">
<Unit0>
<Filename Value="wetter.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="12" Y="6"/>
- <UsageCount Value="45"/>
+ <UsageCount Value="53"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
@@ -18,10 +18,9 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
- <IsVisibleTab Value="True"/>
- <TopLine Value="51"/>
- <CursorPos X="40" Y="73"/>
- <UsageCount Value="45"/>
+ <TopLine Value="184"/>
+ <CursorPos X="13" Y="213"/>
+ <UsageCount Value="53"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
@@ -29,15 +28,15 @@
<Filename Value="original/pegelunit.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
- <UsageCount Value="45"/>
+ <UsageCount Value="53"/>
</Unit2>
<Unit3>
<Filename Value="fhunit.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="2"/>
- <TopLine Value="445"/>
- <CursorPos Y="476"/>
- <UsageCount Value="45"/>
+ <TopLine Value="539"/>
+ <CursorPos X="41" Y="554"/>
+ <UsageCount Value="53"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
@@ -45,14 +44,15 @@
<EditorIndex Value="-1"/>
<TopLine Value="1043"/>
<CursorPos X="5" Y="1083"/>
- <UsageCount Value="22"/>
+ <UsageCount Value="21"/>
</Unit4>
<Unit5>
<Filename Value="pegelunit.pas"/>
+ <IsVisibleTab Value="True"/>
<EditorIndex Value="3"/>
- <TopLine Value="78"/>
- <CursorPos X="20" Y="86"/>
- <UsageCount Value="22"/>
+ <TopLine Value="16"/>
+ <CursorPos Y="56"/>
+ <UsageCount Value="26"/>
<Loaded Value="True"/>
</Unit5>
<Unit6>
@@ -60,13 +60,13 @@
<EditorIndex Value="-1"/>
<TopLine Value="116"/>
<CursorPos Y="159"/>
- <UsageCount Value="8"/>
+ <UsageCount Value="7"/>
</Unit6>
<Unit7>
<Filename Value="wetter.konf"/>
<EditorIndex Value="1"/>
- <CursorPos X="36" Y="3"/>
- <UsageCount Value="22"/>
+ <CursorPos Y="3"/>
+ <UsageCount Value="26"/>
<Loaded Value="True"/>
<DefaultSyntaxHighlighter Value="None"/>
</Unit7>
@@ -75,7 +75,7 @@
<EditorIndex Value="-1"/>
<TopLine Value="157"/>
<CursorPos X="73" Y="178"/>
- <UsageCount Value="8"/>
+ <UsageCount Value="7"/>
</Unit8>
<Unit9>
<Filename Value="/usr/lib/lazarus/components/lazutils/lazutf8.pas"/>
@@ -83,152 +83,157 @@
<EditorIndex Value="-1"/>
<TopLine Value="150"/>
<CursorPos X="3" Y="171"/>
- <UsageCount Value="8"/>
+ <UsageCount Value="7"/>
</Unit9>
<Unit10>
<Filename Value="../units/mystringlistunit.pas"/>
- <EditorIndex Value="4"/>
- <TopLine Value="157"/>
- <CursorPos X="18" Y="194"/>
+ <EditorIndex Value="-1"/>
+ <TopLine Value="35"/>
+ <CursorPos X="3" Y="22"/>
<UsageCount Value="10"/>
- <Loaded Value="True"/>
</Unit10>
<Unit11>
<Filename Value="../units/lowlevelunit.pas"/>
<EditorIndex Value="-1"/>
- <TopLine Value="697"/>
- <CursorPos X="43" Y="843"/>
- <UsageCount Value="9"/>
+ <TopLine Value="58"/>
+ <CursorPos X="19" Y="77"/>
+ <UsageCount Value="10"/>
</Unit11>
<Unit12>
<Filename Value="letzte_Pegel.txt"/>
<EditorIndex Value="-1"/>
<TopLine Value="949303"/>
<CursorPos X="17" Y="949336"/>
- <UsageCount Value="8"/>
+ <UsageCount Value="7"/>
<DefaultSyntaxHighlighter Value="None"/>
</Unit12>
+ <Unit13>
+ <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>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
- <Filename Value="pegelunit.pas"/>
- <Caret Line="552" TopLine="523"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="545" Column="10" TopLine="527"/>
</Position1>
<Position2>
<Filename Value="fhunit.pas"/>
- <Caret Line="599" TopLine="572"/>
+ <Caret Line="269" Column="11" TopLine="252"/>
</Position2>
<Position3>
<Filename Value="fhunit.pas"/>
- <Caret Line="91" Column="14" TopLine="79"/>
+ <Caret Line="613" Column="8" TopLine="590"/>
</Position3>
<Position4>
- <Filename Value="pegelunit.pas"/>
- <Caret Line="81" Column="14" TopLine="60"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="244" Column="16" TopLine="206"/>
</Position4>
<Position5>
- <Filename Value="unit1.pas"/>
- <Caret Line="244" TopLine="211"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="584" Column="3" TopLine="558"/>
</Position5>
<Position6>
<Filename Value="fhunit.pas"/>
- <Caret Line="614" TopLine="582"/>
+ <Caret Line="244" Column="17" TopLine="228"/>
</Position6>
<Position7>
<Filename Value="fhunit.pas"/>
- <Caret Line="92" Column="15" TopLine="79"/>
+ <Caret Line="493" Column="3" TopLine="464"/>
</Position7>
<Position8>
- <Filename Value="unit1.pas"/>
- <Caret Line="241" Column="15" TopLine="221"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="548" Column="16" TopLine="541"/>
</Position8>
<Position9>
- <Filename Value="unit1.pas"/>
- <Caret Line="243" Column="27" TopLine="223"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="553" Column="36" TopLine="512"/>
</Position9>
<Position10>
- <Filename Value="unit1.pas"/>
- <Caret Line="244" Column="13" TopLine="224"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="239" Column="83" TopLine="214"/>
</Position10>
<Position11>
<Filename Value="fhunit.pas"/>
- <Caret Line="92" Column="13" TopLine="71"/>
+ <Caret Line="555" Column="39" TopLine="549"/>
</Position11>
<Position12>
<Filename Value="fhunit.pas"/>
- <Caret Line="621" Column="69" TopLine="594"/>
+ <Caret Line="236" TopLine="220"/>
</Position12>
<Position13>
<Filename Value="fhunit.pas"/>
- <Caret Line="101" TopLine="78"/>
+ <Caret Line="582" Column="25" TopLine="559"/>
</Position13>
<Position14>
<Filename Value="fhunit.pas"/>
- <Caret Line="626" TopLine="606"/>
+ <Caret Line="548" Column="30" TopLine="571"/>
</Position14>
<Position15>
<Filename Value="fhunit.pas"/>
- <Caret Line="100" Column="26" TopLine="78"/>
+ <Caret Line="60" Column="14" TopLine="40"/>
</Position15>
<Position16>
<Filename Value="fhunit.pas"/>
- <Caret Line="108" Column="23" TopLine="100"/>
+ <Caret Line="40" Column="18" TopLine="19"/>
</Position16>
<Position17>
<Filename Value="fhunit.pas"/>
- <Caret Line="462" Column="27" TopLine="433"/>
+ <Caret Line="60" Column="18" TopLine="27"/>
</Position17>
<Position18>
<Filename Value="fhunit.pas"/>
- <Caret Line="453" Column="6" TopLine="433"/>
+ <Caret Line="247" Column="25" TopLine="223"/>
</Position18>
<Position19>
<Filename Value="fhunit.pas"/>
- <Caret Line="113" Column="47" TopLine="98"/>
+ <Caret Line="470" Column="21" TopLine="455"/>
</Position19>
<Position20>
<Filename Value="fhunit.pas"/>
- <Caret Line="491" TopLine="464"/>
+ <Caret Line="485" Column="15" TopLine="470"/>
</Position20>
<Position21>
<Filename Value="fhunit.pas"/>
- <Caret Line="480" Column="6" TopLine="454"/>
+ <Caret Line="498" Column="31" TopLine="470"/>
</Position21>
<Position22>
- <Filename Value="pegelunit.pas"/>
- <Caret Line="437" Column="18" TopLine="417"/>
+ <Filename Value="fhunit.pas"/>
</Position22>
<Position23>
- <Filename Value="pegelunit.pas"/>
- <Caret Line="86" Column="47" TopLine="78"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="40" Column="18" TopLine="7"/>
</Position23>
<Position24>
- <Filename Value="pegelunit.pas"/>
- <Caret Line="456" TopLine="438"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="60" Column="18" TopLine="27"/>
</Position24>
<Position25>
- <Filename Value="pegelunit.pas"/>
- <Caret Line="448" Column="19" TopLine="427"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="247" Column="25" TopLine="229"/>
</Position25>
<Position26>
<Filename Value="fhunit.pas"/>
- <Caret Line="113" Column="19" TopLine="92"/>
+ <Caret Line="470" Column="21" TopLine="455"/>
</Position26>
<Position27>
- <Filename Value="pegelunit.pas"/>
- <Caret Line="490" Column="44" TopLine="483"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="485" Column="15" TopLine="455"/>
</Position27>
<Position28>
- <Filename Value="../units/mystringlistunit.pas"/>
- <Caret Line="46" Column="41" TopLine="16"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="498" Column="31" TopLine="477"/>
</Position28>
<Position29>
- <Filename Value="unit1.pas"/>
- <Caret Line="244" Column="14" TopLine="187"/>
+ <Filename Value="fhunit.pas"/>
+ <Caret Line="502" Column="33" TopLine="477"/>
</Position29>
<Position30>
- <Filename Value="unit1.pas"/>
- <Caret Line="179" Column="10" TopLine="174"/>
+ <Filename Value="pegelunit.pas"/>
+ <Caret Line="222" Column="35" TopLine="215"/>
</Position30>
</JumpHistory>
</ProjectSession>