aboutsummaryrefslogtreecommitdiff
path: root/math/slalib/slaTest.c
blob: ab6845587a0dfb20562a4c4d13a651e20d95b860 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 *+
 *  Name:
 *     slaTest

 *  Purpose:
 *     Test C interface to SLA

 *  Language:
 *     Starlink ANSI C

 *  Description:
 *     Provides a simple test of the C interface. Test coverage is not
 *     complete because not all Fortran routines have wrappers.

 *  Copyright:
 *     Copyright (C) 2006 Particle Physics and Engineering Research Council

 *  Licence:
 *     This program is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License as
 *     published by the Free Software Foundation; either version 2 of
 *     the License, or (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be
 *     useful,but WITHOUT ANY WARRANTY; without even the implied
 *     warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 *     PURPOSE. See the GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program; if not, write to the Free Software
 *     Foundation, Inc., 51 Franklin Street,Fifth Floor, Boston, MA
 *     02110-1301, USA

 *  Authors:
 *     TIMJ: Tim Jenness (JAC, Hawaii)
 *     {enter_new_authors_here}

 *  History:
 *     07-AUG-2006 (TIMJ):
 *       Original version.

 *-
 */

#if HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "slalib.h"

#if HAVE_FC_MAIN
void FC_MAIN ( void );
void FC_MAIN ( ) {}
#endif


int main ( void ) {
  double w, p, h;
  char telname[41];
  char telshort[11];
  int  exstatus = EXIT_SUCCESS;


  /* call slaObs - initialise to recognisable state */
  w = 0.0; p = 0.0; h = -1.0;

  /* first call by short name */
  slaObs( 0, "JCMT", telname, &w, &p, &h );
  if ( h == -1.0 ) {
    printf( "Error obtaining information on JCMT\n");
    exstatus = EXIT_FAILURE;
  } else {
    printf( "Telescope JCMT is '%s' w = %f, p = %f, h = %f\n",
	    telname, w, p, h);
  }

  /* call by index */
  h = -1.0; w = 0.0; p = 0.0;
  slaObs( 1, telshort, telname, &w, &p, &h );
  if (h == -1.0 ) {
    printf( "Error obtaining information on telescope 1\n");
    exstatus = EXIT_FAILURE;
  } else {
    printf( "Telescope 1 is '%s' aka '%s' w = %f, p = %f, h = %f\n",
	    telshort, telname, w, p, h);
  }

  /* deliberately fail - with bad index */
  h = -1.0; w = 0.0; p = 0.0; strcpy( telshort, "unknown" );
  slaObs( 100000, telshort, telname, &w, &p, &h );
  if (h != -1.0 || telname[0] != '?') {
    printf("Attempt to decode unfeasibly large telescope index should have failed\n");
    printf("Got this result:  Tel: '%s' aka '%s', w=%f p=%f h=%f\n", telshort,
	   telname, w, p, h);
    exstatus = EXIT_FAILURE;
  }

  /* deliberately fail - with bad name */
  h = -1.0; w = 0.0; p = 0.0;
  slaObs( 0, "AFakeTel", telname, &w, &p, &h );
  if (h != -1.0 || telname[0] != '?') {
    printf("Attempt to decode unknown telescope should have failed\n");
    printf("Got this result:  Tel: '%s', w=%f p=%f h=%f\n", telname, w, p, h);
    exstatus = EXIT_FAILURE;
  }

  return exstatus;
}