Пример #1
0
static intBool CheckRangeConstraint(
  void *theEnv,
  EXEC_STATUS,
  int type,
  void *vPtr,
  CONSTRAINT_RECORD *constraints)
  {
   struct expr *minList, *maxList;

   /*===================================*/
   /* If the constraint record is NULL, */
   /* there are no range restrictions.  */
   /*===================================*/

   if (constraints == NULL) return(TRUE);

   /*============================================*/
   /* If the value being checked isn't a number, */
   /* then the range restrictions don't apply.   */
   /*============================================*/

   if ((type != INTEGER) && (type != FLOAT)) return(TRUE);

   /*=====================================================*/
   /* Check each of the range restrictions to see if the  */
   /* number falls within at least one of the allowed     */
   /* ranges. If it falls within one of the ranges, then  */
   /* return TRUE since the constraint is satisifed.      */
   /*=====================================================*/

   minList = constraints->minValue;
   maxList = constraints->maxValue;

   while (minList != NULL)
     {
      if (CompareNumbers(theEnv,execStatus,type,vPtr,minList->type,minList->value) == LESS_THAN)
        {
         minList = minList->nextArg;
         maxList = maxList->nextArg;
        }
      else if (CompareNumbers(theEnv,execStatus,type,vPtr,maxList->type,maxList->value) == GREATER_THAN)
        {
         minList = minList->nextArg;
         maxList = maxList->nextArg;
        }
      else
        { return(TRUE); }
     }

   /*===========================================*/
   /* Return FALSE since the number didn't fall */
   /* within one of the allowed numeric ranges. */
   /*===========================================*/

   return(FALSE);
  }
Пример #2
0
// smart name comparison (case insensitive); it treats all consecutive digits as a single character
// with value equal to the number
//
extern bool NameIsLess(const TCHAR* p, const TCHAR* q)
{
	for ( ; *p && *q; ++p, ++q)
	{
		if (*p == *q)
			continue;

		unsigned int c1= _totlower(*p);
		unsigned int c2= _totlower(*q);

		if (c1 == c2)
			continue;

		if (c1 >= '0' && c1 <= '9' && c2 >= '0' && c2 <= '9')
		{
			int cmp= CompareNumbers(p, q);
			if (cmp < 0)
				return true;
			else if (cmp > 0)
				return false;
			else
				continue;
		}

		return c1 < c2;
	}

	if (*p == 0)
	{
		if (*q == 0)
			return false;
		else
			return true;
	}
	else
	{
		if (*q == 0)
			return false;
		else
		{ ASSERT(false); }
//			return true;
	}

	ASSERT(false);
	return false;
}
Пример #3
0
static intBool ParseRangeCardinalityAttribute(
  void *theEnv,
  char *readSource,
  CONSTRAINT_RECORD *constraints,
  CONSTRAINT_PARSE_RECORD *parsedConstraints,
  char *constraintName,
  int multipleValuesAllowed)
  {
   struct token inputToken;
   int range;
   char *tempPtr = NULL;

   /*=================================*/
   /* Determine if we're parsing the  */
   /* range or cardinality attribute. */
   /*=================================*/

   if (strcmp(constraintName,"range") == 0)
     {
      parsedConstraints->range = TRUE;
      range = TRUE;
     }
   else
     {
      parsedConstraints->cardinality = TRUE;
      range = FALSE;
     }

   /*===================================================================*/
   /* The cardinality attribute can only be used with multifield slots. */
   /*===================================================================*/

   if ((range == FALSE) &&
       (multipleValuesAllowed == FALSE))
     {
      PrintErrorID(theEnv,"CSTRNPSR",5,TRUE);
      EnvPrintRouter(theEnv,WERROR,"The cardinality attribute ");
      EnvPrintRouter(theEnv,WERROR,"can only be used with multifield slots.\n");
      return(FALSE);
     }

   /*====================================================*/
   /* The range attribute is not allowed with the        */
   /* allowed-values/numbers/integers/floats attributes. */
   /*====================================================*/

   if ((range == TRUE) &&
       (parsedConstraints->allowedValues ||
        parsedConstraints->allowedNumbers ||
        parsedConstraints->allowedIntegers ||
        parsedConstraints->allowedFloats))
     {
      if (parsedConstraints->allowedValues) tempPtr = "allowed-values";
      else if (parsedConstraints->allowedIntegers) tempPtr = "allowed-integers";
      else if (parsedConstraints->allowedFloats) tempPtr = "allowed-floats";
      else if (parsedConstraints->allowedNumbers) tempPtr = "allowed-numbers";
      NoConjunctiveUseError(theEnv,"range",tempPtr);
      return(FALSE);
     }

   /*==========================*/
   /* Parse the minimum value. */
   /*==========================*/

   SavePPBuffer(theEnv," ");
   GetToken(theEnv,readSource,&inputToken);
   if ((inputToken.type == INTEGER) || ((inputToken.type == FLOAT) && range))
     {
      if (range)
        {
         ReturnExpression(theEnv,constraints->minValue);
         constraints->minValue = GenConstant(theEnv,inputToken.type,inputToken.value);
        }
      else
        {
         ReturnExpression(theEnv,constraints->minFields);
         constraints->minFields = GenConstant(theEnv,inputToken.type,inputToken.value);
        }
     }
   else if ((inputToken.type == SF_VARIABLE) && (strcmp(inputToken.printForm,"?VARIABLE") == 0))
     { /* Do nothing. */ }
   else
     {
      char tempBuffer[120];
      gensprintf(tempBuffer,"%s attribute",constraintName);
      SyntaxErrorMessage(theEnv,tempBuffer);
      return(FALSE);
     }

   /*==========================*/
   /* Parse the maximum value. */
   /*==========================*/

   SavePPBuffer(theEnv," ");
   GetToken(theEnv,readSource,&inputToken);
   if ((inputToken.type == INTEGER) || ((inputToken.type == FLOAT) && range))
     {
      if (range)
        {
         ReturnExpression(theEnv,constraints->maxValue);
         constraints->maxValue = GenConstant(theEnv,inputToken.type,inputToken.value);
        }
      else
        {
         ReturnExpression(theEnv,constraints->maxFields);
         constraints->maxFields = GenConstant(theEnv,inputToken.type,inputToken.value);
        }
     }
   else if ((inputToken.type == SF_VARIABLE) && (strcmp(inputToken.printForm,"?VARIABLE") == 0))
     { /* Do nothing. */ }
   else
     {
      char tempBuffer[120];
      gensprintf(tempBuffer,"%s attribute",constraintName);
      SyntaxErrorMessage(theEnv,tempBuffer);
      return(FALSE);
     }

   /*================================*/
   /* Parse the closing parenthesis. */
   /*================================*/

   GetToken(theEnv,readSource,&inputToken);
   if (inputToken.type != RPAREN)
     {
      SyntaxErrorMessage(theEnv,"range attribute");
      return(FALSE);
     }

   /*====================================================*/
   /* Minimum value must be less than the maximum value. */
   /*====================================================*/

   if (range)
     {
      if (CompareNumbers(theEnv,constraints->minValue->type,
                         constraints->minValue->value,
                         constraints->maxValue->type,
                         constraints->maxValue->value) == GREATER_THAN)
        {
         PrintErrorID(theEnv,"CSTRNPSR",2,TRUE);
         EnvPrintRouter(theEnv,WERROR,"Minimum range value must be less than\n");
         EnvPrintRouter(theEnv,WERROR,"or equal to the maximum range value\n");
         return(FALSE);
        }
     }
   else
     {
      if (CompareNumbers(theEnv,constraints->minFields->type,
                         constraints->minFields->value,
                         constraints->maxFields->type,
                         constraints->maxFields->value) == GREATER_THAN)
        {
         PrintErrorID(theEnv,"CSTRNPSR",2,TRUE);
         EnvPrintRouter(theEnv,WERROR,"Minimum cardinality value must be less than\n");
         EnvPrintRouter(theEnv,WERROR,"or equal to the maximum cardinality value\n");
         return(FALSE);
        }
     }

   /*====================================*/
   /* Return TRUE to indicate that the   */
   /* attribute was successfully parsed. */
   /*====================================*/

   return(TRUE);
  }
