IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41710


Ignore:
Timestamp:
Jul 10, 2021, 2:40:08 PM (5 years ago)
Author:
eugene
Message:

add fits output to mpcorb_predict (moment)

Location:
trunk/Ohana/src/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/tools/Makefile

    r41684 r41710  
    7676$(DESTLIB)/libsla.a:
    7777        echo "missing SLALIB libsla.a: install in $(DESTLIB)"
     78        @exit 2
    7879
    7980$(DESTINC)/slalib.h:
    8081        echo "missing SLALIB slalib.h: install in $(DESTINC)"
     82        @exit 2
    8183
    82 mpcorb_predict: $(DESTBIN)/mpcorb_predict $(DESTLIB)/libsla.a $(DESTINC)/slalib.h
     84mpcorb_predict: $(DESTLIB)/libsla.a $(DESTINC)/slalib.h $(DESTBIN)/mpcorb_predict
     85
     86mpcorb: mpcorb_predict
    8387
    8488%.clean:
  • trunk/Ohana/src/tools/src/mpcorb_predict.c

    r41684 r41710  
    3838Planets *mpcorb_read_fits (char *filename, int *nplanets);
    3939void     mpcorb_save_fits (char *filename, Planets *planets, int Nplanets);
     40void     mpcorb_refs_fits (char *filename, Planets *planets, int Nplanets);
    4041
    4142void mpcorb_predict (Planets *planet, double mjdObs, double *Robs, double *Dobs, int FullCalc);
     
    151152  char  *output   = argv[8];
    152153
    153   FILE *fout = fopen (output, "w");
    154   if (!fout) Shutdown ("ERROR: unable to open file for output %s\n", output);
     154  // FILE *fout = fopen (output, "w");
     155  // if (!fout) Shutdown ("ERROR: unable to open file for output %s\n", output);
    155156
    156157  int Nplanets = 0;
    157158  Planets *planets = mpcorb_read_fits (filename, &Nplanets);
    158159  if (VERBOSE) fprintf (stderr, "loaded %d planets\n", Nplanets);
     160
     161  int NplanetsSave = 0;
     162  int NPLANETSSAVE = 1000;
     163  ALLOCATE_PTR (planetsSave, Planets, NPLANETSSAVE);
    159164
    160165  // transform all objects and identify those in the target region:
     
    173178    // if it is in the region, use the more accurate calculation
    174179    mpcorb_predict (&planets[i], mjdObs, &Robs, &Dobs, TRUE);
    175     fprintf (fout, "%8s %12.6f %12.6f\n", planets[i].ID, Robs, Dobs);
     180
     181    // fprintf (fout, "%8s %12.6f %12.6f\n", planets[i].ID, Robs, Dobs);
     182
     183    // save this prediction, with R,D in both @min & @max
     184    planetsSave[NplanetsSave] = planets[i];
     185    planetsSave[NplanetsSave].mjdMin = mjdObs;
     186    planetsSave[NplanetsSave].RatMin = Robs;
     187    planetsSave[NplanetsSave].DatMin = Dobs;
     188    planetsSave[NplanetsSave].mjdMax = mjdObs;
     189    planetsSave[NplanetsSave].RatMax = Robs;
     190    planetsSave[NplanetsSave].DatMax = Dobs;
     191   
     192    NplanetsSave++;
     193    CHECK_REALLOCATE (planetsSave, Planets, NPLANETSSAVE, NplanetsSave, 1000);
    176194  }
    177   fclose (fout);
    178195  fprintf (stderr, "\n");
     196
     197  mpcorb_refs_fits (output, planetsSave, NplanetsSave);
    179198
    180199  exit (0);
     
    183202// STATUS is value expected for success
    184203# define CHECK_STATUS(STATUS,MSG,...) if (!(STATUS)) { Shutdown (MSG, __VA_ARGS__); }
     204
     205// write minor planet positions (Rref,Dref,Mref) to a FITS table
     206void mpcorb_refs_fits (char *filename, Planets *planets, int Nplanets) {
     207
     208  Header header;
     209  Header theader;
     210  Matrix matrix;
     211  FTable ftable;
     212
     213  gfits_init_header (&header);
     214  header.extend = TRUE;
     215  gfits_create_header (&header);
     216  gfits_create_matrix (&header, &matrix);
     217
     218  gfits_create_table_header (&theader, "BINTABLE", "DATA");
     219
     220  gfits_define_bintable_column (&theader, "8A", "ID",   "name", "none",        1.0, 0.0);
     221  gfits_define_bintable_column (&theader,  "D", "Rref", "RA",   "degrees",     1.0, 0.0);
     222  gfits_define_bintable_column (&theader,  "D", "Dref", "DEC",  "degrees",     1.0, 0.0);
     223  gfits_define_bintable_column (&theader,  "D", "Mref", "Mag",  "magnitudes",  1.0, 0.0);
     224
     225  // generate the output array that carries the data
     226  gfits_create_table (&theader, &ftable);
     227
     228  // create intermediate storage arrays
     229  ALLOCATE_PTR (ID,                     char, Nplanets*8);
     230  ALLOCATE_PTR (Rref,                 double, Nplanets);
     231  ALLOCATE_PTR (Dref,                 double, Nplanets);
     232  ALLOCATE_PTR (Mref,                 double, Nplanets);
     233
     234  // set intermediate storage arrays
     235  for (int i = 0; i < Nplanets; i++) {
     236    Rref[i]        = planets[i].RatMin;
     237    Dref[i]        = planets[i].DatMin;
     238    Mref[i]        = 16.0; // need to add this to prediction
     239    memcpy(&ID[i*8], planets[i].ID, 8);
     240  }
     241
     242  // add the columns to the output array
     243  gfits_set_bintable_column (&theader, &ftable, "ID",   ID,   Nplanets);
     244  gfits_set_bintable_column (&theader, &ftable, "Rref", Rref, Nplanets);
     245  gfits_set_bintable_column (&theader, &ftable, "Dref", Dref, Nplanets);
     246  gfits_set_bintable_column (&theader, &ftable, "Mref", Mref, Nplanets);
     247
     248  // free intermediate storage arrays
     249  free (ID);
     250  free (Rref);
     251  free (Dref);
     252  free (Mref);
     253
     254  // open the output file
     255  FILE *f = fopen (filename, "w");
     256  if (!f) Shutdown ("ERROR: cannot open mpcorb file for output %s\n", filename);
     257
     258  int status;
     259  status = gfits_fwrite_header  (f, &header);
     260  CHECK_STATUS (status, "ERROR: cannot write header for mpcorbs %s\n", filename);
     261
     262  status = gfits_fwrite_matrix  (f, &matrix);
     263  CHECK_STATUS (status, "ERROR: cannot write matrix for mpcorbs %s\n", filename);
     264
     265  status = gfits_fwrite_Theader (f, &theader);
     266  CHECK_STATUS (status, "ERROR: cannot write table header for mpcorbs %s\n", filename);
     267
     268  status = gfits_fwrite_table  (f, &ftable);
     269  CHECK_STATUS (status, "ERROR: cannot write table data for mpcorbs %s\n", filename);
     270
     271  gfits_free_header (&header);
     272  gfits_free_matrix (&matrix);
     273  gfits_free_header (&theader);
     274  gfits_free_table (&ftable);
     275
     276  int fd = fileno (f);
     277
     278  status = fflush (f);
     279  CHECK_STATUS (!status, "ERROR: cannot flush file mpcorbs %s\n", filename);
     280
     281  status = fsync (fd);
     282  CHECK_STATUS (!status, "ERROR: cannot flush file mpcorbs %s\n", filename);
     283
     284  status = fclose (f);
     285  CHECK_STATUS (!status, "ERROR: problem closing mpcorbs file %s\n", filename);
     286
     287  return;
     288}
    185289
    186290// write minor planet orbital elements (plus (R,D,T)[min,max]) to a FITS table
Note: See TracChangeset for help on using the changeset viewer.