/** $Header: cdi_stability.c,v 1.22 99/10/14 12:57:55 jaaps Exp $ ********************************** - - **************************************** * * _/_/_/_/_/_/ _/_/_/ _/_/ _/_/ SRON Utrecht * _/_/_/_/ _/_/ _/_/_/_/_/ _/_/_/ _/_/_/ * _/_/_/ _/_/ _/_/ _/_/_/_/_/ _/ _/ _/_/_/_/ _/_/_/ * _/_/_/_/_/ _/_/_/_/_/_/_/ _/_/_/ _/ _/ _/ _/_/ * _/_/_/_/_/_/_/_/_/_/ _/_/_/_/_/ _/_/ _/ _/ _/ _/_/_/ _/ * _/_/ _/_/_/_/_/_/ _/_/_/_/_/ _/_/_/ _/_/ _/_/ _/ _/_/ * _/_/_/_/_/_/ _/_/ _/_/_/_/ _/_/ _/ _/ _/ _/_/_/ * * - - - - - - - - - - - - - - - - - - - - - - - * Use : cdi_stability (); * * Parameters : * * - - - - - - - - - - - - - - - - - - - - - - - * Dependencies: * * - - - - - - - - - - - - - - - - - - - - - - - * Description : scan attitude data over the selected period, * create a 2D pointing histogram * * - - - - - - - - - - - - - - - - - - - - - - - * $Log: cdi_stability.c,v $ * Revision 1.22 99/10/14 12:57:55 12:57:55 jaaps (Jaap Schuurmans) * non essential, cosmetic adjustments (no reason found in source). * * Revision 1.21 99/05/21 13:30:50 13:30:50 jaaps (Jaap Schuurmans) * cdi_stability--att_open: do not try to open files named "-". * * Revision 1.21 99/05/21 12:28:03 12:28:03 jaaps (Jaap Schuurmans) * cdi_stability--att_open: do not try to open files named "-". * * Revision 1.20 98/07/01 14:10:05 14:10:05 jaaps (Jaap Schuurmans) * non essential, cosmetic adjustments (no reason found in source). * * Revision 1.19 1998/06/18 07:42:17 jaaps * non essential, cosmetic adjustments (no reason found in source). * * Revision 1.18 1998/05/13 10:28:54 jaaps * att_open: gracefully handle 0 length attitude datafiles, did cause abort. * * Revision 1.17 1997/09/10 14:56:01 jaaps * non essential, cosmetic adjustments (no reason found in source). * * Revision 1.15 1997/09/10 10:34:26 jaaps * no entry * * Revision 1.13 1997/09/10 07:59:10 jaaps * non essential, cosmetic adjustments (no reason found in source). * * Revision 1.12 1997/09/09 13:59:41 jaaps * cdi_finistab: as before, there is no reason not to treat the northangle * likewise, ecco. * * Revision 1.11 1997/09/09 13:52:36 jaaps * cdi_finistab: apply any sax/wfc misalignment correction not only to x/y mean * but to found range also. (mean sometimes shifts outside range). * * Revision 1.9 1997/09/08 08:25:43 jaaps * cdi_initstab: preserve the initial pointing, used as reference in attitude drift * computation. * * Revision 1.8 1997/06/18 14:05:49 jaaps * cdi_finistab: apply the dx, dy camera misalignment corrections. * * Revision 1.7 1997/06/04 15:21:50 jaaps * non essential, cosmetic adjustments (no reason found in source). * * Revision 1.6 1997/04/18 14:22:08 jaaps * cdi_stability: all attitude data were inadvertendly skipped if the attitude time span * was fully within 1 single event timewindow, fixed. * att_open : failure may also arise from 'no events in timewindow' on a file that * could be opened, error message changed to report this possibility. * * Revision 1.5 1997/04/11 15:22:30 jaaps * cdi_cna : repair omission in na computation (add 90 deg). * cdi_stability: give correct units in info output. * * Revision 1.4 1997/03/13 09:44:51 jaaps * cdi_stability: changed pointing-stability data unit from 'detector-pixel' * to millimeter. * * Revision 1.3 1997/03/10 08:58:58 jaaps * RCS-test * * Revision 1.2 1997/03/10 08:49:35 jaaps * non essential, cosmetic adjustments (no reason found in source). * * Revision 1.1 1997/03/10 08:36:57 jaaps * Initial revision * ********************************** - - ****************************************/ #include #include #include #include #include #include #include "wfcglobals.h" #include "fits.h" #include "util.h" #include "instrument.h" #include "expose.h" #define C_CALLOC(s,a,b) secure_alloc (#s, a, b) static char *RCSID = "$Header: cdi_stability.c,v 1.22 99/10/14 12:57:55 jaaps Exp $"; static char *cdi_stab_dbgcv (char *s, double t) { double msec; int hh, mm, ss; *s= '\0'; if (t > 0.0) { msec= 24.0*fmod (t, 1.0); hh= (int) (msec); msec= 60.0*(msec - (double) hh); mm= (int) (msec); msec= 60.0*(msec - (double) mm); ss= (int) (msec); msec= 1000.0*(msec - (double) ss)+0.5; if ((int) msec > 999) { msec= 0.0; ss += 1; if (ss == 60) { ss= 0; mm += 1; if (mm == 60) { mm= 0; hh = (hh+1)%24;} } } sprintf (s, " (%2.2d:%2.2d:%2.2d.%3.3d)", hh, mm, ss, (int) msec); } return s; } static void cdi_dbgout_hdr (cardinal Lvl) { wLog (Lvl, " t rel mjd (h:m:s) object event exposure-time\n"); } static void cdi_stab_dbgout (double t, double start, char *name, char *action, double est) { char s0[256], s1[64], s2[64], s3[64]; double msec; int hh, mm, ss; strcpy (s1, " ---- ---- "); if (t != 0.0 || start != 0.0) sprintf (s1, "+%10.3f %12.6f", (t-start)*WFC_SECpDAY, t); cdi_stab_dbgcv (s2, t); *s3= '\0'; if (est > 0.0) sprintf (s3, " et += %9.3f sec.", (t-est)*WFC_SECpDAY); sprintf (s0, "%24.24s %12s %-10.10s %10.10s %s\n", s1, s2, (name != NULL) ? name : " ", (action != NULL) ? action : " ", s3); wLog (DBG_CONT, s0); } static char *cdi_attfromevl (char *r, WFC_EXPOSEPTR exp, cardinal len) { char *n, *s; char template[]= "W%s_%4.4dw%1.1datt1.fits"; *r= '\0'; if (exp != NULL) { strncpy (r, exp->evtlist[0], len); if ((n= strrchr (r, '/')) == NULL) n= r; if (*n == '/') n++; sprintf (n, template, exp->obsPeriod, 0, exp->wfc); } /*** **** if ((s= strstr (n, "prn")) == NULL) s= strstr (n, "srn"); **** if (s != NULL && s[3] >= '0' && s[3] <= '9') strncpy (s, "att1", 4); ***/ return r; } WFC_EVENTFILEPTR att_open (char *name, WFC_EXPOSEPTR exp, WFC_FILTERPTR fltr) { WFC_EVENTFILEPTR afp= NULL; char mess[256], afname[WFCMINPATHLENGTH], ts[256]; if (name == NULL || *name == '\0') name= cdi_attfromevl (afname, exp, WFCMINPATHLENGTH); if (strcmp (name, "-") == 0) return NULL; afp= evt_init (name, fltr, NULL /** WFC_XCBFNCPTR ocb **/, NULL /** WFC_XCBFNCPTR ccb **/, NULL /** void *argcb ccb **/, 0 /** cardinal bufSize **/); if (afp == NULL || afp->f == NULL) { sprintf (mess, "att_open: \"%s\" attitude, cannot open or no events in timewindow.\n", name); wLog (DBG_ERROR, mess); sprintf (mess, " use \"-b attfile\" (parameter attfile) to override default.\n"); wLog (DBG_CONT, mess); sprintf (mess, " exact source exposure time not established.\n"); wLog (DBG_CONT, mess); return NULL; } if (exp != NULL && exp->wfc != 0 && afp->wfc != exp->wfc) { sprintf (mess, "att_open: \"%s\" attitude data for wfc%d, event data from wfc%d.\n", afp->evt->evtfile, afp->wfc, exp->wfc); wLog (DBG_ERROR, mess); wLog (DBG_CONT, "********! MIXING DATA FROM BOTH Wide Field Camera's !********\n\n"); } if (exp != NULL && exp->obsPeriod != NULL && afp->obsPeriod != NULL && strcmp (exp->obsPeriod, afp->obsPeriod) != 0) { sprintf (mess, "att_open: attitude data from obs.period %s (\"%s\"),\n", afp->obsPeriod, afp->namelist[0]); wLog (DBG_ERROR, mess); sprintf (mess, " event data from obs.period %s (\"%s\").\n", exp->obsPeriod, exp->expfile); wLog (DBG_CONT, mess); wLog (DBG_CONT, "********! MIXING DATA FROM DIFFERENT OBSERVATION PERIODS !********\n\n"); } if (fltr != NULL && fltr->t != NULL && afp->evt != NULL && (afp->evt->mjds - fltr->t->r.s) > (1.0/WFC_SECpDAY) ) {