Пример #4
0
int main (int argc, char **argv) {

    char *inlist;		/* input file name */
    char *outlist;		/* output blev file name */
    /*int switch_on = 0;*/	/* was any switch specified? */
    int printtime = NO;	/* print time after each step? */
    int verbose = NO;	/* print additional info? */
    int quiet = NO;	/* print additional info? */
    int too_many = 0;	/* too many command-line arguments? */
    int i, j;		/* loop indexes */
    int k;

    IRAFPointer i_imt, o_imt;	/* imt list pointers */
    char *input;		/* name of input science file */
    char *output;		/* name of output file */
    int n_in, n_out;	/* number of files in each list */
    int n;

    /* Input and output suffixes. */
    char isuffix[] = "_raw";
    char osuffix[] = "_blv_tmp";

    /* A structure to pass the calibration switches to ACSCCD */
    CalSwitch ccd_sw;

    /* reference file keywords and names */
    RefFileInfo refnames;

    void InitRefFile (RefFileInfo *);
    void FreeRefFile (RefFileInfo *);
    void initSwitch (CalSwitch *);

    int ACSccd (char *, char *, CalSwitch *, RefFileInfo *, int, int);
    int DefSwitch (char *);
    int MkName (char *, char *, char *, char *, char *, int);
    void WhichError (int);
    int CompareNumbers (int, int, char *);

    /* For image header access */
    Hdr phdr;
    int LoadHdr (char *, Hdr *);
    int GetSwitch (Hdr *, char *, int *);

    c_irafinit (argc, argv);

    /* Allocate space for file names. */
    inlist = calloc (ACS_LINE+1, sizeof (char));
    outlist = calloc (ACS_LINE+1, sizeof (char));
    input = calloc (ACS_LINE+1, sizeof (char));
    output = calloc (ACS_LINE+1, sizeof (char));

    if (inlist == NULL || outlist == NULL ||
        input == NULL || output == NULL) {
        printf ("Can't even begin; out of memory.\n");
        exit (ERROR_RETURN);
    }
    inlist[0] = '\0';
    outlist[0] = '\0';
    input[0] = '\0';
    output[0] = '\0';

    /* Initialize the lists of reference file keywords and names. */
    InitRefFile (&refnames);

    /* Initial values. */
    initSwitch (&ccd_sw);

    for (i = 1;  i < argc;  i++) {

        /**********
        if (strcmp (argv[i], "-dqi") == 0) {
            ccd_sw.dqicorr = PERFORM;
            switch_on = 1;
        } else if (strcmp (argv[i], "-atod") == 0) {
            ccd_sw.atodcorr = PERFORM;
            switch_on = 1;
        } else if (strcmp (argv[i], "-blev") == 0) {
            ccd_sw.blevcorr = PERFORM;
            switch_on = 1;
        } else if (strcmp (argv[i], "-bias") == 0) {
            ccd_sw.biascorr = PERFORM;
            switch_on = 1;
        } else if (argv[i][0] == '-') {
        **********/
        if (argv[i][0] == '-') {
            for (j = 1;  argv[i][j] != '\0';  j++) {
                if (argv[i][j] == 't') {
                    printtime = YES;
                } else if (argv[i][j] == 'v') {
                    verbose = YES;
                } else if (argv[i][j] == 'q') {
                    quiet = YES;
                } else {
                    printf (MsgText, "Unrecognized option %s\n", argv[i]);
                    FreeNames (inlist, outlist, input, output);
                    exit (1);
                }
            }
        } else if (inlist[0] == '\0') {
            strcpy (inlist, argv[i]);
        } else if (outlist[0] == '\0') {
            strcpy (outlist, argv[i]);
        } else {
            too_many = 1;
        }
    }
    if (inlist[0] == '\0' || too_many) {
        printf ("syntax:  acsccd [-t] [-v] [-q] input output\n");
        /*
        printf ("  command-line switches:\n");
        printf ("       -dqi -atod -blev -bias\n");
        */
        FreeNames (inlist, outlist, input, output);
        exit (ERROR_RETURN);
    }
    /* Initialize the structure for managing trailer file comments */
    InitTrlBuf ();

    /* Copy command-line value for QUIET to structure */
    SetTrlQuietMode(quiet);

    /* Was no calibration switch specified on command line?
       default values (mostly PERFORM) except ATODCORR
    if (!switch_on) {*/
    ccd_sw.dqicorr  = DefSwitch ("dqicorr");
    ccd_sw.atodcorr = DefSwitch ("atodcorr");
    ccd_sw.blevcorr = DefSwitch ("blevcorr");
    ccd_sw.biascorr = DefSwitch ("biascorr");
    /*}*/

    /* Expand the templates. */
    i_imt = c_imtopen (inlist);
    o_imt = c_imtopen (outlist);
    n_in = c_imtlen (i_imt);
    n_out = c_imtlen (o_imt);

    /* The number of input and output files must be the same. */
    if (CompareNumbers (n_in, n_out, "output"))
        status = 1;
    if (status) {
        FreeNames (inlist, outlist, input, output);
        CloseTrlBuf();
        exit (ERROR_RETURN);
    }

    /* Loop over the list of input files. */
    for (n = 0;  n < n_in;  n++) {

        k = c_imtgetim (i_imt, input, ACS_LINE);

        if (n_out > 0)
            k = c_imtgetim (o_imt, output, ACS_LINE);
        else
            output[0] = '\0';

        /* Open input image in order to read its primary header. */
        if (LoadHdr (input, &phdr)) {
            WhichError (status);
            sprintf (MsgText, "Skipping %s", input);
            trlmessage (MsgText);
            continue;
        }

        /* Determine osuffix. */
        strcpy(osuffix, "_blv_tmp");

        if (MkName (input, isuffix, osuffix, "", output, ACS_LINE)) {
            WhichError (status);
            sprintf (MsgText, "Skipping %s", input);
            trlmessage (MsgText);
            continue;
        }

        /* Calibrate the current input file. */
        if (ACSccd (input, output, &ccd_sw, &refnames, printtime, verbose)) {
            sprintf (MsgText, "Error processing %s.", input);
            trlerror (MsgText);
            WhichError (status);
        }
    }

    /* Close lists of file names, and free name buffers. */
    c_imtclose (i_imt);
    c_imtclose (o_imt);
    CloseTrlBuf();
    FreeRefFile (&refnames);
    FreeNames (inlist, outlist, input, output);

    if (status)
        exit (ERROR_RETURN);
    else
        exit (0);
}
Пример #5
0
int main (int argc, char **argv) {

	char *inlist;		/* input file name */
	char *outlist;		/* output blev file name */
	int switch_on = 0;	/* was any switch specified? */
	int printtime = NO;	/* print time after each step? */
	int verbose = NO;	/* print additional info? */
	int quiet = NO;		/* print additional info? */
	int too_many = 0;	/* too many command-line arguments? */
	int i, j;		/* loop indexes */

	IRAFPointer i_imt, o_imt;	/* imt list pointers */
	char *input;		/* name of input science file */
	char *output;		/* name of output file */
	int n_in, n_out;	/* number of files in each list */
	int n;

	/* Input and output suffixes. */
	char *isuffix[] = {"_raw", "_rac_tmp"};
	char *osuffix[] = {"_blv_tmp", "_blc_tmp"};

	int nsuffix = 2;

	/* A structure to pass the calibration switches to WF3CCD */
	CCD_Switch ccd_sw;

	/* reference file keywords and names */
	RefFileInfo refnames;
		
	void InitRefFile (RefFileInfo *);
	void FreeRefFile (RefFileInfo *);
	void initCCDSwitches (CCD_Switch *);

	int WF3ccd (char *, char *, CCD_Switch *, RefFileInfo *, int, int);
    int DefSwitch (char *);
	int MkName (char *, char *, char *, char *, char *, int);
	void WhichError (int);
	int CompareNumbers (int, int, char *);

/*===========================================================================*/

	/* Initialize IRAF interface environment */
	c_irafinit (argc, argv);

	/* Post HSTIO error handler */
	push_hstioerr (errchk);

	/* Allocate space for file names. */
	inlist  = calloc (SZ_LINE+1, sizeof (char));
	outlist = calloc (SZ_LINE+1, sizeof (char));
	input   = calloc (SZ_LINE+1, sizeof (char));
	output  = calloc (SZ_LINE+1, sizeof (char));

	if (inlist == NULL || outlist == NULL ||
	    input == NULL || output == NULL) {
	    printf ("Can't even begin; out of memory.\n");
	    exit (ERROR_RETURN);
	}
	inlist[0]  = '\0';
	outlist[0] = '\0';
	input[0]   = '\0';
	output[0]  = '\0';
	
	/* Initialize the lists of reference file keywords and names. */
	InitRefFile (&refnames);

	/* Initial values. */
	initCCDSwitches (&ccd_sw);

	/* Parse the command-line arguments */
	for (i = 1;  i < argc;  i++) {
	    if (!(strcmp(argv[i],"--version"))) {
		printf("%s\n",WF3_CAL_VER_NUM);
		exit(0);
	    }

	    if (strcmp (argv[i], "-dqi") == 0) {	/* turn on */
			ccd_sw.dqicorr = PERFORM;
			switch_on = 1;
	    } else if (strcmp (argv[i], "-atod") == 0) {
			ccd_sw.atodcorr = PERFORM;
			switch_on = 1;
	    } else if (strcmp (argv[i], "-blev") == 0) {
			ccd_sw.blevcorr = PERFORM;
			switch_on = 1;
	    } else if (strcmp (argv[i], "-bias") == 0) {
			ccd_sw.biascorr = PERFORM;
			switch_on = 1;
	    } else if (strcmp (argv[i], "-flash") == 0) {
			ccd_sw.flashcorr = PERFORM;
			switch_on = 1;
	    } else if (argv[i][0] == '-') {
		for (j = 1;  argv[i][j] != '\0';  j++) {
		    if (argv[i][j] == 't') {
			printtime = YES;
		    } else if (argv[i][j] == 'v') {
			verbose = YES;
		    } else if (argv[i][j] == 'q') {
			quiet = YES;
            } else if (argv[i][j] == 'r'){
                printf ("Current version: %s\n", WF3_CAL_VER);
                exit(0);
		    } else {
			printf (MsgText, "Unrecognized option %s\n", argv[i]);
			FreeNames (inlist, outlist, input, output);
			exit (1);
		    }
		}
	    } else if (inlist[0] == '\0') {
			strcpy (inlist, argv[i]);
	    } else if (outlist[0] == '\0') {
			strcpy (outlist, argv[i]);
	    } else {
			too_many = 1;
	    }
	}

	if (inlist[0] == '\0' || too_many) {
	    printf ("syntax:  wf3ccd [-t] [-v] [-q] [-r] input output\n");
	    printf ("  command-line switches:\n");
	    printf ("       -dqi  -atod -blev -bias\n");
	    FreeNames (inlist, outlist, input, output);
	    exit (ERROR_RETURN);
	}

	/* Initialize the structure for managing trailer file comments */
	InitTrlBuf ();
	
	/* Copy command-line value for QUIET to structure */
	SetTrlQuietMode(quiet);

	/* Was no calibration switch specified on command line? */
	if (!switch_on) {	/* default values (mostly PERFORM) */
	    ccd_sw.dqicorr  = DefSwitch ("dqicorr");
	    ccd_sw.atodcorr = DefSwitch ("atodcorr");
	    ccd_sw.blevcorr = DefSwitch ("blevcorr");
	    ccd_sw.biascorr = DefSwitch ("biascorr");
	    ccd_sw.flashcorr = DefSwitch ("flshcorr");
        ccd_sw.fluxcorr = DefSwitch ("fluxcorr");
        ccd_sw.pctecorr = DefSwitch ("pctecorr");
	}

	/* Expand the templates. */
	i_imt = c_imtopen (inlist);
	o_imt = c_imtopen (outlist);
	n_in  = c_imtlen (i_imt);
	n_out = c_imtlen (o_imt);

	/* The number of input and output files must be the same. */
	if (CompareNumbers (n_in, n_out, "output"))
	    status = 1;
	if (status) {
	    FreeNames (inlist, outlist, input, output);
	    CloseTrlBuf();
	    exit (ERROR_RETURN);
	}

	/* Loop over the list of input files. */
	for (n = 0;  n < n_in;  n++) {

	    i = c_imtgetim (i_imt, input, SZ_LINE);
		
	    if (n_out > 0) {
		    i = c_imtgetim (o_imt, output, SZ_LINE);
	    } else {
    		output[0] = '\0';
        }
        
	    if (MkOutName (input, isuffix, osuffix, nsuffix, output, SZ_LINE)) {
	        WhichError (status);
	        sprintf (MsgText, "Skipping %s", input);
	        trlmessage (MsgText);
	        continue;	    
        }

	    /* Calibrate the current input file. */
	    if (WF3ccd (input, output, &ccd_sw, &refnames, printtime, verbose)){
		    sprintf (MsgText, "Error processing %s.", input);
		    trlerror (MsgText);
		    WhichError (status);
	    }
	}

	/* Close lists of file names, and free name buffers. */
	c_imtclose (i_imt);
	c_imtclose (o_imt);
	CloseTrlBuf();
	FreeRefFile (&refnames);
	FreeNames (inlist, outlist, input, output);

	if (status)
	    exit (ERROR_RETURN);
	else
	    exit (0);
}
Пример #6
0
static void UnionRangeMinMaxValueWithList(
  void *theEnv,
  struct expr *addmin,
  struct expr *addmax,
  struct expr **theMinList,
  struct expr **theMaxList)
  {
   struct expr *tmpmin, *tmpmax, *lastmin, *lastmax;
   struct expr *themin, *themax, *nextmin, *nextmax;
   int cmaxmin, cmaxmax, cminmin, cminmax;

   /*=========================================================*/
   /* If no values are on the lists, then use the new values. */
   /*=========================================================*/

   if (*theMinList == NULL)
     {
      *theMinList = GenConstant(theEnv,addmin->type,addmin->value);
      *theMaxList = GenConstant(theEnv,addmax->type,addmax->value);
      return;
     }

   lastmin = NULL;
   lastmax = NULL;
   tmpmin = (*theMinList);
   tmpmax = (*theMaxList);

   while (tmpmin != NULL)
     {
      cmaxmax = CompareNumbers(theEnv,addmax->type,addmax->value,
                               tmpmax->type,tmpmax->value);

      cminmin = CompareNumbers(theEnv,addmin->type,addmin->value,
                               tmpmin->type,tmpmin->value);

      cmaxmin = CompareNumbers(theEnv,addmax->type,addmax->value,
                               tmpmin->type,tmpmin->value);

      cminmax = CompareNumbers(theEnv,addmin->type,addmin->value,
                               tmpmax->type,tmpmax->value);

      /*=================================*/
      /* Check to see if the range is    */
      /* contained within another range. */
      /*=================================*/

      if (((cmaxmax == LESS_THAN) || (cmaxmax == EQUAL)) &&
          ((cminmin == GREATER_THAN) || (cminmin == EQUAL)))
        { return; }

      /*================================*/
      /* Extend the greater than range. */
      /*================================*/

      if ((cmaxmax == GREATER_THAN) &&
          ((cminmax == LESS_THAN) || (cminmax == EQUAL)))
        {
         tmpmax->type = addmax->type;
         tmpmax->value = addmax->value;
        }

      /*=============================*/
      /* Extend the less than range. */
      /*=============================*/

      if ((cminmin == LESS_THAN) &&
          ((cmaxmin == GREATER_THAN) || (cmaxmin == EQUAL)))
        {
         tmpmin->type = addmin->type;
         tmpmin->value = addmin->value;
        }

      /*====================*/
      /* Handle insertions. */
      /*====================*/

      if (cmaxmin == LESS_THAN)
        {
         if (lastmax == NULL)
           {
            themin = GenConstant(theEnv,addmin->type,addmin->value);
            themax = GenConstant(theEnv,addmax->type,addmax->value);
            themin->nextArg = *theMinList;
            themax->nextArg = *theMaxList;
            *theMinList = themin;
            *theMaxList = themax;
            return;
           }

         if (CompareNumbers(theEnv,addmin->type,addmin->value,
                            lastmax->type,lastmax->value) == GREATER_THAN)
           {
            themin = GenConstant(theEnv,addmin->type,addmin->value);
            themax = GenConstant(theEnv,addmax->type,addmax->value);

            themin->nextArg = lastmin->nextArg;
            themax->nextArg = lastmax->nextArg;

            lastmin->nextArg = themin;
            lastmax->nextArg = themax;
            return;
           }
        }

      /*==========================*/
      /* Move on to the next one. */
      /*==========================*/

      tmpmin = tmpmin->nextArg;
      tmpmax = tmpmax->nextArg;
     }

   /*===========================*/
   /* Merge overlapping ranges. */
   /*===========================*/

   tmpmin = (*theMinList);
   tmpmax = (*theMaxList);

   while (tmpmin != NULL)
     {
      nextmin = tmpmin->nextArg;
      nextmax = tmpmax->nextArg;
      if (nextmin != NULL)
        {
         cmaxmin = CompareNumbers(theEnv,tmpmax->type,tmpmax->value,
                                  nextmin->type,nextmin->value);
         if ((cmaxmin == GREATER_THAN) || (cmaxmin == EQUAL))
           {
            tmpmax->type = nextmax->type;
            tmpmax->value = nextmax->value;
            tmpmax->nextArg = nextmax->nextArg;
            tmpmin->nextArg = nextmin->nextArg;

            rtn_struct(theEnv,expr,nextmin);
            rtn_struct(theEnv,expr,nextmax);
           }
         else
           {
            tmpmin = tmpmin->nextArg;
            tmpmax = tmpmax->nextArg;
           }
        }
      else
        {
         tmpmin = nextmin;
         tmpmax = nextmax;
        }
     }
  }
