| 1 |
2 |
bertin |
/*
|
| 2 |
|
|
prefs.c
|
| 3 |
|
|
|
| 4 |
|
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 5 |
|
|
*
|
| 6 |
|
|
* Part of: SExtractor
|
| 7 |
|
|
*
|
| 8 |
|
|
* Author: E.BERTIN (IAP)
|
| 9 |
|
|
*
|
| 10 |
|
|
* Contents: Functions to handle the configuration file.
|
| 11 |
|
|
*
|
| 12 |
230 |
bertin |
* Last modify: 22/09/2010
|
| 13 |
2 |
bertin |
*
|
| 14 |
|
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 15 |
|
|
*/
|
| 16 |
|
|
|
| 17 |
|
|
#ifdef HAVE_CONFIG_H
|
| 18 |
|
|
#include "config.h"
|
| 19 |
|
|
#endif
|
| 20 |
|
|
|
| 21 |
|
|
#include <ctype.h>
|
| 22 |
|
|
#include <math.h>
|
| 23 |
|
|
#include <stdio.h>
|
| 24 |
|
|
#include <stdlib.h>
|
| 25 |
|
|
#include <string.h>
|
| 26 |
173 |
bertin |
#include <unistd.h>
|
| 27 |
|
|
#if defined(USE_THREADS) \
|
| 28 |
|
|
&& (defined(__APPLE__) || defined(FREEBSD) || defined(NETBSD)) /* BSD, Apple */
|
| 29 |
|
|
#include <sys/types.h>
|
| 30 |
|
|
#include <sys/sysctl.h>
|
| 31 |
|
|
#elif defined(USE_THREADS) && defined(HAVE_MPCTL) /* HP/UX */
|
| 32 |
|
|
#include <sys/mpctl.h>
|
| 33 |
|
|
#endif
|
| 34 |
2 |
bertin |
|
| 35 |
|
|
#include "define.h"
|
| 36 |
|
|
#include "globals.h"
|
| 37 |
|
|
#include "prefs.h"
|
| 38 |
|
|
#include "preflist.h"
|
| 39 |
|
|
#include "fits/fitscat.h"
|
| 40 |
|
|
|
| 41 |
|
|
|
| 42 |
|
|
/********************************* dumpprefs ********************************/
|
| 43 |
|
|
/*
|
| 44 |
|
|
Print the default preference parameters.
|
| 45 |
|
|
*/
|
| 46 |
|
|
void dumpprefs(int state)
|
| 47 |
|
|
{
|
| 48 |
|
|
char **dp;
|
| 49 |
|
|
|
| 50 |
|
|
dp = default_prefs;
|
| 51 |
|
|
while (**dp)
|
| 52 |
|
|
if (**dp != '*')
|
| 53 |
|
|
printf("%s\n",*(dp++));
|
| 54 |
|
|
else if (state)
|
| 55 |
|
|
printf("%s\n",*(dp++)+1);
|
| 56 |
|
|
else
|
| 57 |
|
|
dp++;
|
| 58 |
|
|
return;
|
| 59 |
|
|
}
|
| 60 |
|
|
|
| 61 |
|
|
|
| 62 |
|
|
/********************************* readprefs ********************************/
|
| 63 |
|
|
/*
|
| 64 |
|
|
Read a configuration file in ``standard'' format (see the SExtractor
|
| 65 |
|
|
documentation)
|
| 66 |
|
|
*/
|
| 67 |
|
|
void readprefs(char *filename, char **argkey, char **argval, int narg)
|
| 68 |
|
|
|
| 69 |
|
|
{
|
| 70 |
|
|
FILE *infile;
|
| 71 |
15 |
bertin |
char *cp, str[MAXCHARL], *keyword, *value, **dp;
|
| 72 |
2 |
bertin |
int i, ival, nkey, warn, argi, flagc, flagd, flage, flagz;
|
| 73 |
|
|
float dval;
|
| 74 |
|
|
#ifndef NO_ENVVAR
|
| 75 |
15 |
bertin |
static char value2[MAXCHARL],envname[MAXCHAR];
|
| 76 |
2 |
bertin |
char *dolpos;
|
| 77 |
|
|
#endif
|
| 78 |
|
|
|
| 79 |
|
|
|
| 80 |
|
|
if ((infile = fopen(filename,"r")) == NULL)
|
| 81 |
|
|
{
|
| 82 |
|
|
flage = 1;
|
| 83 |
|
|
warning(filename, " not found, using internal defaults");
|
| 84 |
|
|
}
|
| 85 |
|
|
else
|
| 86 |
|
|
flage = 0;
|
| 87 |
|
|
|
| 88 |
|
|
/*Build the keyword-list from pkeystruct-array */
|
| 89 |
|
|
|
| 90 |
|
|
for (i=0; key[i].name[0]; i++)
|
| 91 |
|
|
strcpy(keylist[i], key[i].name);
|
| 92 |
|
|
keylist[i][0] = '\0';
|
| 93 |
|
|
|
| 94 |
|
|
|
| 95 |
|
|
/*Scan the configuration file*/
|
| 96 |
|
|
|
| 97 |
|
|
argi=0;
|
| 98 |
|
|
flagc = 0;
|
| 99 |
|
|
flagd = 1;
|
| 100 |
|
|
dp = default_prefs;
|
| 101 |
|
|
for (warn=0;;)
|
| 102 |
|
|
{
|
| 103 |
|
|
if (flagd)
|
| 104 |
|
|
{
|
| 105 |
|
|
if (**dp)
|
| 106 |
|
|
{
|
| 107 |
|
|
if (**dp=='*')
|
| 108 |
|
|
strcpy(str, *(dp++)+1);
|
| 109 |
|
|
else
|
| 110 |
|
|
strcpy(str, *(dp++));
|
| 111 |
|
|
}
|
| 112 |
|
|
else
|
| 113 |
|
|
flagd = 0;
|
| 114 |
|
|
}
|
| 115 |
|
|
if (!flagc && !flagd)
|
| 116 |
15 |
bertin |
if (flage || !fgets(str, MAXCHARL, infile))
|
| 117 |
2 |
bertin |
flagc=1;
|
| 118 |
|
|
|
| 119 |
|
|
if (flagc)
|
| 120 |
|
|
{
|
| 121 |
|
|
if (argi<narg)
|
| 122 |
|
|
{
|
| 123 |
|
|
sprintf(str, "%s %s", argkey[argi], argval[argi]);
|
| 124 |
|
|
argi++;
|
| 125 |
|
|
}
|
| 126 |
|
|
else
|
| 127 |
|
|
break;
|
| 128 |
|
|
}
|
| 129 |
|
|
|
| 130 |
|
|
keyword = strtok(str, notokstr);
|
| 131 |
|
|
if (keyword && keyword[0]!=0 && keyword[0]!=(char)'#')
|
| 132 |
|
|
{
|
| 133 |
|
|
if (warn>=10)
|
| 134 |
|
|
error(EXIT_FAILURE, "*Error*: No valid keyword found in ", filename);
|
| 135 |
|
|
nkey = findkeys(keyword, keylist, FIND_STRICT);
|
| 136 |
|
|
if (nkey!=RETURN_ERROR)
|
| 137 |
|
|
{
|
| 138 |
|
|
value = strtok((char *)NULL, notokstr);
|
| 139 |
|
|
#ifndef NO_ENVVAR
|
| 140 |
|
|
/*------ Expansion of environment variables (preceded by '$') */
|
| 141 |
|
|
if (value && (dolpos=strchr(value, '$')))
|
| 142 |
|
|
{
|
| 143 |
|
|
int nc;
|
| 144 |
|
|
char *valuet,*value2t, *envval;
|
| 145 |
|
|
|
| 146 |
|
|
value2t = value2;
|
| 147 |
|
|
valuet = value;
|
| 148 |
|
|
while (dolpos)
|
| 149 |
|
|
{
|
| 150 |
|
|
while (valuet<dolpos)
|
| 151 |
|
|
*(value2t++) = *(valuet++); /* verbatim copy before '$' */
|
| 152 |
|
|
if (*(++valuet) == (char)'{')
|
| 153 |
|
|
valuet++;
|
| 154 |
|
|
strncpy(envname, valuet, nc=strcspn(valuet,"}/:\"\'\\"));
|
| 155 |
|
|
*(envname+nc) = (char)'\0';
|
| 156 |
|
|
if (*(valuet+=nc) == (char)'}')
|
| 157 |
|
|
valuet++;
|
| 158 |
|
|
if (!(envval=getenv(envname)))
|
| 159 |
|
|
error(EXIT_FAILURE, "Environment variable not found: ",
|
| 160 |
|
|
envname);
|
| 161 |
|
|
while(*envval) /* Copy the ENV content */
|
| 162 |
|
|
*(value2t++) = *(envval++);
|
| 163 |
|
|
while(*valuet && *valuet!=(char)'$')/* Continue verbatim copy */
|
| 164 |
|
|
*(value2t++) = *(valuet++);
|
| 165 |
|
|
if (*valuet)
|
| 166 |
|
|
dolpos = valuet;
|
| 167 |
|
|
else
|
| 168 |
|
|
{
|
| 169 |
|
|
dolpos = NULL;
|
| 170 |
|
|
*value2t = (char)'\0';
|
| 171 |
|
|
}
|
| 172 |
|
|
}
|
| 173 |
|
|
|
| 174 |
|
|
value = value2;
|
| 175 |
|
|
}
|
| 176 |
|
|
#endif
|
| 177 |
|
|
switch(key[nkey].type)
|
| 178 |
|
|
{
|
| 179 |
|
|
case P_FLOAT:
|
| 180 |
|
|
if (!value || value[0]==(char)'#')
|
| 181 |
|
|
error(EXIT_FAILURE, keyword," keyword has no value!");
|
| 182 |
|
|
dval = atof(value);
|
| 183 |
|
|
if (dval>=key[nkey].dmin && dval<=key[nkey].dmax)
|
| 184 |
|
|
*(double *)(key[nkey].ptr) = dval;
|
| 185 |
|
|
else
|
| 186 |
|
|
error(EXIT_FAILURE, keyword," keyword out of range");
|
| 187 |
|
|
break;
|
| 188 |
|
|
|
| 189 |
|
|
case P_INT:
|
| 190 |
|
|
if (!value || value[0]==(char)'#')
|
| 191 |
|
|
error(EXIT_FAILURE, keyword," keyword has no value!");
|
| 192 |
|
|
ival = atoi(value);
|
| 193 |
|
|
if (ival>=key[nkey].imin && ival<=key[nkey].imax)
|
| 194 |
|
|
*(int *)(key[nkey].ptr) = ival;
|
| 195 |
|
|
else
|
| 196 |
|
|
error(EXIT_FAILURE, keyword, " keyword out of range");
|
| 197 |
|
|
break;
|
| 198 |
|
|
|
| 199 |
|
|
case P_STRING:
|
| 200 |
|
|
if (!value || value[0]==(char)'#')
|
| 201 |
|
|
error(EXIT_FAILURE, keyword," string is empty!");
|
| 202 |
|
|
strcpy((char *)key[nkey].ptr, value);
|
| 203 |
|
|
break;
|
| 204 |
|
|
|
| 205 |
|
|
case P_BOOL:
|
| 206 |
|
|
if (!value || value[0]==(char)'#')
|
| 207 |
|
|
error(EXIT_FAILURE, keyword," keyword has no value!");
|
| 208 |
|
|
if ((cp = strchr("yYnN", (int)value[0])))
|
| 209 |
|
|
*(int *)(key[nkey].ptr) = (tolower((int)*cp)=='y')?1:0;
|
| 210 |
|
|
else
|
| 211 |
|
|
error(EXIT_FAILURE, keyword, " value must be Y or N");
|
| 212 |
|
|
break;
|
| 213 |
|
|
|
| 214 |
|
|
case P_KEY:
|
| 215 |
|
|
if (!value || value[0]==(char)'#')
|
| 216 |
|
|
error(EXIT_FAILURE, keyword," keyword has no value!");
|
| 217 |
|
|
if ((ival = findkeys(value, key[nkey].keylist,FIND_STRICT))
|
| 218 |
|
|
!= RETURN_ERROR)
|
| 219 |
|
|
*(int *)(key[nkey].ptr) = ival;
|
| 220 |
|
|
else
|
| 221 |
|
|
error(EXIT_FAILURE, keyword, " set to an unknown keyword");
|
| 222 |
|
|
break;
|
| 223 |
|
|
|
| 224 |
|
|
case P_BOOLLIST:
|
| 225 |
|
|
for (i=0; i<MAXLIST&&value&&value[0]!=(char)'#'; i++)
|
| 226 |
|
|
{
|
| 227 |
|
|
if (i>=key[nkey].nlistmax)
|
| 228 |
|
|
error(EXIT_FAILURE, keyword, " has too many members");
|
| 229 |
|
|
if ((cp = strchr("yYnN", (int)value[0])))
|
| 230 |
|
|
((int *)(key[nkey].ptr))[i] = (tolower((int)*cp)=='y')?1:0;
|
| 231 |
|
|
else
|
| 232 |
|
|
error(EXIT_FAILURE, keyword, " value must be Y or N");
|
| 233 |
|
|
value = strtok((char *)NULL, notokstr);
|
| 234 |
|
|
}
|
| 235 |
|
|
if (i<key[nkey].nlistmin)
|
| 236 |
|
|
error(EXIT_FAILURE, keyword, " list has not enough members");
|
| 237 |
|
|
*(key[nkey].nlistptr) = i;
|
| 238 |
|
|
break;
|
| 239 |
|
|
|
| 240 |
|
|
case P_INTLIST:
|
| 241 |
|
|
for (i=0; i<MAXLIST&&value&&value[0]!=(char)'#'; i++)
|
| 242 |
|
|
{
|
| 243 |
|
|
if (i>=key[nkey].nlistmax)
|
| 244 |
|
|
error(EXIT_FAILURE, keyword, " has too many members");
|
| 245 |
|
|
ival = strtol(value, NULL, 0);
|
| 246 |
|
|
if (ival>=key[nkey].imin && ival<=key[nkey].imax)
|
| 247 |
|
|
((int *)key[nkey].ptr)[i] = ival;
|
| 248 |
|
|
else
|
| 249 |
|
|
error(EXIT_FAILURE, keyword, " keyword out of range");
|
| 250 |
|
|
value = strtok((char *)NULL, notokstr);
|
| 251 |
|
|
}
|
| 252 |
|
|
if (i<key[nkey].nlistmin)
|
| 253 |
|
|
error(EXIT_FAILURE, keyword, " list has not enough members");
|
| 254 |
|
|
*(key[nkey].nlistptr) = i;
|
| 255 |
|
|
break;
|
| 256 |
|
|
|
| 257 |
|
|
case P_FLOATLIST:
|
| 258 |
|
|
for (i=0; i<MAXLIST&&value&&value[0]!=(char)'#'; i++)
|
| 259 |
|
|
{
|
| 260 |
|
|
if (i>=key[nkey].nlistmax)
|
| 261 |
|
|
error(EXIT_FAILURE, keyword, " has too many members");
|
| 262 |
|
|
dval = atof(value);
|
| 263 |
|
|
if (dval>=key[nkey].dmin && dval<=key[nkey].dmax)
|
| 264 |
|
|
((double *)key[nkey].ptr)[i] = dval;
|
| 265 |
|
|
else
|
| 266 |
|
|
error(EXIT_FAILURE, keyword, " keyword out of range");
|
| 267 |
|
|
value = strtok((char *)NULL, notokstr);
|
| 268 |
|
|
}
|
| 269 |
|
|
if (i<key[nkey].nlistmin)
|
| 270 |
|
|
error(EXIT_FAILURE, keyword, " list has not enough members");
|
| 271 |
|
|
*(key[nkey].nlistptr) = i;
|
| 272 |
|
|
break;
|
| 273 |
|
|
|
| 274 |
|
|
case P_KEYLIST:
|
| 275 |
|
|
for (i=0; i<MAXLIST && value && value[0]!=(char)'#'; i++)
|
| 276 |
|
|
{
|
| 277 |
|
|
if (i>=key[nkey].nlistmax)
|
| 278 |
|
|
error(EXIT_FAILURE, keyword, " has too many members");
|
| 279 |
|
|
if ((ival = findkeys(value, key[nkey].keylist, FIND_STRICT))
|
| 280 |
|
|
!= RETURN_ERROR)
|
| 281 |
|
|
((int *)(key[nkey].ptr))[i] = ival;
|
| 282 |
|
|
else
|
| 283 |
|
|
error(EXIT_FAILURE, keyword, " set to an unknown keyword");
|
| 284 |
|
|
value = strtok((char *)NULL, notokstr);
|
| 285 |
|
|
}
|
| 286 |
|
|
if (i<key[nkey].nlistmin)
|
| 287 |
|
|
error(EXIT_FAILURE, keyword, " list has not enough members");
|
| 288 |
|
|
*(key[nkey].nlistptr) = i;
|
| 289 |
|
|
break;
|
| 290 |
|
|
|
| 291 |
|
|
case P_STRINGLIST:
|
| 292 |
|
|
if (!value || value[0]==(char)'#')
|
| 293 |
|
|
{
|
| 294 |
|
|
value = "";
|
| 295 |
|
|
flagz = 1;
|
| 296 |
|
|
}
|
| 297 |
|
|
else
|
| 298 |
|
|
flagz = 0;
|
| 299 |
|
|
for (i=0; i<MAXLIST && value && value[0]!=(char)'#'; i++)
|
| 300 |
|
|
{
|
| 301 |
|
|
if (i>=key[nkey].nlistmax)
|
| 302 |
|
|
error(EXIT_FAILURE, keyword, " has too many members");
|
| 303 |
|
|
free(((char **)key[nkey].ptr)[i]);
|
| 304 |
|
|
QMALLOC(((char **)key[nkey].ptr)[i], char, MAXCHAR);
|
| 305 |
|
|
strcpy(((char **)key[nkey].ptr)[i], value);
|
| 306 |
|
|
value = strtok((char *)NULL, notokstr);
|
| 307 |
|
|
}
|
| 308 |
|
|
if (i<key[nkey].nlistmin)
|
| 309 |
|
|
error(EXIT_FAILURE, keyword, " list has not enough members");
|
| 310 |
|
|
*(key[nkey].nlistptr) = flagz?0:i;
|
| 311 |
|
|
break;
|
| 312 |
|
|
|
| 313 |
|
|
default:
|
| 314 |
|
|
error(EXIT_FAILURE, "*Internal ERROR*: Type Unknown",
|
| 315 |
|
|
" in readprefs()");
|
| 316 |
|
|
break;
|
| 317 |
|
|
}
|
| 318 |
|
|
key[nkey].flag = 1;
|
| 319 |
|
|
}
|
| 320 |
|
|
else
|
| 321 |
|
|
{
|
| 322 |
|
|
warning(keyword, " keyword unknown");
|
| 323 |
|
|
warn++;
|
| 324 |
|
|
}
|
| 325 |
|
|
}
|
| 326 |
|
|
}
|
| 327 |
|
|
|
| 328 |
|
|
for (i=0; key[i].name[0]; i++)
|
| 329 |
|
|
if (!key[i].flag)
|
| 330 |
|
|
error(EXIT_FAILURE, key[i].name, " configuration keyword missing");
|
| 331 |
|
|
if (!flage)
|
| 332 |
|
|
fclose(infile);
|
| 333 |
|
|
|
| 334 |
|
|
return;
|
| 335 |
|
|
}
|
| 336 |
|
|
|
| 337 |
|
|
|
| 338 |
|
|
/********************************** findkeys **********************************/
|
| 339 |
|
|
/*
|
| 340 |
|
|
find an item within a list of keywords, SExtractor version.
|
| 341 |
|
|
*/
|
| 342 |
|
|
int findkeys(char *str, char keyw[][32], int mode)
|
| 343 |
|
|
|
| 344 |
|
|
{
|
| 345 |
|
|
int i;
|
| 346 |
|
|
|
| 347 |
|
|
for (i=0; keyw[i][0]; i++)
|
| 348 |
|
|
if (!cistrcmp(str, keyw[i], mode))
|
| 349 |
|
|
return i;
|
| 350 |
|
|
|
| 351 |
|
|
return RETURN_ERROR;
|
| 352 |
|
|
}
|
| 353 |
|
|
|
| 354 |
|
|
|
| 355 |
|
|
/******************************* cistrcmp ***********************************/
|
| 356 |
|
|
/*
|
| 357 |
|
|
case-insensitive strcmp.
|
| 358 |
|
|
*/
|
| 359 |
|
|
int cistrcmp(char *cs, char *ct, int mode)
|
| 360 |
|
|
|
| 361 |
|
|
{
|
| 362 |
|
|
int i, diff;
|
| 363 |
|
|
|
| 364 |
|
|
if (mode)
|
| 365 |
|
|
{
|
| 366 |
|
|
for (i=0; cs[i]&&ct[i]; i++)
|
| 367 |
|
|
if ((diff=tolower((int)cs[i])-tolower((int)ct[i])))
|
| 368 |
|
|
return diff;
|
| 369 |
|
|
}
|
| 370 |
|
|
else
|
| 371 |
|
|
{
|
| 372 |
|
|
for (i=0; cs[i]||ct[i]; i++)
|
| 373 |
|
|
if ((diff=tolower((int)cs[i])-tolower((int)ct[i])))
|
| 374 |
|
|
return diff;
|
| 375 |
|
|
}
|
| 376 |
|
|
|
| 377 |
|
|
return 0;
|
| 378 |
|
|
}
|
| 379 |
|
|
|
| 380 |
|
|
|
| 381 |
173 |
bertin |
/********************************* preprefs **********************************/
|
| 382 |
|
|
/*
|
| 383 |
|
|
Set number of threads and endianity.
|
| 384 |
|
|
*/
|
| 385 |
|
|
void preprefs()
|
| 386 |
|
|
|
| 387 |
|
|
{
|
| 388 |
|
|
unsigned short ashort=1;
|
| 389 |
|
|
#ifdef USE_THREADS
|
| 390 |
|
|
int nproc;
|
| 391 |
|
|
#endif
|
| 392 |
|
|
|
| 393 |
|
|
/* Test if byteswapping will be needed */
|
| 394 |
|
|
bswapflag = *((char *)&ashort);
|
| 395 |
|
|
|
| 396 |
|
|
/* Multithreading */
|
| 397 |
|
|
#ifdef USE_THREADS
|
| 398 |
|
|
if (!prefs.nthreads)
|
| 399 |
|
|
{
|
| 400 |
|
|
/*-- Get the number of processors for parallel builds */
|
| 401 |
|
|
/*-- See, e.g. http://ndevilla.free.fr/threads */
|
| 402 |
|
|
nproc = -1;
|
| 403 |
|
|
#if defined(_SC_NPROCESSORS_ONLN) /* AIX, Solaris, Linux */
|
| 404 |
|
|
nproc = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
| 405 |
|
|
#elif defined(_SC_NPROCESSORS_CONF)
|
| 406 |
|
|
nproc = (int)sysconf(_SC_NPROCESSORS_CONF);
|
| 407 |
|
|
#elif defined(__APPLE__) || defined(FREEBSD) || defined(NETBSD) /* BSD, Apple */
|
| 408 |
|
|
{
|
| 409 |
|
|
int mib[2];
|
| 410 |
|
|
size_t len;
|
| 411 |
|
|
|
| 412 |
|
|
mib[0] = CTL_HW;
|
| 413 |
|
|
mib[1] = HW_NCPU;
|
| 414 |
|
|
len = sizeof(nproc);
|
| 415 |
|
|
sysctl(mib, 2, &nproc, &len, NULL, 0);
|
| 416 |
|
|
}
|
| 417 |
|
|
#elif defined (_SC_NPROC_ONLN) /* SGI IRIX */
|
| 418 |
|
|
nproc = sysconf(_SC_NPROC_ONLN);
|
| 419 |
|
|
#elif defined(HAVE_MPCTL) /* HP/UX */
|
| 420 |
|
|
nproc = mpctl(MPC_GETNUMSPUS_SYS, 0, 0);
|
| 421 |
|
|
#endif
|
| 422 |
|
|
|
| 423 |
|
|
if (nproc>0)
|
| 424 |
|
|
prefs.nthreads = nproc;
|
| 425 |
|
|
else
|
| 426 |
|
|
{
|
| 427 |
|
|
prefs.nthreads = 2;
|
| 428 |
|
|
warning("Cannot find the number of CPUs on this system:",
|
| 429 |
|
|
"NTHREADS defaulted to 2");
|
| 430 |
|
|
}
|
| 431 |
|
|
}
|
| 432 |
197 |
bertin |
#ifndef HAVE_ATLAS_MP
|
| 433 |
|
|
if (prefs.nthreads>1)
|
| 434 |
|
|
warning("This executable has been compiled using a version of the ATLAS "
|
| 435 |
|
|
"library without support for multithreading. ",
|
| 436 |
|
|
"Performance will be degraded.");
|
| 437 |
|
|
#endif
|
| 438 |
|
|
|
| 439 |
173 |
bertin |
#else
|
| 440 |
|
|
if (prefs.nthreads != 1)
|
| 441 |
|
|
{
|
| 442 |
|
|
prefs.nthreads = 1;
|
| 443 |
|
|
warning("NTHREADS != 1 ignored: ",
|
| 444 |
|
|
"this build of " BANNER " is single-threaded");
|
| 445 |
|
|
}
|
| 446 |
|
|
#endif
|
| 447 |
|
|
}
|
| 448 |
|
|
|
| 449 |
|
|
|
| 450 |
2 |
bertin |
/********************************* useprefs **********************************/
|
| 451 |
|
|
/*
|
| 452 |
|
|
Update various structures according to the prefs.
|
| 453 |
|
|
*/
|
| 454 |
|
|
void useprefs()
|
| 455 |
|
|
|
| 456 |
|
|
{
|
| 457 |
|
|
int i, margin, naper;
|
| 458 |
|
|
char *str;
|
| 459 |
|
|
|
| 460 |
|
|
/*-------------------------------- Images ----------------------------------*/
|
| 461 |
|
|
prefs.dimage_flag = (prefs.nimage_name>1);
|
| 462 |
|
|
|
| 463 |
|
|
/*--------------------------------- ASSOC ----------------------------------*/
|
| 464 |
|
|
prefs.assoc_flag = FLAG(obj2.assoc) || FLAG(obj2.assoc_number);
|
| 465 |
|
|
|
| 466 |
|
|
/*-------------------------------- Extracting ------------------------------*/
|
| 467 |
|
|
if (prefs.nthresh_type<2)
|
| 468 |
|
|
prefs.thresh_type[1] = prefs.thresh_type[0];
|
| 469 |
|
|
|
| 470 |
|
|
/*-------------------------------- Deblending ------------------------------*/
|
| 471 |
|
|
prefs.deb_maxarea = (prefs.ext_minarea<MAXDEBAREA ?
|
| 472 |
|
|
prefs.ext_minarea:MAXDEBAREA);
|
| 473 |
|
|
|
| 474 |
|
|
/*-------------------------------- Astrometry ------------------------------*/
|
| 475 |
|
|
prefs.world_flag = FLAG(obj2.mxw) || FLAG(obj2.mamaposx)
|
| 476 |
|
|
|| FLAG(obj2.peakxw) || FLAG(obj2.winpos_xw)
|
| 477 |
|
|
|| FLAG(obj2.mx2w) || FLAG(obj2.win_mx2w)
|
| 478 |
173 |
bertin |
|| FLAG(obj2.xw_prof) || FLAG(obj2.poserrmx2w_prof)
|
| 479 |
2 |
bertin |
|| FLAG(obj2.poserr_mx2w) || FLAG(obj2.winposerr_mx2w)
|
| 480 |
206 |
bertin |
|| FLAG(obj2.area_flagw) || FLAG(obj2.prof_flagw);
|
| 481 |
|
|
|
| 482 |
16 |
bertin |
/* Default astrometric settings */
|
| 483 |
|
|
strcpy(prefs.coosys, "ICRS");
|
| 484 |
|
|
prefs.epoch = 2000.0;
|
| 485 |
2 |
bertin |
|
| 486 |
|
|
/*-------------------------------- Photometry ------------------------------*/
|
| 487 |
|
|
|
| 488 |
|
|
/* Find the largest APERture-photometry vector */
|
| 489 |
|
|
if (FLAG(obj2.flux_aper))
|
| 490 |
|
|
{
|
| 491 |
|
|
naper = prefs.flux_apersize;
|
| 492 |
|
|
if (prefs.fluxerr_apersize>naper)
|
| 493 |
|
|
naper = prefs.fluxerr_apersize;
|
| 494 |
|
|
if (prefs.mag_apersize>naper)
|
| 495 |
|
|
naper = prefs.mag_apersize;
|
| 496 |
|
|
if (prefs.magerr_apersize>naper)
|
| 497 |
|
|
naper = prefs.magerr_apersize;
|
| 498 |
|
|
if (naper>prefs.naper)
|
| 499 |
|
|
{
|
| 500 |
|
|
warning("Not enough apertures provided in config.:\n",
|
| 501 |
|
|
" some APER photometric values will remain blank ");
|
| 502 |
|
|
naper = prefs.naper;
|
| 503 |
|
|
}
|
| 504 |
|
|
else
|
| 505 |
|
|
prefs.naper = naper;
|
| 506 |
|
|
}
|
| 507 |
|
|
else
|
| 508 |
|
|
naper = 0; /* To avoid gcc -Wall warnings */
|
| 509 |
|
|
|
| 510 |
|
|
/* Find the largest "minimum margin" necessary for apertures */
|
| 511 |
|
|
prefs.cleanmargin = 0;
|
| 512 |
|
|
if (FLAG(obj2.vignet)
|
| 513 |
|
|
&& (margin=(prefs.vignetsize[1]+1)/2) > prefs.cleanmargin)
|
| 514 |
|
|
prefs.cleanmargin = margin;
|
| 515 |
|
|
if (FLAG(obj2.vigshift)
|
| 516 |
|
|
&& (margin=(prefs.vigshiftsize[1]+1)/2+3)>prefs.cleanmargin)
|
| 517 |
|
|
prefs.cleanmargin = margin;
|
| 518 |
|
|
if (FLAG(obj2.flux_aper))
|
| 519 |
|
|
for (i=0; i<naper; i++)
|
| 520 |
|
|
if ((margin=(int)((prefs.apert[i]+1)/2)+1) > prefs.cleanmargin)
|
| 521 |
|
|
prefs.cleanmargin = margin;
|
| 522 |
|
|
|
| 523 |
|
|
/* Growth-curve flag */
|
| 524 |
|
|
if (FLAG(obj2.flux_growth)
|
| 525 |
|
|
|| FLAG(obj2.mag_growth)
|
| 526 |
|
|
|| FLAG(obj2.flux_radius)
|
| 527 |
|
|
|| FLAG(obj2.hl_radius)
|
| 528 |
|
|
|| FLAG(obj2.flux_growthstep)
|
| 529 |
|
|
|| FLAG(obj2.mag_growthstep))
|
| 530 |
|
|
prefs.growth_flag = 1;
|
| 531 |
|
|
|
| 532 |
|
|
if (FLAG(obj2.flux_radius) && prefs.flux_radiussize)
|
| 533 |
|
|
if (prefs.nflux_frac>prefs.flux_radiussize)
|
| 534 |
|
|
prefs.nflux_frac = prefs.flux_radiussize;
|
| 535 |
|
|
|
| 536 |
|
|
/*------------------------------- MASKing ----------------------------------*/
|
| 537 |
|
|
prefs.blank_flag = (prefs.mask_type!=MASK_NONE);
|
| 538 |
|
|
|
| 539 |
|
|
/*--------------------------- SOM-fitting ----------------------------------*/
|
| 540 |
|
|
prefs.somfit_flag = FLAG(obj2.flux_somfit);
|
| 541 |
|
|
|
| 542 |
|
|
/*------------------------------ Background --------------------------------*/
|
| 543 |
|
|
if (prefs.nbacksize<2)
|
| 544 |
|
|
prefs.backsize[1] = prefs.backsize[0];
|
| 545 |
|
|
if (prefs.nbackfsize<2)
|
| 546 |
|
|
prefs.backfsize[1] = prefs.backfsize[0];
|
| 547 |
|
|
if (prefs.nback_type<2)
|
| 548 |
|
|
prefs.back_type[1] = prefs.back_type[0];
|
| 549 |
|
|
|
| 550 |
|
|
/*------------------------------ FLAG-images -------------------------------*/
|
| 551 |
|
|
prefs.nimaisoflag = (prefs.imaflag_size > prefs.imanflag_size) ?
|
| 552 |
|
|
prefs.imaflag_size : prefs.imanflag_size;
|
| 553 |
|
|
prefs.nimaflag = (prefs.nimaisoflag < prefs.nfimage_name) ?
|
| 554 |
|
|
prefs.nimaisoflag : prefs.nfimage_name;
|
| 555 |
|
|
|
| 556 |
|
|
/*----------------------------- CHECK-images -------------------------------*/
|
| 557 |
|
|
prefs.check_flag = 0;
|
| 558 |
|
|
for (i=0; i<prefs.ncheck_type; i++)
|
| 559 |
|
|
if (prefs.check_type[i] != CHECK_NONE) /* at least 1 is not NONE */
|
| 560 |
|
|
prefs.check_flag = 1;
|
| 561 |
|
|
|
| 562 |
|
|
if (prefs.check_flag && prefs.ncheck_name!=prefs.ncheck_type)
|
| 563 |
|
|
error(EXIT_FAILURE, "*Error*: CHECKIMAGE_NAME(s) and CHECKIMAGE_TYPE(s)",
|
| 564 |
|
|
" are not in equal number");
|
| 565 |
|
|
|
| 566 |
|
|
/*---------------------------- PSF-fitting ---------------------------------*/
|
| 567 |
5 |
bertin |
if (FLAG(obj2.flux_psf) )
|
| 568 |
|
|
{
|
| 569 |
2 |
bertin |
prefs.psf_flag = 1;
|
| 570 |
5 |
bertin |
prefs.dpsf_flag = (prefs.npsf_name>1); /*?*/
|
| 571 |
|
|
}
|
| 572 |
2 |
bertin |
if (prefs.check_flag)
|
| 573 |
|
|
for (i=0; i<prefs.ncheck_type; i++)
|
| 574 |
|
|
if (prefs.check_type[i] == CHECK_SUBPSFPROTOS
|
| 575 |
|
|
|| prefs.check_type[i] == CHECK_PSFPROTOS)
|
| 576 |
|
|
prefs.psf_flag = 1;
|
| 577 |
|
|
|
| 578 |
|
|
/*---------------------------- PC-fitting ----------------------------------*/
|
| 579 |
|
|
/* PC-fitting is possible only if a PSF file is loaded */
|
| 580 |
|
|
if (prefs.psf_flag)
|
| 581 |
|
|
{
|
| 582 |
|
|
prefs.pc_flag = FLAG(obj2.mx2_pc);
|
| 583 |
|
|
if (prefs.check_flag)
|
| 584 |
|
|
for (i=0; i<prefs.ncheck_type; i++)
|
| 585 |
|
|
if (prefs.check_type[i] == CHECK_SUBPCPROTOS
|
| 586 |
|
|
|| prefs.check_type[i] == CHECK_PCPROTOS
|
| 587 |
|
|
|| prefs.check_type[i] == CHECK_PCOPROTOS)
|
| 588 |
|
|
prefs.pc_flag = 1;
|
| 589 |
|
|
}
|
| 590 |
|
|
|
| 591 |
221 |
bertin |
/*----------------------------- Model-fitting -------------------------------*/
|
| 592 |
173 |
bertin |
if (prefs.check_flag)
|
| 593 |
|
|
for (i=0; i<prefs.ncheck_type; i++)
|
| 594 |
221 |
bertin |
if (prefs.check_type[i] == CHECK_PROFILES
|
| 595 |
|
|
|| prefs.check_type[i] == CHECK_SUBPROFILES
|
| 596 |
|
|
|| prefs.check_type[i] == CHECK_SPHEROIDS
|
| 597 |
|
|
|| prefs.check_type[i] == CHECK_SUBSPHEROIDS
|
| 598 |
|
|
|| prefs.check_type[i] == CHECK_DISKS
|
| 599 |
|
|
|| prefs.check_type[i] == CHECK_SUBDISKS)
|
| 600 |
173 |
bertin |
prefs.prof_flag = 1;
|
| 601 |
|
|
|
| 602 |
221 |
bertin |
/*--------------------------- Adaptive class-star ---------------------------*/
|
| 603 |
230 |
bertin |
if (prefs.seeing_fwhm == 0 && FLAG(obj2.sprob))
|
| 604 |
221 |
bertin |
prefs.psf_flag = 1;
|
| 605 |
|
|
|
| 606 |
173 |
bertin |
/*-------------------------- Pattern-fitting -------------------------------*/
|
| 607 |
|
|
/* Profile-fitting is possible only if a PSF file is loaded */
|
| 608 |
|
|
if (prefs.check_flag)
|
| 609 |
|
|
for (i=0; i<prefs.ncheck_type; i++)
|
| 610 |
|
|
if (prefs.check_type[i] == CHECK_PATTERNS)
|
| 611 |
|
|
prefs.pattern_flag = 1;
|
| 612 |
|
|
|
| 613 |
2 |
bertin |
/*----------------------------- WEIGHT-images ------------------------------*/
|
| 614 |
|
|
if (prefs.nweight_type<2)
|
| 615 |
|
|
prefs.weight_type[1] = prefs.weight_type[0];
|
| 616 |
|
|
|
| 617 |
|
|
prefs.dweight_flag = (prefs.weight_type[0]!= WEIGHT_NONE);
|
| 618 |
|
|
prefs.weight_flag = (prefs.weight_type[1]!= WEIGHT_NONE);
|
| 619 |
|
|
|
| 620 |
|
|
if (prefs.dweight_flag || prefs.weight_flag)
|
| 621 |
|
|
{
|
| 622 |
|
|
/*-- Handle the default weight-threshold values */
|
| 623 |
|
|
if (prefs.nweight_thresh<2)
|
| 624 |
|
|
for (i=2; --i >= prefs.nweight_thresh;)
|
| 625 |
|
|
prefs.weight_thresh[i] = (prefs.weight_type[i]==WEIGHT_FROMWEIGHTMAP)?
|
| 626 |
|
|
0.0 : BIG;
|
| 627 |
|
|
/*-- Check WEIGHT_IMAGE parameter(s) */
|
| 628 |
|
|
if ((!prefs.nwimage_name
|
| 629 |
|
|
&& ((prefs.weight_type[0]!=WEIGHT_FROMBACK
|
| 630 |
|
|
&& prefs.weight_type[0]!=WEIGHT_NONE)
|
| 631 |
|
|
|| (prefs.weight_type[1]!=WEIGHT_FROMBACK
|
| 632 |
|
|
&& prefs.weight_type[1]!=WEIGHT_NONE)))
|
| 633 |
|
|
|| (prefs.nwimage_name<2
|
| 634 |
|
|
&& prefs.weight_type[0]!=WEIGHT_FROMBACK
|
| 635 |
|
|
&& prefs.weight_type[0]!=WEIGHT_NONE
|
| 636 |
|
|
&& prefs.weight_type[1]!=WEIGHT_FROMBACK
|
| 637 |
|
|
&& prefs.weight_type[1]!=WEIGHT_NONE
|
| 638 |
|
|
&& prefs.weight_type[0]!=prefs.weight_type[1]))
|
| 639 |
|
|
error(EXIT_FAILURE, "*Error*: WEIGHT_IMAGE missing","");
|
| 640 |
|
|
|
| 641 |
|
|
if (prefs.nwimage_name && prefs.nwimage_name<2)
|
| 642 |
|
|
prefs.wimage_name[1] = prefs.wimage_name[0];
|
| 643 |
|
|
if (prefs.nwimage_name==2 && prefs.nweight_type==1)
|
| 644 |
|
|
prefs.nweight_type = 2;
|
| 645 |
|
|
|
| 646 |
|
|
/*-- If detection-only interpolation is needed with 1 Weight image... */
|
| 647 |
|
|
/*-- ...pretend we're using 2, with only one being interpolated */
|
| 648 |
|
|
if (prefs.nweight_type==1
|
| 649 |
|
|
&& prefs.nwimage_name && prefs.wimage_name[1]==prefs.wimage_name[0]
|
| 650 |
|
|
&& prefs.interp_type[0]==INTERP_VARONLY )
|
| 651 |
|
|
{
|
| 652 |
|
|
prefs.nweight_type = 2;
|
| 653 |
|
|
prefs.weight_type[1] = prefs.weight_type[0];
|
| 654 |
|
|
prefs.weight_type[0] = WEIGHT_FROMINTERP;
|
| 655 |
|
|
prefs.wimage_name[1] = prefs.wimage_name[0];
|
| 656 |
|
|
prefs.interp_type[1] = INTERP_NONE;
|
| 657 |
|
|
prefs.dweight_flag = 1;
|
| 658 |
|
|
if (prefs.nweight_thresh<2)
|
| 659 |
|
|
{
|
| 660 |
|
|
prefs.nweight_thresh = 2;
|
| 661 |
|
|
prefs.weight_thresh[1] = prefs.weight_thresh[0];
|
| 662 |
|
|
}
|
| 663 |
|
|
}
|
| 664 |
|
|
}
|
| 665 |
|
|
|
| 666 |
|
|
/*------------------------------ Catalogue ---------------------------------*/
|
| 667 |
|
|
|
| 668 |
|
|
if (!strcmp(prefs.cat_name, "STDOUT"))
|
| 669 |
|
|
prefs.pipe_flag = 1;
|
| 670 |
|
|
|
| 671 |
|
|
if ((str=strrchr(prefs.filter_name, '/')))
|
| 672 |
|
|
strcpy(thecat.filter_name, str+1);
|
| 673 |
|
|
else
|
| 674 |
|
|
strcpy(thecat.filter_name, prefs.filter_name);
|
| 675 |
|
|
|
| 676 |
|
|
if ((str=strrchr(prefs.prefs_name, '/')))
|
| 677 |
|
|
strcpy(thecat.prefs_name, str+1);
|
| 678 |
|
|
else
|
| 679 |
|
|
strcpy(thecat.prefs_name, prefs.prefs_name);
|
| 680 |
|
|
|
| 681 |
|
|
if ((str=strrchr(prefs.nnw_name, '/')))
|
| 682 |
|
|
strcpy(thecat.nnw_name, str+1);
|
| 683 |
|
|
else
|
| 684 |
|
|
strcpy(thecat.nnw_name, prefs.nnw_name);
|
| 685 |
|
|
|
| 686 |
|
|
if ((str=strrchr(prefs.image_name[prefs.nimage_name-1], '/')))
|
| 687 |
|
|
strcpy(thecat.image_name, str+1);
|
| 688 |
|
|
else
|
| 689 |
|
|
strcpy(thecat.image_name, prefs.image_name[prefs.nimage_name-1]);
|
| 690 |
|
|
|
| 691 |
|
|
sprintf(thecat.soft_name, "%s %s", BANNER, VERSION);
|
| 692 |
|
|
|
| 693 |
|
|
return;
|
| 694 |
|
|
}
|
| 695 |
|
|
|
| 696 |
|
|
|
| 697 |
173 |
bertin |
/********************************* endprefs *********************************/
|
| 698 |
|
|
/*
|
| 699 |
|
|
Mostly free memory allocate for static arrays.
|
| 700 |
|
|
*/
|
| 701 |
|
|
void endprefs(void)
|
| 702 |
|
|
|
| 703 |
|
|
{
|
| 704 |
|
|
int i;
|
| 705 |
|
|
|
| 706 |
|
|
for (i=0; i<prefs.nfimage_name; i++)
|
| 707 |
|
|
free(prefs.fimage_name[i]);
|
| 708 |
|
|
for (i=0; i<prefs.nwimage_name; i++)
|
| 709 |
|
|
free(prefs.wimage_name[i]);
|
| 710 |
|
|
for (i=0; i<prefs.npsf_name; i++)
|
| 711 |
|
|
free(prefs.psf_name[i]);
|
| 712 |
|
|
for (i=0; i<prefs.ncheck_name; i++)
|
| 713 |
|
|
free(prefs.check_name[i]);
|
| 714 |
|
|
|
| 715 |
|
|
return;
|
| 716 |
|
|
}
|