-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.php
61 lines (50 loc) · 1.45 KB
/
build.php
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
<?php
// Utility script to convert CSV files created by the Land Information
// New Zealand tidal service into one entry per line CSv for the run.php
// script
$in = fopen('data.csv', 'r');
$out = fopen('out.csv', 'w');
// First day of the file
$day = 1;
$month = 1;
$year = 2009;
// Is the first tide high?
$isHigh = true;
while (($data = fgetcsv($in)) !== FALSE) {
$day = $data[0];
$month = $data[2];
$year = $data[3];
// First tide of the day
$time = $data[4];
$height = $data[5];
fwrite($out, $day.','.$month.','.$year.','.$time.','.$height);
if ($isHigh) { fwrite($out, ',h'); } else { fwrite($out, ',l'); }
fwrite($out, "\n");
$isHigh = !$isHigh;
// Second tide of the day
$time = $data[6];
$height = $data[7];
fwrite($out, $day.','.$month.','.$year.','.$time.','.$height);
if ($isHigh) { fwrite($out, ',h'); } else { fwrite($out, ',l'); }
fwrite($out, "\n");
$isHigh = !$isHigh;
// Optional third tide of the day
$time = $data[8];
$height = $data[9];
fwrite($out, $day.','.$month.','.$year.','.$time.','.$height);
if ($isHigh) { fwrite($out, ',h'); } else { fwrite($out, ',l'); }
fwrite($out, "\n");
$isHigh = !$isHigh;
// Optional fourth tide of the day
if ($data[10] != '') {
$time = $data[10];
$height = $data[11];
fwrite($out, $day.','.$month.','.$year.','.$time.','.$height);
if ($isHigh) { fwrite($out, ',h'); } else { fwrite($out, ',l'); }
fwrite($out, "\n");
$isHigh = !$isHigh;
}
}
fclose($in);
fclose($out);
?>