Пример #7
0
static void IntersectNumericExpressions(
  void *theEnv,
  CONSTRAINT_RECORD *constraint1,
  CONSTRAINT_RECORD *constraint2,
  CONSTRAINT_RECORD *newConstraint,
  int range)
  {
   struct expr *tmpmin1, *tmpmax1, *tmpmin2, *tmpmax2, *theMin, *theMax;
   struct expr *theMinList, *theMaxList, *lastMin = NULL, *lastMax = NULL;
   int cmaxmax, cminmin, cmaxmin, cminmax;

   /*==========================================*/
   /* Initialize the new range/min/max values  */
   /* for the intersection of the constraints. */
   /*==========================================*/

   theMinList = NULL;
   theMaxList = NULL;

   /*=================================*/
   /* Determine the min/max values of */
   /* the first constraint record.    */
   /*=================================*/

   if (range)
     {
      tmpmin1 = constraint1->minValue;
      tmpmax1 = constraint1->maxValue;
     }
   else
     {
      tmpmin1 = constraint1->minFields;
      tmpmax1 = constraint1->maxFields;
     }

   /*===========================================*/
   /* Loop through each of range/min/max values */
   /* from the first constraint record.         */
   /*===========================================*/

   for (;
        tmpmin1 != NULL;
        tmpmin1 = tmpmin1->nextArg, tmpmax1 = tmpmax1->nextArg)
     {
      /*============================================*/
      /* Get the appropriate values from the second */
      /* constraint record for comparison.          */
      /*============================================*/

      if (range)
        {
         tmpmin2 = constraint2->minValue;
         tmpmax2 = constraint2->maxValue;
        }
      else
        {
         tmpmin2 = constraint2->minFields;
         tmpmax2 = constraint2->maxFields;
        }

      /*================================================*/
      /* Loop through each of range/min/max values from */
      /* the second constraint record comparing it to   */
      /* the values from the first constraint record.   */
      /*================================================*/

      for (;
           tmpmin2 != NULL;
           tmpmin2 = tmpmin2->nextArg, tmpmax2 = tmpmax2->nextArg)
        {
         /*==============================================*/
         /* Determine the relationship between the four  */
         /* combinations of min/max values (>, <, or =). */
         /*==============================================*/

         cmaxmax = CompareNumbers(theEnv,tmpmax1->type,tmpmax1->value,
                                  tmpmax2->type,tmpmax2->value);

         cminmin = CompareNumbers(theEnv,tmpmin1->type,tmpmin1->value,
                                  tmpmin2->type,tmpmin2->value);

         cmaxmin = CompareNumbers(theEnv,tmpmax1->type,tmpmax1->value,
                                  tmpmin2->type,tmpmin2->value);

         cminmax = CompareNumbers(theEnv,tmpmin1->type,tmpmin1->value,
                                  tmpmax2->type,tmpmax2->value);

         /*============================================*/
         /* If the range/min/max values don't overlap, */
         /* then proceed to the next pair of numbers   */
         /* to see if they overlap.                    */
         /*============================================*/

         if ((cmaxmin == LESS_THAN) || (cminmax == GREATER_THAN))
           { continue; }

         /*=======================================*/
         /* Compute the new minimum value for the */
         /* intersected range/min/max values.     */
         /*=======================================*/

         if (cminmin == GREATER_THAN)
           { theMin = GenConstant(theEnv,tmpmin1->type,tmpmin1->value); }
         else
           { theMin = GenConstant(theEnv,tmpmin2->type,tmpmin2->value); }

         /*=======================================*/
         /* Compute the new maximum value for the */
         /* intersected range/min/max values.     */
         /*=======================================*/

         if (cmaxmax == LESS_THAN)
           { theMax = GenConstant(theEnv,tmpmax1->type,tmpmax1->value); }
         else
           { theMax = GenConstant(theEnv,tmpmax2->type,tmpmax2->value); }

         /*==================================*/
         /* Add the new range/min/max values */
         /* to the intersection list.        */
         /*==================================*/

         if (lastMin == NULL)
           {
            theMinList = theMin;
            theMaxList = theMax;
           }
         else
           {
            lastMin->nextArg = theMin;
            lastMax->nextArg = theMax;
           }

         lastMin = theMin;
         lastMax = theMax;
        }
     }

   /*============================================================*/
   /* If the intersection produced a pair of valid range/min/max */
   /* values, then replace the previous values of the constraint */
   /* record to the new intersected values.                      */
   /*============================================================*/

   if (theMinList != NULL)
     {
      if (range)
        {
         ReturnExpression(theEnv,newConstraint->minValue);
         ReturnExpression(theEnv,newConstraint->maxValue);
         newConstraint->minValue = theMinList;
         newConstraint->maxValue = theMaxList;
        }
      else
        {
         ReturnExpression(theEnv,newConstraint->minFields);
         ReturnExpression(theEnv,newConstraint->maxFields);
         newConstraint->minFields = theMinList;
         newConstraint->maxFields = theMaxList;
        }
     }

   /*===============================================================*/
   /* Otherwise, the intersection produced no valid range/min/max   */
   /* values. For the range attribute, this means that no numbers   */
   /* can satisfy the constraint. For the min/max fields attribute, */
   /* it means that no value can satisfy the constraint.            */
   /*===============================================================*/

   else
     {
      if (range)
        {
         if (newConstraint->anyAllowed) SetAnyAllowedFlags(newConstraint,FALSE);
         newConstraint->integersAllowed = FALSE;
         newConstraint->floatsAllowed = FALSE;
        }
      else
        {
         SetAnyAllowedFlags(newConstraint,TRUE);
         newConstraint->singlefieldsAllowed = FALSE;
         newConstraint->multifieldsAllowed = FALSE;
         newConstraint->anyAllowed = FALSE;
        }
     }
  }
