-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypearray2d.adb
More file actions
71 lines (59 loc) · 1.81 KB
/
Copy pathtypearray2d.adb
File metadata and controls
71 lines (59 loc) · 1.81 KB
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
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO;
package body TypeArray2D is
procedure Initialize_array(Array2 : in out Array2D; I : Integer; J : Integer) is
begin
for X in 1 .. I loop
for Y in 1 .. J loop
Array2 (X, Y) := Float (X + Y);
end loop;
end loop;
end Initialize_array;
procedure PrintArray(arr : Array2D; I : Integer; J : Integer) is
begin
for X in 1 .. I loop
for Y in 1 .. J loop
if arr(X, Y) = 1.0 then
Put("X ");
else
Put(" ");
end if;
end loop;
Put_Line("");
end loop;
end PrintArray;
function ArrayFromFile(Filename: String; sizeI : Integer; sizeJ : Integer) return Array2D is
File : File_Type;
Char : Character;
Result_arr : Array2D(1..sizeI,1..sizeJ);
I : Integer := 1;
J : Integer := 1;
str : String(1..1);
begin
while I > sizeI loop
while J > sizeJ loop
Result_arr(I,J) := 0.0;
J := J + 1;
end loop;
I := I + 1;
end loop;
I := 1;
J := 1;
Open (File, In_File, Filename);
while not End_of_file(File) loop
Get(File, Char);
str(1) := Char;
if Char /= ' ' then
Result_arr(I,J) := Float'Value(str);
J := J + 1;
if J > sizeJ then
J := 1;
I := I + 1;
exit when I > sizeI;
end if;
end if;
end loop;
Close (File);
return Result_arr;
end ArrayFromFile;
end TypeArray2D;