next up previous
Next: Scope
Previous: Purpose

Example Application

Here is a simple example of an application program written using SLALIB calls:

         PROGRAM FK4FK5
   *  Read a B1950 position from I/O unit 5 and reply on I/O unit 6
   *  with the J2000 equivalent.  Enter a period to quit.
         CHARACTER C*80,S
         INTEGER I,J,IHMSF(4),IDMSF(4)
         LOGICAL BAD

   *   Loop until a period is entered
         C = ' '
         DO WHILE (C(:1).NE.'.')

   *     Read h m s d ' "
            READ (5,'(A)') C
            IF (C(:1).NE.'.') THEN
               BAD = .TRUE.

   *        Decode the RA
               I = 1
               CALL sla_DAFIN(C,I,R4,J)
               IF (J.EQ.0) THEN
                  R4 = 15D0*R4

   *           Decode the Dec
                  CALL sla_DAFIN(C,I,D4,J)
                  IF (J.EQ.0) THEN

   *              FK4 to FK5
                     CALL sla_FK45Z(R4,D4,1950D0,R5,D5)

   *              Format and output the result
                     CALL sla_DR2TF(2,R5,S,IHMSF)
                     CALL sla_DR2AF(1,D5,S,IDMSF)
                     WRITE (6,
        :       '(1X,I2.2,2I3.2,''.'',I2.2,2X,A,I2.2,2I3.2,''.'',I1)')
        :                                                     IHMSF,S,IDMSF
                     BAD = .FALSE.
                  END IF
               END IF
               IF (BAD) WRITE (6,'(1X,''?'')')
            END IF
         END DO

In this example, SLALIB not only provides the complicated FK4 to FK5 transformation but also simplifies the tedious and error-prone tasks of decoding and formatting angles expressed as hours, minutes etc. The example incorporates range checking, and avoids the notorious ``minus zero'' problem (an often-perpetrated bug where declinations between $0^{\circ}$ and $-1^{\circ}$ lose their minus sign). With a little extra elaboration and a few more calls to SLALIB, defaulting can be provided (enabling unused fields to be replaced with commas to avoid retyping), proper motions can be handled, different epochs can be specified, and so on. See the program COCO (SUN/56) for further ideas.

next up previous
Next: Scope
Previous: Purpose

SLALIB --- Positional Astronomy Library
Starlink User Note 67
P. T. Wallace
12 October 1999