/[drupal]/contributions/modules/ham/amateur_radio.inc
ViewVC logotype

Contents of /contributions/modules/ham/amateur_radio.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Mon Nov 3 18:48:46 2008 UTC (12 months, 3 weeks ago) by ppicazo
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +17 -18 lines
File MIME type: text/x-php
Removed one line from each locator conversion function which had no effect in function. Band is now determined when the logbook is imported, updated the database and install script to store the band information. Added band summary table to the main page. Also put in a stub function for the caching of the summary page tables which will be implemented soon.
1 <?php
2 // $Id: amateur_radio.inc,v 1.1 2008/10/15 19:41:44 ppicazo Exp $
3
4 // function to calculate latitude from maidenhead grid locator
5 function loc2lat($locator) {
6
7 $ascii = array("0" => 48, "1" => 49, "2" => 50, "3" => 51, "4" => 52, "5" => 53, "6" => 54, "7" => 55, "8" => 56, "9" => 57, ":" => 58, ";" => 59, "<" => 60, "=" => 61, ">" => 62, "?" => 63, "@" => 64, "A" => 65, "B" => 66, "C" => 67, "D" => 68, "E" => 69, "F" => 70, "G" => 71, "H" => 72, "I" => 73, "J" => 74, "K" => 75, "L" => 76, "M" => 77, "N" => 78, "O" => 79, "P" => 80, "Q" => 81, "R" => 82, "S" => 83, "T" => 84, "U" => 85, "V" => 86, "W" => 87, "X" => 88, "Y" => 89, "Z" => 90);
8
9 $locator = strtoupper($locator);
10
11 $lat = ($ascii[$locator[1]] - 65) * 10 + ($ascii[$locator[3]] - 48) + ($ascii[$locator[5]] - 65 + 0.5) / 24 - 90;
12
13 return $lat;
14 }
15
16 // function to calculate longitude from maidenhead grid locator
17 function loc2lon($locator)
18 {
19 $ascii = array("0" => 48, "1" => 49, "2" => 50, "3" => 51, "4" => 52, "5" => 53, "6" => 54, "7" => 55, "8" => 56, "9" => 57, ":" => 58, ";" => 59, "<" => 60, "=" => 61, ">" => 62, "?" => 63, "@" => 64, "A" => 65, "B" => 66, "C" => 67, "D" => 68, "E" => 69, "F" => 70, "G" => 71, "H" => 72, "I" => 73, "J" => 74, "K" => 75, "L" => 76, "M" => 77, "N" => 78, "O" => 79, "P" => 80, "Q" => 81, "R" => 82, "S" => 83, "T" => 84, "U" => 85, "V" => 86, "W" => 87, "X" => 88, "Y" => 89, "Z" => 90);;
20
21 $locator = strtoupper($locator);
22
23 $lon = ($ascii[$locator[0]] - 65) * 20 + ($ascii[$locator[2]] - 48) * 2 + ($ascii[$locator[4]] - 65 + 0.5) / 12 - 180;
24
25 return $lon;
26 }
27
28 // fucntion that parses a single line from an ADIF logbook file
29 // high priority to properly comment this code
30 function parseADIF_Line($strInput) {
31 $retVal = null;
32
33 $valid_record = 0;
34
35 $n = 0;
36
37 while ($n < strlen($strInput)) {
38 $tag = "";
39 $length = "";
40 $datatype = "";
41 $value = "";
42 while ($n < strlen($strInput) && $strInput[$n] != "<") {
43 $n++;
44 }
45 $n++;
46 while ($n < strlen($strInput) && $strInput[$n] != ">" && $strInput[$n] != ":" && $strInput[$n] != "<") {
47 $tag .= $strInput[$n];
48 $n++;
49 }
50 if ($n < strlen($strInput) && $strInput[$n] == ":") {
51 $n++;
52 while ($n < strlen($strInput) && $strInput[$n] != ">" && $strInput[$n] != ":" && $strInput[$n] != "<") {
53 $length .= $strInput[$n];
54 $n++;
55 }
56 $length = intval($length);
57 }
58 if ($n < strlen($strInput) && $strInput[$n] == ":") {
59 $n++;
60 while ($n < strlen($strInput) && $strInput[$n] != ">" && $strInput[$n] != ":" && $strInput[$n] != "<") {
61 $datatype .= $strInput[$n];
62 $n++;
63 }
64 }
65 if ($n < strlen($strInput) && $strInput[$n] == ">") {
66 $n++;
67 for($y = 0; $y < $length; $y++) {
68 $value .= $strInput[$n];
69 $n++;
70 }
71 }
72
73 $tmp = null;
74
75 if (strlen($tag)) {
76 if (strtolower($tag) == "eor") {
77 $valid_record = true;
78 }
79 if (strlen($value)) {
80 $tmp = $value;
81 }
82
83 $retVal[$tag] = $tmp;
84 }
85
86 $n++;
87
88 }
89
90 if ($valid_record) {
91 return $retVal;
92 }
93 return null;
94 }
95
96
97 // function that opens an ADIF logbook file and imports it in to a database table
98 // high priority to properly comment this code
99 // also high priority to make this efficiently import ADIF files without line breaks or with extra line breaks
100 function adif_import($filename) {
101
102 $myHam = new ham();
103 $handle = @fopen($filename, "r");
104 if ($handle) {
105 while (!feof($handle) || $x < 22) {
106 $buffer = fgets($handle, 4096);
107 $line = parseADIF_Line($buffer);
108 if ($line)
109 {
110 if (isset($line['mode'])) {
111 @$mode[$line['mode']]++;
112 }
113
114 $date = null;
115
116 if (isset($line['qso_date']) && isset($line['time_on'])) {
117 $date = date("Y-m-d H:i:s",strtotime($line['qso_date'] . " " . $line['time_on']));
118 }
119
120 if (isset($line['gridsquare'])) {
121 $grid_sql = "'" . $line['gridsquare'] . "'";
122 }
123 else
124 {
125 $grid_sql = "NULL";
126 }
127
128 if (isset($line['my_gridsquare'])) {
129 $mygrid_sql = "'" . $line['my_gridsquare'] . "'";
130 }
131 else
132 {
133 $mygrid_sql = "NULL";
134 }
135
136 if (isset($line['dxcc'])) {
137 $dxcc_sql = "'" . $line['dxcc'] . "'";
138 }
139 else
140 {
141 $dxcc_sql = "NULL";
142 }
143
144 if (isset($line['freq'])) {
145 $freq_sql = "'" . $line['freq'] . "'";
146 $band_sql = "'" . $myHam->freq_band($line['freq']) . "'";
147 }
148 else
149 {
150 $freq_sql = "NULL";
151 $band_sql = "NULL";
152 }
153
154 if (isset($line['mode'])) {
155 $mode_sql = "'" . $line['mode'] . "'";
156 }
157 else
158 {
159 $mode_sql = "NULL";
160 }
161
162 $sql = "INSERT INTO `ham_qso` (`qso_time`, `qso_call`, `qso_remote_grid`, `qso_local_grid`, `qso_dxcc`, `qso_mode`, `qso_band`, `qso_freq`) VALUES ('" .
163 $date . "', '" . $line['call'] . "', " . $grid_sql . ", " . $mygrid_sql . ", " . $dxcc_sql . ", " . $mode_sql . ", " . $band_sql . ", " . $freq_sql . ");";
164
165 $result = @db_query($sql);
166 }
167 $x++;
168 }
169 fclose($handle);
170 }
171 return 0;
172 }
173
174 ?>

  ViewVC Help
Powered by ViewVC 1.1.2