Пример #8
0
int main (int argc, char **argv) {

	int status;		/* zero is OK */
	char *inlist;		/* list of input file names */
	char *outlist;		/* list of output file names */
	int switch_on = 0;	/* was any switch specified? */
	int sgeocorr = OMIT;	/* calibration switches */
	int helcorr = OMIT;
	int fluxcorr = OMIT;
	int statcorr = OMIT;
	int err_algorithm = WGT_VARIANCE;
	int printtime = 0;	/* print time after each step? */
	int verbose = 0;	/* print additional info? */
	int center_target = 0;	/* center target in output image? */
	int too_many = 0;	/* too many command-line arguments? */
	int i, j;		/* loop indexes */
	double blazeshift = NO_VALUE;

	IRAFPointer i_imt, o_imt;	/* imt list pointers */
	char *input;		/* name of input science file */
	char *output;		/* optional name of output file */
	int n_in, n_out;	/* number of files in each list */
	int n;

	/* Input and output suffixes. */
	char *isuffix[] =
		{"_flt", "_crj", "_fwv", "_cwv", "_fwv_tmp", "_cwv_tmp"};
	char *osuffix[] =
		{"_x2d", "_sx2", "_w2d", "_w2d", "_w2d_tmp", "_w2d_tmp"};
	int nsuffix = 6;

	/* reference file keywords and names */
	RefFileInfo refnames;

	c_irafinit (argc, argv);

	inlist = calloc (STIS_LINE+1, sizeof (char));
	outlist = calloc (STIS_LINE+1, sizeof (char));
	input = calloc (STIS_LINE+1, sizeof (char));
	output = calloc (STIS_LINE+1, sizeof (char));
	if (inlist == NULL || outlist == NULL ||
		input == NULL || output == NULL) {
	    printf ("ERROR:  Can't even begin:  out of memory.\n");
	    exit (ERROR_RETURN);
	}

	/* Get command-line arguments. */
	for (i = 1;  i < argc;  i++) {
	    if (strcmp (argv[i], "-x2d") == 0 ||
		strcmp (argv[i], "-geo") == 0) {
		switch_on = 1;
	    } else if (strcmp (argv[i], "-sgeo") == 0) {	/* turn on */
		sgeocorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-hel") == 0) {
		helcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-flux") == 0) {
		fluxcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-stat") == 0) {
		statcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-wgt_err") == 0) {
		err_algorithm = WGT_ERROR;
	    } else if (argv[i][0] == '-') {
		if (strcmp (argv[i], "--version") == 0) {
		    PrVersion();
		    exit (0);
		}
		if (strcmp (argv[i], "-r") == 0) {
		    PrFullVersion();
		    exit (0);
		}
		for (j = 1;  argv[i][j] != '\0';  j++) {
		    if (argv[i][j] == 't') {
			printtime = 1;
		    } else if (argv[i][j] == 'v') {
			verbose = 1;
		    } else if (argv[i][j] == 'c') {
			center_target = 1;	/* yes, center target */
		    } else if (argv[i][j] == 'b') {
	                blazeshift = (double) atof (argv[++i]);
	                if (i == argc-1)
	                    break;
		    } else {
			printf ("ERROR:  Unrecognized option %s\n", argv[i]);
			exit (1);
		    }
		}
	    } else if (inlist[0] == '\0') {
		strcpy (inlist, argv[i]);
	    } else if (outlist[0] == '\0') {
		strcpy (outlist, argv[i]);
	    } else {
		too_many = 1;
	    }
	}
	if (inlist[0] == '\0' || too_many) {
	    printf (
"syntax:  cs7.e [-t] [-v] [-c] [-wgt_err] [-b blazeshift] input output\n");
	    printf ("  command-line switches:  -x2d -sgeo -hel -flux -stat\n");
	    FreeNames (inlist, outlist, input, output);
	    exit (ERROR_RETURN);
	}

	/* Was no calibration switch specified on command line? */
	if (!switch_on) {	/* default values (mostly PERFORM) */
	    sgeocorr = DefSwitch ("sgeocorr");
	    helcorr  = DefSwitch ("helcorr");
	    fluxcorr = DefSwitch ("fluxcorr");
	    statcorr = DefSwitch ("statcorr");
	}

	/* Initialize the list of reference file keywords and names. */
	InitRefFile (&refnames);

	/* Expand the templates. */
	i_imt = c_imtopen (inlist);
	o_imt = c_imtopen (outlist);
	n_in = c_imtlen (i_imt);
	n_out = c_imtlen (o_imt);

	/* The number of input and output files must be the same. */
	if (CompareNumbers (n_in, n_out, "output")) {
	    FreeNames (inlist, outlist, input, output);
	    exit (ERROR_RETURN);
	}

	/* Loop over the list of input files. */
	for (n = 0;  n < n_in;  n++) {

	    j = c_imtgetim (i_imt, input, STIS_LINE);
	    if (n_out > 0)
		j = c_imtgetim (o_imt, output, STIS_LINE);
	    else
		output[0] = '\0';

	    status = 0;
	    if ((status = MkOutName (input, isuffix, osuffix, nsuffix,
                                     output, STIS_LINE))) {
		WhichError (status);
		printf ("Skipping %s\n", input);
		continue;
	    }

	    /* Calibrate the current input file. */
	    if ((status = CalStis7 (input, output,
			sgeocorr, helcorr, fluxcorr, statcorr,
			&refnames, printtime, verbose, center_target,
                                    blazeshift, err_algorithm))) {
		printf ("Error processing %s.\n", input);
		WhichError (status);
	    }
	}

	/* Close lists of file names, and free name buffers. */
	c_imtclose (i_imt);
	c_imtclose (o_imt);
	FreeRefFile (&refnames);
	FreeNames (inlist, outlist, input, output);

	if (status)
	    exit (ERROR_RETURN);
	else
	    exit (0);
}
Пример #9
0
int main (int argc, char **argv) {

	int status;			/* zero is OK */

	char *inlist;		/* list of input file names */
	char *outlist;		/* list of output file names */
	char *blevlist;		/* list of output blev file names */
	int switch_on = 0;	/* was any switch specified? */
	int printtime = 0;	/* print time after each step? */
	int verbose = 0;	/* print additional info? */
	int too_many = 0;	/* too many command-line arguments? */
	int i, j;		/* loop indexes */
	int junk;

	IRAFPointer i_imt, o_imt, b_imt;	/* imt list pointers */
	char *input;		/* name of input science file */
	char *output;		/* optional name of output file */
	char *outblev;		/* optional file for blev values */
	int n_in, n_out, n_blev;	/* number of files in each list */
	int n;

	/* Input and output suffixes. */
	char *isuffix[] = {"_raw", "_blv_tmp", "_crj_tmp", "_wav"};
	char *osuffix[] = {"_flt", "_flt",     "_crj",     "_fwv"};
	int nsuffix = 4;

	/* A structure to pass the calibration switches to CalStis1 */
	cs1_switch cs1_sw;

	/* reference file keywords and names */
	RefFileInfo refnames;

	c_irafinit (argc, argv);

	/* Allocate space for file names. */
	inlist = calloc (1, sizeof (char));	/* allocated later */
	outlist = calloc (1, sizeof (char));
	blevlist = calloc (1, sizeof (char));
	input = calloc (STIS_LINE+1, sizeof (char));
	output = calloc (STIS_LINE+1, sizeof (char));
	outblev = calloc (STIS_LINE+1, sizeof (char));
	if (inlist == NULL || outlist == NULL || blevlist == NULL ||
		input == NULL || output == NULL || outblev == NULL) {
	    printf ("ERROR:  Can't even begin; out of memory.\n");
	    exit (ERROR_RETURN);
	}

	/* Initialize the lists of reference file keywords and names. */
	InitRefFile (&refnames);

	/* Initial values. */
	cs1_sw.dqicorr = OMIT;
	cs1_sw.atodcorr = OMIT;
	cs1_sw.blevcorr = OMIT;
	cs1_sw.doppcorr = OMIT;
	cs1_sw.lorscorr = OMIT;
	cs1_sw.glincorr = OMIT;
	cs1_sw.lflgcorr = OMIT;
	cs1_sw.biascorr = OMIT;
	cs1_sw.darkcorr = OMIT;
	cs1_sw.flatcorr = OMIT;
	cs1_sw.shadcorr = OMIT;
	cs1_sw.photcorr = OMIT;
	cs1_sw.statcorr = OMIT;

	strcpy (cs1_sw.darkscale_string, "");

	for (i = 1;  i < argc;  i++) {

	    if (strcmp (argv[i], "--version") == 0) {
		PrVersion();
		exit (0);
	    }
	    if (strcmp (argv[i], "-r") == 0) {
		PrFullVersion();
		exit (0);
	    }
	    if (strcmp (argv[i], "-dqi") == 0) {	/* turn on */
		cs1_sw.dqicorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-atod") == 0) {
		cs1_sw.atodcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-blev") == 0) {
		cs1_sw.blevcorr = PERFORM;
		switch_on = 1;

	    } else if (strcmp (argv[i], "-dopp") == 0) {
		cs1_sw.doppcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-lors") == 0) {
		cs1_sw.lorscorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-glin") == 0) {
		cs1_sw.glincorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-lflg") == 0) {
		cs1_sw.lflgcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-bias") == 0) {
		cs1_sw.biascorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-dark") == 0) {
		cs1_sw.darkcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-flat") == 0) {
		cs1_sw.flatcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-shad") == 0) {
		cs1_sw.shadcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-phot") == 0) {
		cs1_sw.photcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-stat") == 0) {
		cs1_sw.statcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-dscl") == 0) {
		strcpy (cs1_sw.darkscale_string, argv[++i]);
		switch_on = 1;
	    } else if (argv[i][0] == '-') {
		for (j = 1;  argv[i][j] != '\0';  j++) {
		    if (argv[i][j] == 't') {
			printtime = 1;
		    } else if (argv[i][j] == 'v') {
			verbose = 1;
		    } else {
			printf ("ERROR:  Unrecognized option %s\n", argv[i]);
			exit (1);
		    }
		}
	    } else if (inlist[0] == '\0') {
		free (inlist);
		if ((inlist = calloc (strlen(argv[i])+1, sizeof(char)))
			== NULL) {
		    printf ("ERROR:  Out of memory.\n");
		    exit (ERROR_RETURN);
		}
		strcpy (inlist, argv[i]);
	    } else if (outlist[0] == '\0') {
		free (outlist);
		if ((outlist = calloc (strlen(argv[i])+1, sizeof(char)))
			== NULL) {
		    printf ("ERROR:  Out of memory.\n");
		    exit (ERROR_RETURN);
		}
		strcpy (outlist, argv[i]);
	    } else if (blevlist[0] == '\0') {
		free (blevlist);
		if ((blevlist = calloc (strlen(argv[i])+1, sizeof(char)))
			== NULL) {
		    printf ("ERROR:  Out of memory.\n");
		    exit (ERROR_RETURN);
		}
		strcpy (blevlist, argv[i]);
	    } else {
		too_many = 1;
	    }
	}
	if (inlist[0] == '\0' || too_many) {
	    printf ("syntax:  cs1.e [-t] [-v] input output [outblev]\n");
	    printf ("  command-line switches:\n");
	    printf ("       -dqi  -atod -blev\n");
	    printf ("       -dopp -lors -glin -lflg\n");
	    printf ("       -bias -dark -flat -shad -phot -stat\n");
	    FreeNames (inlist, outlist, blevlist, input, output, outblev);
	    exit (ERROR_RETURN);
	}

	/* Was no calibration switch specified on command line? */
	if (!switch_on) {	/* default values (mostly PERFORM) */
	    cs1_sw.dqicorr  = DefSwitch ("dqicorr");
	    cs1_sw.atodcorr = DefSwitch ("atodcorr");
	    cs1_sw.blevcorr = DefSwitch ("blevcorr");
	    cs1_sw.doppcorr = DefSwitch ("doppcorr");
	    cs1_sw.lorscorr = DefSwitch ("lorscorr");
	    cs1_sw.glincorr = DefSwitch ("glincorr");
	    cs1_sw.lflgcorr = DefSwitch ("lflgcorr");
	    cs1_sw.biascorr = DefSwitch ("biascorr");
	    cs1_sw.darkcorr = DefSwitch ("darkcorr");
	    cs1_sw.flatcorr = DefSwitch ("flatcorr");
	    cs1_sw.shadcorr = DefSwitch ("shadcorr");
	    cs1_sw.photcorr = DefSwitch ("photcorr");
	    cs1_sw.statcorr = DefSwitch ("statcorr");
	}

	/* Expand the templates. */
	i_imt = c_imtopen (inlist);
	o_imt = c_imtopen (outlist);
	b_imt = c_imtopen (blevlist);
	n_in = c_imtlen (i_imt);
	n_out = c_imtlen (o_imt);
	n_blev = c_imtlen (b_imt);

	/* The number of input and output files must be the same. */
	status = 0;
	if (CompareNumbers (n_in, n_out, "output"))
	    status = ERROR_RETURN;
	if (CompareNumbers (n_in, n_blev, "outblev"))
	    status = ERROR_RETURN;
	if (status) {
	    FreeNames (inlist, outlist, blevlist, input, output, outblev);
	    exit (ERROR_RETURN);
	}

	/* Loop over the list of input files. */
	for (n = 0;  n < n_in;  n++) {

	    junk = c_imtgetim (i_imt, input, STIS_LINE);
	    if (n_out > 0)
		junk = c_imtgetim (o_imt, output, STIS_LINE);
	    else
		output[0] = '\0';
	    if (n_blev > 0)
		junk = c_imtgetim (b_imt, outblev, STIS_LINE);
	    else
		outblev[0] = '\0';

	    status = 0;
	    if ((status = MkOutName (input, isuffix, osuffix, nsuffix,
                                     output, STIS_LINE))) {
		WhichError (status);
		printf ("Skipping %s\n", input);
		continue;
	    }

	    /* Calibrate the current input file. */
	    if ((status = CalStis1 (input, output, outblev,
                                    &cs1_sw, &refnames, printtime, verbose))) {
		printf ("Error processing %s.\n", input);
		WhichError (status);
	    }
	}

	/* Close lists of file names, and free name buffers. */
	c_imtclose (i_imt);
	c_imtclose (o_imt);
	c_imtclose (b_imt);
	FreeRefFile (&refnames);
	FreeNames (inlist, outlist, blevlist, input, output, outblev);

	if (status)
	    exit (ERROR_RETURN);
	else
	    exit (0);
}