-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsensorsdb.pas
77 lines (62 loc) · 1.97 KB
/
sensorsdb.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
unit sensorsdb;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
pSensor = ^TSensor;
TSensor = record
width, height: real; //in mm
desc: string;
mfact : real;
diag: real
end;
var
sensors : TList;
procedure initialize;
implementation
uses csvdocument in 'csvdocument/csvdocument.pas', Dialogs;
const
sensorsFile = 'sensors.csv'; //table taken from https://en.wikipedia.org/wiki/Image_sensor_format
procedure initialize;
var
Parser: TCSVParser;
FileStream: TFileStream;
sensor : pSensor;
begin
//https://en.wikipedia.org/wiki/Crop_factor
//view-source:https://www.digified.net/focallength/
//https://www.dpreview.com/forums/post/31310027
//table taken from https://en.wikipedia.org/wiki/Image_sensor_format
if not(FileExists(sensorsFile)) then begin
Dialogs.ShowMessage('cannot find ' + sensorsFile + ' file.');
exit;
end;
Parser := TCSVParser.Create;
FileStream := TFileStream.Create(sensorsFile, fmOpenRead+fmShareDenyWrite);
sensors := TList.Create;
try
Parser.Delimiter:=',';
Parser.SetSource(FileStream);
Parser.ResetParser;
//skip the header
//Parser.CurrentRow := 1;
Parser.ParseNextCell; Parser.ParseNextCell; Parser.ParseNextCell; Parser.ParseNextCell;
Parser.ParseNextCell; Parser.ParseNextCell; Parser.ParseNextCell; Parser.ParseNextCell;
while Parser.ParseNextCell do
begin
new(sensor);
sensor^.desc := Parser.CurrentCellText; Parser.ParseNextCell;
sensor^.diag := StrToFloat(Parser.CurrentCellText); Parser.ParseNextCell;
sensor^.width := StrToFloat(Parser.CurrentCellText); Parser.ParseNextCell;
sensor^.height := StrToFloat(Parser.CurrentCellText); Parser.ParseNextCell;
Parser.ParseNextCell; Parser.ParseNextCell; Parser.ParseNextCell;
sensor^.mfact := StrToFloat(Parser.CurrentCellText);
sensors.Add(sensor);
end;
finally
Parser.Free;
FileStream.Free;
end;
end; //initialize
end.