main.c 4.39 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*
*				main.c
*
* Command line parsing.
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*
*	This file part of:	SExtractor
*
10
*	Copyright:		(C) 1993-2018 IAP/CNRS/UPMC
Emmanuel Bertin's avatar
Emmanuel Bertin committed
11
*
12
*	License:		GNU General Public License
Emmanuel Bertin's avatar
Emmanuel Bertin committed
13
*
14
15
16
17
18
19
20
21
22
23
*	SExtractor 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 3 of the License, or
*	(at your option) any later version.
*	SExtractor 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 SExtractor. If not, see <http://www.gnu.org/licenses/>.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
24
*
25
*	Last modified:		09/01/2018
Emmanuel Bertin's avatar
Emmanuel Bertin committed
26
*
27
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
Emmanuel Bertin's avatar
Emmanuel Bertin committed
28
29
30
31
32
33
34
35
36
37
38
39
40

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

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

#include	"define.h"
#include	"globals.h"
#include	"prefs.h"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
41
#include "pattern.h"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
42
43
#define		SYNTAX \
EXECUTABLE " <image> [<image2>][-c <configuration_file>][-<keyword> <value>]\n" \
Emmanuel Bertin's avatar
Emmanuel Bertin committed
44
45
46
"> to dump a default configuration file:          " EXECUTABLE " -d \n" \
"> to dump a default extended configuration file: " EXECUTABLE " -dd \n" \
"> to dump a full list of measurement parameters: " EXECUTABLE " -dp \n"
Emmanuel Bertin's avatar
Emmanuel Bertin committed
47
48

extern const char       notokstr[];
Emmanuel Bertin's avatar
Emmanuel Bertin committed
49
extern keystruct	objkey[];
Emmanuel Bertin's avatar
Emmanuel Bertin committed
50
51
52
53
54

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

  {
55
   double	tdiff, lines, dets;
Emmanuel Bertin's avatar
Emmanuel Bertin committed
56
   int		a, narg, nim, opt, opt2;
57
58
59
   char		str[MAXCHARL],
		**argkey, **argval,
		*pstr;
Emmanuel Bertin's avatar
Emmanuel Bertin committed
60

61
62
setlinebuf(stdout);
 if (argc<2)
Emmanuel Bertin's avatar
Emmanuel Bertin committed
63
64
    {
    fprintf(OUTPUT, "\n         %s  version %s (%s)\n", BANNER,MYVERSION,DATE);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
65
    fprintf(OUTPUT, "\nWritten by %s\n", AUTHORS);
66
67
68
    fprintf(OUTPUT, "Copyright %s\n", COPYRIGHT);
    fprintf(OUTPUT, "\nvisit %s\n", WEBSITE);
    fprintf(OUTPUT, "\n%s\n", DISCLAIMER);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
69
70
71
72
73
74
75
76
77
78
    error(EXIT_SUCCESS, "SYNTAX: ", SYNTAX);
    }
  QMALLOC(argkey, char *, argc);
  QMALLOC(argval, char *, argc);

/*default parameters */
  prefs.command_line = argv;
  prefs.ncommand_line = argc;
  prefs.pipe_flag = 0;
  prefs.nimage_name = 1;
79
  strcpy(prefs.image_name[0], "image");
Emmanuel Bertin's avatar
Emmanuel Bertin committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
  strcpy(prefs.prefs_name, "default.sex");
  narg = nim = 0;

  for (a=1; a<argc; a++)
    {
    if (*(argv[a]) == '-')
      {
      opt = (int)argv[a][1];
      if (strlen(argv[a])<4 || opt == '-')
        {
        opt2 = (int)tolower((int)argv[a][2]);
        if (opt == '-')
          {
          opt = opt2;
          opt2 = (int)tolower((int)argv[a][3]);
          }
        switch(opt)
          {
          case 'c':
            if (a<(argc-1))
              strcpy(prefs.prefs_name, argv[++a]);
            break;
          case 'd':
Emmanuel Bertin's avatar
Emmanuel Bertin committed
103
104
105
106
107
108
            if (opt2=='d')
              dumpprefs(1);
            else if (opt2=='p')
              dumpparams();
            else
              dumpprefs(0);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
            exit(EXIT_SUCCESS);
            break;
          case 'v':
            printf("%s version %s (%s)\n", BANNER,MYVERSION,DATE);
            exit(0);
            break;
          case 'h':
          default:
            error(EXIT_SUCCESS,"SYNTAX: ", SYNTAX);
          }
        }
      else
        {
/*------ Config parameters */
        argkey[narg] = &argv[a][1];
        argval[narg++] = argv[++a];
        }       
      }
    else
      {
/*---- The input image filename(s) */
      for(; (a<argc) && (*argv[a]!='-'); a++)
131
132
133
        {
        strncpy(str, argv[a], MAXCHARL-1);
        for (pstr=NULL;(pstr=strtok(pstr?NULL:str, notokstr)); nim++)
Emmanuel Bertin's avatar
Emmanuel Bertin committed
134
          if (nim<MAXIMAGE)
135
            strncpy(prefs.image_name[nim], pstr, MAXCHAR-1);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
136
          else
137
138
            error(EXIT_FAILURE, "*Error*: Too many input images: ", pstr);
        }
Emmanuel Bertin's avatar
Emmanuel Bertin committed
139
140
141
142
143
144
      prefs.nimage_name = nim;
      a--;
      }
    }

  readprefs(prefs.prefs_name, argkey, argval, narg);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
145
  preprefs();
Emmanuel Bertin's avatar
Emmanuel Bertin committed
146
147
148
149
150
151

  free(argkey);
  free(argval);

  makeit();

Emmanuel Bertin's avatar
Emmanuel Bertin committed
152
  endprefs();
Emmanuel Bertin's avatar
Emmanuel Bertin committed
153
  NFPRINTF(OUTPUT, "");
154
  tdiff = prefs.time_diff>0.0? prefs.time_diff : 0.001;
155
156
157
  lines = (double)thefield1.height/tdiff;
  dets = (double)thecat.ntotal/tdiff;
  NPRINTF(OUTPUT,
158
	"> All done (in %.1f s: %.1f line%s/s , %.1f detection%s/s)\n",
159
	prefs.time_diff, lines, lines>1.0? "s":"", dets, dets>1.0? "s":"");
Emmanuel Bertin's avatar
Emmanuel Bertin committed
160
161
162
163

  return EXIT_SUCCESS;
  }