ldactoasc.c 2.24 KB
Newer Older
Emmanuel Bertin's avatar
Emmanuel Bertin committed
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
/*
 				ldactoasc.c

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*
*	Part of:	LDACtoASC
*
*	Author:		E.BERTIN (IAP)
*
*	Contents:	Convert LDAC binary format to ASCII.
*
*	Last modify:	19/12/2007
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/

#ifdef HAVE_CONFIG_H
#include	"config.h"
#endif

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ldactoasc.h"
#include "fits/fitscat.h"

#define		SYNTAX  "ldactoasc catalog\n"
extern const char	notokstr[];

/********************************** main ************************************/
int	main(int argc, char *argv[])

  {
   catstruct		*cat;
   tabstruct		*tab;
   unsigned short	ashort=1;
   char			catname[MAXCHAR];
   int			a, t, opt,opt2, flag;

  if (argc<2)
    {
    fprintf(OUTPUT, "\n                %s  Version %s (%s)\n",
		BANNER, MYVERSION, DATE);
    fprintf(OUTPUT, "\nFor information, please contact: %s\n", COPYRIGHT);
    error(EXIT_SUCCESS, "SYNTAX: ", SYNTAX);
    }

/* Test if byteswapping will be needed */
  bswapflag = *((char *)&ashort);

/* Default parameters */
  for (a=1; a<argc; a++)
    {
    if (*(argv[a]) == '-')
      {
      opt = (int)argv[a][1];
      {
      opt2 = (int)tolower((int)argv[a][2]);
      if (opt == '-')
        {
        opt = opt2;
        opt2 = (int)tolower((int)argv[a][3]);
        }
      switch(opt)
        {
        case 'v':
          printf("%s version %s (%s)\n", BANNER,MYVERSION,DATE);
          exit(EXIT_SUCCESS);
          break;
        case 'h':
          fprintf(OUTPUT, "\nSYNTAX: %s", SYNTAX);
          exit(EXIT_SUCCESS);
          break;
        default:
          error(EXIT_SUCCESS, "SYNTAX: ", SYNTAX);
          }
        }
      }
    else
      strcpy(catname, argv[a]);
    }

  flag = 1;	/* display banner of first extension */
  if ((cat = read_cat(catname)))
    {
    tab = cat->tab;
    for (t=cat->ntab; t--; tab=tab->nexttab)
      if (!strcmp("LDAC_OBJECTS", tab->extname)
	  || !strcmp("OBJECTS", tab->extname))
        {
        show_keys(tab, NULL, NULL, 0, NULL, stdout, 1, flag, 0, SHOW_ASCII);
        flag = 0;
        }
    free_cat(&cat, 1);
    }
  else
    error(EXIT_FAILURE,"Cannot open ",catname);

  return EXIT_SUCCESS;
  }