-
Notifications
You must be signed in to change notification settings - Fork 2
/
matio.formats.minutp.pas
106 lines (90 loc) · 3.55 KB
/
matio.formats.minutp.pas
1
2
3
4
5
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
unit matio.formats.minutp;
////////////////////////////////////////////////////////////////////////////////
//
// Author: Jaap Baak
// https://github.com/transportmodelling/matio
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
interface
////////////////////////////////////////////////////////////////////////////////
Uses
SysUtils, PropSet, matio, matio.formats, matio.minutp;
Type
TMinutpMatrixReaderFormat = Class(TMatrixReaderFormat)
strict protected
Procedure AppendFormatProperties(const [ref] Properties: TPropertySet); override;
public
Function Format: String; override;
Function HasFormat(const Header: TBytes): Boolean; override;
Function CreateReader(const [ref] Properties: TPropertySet): TMatrixReader; override;
end;
TMinutpMatrixWriterFormat = Class(TMatrixWriterFormat)
strict protected
Procedure AppendFormatProperties(const [ref] Properties: TPropertySet); override;
public
Function Format: String; override;
Function CreateWriter(const [ref] Properties: TPropertySet;
const FileLabel: string;
const MatrixLabels: array of String;
const Size: Integer): TMatrixWriter; override;
end;
////////////////////////////////////////////////////////////////////////////////
implementation
////////////////////////////////////////////////////////////////////////////////
Const
PrecisionProperty = 'prec';
Function TMinutpMatrixReaderFormat.Format: String;
begin
Result := 'mtp';
end;
Function TMinutpMatrixReaderFormat.HasFormat(const Header: TBytes): Boolean;
begin
if Length(Header) >= 74 then
begin
if TEncoding.ASCII.GetString(Copy(Header,66,7)) = ' MATRIX' then
if Header[73] = 45 then
Result := true
else
Result := false
else
Result := false;
end else
Result := false;
end;
Procedure TMinutpMatrixReaderFormat.AppendFormatProperties(const [ref] Properties: TPropertySet);
begin
Properties.Append(PrecisionProperty,'0');
end;
Function TMinutpMatrixReaderFormat.CreateReader(const [ref] Properties: TPropertySet): TMatrixReader;
begin
if SameText(Properties[FormatProperty],Format) then
begin
var ExtendedProperties := ExtendProperties(Properties);
Result := TMinutpMatrixReader.Create(ExtendedProperties.ToPath(FileProperty),ExtendedProperties.ToInt(PrecisionProperty));
end else
raise Exception.Create('Invalid format-property');
end;
////////////////////////////////////////////////////////////////////////////////
Function TMinutpMatrixWriterFormat.Format: String;
begin
Result := 'mtp';
end;
Procedure TMinutpMatrixWriterFormat.AppendFormatProperties(const [ref] Properties: TPropertySet);
begin
Properties.Append(PrecisionProperty,'');
end;
Function TMinutpMatrixWriterFormat.CreateWriter(const [ref] Properties: TPropertySet;
const FileLabel: string;
const MatrixLabels: array of String;
const Size: Integer): TMatrixWriter;
begin
if SameText(Properties[FormatProperty],Format) then
begin
var ExtendedProperties := ExtendProperties(Properties);
Result := TMinutpMatrixWriter.Create(ExtendedProperties.ToPath(FileProperty),FileLabel,Length(MatrixLabels),
Size,ExtendedProperties.ToInt(PrecisionProperty));
end else
raise Exception.Create('Invalid format-property');
end;
end.