SwingeyP
Member
Hello again,
I am trying to convert some code to OSHON pic basic but with no success.
The original code is this.
I have this ....
I hope this makes sense. I tried to break down the equation into parts but even that didn't work and I ended up with a value for loc(4) of 96. Which is less than the 97 being added to it. think this might be something to do with divide by zero as the equation works out to 97+(1/0) or 0.084 to be exactish.
Can anyone help me with this please?
Regards - Paul
I am trying to convert some code to OSHON pic basic but with no success.
The original code is this.
Code:
'#! / usr / bin / perl - W
'# (C) 2012 Chris Ruvolo. Licensed under a 2-clause BSD license.
'If($ #argv < 1) {
'printf("Usage: $0 <lat> <long>\n");
'Exit(1);
'}
'my $lat = $ARGV[0];
'my $lon = $argv[1];
'my $grid = "";
'$lon = $lon + 180;
'$lat = $lat + 90;
'$grid .= chr(ord('A') + int($lon / 20));
'$grid .= chr(ord('A') + int($lat / 10));
'$grid .= chr(ord('0') + int(($lon % 20)/2));
'$grid .= chr(ord('0') + int(($lat % 10)/1));
'$grid .= chr(ord('a') + int(($lon - (int($lon/2)*2)) / (5/60)));
'$grid .= chr(ord('a') + int(($lat - (int($lat/1)*1)) / (2.5/60)));
'print "$grid\n";
I have this ....
Code:
'-------------------------------------------------
'Procedures
'-------------------------------------------------
Proc calc_loc(lat As Byte, lng As Byte)
If raw_data(30) = 0x57 Then 'in other words the value would be -1
lng = 179 'so -1 + 180 = 179
Else
lng = lng + 180
Endif
lat = lat + 90
loc(0) = 65 + (lng / 20) '65 = ascii A
loc(1) = 65 + (lat / 10)
loc(2) = 48 + ((lng Mod 20) / 2) '48 = Ascii zero
loc(3) = 48 + ((lat Mod 10) / 1)
'temp1 = lng / 2 '179/2=89
'temp2 = temp1 * 2 '89*2=178
'temp3 = lng - temp2 '179 - 178 = 1
'temp4 = (temp3 / (5 / 60)) + 97 '= 1/0.084 = 98 = b
'loc(4) = temp4
loc(4) = 97 + ((lng - ((lng / 2) * 2)) / (5 / 60)))
'$grid.= chr(ord( 'a') + int(($lat - (int($lat/1)*1)) / (2.5/60)));
End Proc
I hope this makes sense. I tried to break down the equation into parts but even that didn't work and I ended up with a value for loc(4) of 96. Which is less than the 97 being added to it. think this might be something to do with divide by zero as the equation works out to 97+(1/0) or 0.084 to be exactish.
Can anyone help me with this please?
Regards - Paul