コード例 #1
0
ファイル: OutputFileFITS.cpp プロジェクト: ASTRO-BO/libQLBase
void OutputFileFITS::writeKeyword(const std::string& name, const std::string& value, const std::string& comment) {
	int status = 0;
	char card[FLEN_CARD];

	if(!isOpened())
		throwException("Error in OutputFileFITS::writeKeyword() ", status);

	// check if this is a protected keyword that must not be changed.
	fits_read_card(infptr, name.c_str(), card, &status);
	if(status != KEY_NO_EXIST) {
		if (*card && fits_get_keyclass(card) == TYP_STRUC_KEY)
			throwException("Error in OutputFileFITS::writeKeyword() protected ", status);
	}
	if (status != KEY_NO_EXIST && status != 0)
		throwException("Error in OutputFileFITS::writeKeyword() ", status);

	status = 0;
	std::string key = name + " = " + value + " / " + comment;
	int keytype;
	fits_parse_template((char*)key.c_str(), card, &keytype, &status);
	if (status)
		throwException("Error in OutputFileFITS::writeKeyword() ", status);

	fits_update_card(infptr, name.c_str(), card, &status);
	if (status)
		throwException("Error in OutputFileFITS::writeKeyword() ", status);
}
コード例 #2
0
int addkey(char *outfile, char *keyword, char *keyvalue)
{
	fitsfile *outfptr;         /* FITS file pointer, defined in fitsio.h */
	char card[FLEN_CARD], newcard[FLEN_CARD];
	char oldvalue[FLEN_VALUE], comment[FLEN_COMMENT];
	int status = 0;   /*  CFITSIO status value MUST be initialized to zero!  */
	int keytype;

	if (!fits_open_file(&outfptr, outfile, READWRITE, &status))
	{
		if (fits_read_card(outfptr, keyword, card, &status))
		{
			printf("Keyword does not exist\n");
			card[0] = '\0';
			comment[0] = '\0';
			status = 0;  /* reset status after error */
		}
		else
			printf("%s\n",card);

		/* check if this is a protected keyword that must not be changed */
		if (*card && fits_get_keyclass(card) == TYP_STRUC_KEY)
		{
			printf("Protected keyword cannot be modified.\n");
		}
		else
		{
			/* get the comment string */
			if (*card)fits_parse_value(card, oldvalue, comment, &status);

			/* construct template for new keyword */
			strcpy(newcard, keyword);     /* copy keyword name */
			strcat(newcard, " = ");       /* '=' value delimiter */
			strcat(newcard, keyvalue);    /* new value */
			if (*comment) {
				strcat(newcard, " / ");  /* comment delimiter */
				strcat(newcard, comment);     /* append the comment */
			}

			/* reformat the keyword string to conform to FITS rules */
			fits_parse_template(newcard, card, &keytype, &status);

			/* overwrite the keyword with the new value */
			fits_update_card(outfptr, keyword, card, &status);

			printf("Keyword has been changed to:\n");
			printf("%s\n",card);
		}  
		fits_close_file(outfptr, &status);
	}    /* open_file */

	/* if error occured, print out error message */
	if (status) fits_report_error(stderr, status);
	return(status);
}
コード例 #3
0
int main(int argc, char *argv[])
{
  fitsfile *fptr = 0;         /* FITS file pointer, defined in fitsio.h */
  char card[FLEN_CARD], newcard[FLEN_CARD];
  char oldvalue[FLEN_VALUE], comment[FLEN_COMMENT];
  int status = 0;   /*  CFITSIO status value MUST be initialized to zero!  */
  int keytype = 0;

  if (argc != 4) {
    fprintf(stderr, "Usage:  %s filename[ext] keyword newvalue\n", argv[0]);
    fprintf(stderr, "\n");
    fprintf(stderr, "Modify the value of a header keyword.\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "Examples: \n");
    fprintf(stderr, "  %s file.fits dec 30.0 - set DEC = 30.0 \n", argv[0]);
    return (0);
  }

  if (!fits_open_file(&fptr, argv[1], READWRITE, &status)) {
    if (fits_read_card(fptr,argv[2], card, &status)) {
      fprintf(stderr, "Keyword does not exist\n");
      return (1);
    }

    if (fits_get_keyclass(card) == TYP_STRUC_KEY) {
      fprintf(stderr, "Protected keyword cannot be modified\n");
      return (1);
    }

    fits_parse_value(card, oldvalue, comment, &status);

    /* construct template for new keyword */
    strcpy(newcard, argv[2]);     /* copy keyword name */
    strcat(newcard, " = ");       /* '=' value delimiter */
    strcat(newcard, argv[3]);     /* new value */
    if (*comment) {
      strcat(newcard, " / ");  /* comment delimiter */
      strcat(newcard, comment);     /* append the comment */
    }

    /* reformat the keyword string to conform to FITS rules */
    fits_parse_template(newcard, card, &keytype, &status);

    /* overwrite the keyword with the new value */
    fits_update_card(fptr, argv[2], card, &status);

    fits_close_file(fptr, &status);
  }    /* open_file */

  /* if error occured, print out error message */
  if (status) {
    fits_report_error(stderr, status);
  }
  return (status);
}
コード例 #4
0
ファイル: fitsutils.c プロジェクト: sfabbro/allphot
int fits_update_keycard(fitsfile* fptr, char* keystring, int* status) {
  static char keyname[FLEN_KEYWORD];

  /* update directly the full card */
  int l;
  fits_get_keyname(keystring, keyname, &l, status);
  fits_update_card(fptr, keyname, keystring, status);
  fits_print_error(*status);
  
  return *status;
}
コード例 #5
0
int copykey( char *keyword, char *fromfile, char *tofile )
{
	fitsfile *fptr;         /* FITS file pointer, defined in fitsio.h */
	char fromcard[FLEN_CARD], tocard[FLEN_CARD], tempcard[FLEN_CARD];
	char oldvalue[FLEN_VALUE], comment[FLEN_COMMENT];
	int status = 0;   /*  CFITSIO status value MUST be initialized to zero!  */
	int keytype;


	/* Open fromfile and grab keyword and value */
	if (!fits_open_file(&fptr, fromfile, READONLY, &status))
	{
		if (fits_read_card(fptr, keyword, fromcard, &status))
			printf("Keyword does not exist in source.\n");
		else
		{
			printf("Copying the following keyword.\n%s\n",fromcard);
			fits_close_file(fptr, &status);

			/* Open tofile and check for keyword */
			if (!fits_open_file(&fptr, tofile, READWRITE, &status))
			{
				if (fits_read_card(fptr, keyword, tocard, &status))
					printf("Keyword does not exist in target.\nWriting.\n");
				else
					printf("Keyword exists in target.\nOverwriting.\n%s\n",tocard);
				status = 0;

				/* check if this is a protected keyword that must not be changed */
				if (*tocard && fits_get_keyclass(tocard) == TYP_STRUC_KEY)
					printf("Protected keyword cannot be modified.\n");
				else
				{
					/* overwrite the keyword with the new value */
					fits_update_card(fptr, keyword, fromcard, &status);
					printf("Keyword has been changed to:\n");
					printf("%s\n",fromcard);
				}
				fits_close_file(fptr, &status);
			}
		} /* open_target */ 
	}    /* open_source */

	/* if error occured, print out error message */
	if (status) fits_report_error(stderr, status);
	return(status);
}
コード例 #6
0
int appendheader ( char *outfile, char *infile )
{
	fitsfile *infptr, *outfptr;         /* FITS file pointer, defined in fitsio.h */
	char card[FLEN_CARD];   /* Standard string lengths defined in fitsio.h */
	int status = 0;   /* CFITSIO status value MUST be initialized to zero! */
	int nkeys, ii;
	char keyword[FLEN_KEYWORD], keyvalue[FLEN_VALUE], keycomment[FLEN_COMMENT];
	char temp[FLEN_KEYWORD];

	strcpy(temp,"COMMENT");
	if (!fits_open_file(&infptr, infile, READONLY, &status))
	{
		if (!fits_open_file(&outfptr, outfile, READWRITE, &status))
		{
			fits_get_hdrspace(infptr, &nkeys, NULL, &status); /* get # of keywords */

			for (ii = 1; ii <= nkeys; ii++) { /* Read and write each keywords */

				if (fits_read_record(infptr, ii, card, &status))break;
				fits_read_keyn(infptr, ii, keyword, keyvalue, keycomment, &status);

                                /* check if this is a protected keyword that must not be changed */
				if (*card && fits_get_keyclass(card) == TYP_STRUC_KEY)
					printf("%s - Protected keyword cannot be modified.\n", keyword);
				else
				{	if (!strcmp(temp, keyword)) 
					{	/* do not overwrite COMMENTs */
						fits_write_record(outfptr, card, &status);
					}
					else
					{
						fits_update_card(outfptr, keyword, card, &status);
					}
                                        printf("Writing - %s\n", card);
				}

			}
			fits_close_file(outfptr, &status);
		}

		if (status == END_OF_FILE)  status = 0; /* Reset after normal error */

		fits_close_file(infptr, &status);
	}
}
コード例 #7
0
ファイル: modhead.c プロジェクト: Carl4/astrometry.net
int main(int argc, char *argv[])
{
    fitsfile *fptr;         /* FITS file pointer, defined in fitsio.h */
    char card[FLEN_CARD], newcard[FLEN_CARD];
    char oldvalue[FLEN_VALUE], comment[FLEN_COMMENT];
    int status = 0;   /*  CFITSIO status value MUST be initialized to zero!  */
    int iomode, keytype;

    if (argc == 3) 
      iomode = READONLY;
    else if ((argc == 4) || (argc == 5))
		iomode = READWRITE;
    else {
      printf("Usage:  modhead filename[ext] keyword newvalue [newcomment]\n");
      printf("\n");
      printf("Write or modify the value of a header keyword.\n");
      printf("If 'newvalue' is not specified then just print \n");
      printf("the current value. \n");
      printf("\n");
      printf("Examples: \n");
      printf("  modhead file.fits dec      - list the DEC keyword \n");
      printf("  modhead file.fits dec 30.0 - set DEC = 30.0 \n");
      printf("  modhead file.fits dec 30.0 \"The decline of civilization\" - set DEC = 30.0 and add a comment \n");
      return(0);
    }

    if (!fits_open_file(&fptr, argv[1], iomode, &status))
    {
      if (fits_read_card(fptr,argv[2], card, &status))
      {
        printf("Keyword does not exist\n");
        card[0] = '\0';
        comment[0] = '\0';
        status = 0;  /* reset status after error */
      }
      else
        printf("%s\n",card);

      if ((argc == 4) || (argc == 5)) /* write or overwrite the keyword */
      {
          /* check if this is a protected keyword that must not be changed */
		  /*
			if (*card && fits_get_keyclass(card) == TYP_STRUC_KEY)
			{
            printf("Protected keyword cannot be modified.\n");
			}
			else
		  */
          {
            /* get the comment string */
			if (*card)
				fits_parse_value(card, oldvalue, comment, &status);

            /* construct template for new keyword */
            strcpy(newcard, argv[2]);     /* copy keyword name */
            strcat(newcard, " = ");       /* '=' value delimiter */
            strcat(newcard, argv[3]);     /* new value */
			if (argc == 5) {
              strcat(newcard, " / ");  /* comment delimiter */
              strcat(newcard, argv[4]);     /* append the comment */
			} else if (*comment) {
			  /* old comment */
			  strcat(newcard, " / ");  /* comment delimiter */
              strcat(newcard, comment);     /* append the comment */
            }

            /* reformat the keyword string to conform to FITS rules */
            fits_parse_template(newcard, card, &keytype, &status);

            /* overwrite the keyword with the new value */
            fits_update_card(fptr, argv[2], card, &status);

            printf("Keyword has been changed to:\n");
            printf("%s\n",card);
          }
      }
      fits_close_file(fptr, &status);
    }

    /* if error occured, print out error message */
    if (status) fits_report_error(stderr, status);
    return(status);
}