void select_all_packets(Widget w,XtPointer client_data, XtPointer call_data) { Prod_header *hdr; Graphic_product *gp; int *type_ptr, msg_type; /* DEBUG */ /* fprintf(stderr,"DEBUG - Enter select_all_packets()\n"); */ /* set things to display everyting in the product */ /* note: during display everything but the tab is displayed */ sd->packet_select_type = SELECT_ALL; /* if there is a GAB, display it from the beginning */ sd->gab_page = 1; /* DEBUG */ /* if(sd->icd_product == NULL) */ /* fprintf(stderr,"DEBUG - select_all_packets - product not loaded\n"); */ hdr = (Prod_header *)(sd->icd_product); gp = (Graphic_product *) (sd->icd_product+ 96); type_ptr = assoc_access_i(msg_type_list, hdr->g.prod_id); /* DEBUG */ /* if(type_ptr == NULL) */ /* fprintf(stderr,"DEBUG - select_all_packets - msg type not set for id %d\n", */ /* hdr->g.prod_id); */ msg_type = *type_ptr; /* if it's not already open, open a screen to display stuff on */ if(selected_screen == SCREEN_1) { if(screen_1 == NULL) open_display_screen(SCREEN_1); /* TEST - Will the window manager allow us to force the existing */ /* window to the top? Many do not. Are we lucky?????? */ else { XRaiseWindow( XtDisplay(dshell1), XtWindow(dshell1) ); } if(overlay_flag == FALSE) set_prod_resolution(selected_screen); /* if not a geographic product reset screen center */ if(msg_type != GEOGRAPHIC_PRODUCT || overlay_flag == FALSE ) { sd1->x_center_offset = 0; sd1->y_center_offset = 0; } /* and display product */ plot_image(SCREEN_1, TRUE); sd1->last_plotted = TRUE; } /* end SCREEN_1 */ if(selected_screen == SCREEN_2) { if(screen_2 == NULL) open_display_screen(SCREEN_2); /* TEST - Will the window manager allow us to force the existing */ /* window to the top? Many do not. Are we lucky?????? */ else { XRaiseWindow( XtDisplay(dshell2), XtWindow(dshell2) ); } if(overlay_flag == FALSE) set_prod_resolution(selected_screen); /* if not a geographic product reset screen center */ if(msg_type != GEOGRAPHIC_PRODUCT || overlay_flag == FALSE ) { sd2->x_center_offset = 0; sd2->y_center_offset = 0; } /* and display product */ plot_image(SCREEN_2, TRUE); sd2->last_plotted = TRUE; } /* end SCREEN_2 */ if(selected_screen == SCREEN_3) { if(screen_3 == NULL) open_display_screen(SCREEN_3); /* TEST - Will the window manager allow us to force the existing */ /* window to the top? Many do not. Are we lucky?????? */ else { XRaiseWindow( XtDisplay(dshell3), XtWindow(dshell3) ); } if(overlay_flag == FALSE) set_prod_resolution(selected_screen); /* if not a geographic product reset screen center */ if(msg_type != GEOGRAPHIC_PRODUCT || overlay_flag == FALSE ) { sd3->x_center_offset = 0; sd3->y_center_offset = 0; } /* and display product */ plot_image(SCREEN_3, TRUE); sd3->last_plotted = TRUE; } /* end SCREEN_3 */ /* reset animation information */ reset_elev_series(selected_screen, ANIM_FULL_INIT); reset_time_series(selected_screen, ANIM_FULL_INIT); reset_auto_update(selected_screen, ANIM_FULL_INIT); /* make sure that now that we have a window to display stuff in, * the buttons for selecting which window to display in are on */ XtSetSensitive(s1_radio, True); XtSetSensitive(s2_radio, True); XtSetSensitive(s3_radio, True); XtSetSensitive(screen_radio_label, True); } /* end select_all_packets */
int main(int argc,char *argv[]) { int i,j,k,l,m; struct transformation t; struct image img; char *fitsfile=NULL,*reffile=NULL,catfile[128],calfile[128]; FILE *outfile; struct catalog c; float mmin=10.0,rmin=10.0; double mjd0=51544.5,ra0,de0,ra1,de1; float q0,q1; float rmsmin; float x[NMAX],y[NMAX],rx[NMAX],ry[NMAX]; int arg=0,plot=0,add=0,track=0; char *env,starfile[128]; // Environment variables env=getenv("ST_DATADIR"); sprintf(starfile,"%s/data/tycho2.dat",env); // Decode options if (argc>1) { while ((arg=getopt(argc,argv,"f:r:m:R:hpnta"))!=-1) { switch (arg) { case 'f': fitsfile=optarg; break; case 'r': reffile=optarg; break; case 'm': mmin=atof(optarg); break; case 't': track=1; break; case 'R': rmin=atof(optarg); break; case 'p': plot=1; break; case 'a': add=1; break; case 'h': usage(mmin,rmin); return 0; default: usage(mmin,rmin); return 0; } } } else { usage(mmin,rmin); return 0; } // Check if minimum input is provided if (fitsfile==NULL || reffile==NULL) { usage(mmin,rmin); return 0; } // Check this is indeed a FITS file if (is_fits_file(fitsfile)!=1) { printf("%s is not a FITS file\n",fitsfile); return -1 ; } // Check this is indeed a FITS file if (is_fits_file(reffile)!=1) { printf("%s is not a FITS file\n",reffile); return -1 ; } // Read fits file img=read_fits(fitsfile); sprintf(catfile,"%s.cat",fitsfile); sprintf(calfile,"%s.cal",fitsfile); // Read reference transformation t=reference(reffile); // Correct astrometry for fixed or tracked setup if (track==0) { precess(mjd0,t.ra0,t.de0,t.mjd,&ra1,&de1); ra1=modulo(ra1+gmst(img.mjd)-gmst(t.mjd),360.0); precess(img.mjd,ra1,de1,mjd0,&t.ra0,&t.de0); } // Match catalog c=match_catalogs(catfile,starfile,t,img,rmin,mmin); // Plot if (plot==1) plot_image(img,t,c,catfile,mmin); // Do fit if (c.n>10) { for (l=0;l<10;l++) { for (j=0;j<5;j++) { // Transform for (i=0;i<c.n;i++) forward(t.ra0,t.de0,c.ra[i],c.de[i],&c.rx[i],&c.ry[i]); // Select for (i=0,k=0;i<c.n;i++) { if (c.usage[i]==1) { x[k]=c.x[i]; y[k]=c.y[i]; rx[k]=(float) c.rx[i]; ry[k]=(float) c.ry[i]; k++; } } // Fit lfit2d(x,y,rx,k,t.a); lfit2d(x,y,ry,k,t.b); // Move reference point reverse(t.ra0,t.de0,t.a[0],t.b[0],&ra0,&de0); t.ra0=ra0; t.de0=de0; } // Compute and plot residuals for (i=0,t.xrms=0.0,t.yrms=0.0,m=0;i<c.n;i++) { if (c.usage[i]==1) { c.xres[i]=c.rx[i]-(t.a[0]+t.a[1]*c.x[i]+t.a[2]*c.y[i]); c.yres[i]=c.ry[i]-(t.b[0]+t.b[1]*c.x[i]+t.b[2]*c.y[i]); c.res[i]=sqrt(c.xres[i]*c.xres[i]+c.yres[i]*c.yres[i]); t.xrms+=c.xres[i]*c.xres[i]; t.yrms+=c.yres[i]*c.yres[i]; t.rms+=c.xres[i]*c.xres[i]+c.yres[i]*c.yres[i]; m++; } } t.xrms=sqrt(t.xrms/(float) m); t.yrms=sqrt(t.yrms/(float) m); t.rms=sqrt(t.rms/(float) m); // Deselect outliers for (i=0;i<c.n;i++) { if (c.res[i]>2*t.rms) c.usage[i]=0; } } } else { t.xrms=0.0; t.yrms=0.0; t.rms=0.0; } // Print results outfile=fopen(calfile,"w"); for (i=0;i<c.n;i++) if (c.usage[i]==1) fprintf(outfile,"%10.4f %10.4f %10.6f %10.6f %8.3f %8.3f %8.3f %8.3f %8.3f\n",c.x[i],c.y[i],c.ra[i],c.de[i],c.vmag[i],c.imag[i],c.fb[i],c.fm[i],c.bg[i]); fclose(outfile); printf("%s %8.4lf %8.4lf ",fitsfile,t.ra0,t.de0); printf("%3d/%3d %6.1f %6.1f %6.1f\n",m,c.n,t.xrms,t.yrms,t.rms); // Add keywords if (add==1) add_fits_keywords(t,fitsfile); else modify_fits_keywords(t,fitsfile); return 0; }
void select_layer_or_packet(Widget w,XtPointer client_data, XtPointer call_data) { XmSelectionBoxCallbackStruct *cbs = (XmSelectionBoxCallbackStruct *)call_data; /* in the future, get the position with list_cbs->item_position */ /* XmListCallbackStruct *list_cbs; */ int i, pos; char *cbuf; /*CVG 9.0 */ int j, packet; unsigned char is_set; Prod_header *hdr; Graphic_product *gp; int *type_ptr, msg_type; printf("-> inside select_layer_or_packet\n"); /* get rid of the parent shell */ /* required because not the OK button */ XtPopdown(XtParent(packetsel_dialog)); /* DETERMINE THE LAYER SELECTED OR THE INDIVIDUAL PACKET SELECTED FOR DISPLAY */ XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &cbuf); /* get the position that was selected */ sscanf(cbuf, "%d", &pos); /* DEBUG */ /*printf(" DEBUG - store index selected from packet list=%d\n", pos); */ /*printf(" DEBUG - number of layers to check=%d\n", sd->num_layers); */ /* DEBUG */ /* fprintf(stderr,"DEBUG select_layer_or_packet - looking for layer selected\n"); */ /* find if a layer or a packet was selected, * and set the selection values accordingly */ /* CVG 9.0 */ sd->packet_select_type = SELECT_NONE; sd->layer_select = 0; for(i=0; i<sd->num_layers;i++) { if(sd->layers[i].index == pos) { sd->packet_select_type = SELECT_LAYER; sd->layer_select = i; printf("Selected Layer %d\n", sd->layer_select+1); break; } } /* end for num layers */ /* if we didn't select a layer, we need to figure out which packet * in which layer to select */ if(sd->packet_select_type == SELECT_NONE) { sd->packet_select_type = SELECT_PACKET; /* CVG 9.0 - new logic for determining layer and packet within */ /* a layer when select_type is SELECT_PACKET */ /* sd->packet_select = pos - sd->layers[sd->layer_select].index - 1; */ for(i=0; i<sd->num_layers;i++) { if(pos > sd->layers[i].index) { sd->layer_select = i; sd->packet_select = pos - sd->layers[i].index -1; } if(pos < sd->layers[i].index) break; } /* end for num layers */ printf("Selected Packet %d from Layer %d\n", sd->packet_select+1, sd->layer_select+1); } /* end if still SELECT_NONE */ /* CVG 9.0 - added this section to correctly determine the value of overlay_flag */ /* DETERMINE IF THE PACKET SELECTED IS OR THE LAYER SELECTED CONTAINS AN IMAGE */ /* AND SET OVERLAY_FLAG ACCORDINGLY */ sd->this_image = NO_IMAGE; /* used by check_overlay() */ if(sd->packet_select_type == SELECT_PACKET) { packet = transfer_packet_code( sd->layers[sd->layer_select].codes[sd->packet_select] ); switch(packet) { case DIGITAL_RADIAL_DATA_ARRAY: /* 16 */ sd->this_image = DIGITAL_IMAGE; break; case DIGITAL_PRECIP_DATA_ARRAY: /* 17 */ sd->this_image = PRECIP_ARRAY_IMAGE; break; case PRECIP_RATE_DATA_ARRAY: /* 18 */ sd->this_image = OTHER_2D_IMAGE; break; case GENERIC_RADIAL_DATA: sd->this_image = GENERIC_RADIAL; break; case GENERIC_GRID_DATA: sd->this_image = GENERIC_GRID; break; case RADIAL_DATA_16_LEVELS: sd->this_image = RLE_IMAGE; break; case RASTER_DATA_7: case RASTER_DATA_F: sd->this_image = RASTER_IMAGE; break; default: break; } /* end sitch */ } else if(sd->packet_select_type == SELECT_LAYER) { for(j=0;j<sd->layers[sd->layer_select].num_packets;j++) { packet = transfer_packet_code(sd->layers[sd->layer_select].codes[j]); switch(packet) { case DIGITAL_RADIAL_DATA_ARRAY: /* 16 */ sd->this_image = DIGITAL_IMAGE; break; case DIGITAL_PRECIP_DATA_ARRAY: /* 17 */ sd->this_image = PRECIP_ARRAY_IMAGE; break; case PRECIP_RATE_DATA_ARRAY: /* 18 */ sd->this_image = OTHER_2D_IMAGE; break; case GENERIC_RADIAL_DATA: sd->this_image = GENERIC_RADIAL; break; case GENERIC_GRID_DATA: sd->this_image = GENERIC_GRID; break; case RADIAL_DATA_16_LEVELS: sd->this_image = RLE_IMAGE; break; case RASTER_DATA_7: case RASTER_DATA_F: sd->this_image = RASTER_IMAGE; break; default: break; } /* end sitch */ } /* end for num_packets */ } /* overbut is on the packet selection dialog */ XtVaGetValues(overbut, XmNset, &is_set, NULL); if(is_set == XmSET) { check_overlay(TRUE); /* permit overlay of non-geographic content */ } else { overlay_flag = FALSE; } /* DISPLAY SELECTED PACKETS BY CALLNG PLOT_IMAGE FOR APPROPRIATE SCREEN */ /* if there is a GAB, display it from the beginning */ sd->gab_page = 1; /* DEBUG */ /* if(sd->icd_product == NULL) */ /* fprintf(stderr,"DEBUG - select_layer_or_packet - product not loaded\n"); */ hdr = (Prod_header *)(sd->icd_product); gp = (Graphic_product *) (sd->icd_product+ 96); type_ptr = assoc_access_i(msg_type_list, hdr->g.prod_id); /* DEBUG */ /* if(type_ptr == NULL) */ /* fprintf(stderr,"DEBUG - select_layer_or_packet - msg type not set for id %d\n", */ /* hdr->g.prod_id); */ msg_type = *type_ptr; /* if it's not already open, open a screen to display stuff on */ if(selected_screen == SCREEN_1) { if(screen_1 == NULL) open_display_screen(SCREEN_1); /* TEST - Will the window manager allow us to force the existing */ /* window to the top? Many do not. Are we lucky?????? */ else { /* fprintf(stderr,"TEST RAISING WINDOW 1\n"); */ XRaiseWindow( XtDisplay(dshell1), XtWindow(dshell1) ); } if(overlay_flag == FALSE) set_prod_resolution(selected_screen); /* if not a geographic product reset screen center */ if(msg_type != GEOGRAPHIC_PRODUCT || overlay_flag == FALSE /* IS THIS DESIRABLE??? */ ) { sd1->x_center_offset = 0; sd1->y_center_offset = 0; } /* and display product */ plot_image(SCREEN_1, TRUE); sd1->last_plotted = TRUE; } /* end SCREEN_1 */ if(selected_screen == SCREEN_2) { if(screen_2 == NULL) open_display_screen(SCREEN_2); /* TEST - Will the window manager allow us to force the existing */ /* window to the top? Many do not. Are we lucky?????? */ else { /* fprintf(stderr,"TEST RAISING WINDOW 2\n"); */ XRaiseWindow( XtDisplay(dshell2), XtWindow(dshell2) ); } if(overlay_flag == FALSE) set_prod_resolution(selected_screen); /* if not a geographic product reset screen center */ if(msg_type != GEOGRAPHIC_PRODUCT || overlay_flag == FALSE /* IS THIS DESIRABLE??? */ ) { sd2->x_center_offset = 0; sd2->y_center_offset = 0; } /* and display product */ plot_image(SCREEN_2, TRUE); sd2->last_plotted = TRUE; } /* end SCREEN_2 */ if(selected_screen == SCREEN_3) { if(screen_3 == NULL) open_display_screen(SCREEN_3); /* TEST - Will the window manager allow us to force the existing */ /* window to the top? Many do not. Are we lucky?????? */ else { XRaiseWindow( XtDisplay(dshell3), XtWindow(dshell3) ); } if(overlay_flag == FALSE) set_prod_resolution(selected_screen); /* if not a geographic product reset screen center */ if(msg_type != GEOGRAPHIC_PRODUCT || overlay_flag == FALSE /* IS THIS DESIRABLE??? */ ) { sd3->x_center_offset = 0; sd3->y_center_offset = 0; } /* and display product */ plot_image(SCREEN_3, TRUE); sd3->last_plotted = TRUE; } /* end SCREEN_3 */ /* reset animation information */ reset_elev_series(selected_screen, ANIM_FULL_INIT); reset_time_series(selected_screen, ANIM_FULL_INIT); reset_auto_update(selected_screen, ANIM_FULL_INIT); /* make sure that now that we have a window to display stuff in, * the buttons for selecting which window to display in are on */ XtSetSensitive(s1_radio, True); XtSetSensitive(s2_radio, True); XtSetSensitive(s3_radio, True); XtSetSensitive(screen_radio_label, True); } /* end select_layer_or_packet */