ERRATA There is a small
typo in Table 1, page 36. In the Visual
Basic listing, "Text2.txt =
Length" should be "Text2.text =
Length". This should not affect any
of the programming code.
HOW
ACCURATE ARE THE BEARING/DISTANCE
CALCULATIONS? The calculations of
great circle distance depend on spherical
geometry and the assumption the Earth is
round. Since the Earth has an oblate
shape (squatter at the equator), a
spherical model has some inherent error.
The
Earth's semi-minor axis is used to
calibrate the algorithm calculations. The
Earth's: semi-major axis is 6378.206 km;
semi-minor axis is 6356.583 km and the
radius of a sphere of equal area is
6370.997 km (various sources publish
slightly different values).
The
algorithm in QST uses a value of 6356.775
for the semi-minor axis (it's easy to
find in the code). With it, measurements
are quite accurate for most purposes and
the distance determined by the algorithm
will never be overestimated. Alun,
GW7KYT, suggests one might achieve a
better estimate with a value of 6371.291.
In 1987, Region 1 of the IARU recommended
using this value to calculate distances
for contest scoring.
Which
value should you use? Neither value is
precise for all communications paths and
both introduce errors in the calculation
of great circle paths. Consider the
following:
The
distance between Alun's QTH at 51.547 N,
3.564 W. to 33.01 North, 96.892 West
results in:
1) S. geometry and 6356.775 is 7,395km
2) S. geometry and 6371.291 is 7,411km
3) S. geometry and 6367 is 7406km *
4) S. geometry and 6378 is 7419 km**
(*
arithmetic average of the semi-major and
minor axes. ** semi-major axis. S.
geometry is abbreviation for spherical
geometry) using the
Bearing/Distance program.
A 1% error at these
distances is approximately 74 km. A 0.1%
error is a difference of about 7.4 km.
The error using a spherical geometry
calculation can be as large as about 0.3%
or more.
A more
precise great circle distance could be
calculated using a distance model based
on the actual ellipticity of the Earth.
The spherical model, using an 'average'
axis value of 6371 km, has an accuracy of
about 0.3 percent or better. Some claim
using an elliptical model reduces the
error to a range of 0.1 to 0.3 percent,
however, experts in geodesy indicate all
these calculated measurements are
approximations.
Alun
alerted me to a Pascal program by W9IP
and N1BWT that depends on an actual
oblate Earth geometry and algorithms
described by P.D. Thomas, 1970,
"Spheroidal geodesics,reference
systems & local geometry", U.S.
NavalOceanographic Office SP-138, 165 pp.
The mathematics is more involved than for
the simple spherical model shown in the
article and may interest some readers.
The source code is in the public domain.
I've converted it to Delphi and will post
the revised source shortly if anyone
asks.
QUESTIONS
REGARDING THE CALCULATION OF BEARINGS AND
DISTANCES...LATITUDE REQUIRES A (-) FOR
(S) .. DOES LONGITUDE REQUIRE A (-) FOR
(E) ? HOW DO I ENTER A DESTINATION
LONGITUDE OF 100 E ? Yes, south
latitudes (below the equator) require a
(-) and longitude east also require a (-)
as the algorithm is written.
You enter a longitude of 100 degrees east
like:
- 100 or 100.23 east as -100.23 West
longitudes are entered as positive
values, East longitudes are entered as
negative values.
Think of a flat, Mercator-like map of the
world that has a framework like this:
For
locations up to 180 degrees West of the
prime meridian, that is Canada, USA,
South America, use a positive longitude.
Use a negative value for degrees east.
Some programs reverse this convention,
that is,-180 longW ---0--- +180E as shown
in black in the above figure. Geographers
and cartographers use West and East,
programmers assign a sign to these
measurements.
If you
prefer to enter West longitude as a
negative value, remove the negative signs
in front of the Wr and Wt values in the
algorithim i.e. change
Wr = -(W1-180... to Wr = (W1-180 in the
program listing and do the same for the
Wt value.
What
coordinate system you use depends on what
other utilities your algorithm might
interface with and the form any
coordinate information needs to be in to
work with other parts of your program.
DELPHI
ROUNDING--STEVE, I WANTED TO USE THE
ROUNDTO FUCTION BUT I GUESS DELPHI 5
DOESN'T SEEM TO HAVE IT SO THAT I COULD
ROUND OFF THE DECIMAL TO 2 PLACES. IS
THERE ANY FUNCTION IN DELPHI TO DO THIS??
I KNOW DELPHI-6 HAS ROUNDTO. D5 has
the Int, Round, Trunc and Frac functions.
The last one gives you the fractional
part, the others functions give you the
big part (use help on your D5 to find out
exactly how they differ). None do exactly
what you want to do, so try this using
the Dipole example code:
begin
MHz := StrToFloat(Edit1.text);
Length := 468/Mhz;
length := length * 100;
length := int(length) * 0.01;
Edit2.Text := FloatToStr(Length);
end; |
to
actually truncate the value.
Or, you can do this:
begin
MHz := StrToFloat(Edit1.text);
Length := 468/Mhz;
// Edit2.Text :=
FloatToStr(Length);
Edit2.text
:=(format('%.2f',[length]));
end; |
to make
the output look pretty without changing
the variable value!
Change the 2f to 4f to get additional
decimal places (or 3f or 6f etc).
Or you can write your own function:
function
RoundTo(X : Real) : Real; begin
X:= X * 100;
X := int(X) * 0.01;
Result := X
end;
|
To use
the Delphi RoundTo function, place the
RoundTo function code in a form's global
area (Just below the
implementation
{$R *.DFM}
********** <---- goes here!!!
Put the following code in the event
handler (in this case the event handler
is the Form1 button click).
begin
MHz := StrToFloat(Edit1.text);
Length := 468/Mhz;
length := RoundTo(length);
Edit2.Text := FloatToStr(Length);
end; |
If you
want to round another variable in the
same program, just call otherVariable :=
RoundTo(otherVariable);
What
about Visual Basic? Try:
Private
Sub Command1_Click()
Mhz = Text1.Text
Length = 468 / Mhz
'Text2.Text = Length
Text2.Text = Format(Length,
"###0.00")
End Sub |
or
Private
Sub Command1_Click()
Mhz = Text1.Text
Length = 468 / Mhz
Length = Int(Length * 100)
Length = Length * 0.01
Text2.Text = Length
End Sub |
WHERE
ARE THE WORLD BITMAPS?, WHERE CAN I
DOWNLOAD DIGITAL COASTLINE DATA?, WHERE
CAN I FIND THE WORLDMAP.DAT FILE?
Digital images (bitmaps) of the World are
available at:
http://www.evl.uic.edu/pape/data/Earth/
Earth must be spelled with a capital 'E'
as is printed on page 42 of Feb. 2003
QST. The images are available at several
scales and formats. They are very nice.
If you are interested in the huge digital
images databases of coastline and
cultural data, go here: http://www.evl.uic.edu/pape/data/WDB/
The largest text based dataset is about
30 Mb and is only available in a tar
compression file. Winzip won't handle
them. A different file decompressor is
needed. You may be able to find one on
the Web.
If you are interested in the small
coastline data set used in the
demonstration program described in the
article, you need to first download the
1.2 Mb zip file package mentioned in the
article at the ARRLWeb: www.arrl.org/files/qst-binaries
Evidently
this link no longer works since the ARRL
created its 'new' web site in 2010.
After you reach the download page, locate
the file in the list called 0303Grad.zip.
There are four folders in the
0303Grad.zip file. A copy of the smaller
database mapping file worldmap.dat, the
small text based file with
latitude/longitude coordinates for world
coastlines, is included in three of these
folders. Find the folder DMap or, VB5Maps
or VBMap. Each folder has the source code
for the map demonstration program, the
executable file and a copy of the file
WORLDMAP.dat. WORLDMAP.dat can be read
with Notepad, the text editor that
is part of all Windows programs.
The digital files at
www.cia.gov/cia/publications/factbook are
no longer available at that site. There
is other information there that might be
useful in your programming. Mr. Pape's
WDB site mentioned above has links to a
source which contains HUGE binary
files..but Mr. Pape's recently indicated,
the links may be permanently broken.
HOW
CAN I GET THE BEARING/DISTANCE PROGRAM TO
GIVE ME THE DISTANCE IN MILES RATHER THAN
KILOMETERS? Multiplying kilometers by
0.6214 results in a conversion to miles.
Substitute the following:
Distance
= Int(6356.775 * GG +.5) * 0.6214 for VB
or
Distance
:= INT(6356.775 * GG +.5) * 0.6214; for
Delphi.
Want
both measurements? Name the miles
conversion Distance2 instead of Distance.
Put the Distance2 line immediately after
the existing Distance line. Place an
additional Delphi edit box or VB text box
on the form. Depending what this
edit/text box is named, insert the
following code after the line beginning
Edit2.Text in Delphi or the line
Text6.Text in VB --
EditMiles.text
:= FloatToStr(Distance2); for Delphi or
TextMiles.text
=Str$(Distance2) for VB.
where
the EditMiles or TextMiles is the name of
the box.
HOW
CAN I INCLUDE PRINTER COMMANDS, HOW CAN I
USE A SOUND CARD, HOW CAN I...?
Depending on which compiler you have, you
can get excellent answers to these and
other questions about general programming
tasks at one of the Internet sites
mentioned in Table 3 of Part 1 of the
article. Look for a heading on these
sites like PROGRAM, FAQ, or TIPS. Then
search for the topic or control for which
you want to find some example code.
Someone likely has posted a detailed
explanation. Alternatively, search the
Internet with a search engine phrase
looking something like ---- "Visual
Basic""Sound Card" source
or "Delphi""Sound
Card" source to find alternative
sites. You may have to add additional
words to narrow your search ...
"source code", tip, soundcard,
etc. The examples in books in your local
library should be adequate for most
tasks. Sometimes reading another
explanation in a different book might
make the process clearer. There is no
single way to program
anything...different
programmer--different route. Do whatever
works for you. If you've tried the above
and can't find anything, I would be glad
to try to help -- send me an e-mail, I'll
answer when I can. I'm like most of you,
not a professional programmer and am
still learning too.
The
correct way to print is to use a printer
dialog with a drop down menu and such in
both VB and Delphi. Consult the library
or a programming guru. The following will
work but I don't necessarily recommend
doing it this way, but it will get you
technical data output on paper quickly.
To print to the screen, use this code
with VB after putting a Picture box on
your form:
Picture1.Print a, code
--the a and code are your output
variables. To print to a printer, use
this code with VB :
Printer.Print a, code
--The a and code are your output
variables. This is simple, non-formatted
but works. With Delphi, add the word
Printers to the uses clause in the main
code window and this code:
begin
Printer.BeginDoc;
Printer.Canvas.TextOut(0,10,(floattostr(a)
+' '+floattostr(code)));
//continues from above line
Printer.EndDoc;
end; |
assuming
a and code are double precision or use
Printer.Canvas.TextOut(0,10,(a+'
'+code)); if they are strings.
Sound
Cards? Try the ActiveX tutorial by Jack
Hoxley at www.dx4vb.da.ru or look at
G4ILO's site as shown in Table 4 of Part
1 and view his Delphi code practice
program source code. I think it was done
in Delphi 3 but the code works with D5
too. He uses a sound card to produce
Morse CW audio, all manually coded.
Checkout www.programmersheaven.com and
look for the following files: gravis.zip,
nsbtut10.zip, sblast09.zip, awe32prg.zip
--I believe most of this code is in Turbo
Pascal. Also try
www.giangrandi.ch/jack//radio/morse-e.shtml
---look for Tymorse, again in Turbo
Pascal.
WHAT
IS THE VARIABLE H0 FOR IN THE
BEARING/DISTANCE PROGRAM? The H0
variable is a remnant of a previous
programming exercise. When the original
code was developed,the length of BASIC
variables was limited to a few
characters. H0 was calculated to relate
the angular distance data to a statute
miles scale rather than to kilometers. It
has no function in the current program.
back to top
HOW
CAN I WRITE A LOGGING PROGRAM? Coding
a logging program is a bit too much to
explain in a beginners magazine article.
There isn't enough space to discuss all
the coding issues involved even here.
I have
written a PSK program using WA0TTN's PSK
ActiveX control (the application's screen
is shown in a QEX article) that has a
self contained logger. I've also written
the log program whose main screen is
shown in the Part 1 QST article. The
original log program was written in
Delphi 1 Professional. It had very few
lines of code. It was very simple. The
latest version got very complex as I
added additional logging routines and
features. I'll try to find time to clean
up the code and post it on this site's
Delphi Code page in the next few weeks
for these projects. (Sorry, I wont' be
able to post this till some time after
May I have however posted Delphi and VB
logging projects that use only the
STANDARD controls on the Delphi and VB
Code pages.)
I find
working with databases is easier in
Delphi than VB. It's a personal
preference. If you use an Access
database, certainly use VB...it was
designed to work well with it. I designed
my Delphi logger to use a dBASE dbIV
database for the logbook. Why? I can use
built-in search and sort routines and the
database can be easily accessed by both
VB and Delphi. I am finalizing several
simple logging programs using both VB and
Delphi. I hope they will be the basis of
a possible future QST article or book
that will discuss programming and a
logging program, among other things. The
article will show how to use text files,
simple binary files, Access and
dbIV to store the log.
Part of
the 'secret' of writing a logging program
is to establish a database template for
the log information you'll capture before
you start coding your program. The
database would contain fields for time,
date, station, RST....whatever you want
to log. I include several 'dummy' fields
in the template for expansion. If you
code your program and discover you don't
have enough data fields, you are looking
at a major program rewrite. With dummy
fields, you use more space in your
database to store data in return for
future flexibility!
Part 3
of the QST article directs you to
articles in the literature that describe
how to write a logging program in BASIC.
The resources in Listing 5 should give
you ideas and some nifty example code
(Listing 5 is actually in the ARRLWeb
download). For Access and dBASE,
consult the sections in the book you use
to help with your programming that
discusses databases. In its simplest
terms, a logging program is just a
database with a lot of fancy attachments.
It will require lots of manual code if
you use a text or binary based database
and much less with a 'standard' database
like dBASE or Access. In a way,
you trade one kind of headache for
another depending on which programming
route you follow.
THE
FREE DELPHI PROGRAM MENTIONED WOULD NOT
DOWNLOAD. HOW CAN I GET IT?. The
"free" software is no longer
available. The company decided to
discontinue its free version.
Alternatively,
consider the free "Lazarus"
compiler or the free version of Microsoft
Visual Studio.
I
CAN'T DOWNLOAD THE LARGE DELPHI OR VISUAL
BASIC PROGRAMS MENTIONED WITH MY SLOW
CONNECTION!. Look for one of the
suggested books that have a working
version of VB6 on CD at your library or
used book store. My local library has 4
different books that have a disk with a
copy of either a VB5 or VB6 demo. These
work - I used one demo to confirm that my
VB5 programs load with VB6. A
semi-regional book chain called
Half-Price Books here in Dallas has had
copies of the some of the books in the
Book List recently. They also have other
books not mentioned in the article that
have a disk (and versions describing VB5)
at prices between 3 and 15$. I am aware
of a book devoted to Delphi that includes
a copy of Delphi 4 Standard but only saw
it in a second hand store once. Any of
these will get you an inexpensive
introduction as described in the article.
I
WANT TO PROGRAM THE COM PORTS (SERIAL
PORTS). WHAT DO I NEED? The
professional versions of Visual Basic
have a control called MSComm. It will
allow you to easily program the ports for
most functions. Visual Basic standard and
both the standard and professional
versions of Delphi DO NOT have a
communication control. With Delphi, I
have successfully used a free control
called TComport referenced on page 37 in
Feb. QST and recently the excellent and
free TurboPower Async Professional. (see
the Recent News to see how to get it!)
Several
vbx and ocx controls and a DLL are
available that I believe can be used with
Visual Basic standard. I don't use the VB
controls/dll nor do I have a link
reference so you're own your own to
search the net. The article by W0DZ in
QST (Feb 2002, pp. 33-35) mentioned in my
article uses the MSComm control. I think
the complete code can now be downloaded
from the Internet. Search for W0DZ and
Slide Rule Dial or something like that.
His code works nicely. He did a great
job!
It is
possible to program the serial ports
using ANY of these products using Windows
API calls -- it requires a lot of manual
programming to do anything fancy.
However, turning on and off a switch (the
DTR line for example) is not hard. I have
not closely looked at the Delphi code
described by Mark Erbaugh, N8ME, in his
article in the Sept/Oct 2002 QEX where he
described an ActiveX control to control
the Ten-Tec Pegasus. It appears he wrote
his own Delphi 5 code for serial
communication (included in the following
download). His code is at
http://www.arrl.org/qexfiles under the
name 0209ERBAUGH.ZIP . Mark's article is
called "Customize the Ten-Tec
Pegasus--Without Soldering."
WILL
DELPHI V5.0 PRO RUN ON MY WINDOWS XP FOR
HOME? I had some experiences with XP
where some software was not compatible
but D5 is OK. I know that the VB6 trial
software that comes with a VB6 book by
Reselman would not load on my Xp computer
but it loaded fine on another computer
with Windows 95. Visual Basic 5 Pro
loaded just fine on Xp so I believe that
the Xp problem is with that particular
trial edition. Whether there are problems
with loading other software on Xp or not,
I don't know. Since a reader loaded the
VB6 trial that comes with Sams
"Teach..VB6 in 21 days" OK on
his Xp, other versions are probably
alright. My copies of Delphi 1 and Visual
Basic 3 are on another computer with
Windows 95.