Example: A Basic GPSTk Application

This example serves as an introduction to using the GPSTk. The code associated with the example can be found in the file gpstk/dev/examples/example1.cpp.
Its purpose is to illustrate the most basic concepts required for effective use of the GPSTk.

Lines 1 and 2 include declarations for the classes used in this example.
Note that line 2 uses quotes to include the class declaration for the GPSTk class DayTime.
As you might expect, DayTime is a class that represents time. As time is an integral concept to
GPS, this class plays an important part in the foundation of the GPSTk.

In lines 3 and 4 we define which namespaces we will use for the following code.
In the GPSTk the concept of namespace is used extensively. Using namespaces is an excellent way to
reduce name clashes.

Line 7 establishes a try-catch block, so that if a GPSTk-derived exception is thrown it is caught and displayed, in lines 18-22.

Lines 9 through 16 demonstrate use of the DayTime class. Note that the default constructor represents the current system time.

To compile the above and execute in Linux with gcc would look like the following.

user@host:~/gpstk/examples$ g++ -o example -I~/gpstk/src
-L~/gpstk/src -lgpstk example1.cpp
user@host:~/gpstk/examples$ ./example
Hello world!
The current GPS week is 1281
The day of the GPS week is 5
The seconds of the GPS week is 499360

The compilation command would simplified if you installed the GPSTk
as a system library. The -I and -L options would not be necessary. In
that case the compilation command would be simply

g++ -o example -lgpstk example1.cpp

More example code can be found in the source distribution under gpstk/dev/examples, gpstk/dev/tests and gpstk/dev/apps.