IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 25, 2005, 6:23:25 AM (21 years ago)
Author:
eugene
Message:

adding autocode to imphotsearch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/imregister/imphot/dumpfits.c

    r3650 r4024  
    1 int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep) {
     1# include "imregister.h"
     2# include "imphot.h"
     3
     4/* write out complete binary FITS table in format of db */
     5int DumpFitsBintable (char *filename, Image *image, int *match, int Nmatch) {
     6
     7  int i, j;
     8  FILE *f;
     9  Header header;
     10  Matrix matrix;
     11  Header theader;
     12  FTable ftable;
     13  Image *subset;
     14
     15  ALLOCATE (subset, Image, MAX (1, Nmatch));
     16  for (i = 0; i < Nmatch; i++){
     17    j = match[i];
     18    memcpy (&subset[i], &image[j], sizeof (Image));
     19  }
     20
     21  /* open file for output */
     22  f = fopen (filename, "w");
     23  if (f == NULL) {
     24    fprintf (stderr, "ERROR: can't open output file %s\n", filename);
     25    exit (1);
     26  }
     27
     28  /* create primary header */
     29  fits_init_header (&header);   
     30  header.extend = TRUE;
     31  fits_create_header (&header);
     32  fits_create_matrix (&header, &matrix);
     33  fits_print (&header, "NEXTEND", "%d", 1, 1);
     34
     35  ftable.header = &theader;
     36  fits_table_set_Image (&ftable, subset, Nmatch);
     37
     38  fits_fwrite_header  (f, &header);
     39  fits_fwrite_matrix  (f, &matrix);
     40  fits_fwrite_Theader (f, &theader);
     41  fits_fwrite_table   (f, &ftable);
     42  fclose (f);
     43  exit (0);
     44}
     45
     46int DumpFitsTable (char *filename, Image *image, int *match, int Nmatch) {
    247 
    3   Header header, theader;
     48  Header header;
    449  Matrix matrix;
    5   FTable table;
    6   Image *newdata;
     50  Header theader;
     51  FTable ftable;
     52  Image *subset;
    753  FILE *f;
    854  char *startstr, *filtstr, *datestr, *line;
     
    1864  fits_print (&header, "NEXTEND", "%d", 1, 1);
    1965 
     66  /* the ASCII table is always a little harder than the binary:
     67   * we need to build the data line a bit carefully
     68   */
     69
    2070  /* create table header */
    2171  fits_create_table_header (&theader, "TABLE", "ZPTS");
    22    
     72
    2373  /* add current date/time to header */
    2474  str_to_time ("now", &tsecond);
     
    3787  fits_define_table_column (&theader, "F7.1",  "SKY",        "median sky flux",           "counts");
    3888  fits_define_table_column (&theader, "I6",    "NSTAR",      "Number of stars in image",  "stars");
    39  
     89
    4090  /* define TNULL, TNVAL values */
    4191  fits_modify (&theader, "TNULL1",  "%s", 1, "NULL"); /* START_TIME */
     
    59109  fits_modify (&theader, "TNVAL9",  "%s", 1,  "-2");  /* NSTAR      */
    60110
    61   /* create table, add data values */
    62   fits_create_table (&theader, &table);
    63  
    64   /* add selected data to table */
    65   for (i = 0; i < Nkeep; i++) {
    66     newdata  = &image[index[i]];
    67     startstr = sec_to_date (newdata[0].tzero);
    68     filtstr  = GetPhotcodeNamebyCode (newdata[0].source);
    69     zp       = 0.001*newdata[0].Mcal;
    70     dzp      = 0.001*newdata[0].dMcal;
    71    
    72     XY_to_RD (&ra, &dec, 0.0, 0.0, &newdata[0].coords);
    73     airmass  = 0.001*newdata[0].secz;
    74     sky      = newdata[0].Myyyy + 0x8000;
     111  /* add data to table */
     112  for (i = 0; i < Nmatch; i++) {
     113    subset   = &image[match[i]];
     114    startstr = sec_to_date (subset[0].tzero);
     115    filtstr  = GetPhotcodeNamebyCode (subset[0].source);
     116    zp       = 0.001*subset[0].Mcal;
     117    dzp      = 0.001*subset[0].dMcal;
     118    XY_to_RD (&ra, &dec, 0.0, 0.0, &subset[0].coords);
     119    airmass  = 0.001*subset[0].secz;
     120    sky      = subset[0].Myyyy + 0x8000;
    75121
    76     line = fits_table_print (&table, startstr, filtstr, zp, dzp, ra, dec, airmass, sky, newdata[0].nstar);
    77     fits_add_rows (&table, line, 1, strlen(line));
    78 
     122    /* we should get an error here if we don't construct this line correctly */
     123    line = fits_table_print (&ftable, startstr, filtstr, zp, dzp, ra, dec, airmass, sky, subset[0].nstar);
     124    fits_add_rows (&ftable, line, 1, strlen(line));
    79125    free (line);
    80126    free (startstr);
    81127  }
    82    
     128
    83129  /* write data to output file */
    84130  f = fopen (filename, "w");
    85131  if (f == (FILE *) NULL) {
    86132    fprintf (stderr, "Failure writing fits table\n");
    87     return (FALSE);
     133    exit (1);
    88134  }
    89135  fits_fwrite_header  (f, &header);
    90136  fits_fwrite_matrix  (f, &matrix);
    91137  fits_fwrite_Theader (f, &theader);
    92   fits_fwrite_table   (f, &table);
     138  fits_fwrite_table   (f, &ftable);
    93139  fclose (f);
    94140  return (TRUE);
    95141}
    96 
    97 /*
    98 
    99   selection options:
    100 
    101   CCDSelect
    102   TypeSelect
    103   TimeSelect
    104   FilterSelect
    105   ExptimeSelect
    106   EntrySelect
    107   LabelSelect
    108 
    109 */
Note: See TracChangeset for help on using the changeset viewer.