home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / xfitsvew.zip / XFITSview / XFITSview.c < prev    next >
C/C++ Source or Header  |  1998-04-03  |  7KB  |  222 lines

  1. /*    XFITSview : a FITS image viewer for X-windows */
  2. /* This program requires the Motif library */
  3. /*-----------------------------------------------------------------------
  4. *  Copyright (C) 1996-1998
  5. *  Associated Universities, Inc. Washington DC, USA.
  6. *  This program is free software; you can redistribute it and/or
  7. *  modify it under the terms of the GNU General Public License as
  8. *  published by the Free Software Foundation; either version 2 of
  9. *  the License, or (at your option) any later version.
  10. *
  11. *  This program is distributed in the hope that it will be useful,
  12. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. *  GNU General Public License for more details.
  15. *
  16. *  You should have received a copy of the GNU General Public
  17. *  License along with this program; if not, write to the Free
  18. *  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
  19. *  MA 02139, USA.
  20. *
  21. *  Correspondence concerning XFITSview should be addressed as follows:
  22. *         Internet email: bcotton@nrao.edu.
  23. *         Postal address: William Cotton
  24. *                         National Radio Astronomy Observatory
  25. *                         520 Edgemont Road
  26. *                         Charlottesville, VA 22903-2475 USA
  27. *-----------------------------------------------------------------------*/
  28. #define XFITSVIEWMAIN
  29. #include <Xm/Xm.h> 
  30. #include <Xm/DrawingA.h> 
  31. #include <Xm/MainW.h> 
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <Xm/Separator.h>
  35. #include <Xm/ScrolledW.h>
  36. #include <Xm/Scale.h>
  37. #include <Xm/Form.h>
  38. #include <Xm/PushB.h>
  39. #include <Xm/CascadeB.h>
  40. #include <Xm/RowColumn.h>
  41. #include <Xm/Label.h>
  42. #include <Xm/ToggleB.h>
  43. #include "xfitsview.h"
  44. #include "imagedisp.h"
  45. #include "FITS2Pix.h"
  46. #include "color.h"
  47. #include "optionbox.h"
  48. #include "moviebox.h"
  49. #include "blinkbox.h"
  50. #include "infobox.h"
  51. #include "control.h"
  52. #include "markpos.h"
  53. #include "cursor.h"
  54. #include "textfile.h"
  55. #include "scrolltext.h"
  56. #include "menu.h"
  57. #include "messagebox.h"
  58. #include "toolbox.h"
  59.  
  60.  
  61. /* internal functions */
  62. void InitImage (ImageDisplay *IDdata, int narg, char *filename);
  63.  
  64.  
  65. /* stuff for error messages */
  66. int hwndErr = 1;
  67. char szErrMess[120];
  68.  
  69. void main ( int argc, char **argv ) 
  70. {
  71.   Widget       mainWindow, menu, control, toolbox, form;
  72.   XtAppContext app;
  73.   ImageData    image;
  74.   ImageDisplay *IDdata;
  75.   Arg          args[10];
  76.   int          n;
  77.  
  78. /*  initialize toolkit */
  79.   Display_shell = XtAppInitialize (&app, 
  80.                    "XFitsview", 
  81.                    NULL, 0, &argc, argv,  NULL, NULL, 0); 
  82. /* Set initial size */
  83.   n = 0;
  84. /*  XtSetArg(args[n], XtNwidth, 640);  n++;
  85.   XtSetArg(args[n], XtNheight, 480);  n++; */
  86.  
  87. /* create main window */
  88.   mainWindow = XtCreateManagedWidget ("mainWindow", xmMainWindowWidgetClass,
  89.                                          Display_shell, args, n);
  90. /* make a form to hang everything on*/
  91.   form = XtVaCreateManagedWidget ("form", xmFormWidgetClass,
  92.                   mainWindow,
  93.                   XmNwidth,     640,
  94.                   XmNheight,    480,
  95.                   XmNx,           0,
  96.                   XmNy,           0,
  97.                   NULL);
  98.  
  99.  
  100. /* make image display window */
  101.   IDdata = MakeDisplay (form, Display_shell);
  102.  
  103. /*  make display control panel */
  104.   control = MakeControl (form, (XtPointer)IDdata);
  105.  
  106. /*  make toolbox panel */
  107.   /* not ready for prime time */
  108.   /*  toolbox = MakeToolbox (form, control, (XtPointer)IDdata); */
  109.  
  110. /* attach image display to control on form */
  111.      XtVaSetValues(IDdata->display, 
  112.            XmNrightAttachment,  XmATTACH_FORM,
  113.            XmNleftAttachment,  XmATTACH_WIDGET,
  114.            XmNleftWidget,  control,
  115.            XmNtopAttachment,  XmATTACH_FORM,
  116.            XmNbottomAttachment,  XmATTACH_FORM,
  117.            NULL);
  118.  
  119. /*  make main menu */
  120.   menu = MakeMainMenu (mainWindow, (XtPointer)&image, 
  121.                (XtPointer)IDdata);
  122.  
  123. /*  save some widget names */
  124.   XtVaSetValues ( mainWindow, XmNmenuBar, menu, NULL );
  125.  
  126. /*  Presto - appear on the screen */
  127.   XtRealizeWidget (Display_shell);
  128.  
  129. /*  create / init color map, cursor */
  130.   SetupColorMap (Display_shell, IDdata);
  131.  
  132. /* set cursor if possible */
  133.   IDdata->cursor = MakeImageCursor (XtDisplay (IDdata->display), 
  134.                     XtWindow(IDdata->canvas));
  135.   if (IDdata->cursor)
  136.     XDefineCursor (XtDisplay (IDdata->display), XtWindow(IDdata->canvas),
  137.            IDdata->cursor);
  138.     
  139.  
  140. /* initialize image, display file given as argument */
  141.   InitImage (IDdata, argc, argv[1]);
  142.  
  143. /*   set display */
  144.   SetDisplay(IDdata);
  145.  
  146. /* save application context */
  147.   IDdata->app = app;
  148.  
  149. /* redraw message box if it contains any start up messages */
  150.   MessageRefresh();
  151.  
  152. /* main event loop */
  153.   XtAppMainLoop (app);
  154. } /* end of main */
  155.  
  156. void InitImage (ImageDisplay *IDdata, int narg, char *filename)
  157. /* initialize image data structures */
  158. {
  159.   int i,j,k;
  160.   char direct[120];
  161.  
  162.   CurImag = 0; /* set current image pointer */
  163.   FITS_dir = NULL;
  164.   mark_dir = NULL;
  165.   log_dir = NULL;
  166.   doLog = 0;   /* position logging initially turned off */
  167.   usr_equinox = -1.0;  /* use equinox of image */
  168. /* Initialize structures */
  169.   for (j=0;j<2;j++) {
  170.     image[j].valid = 0;
  171.     image[j].pixarray = NULL;
  172.     image[j].FileName = MakeString("NONE");
  173.     image[j].Image = NULL;
  174.     image[j].object = MakeString("Unknown");
  175.     image[j].units = MakeString("Unknown");
  176.     image[j].obsdate = MakeString("Unknown");
  177.     image[j].data_max = 0.0;
  178.     image[j].data_min = 0.0;
  179.     image[j].epoch = 0.0;
  180.     image[j].ndim = 0;
  181.     for (i=0; i<7; i++) {
  182.       image[j].cname[i] = MakeString("none");
  183.       image[j].dim[i] = 0;
  184.       image[j].crval[i] = 0.0;
  185.       image[j].crpix[i] = 0.0;
  186.       image[j].crinc[i] = 0.0;
  187.       image[j].crot[i] = 0.0;
  188.     }
  189.     image[j].iImageNx = 0;
  190.     image[j].iImageNy = 0;
  191.     image[j].iNumPlanes = 0;
  192.     image[j].iXPixel = 0;
  193.     image[j].iYPixel = 0;
  194.     image[j].fXpixel = 0.0;
  195.     image[j].fYpixel = 0.0;
  196.     image[j].PixRange[0] = 0.0;
  197.     image[j].PixRange[1] = 0.0;
  198.     image[j].fBpixel = 0;
  199.     image[j].iNonlinear = 0;
  200.     image[j].PlaneNo = 0;
  201.   } /* end of loop over ImageData structures */
  202. /* was a FITS file name passed as an argument? */
  203.   if (narg<2) return;
  204.  
  205. /* read FITS file to pixmap */
  206.   StringFill (image[CurImag].FileName, filename);
  207. /* read FITS file to PixMap */
  208.   if (FITS2Pix (&image[CurImag], IDdata, 1))
  209.     { /* error */
  210.       sprintf (szErrMess, "Error reading FITS file = %80s", filename);
  211.       MessageShow (szErrMess);
  212.     }
  213. /* get directory name */
  214.   j = strlen(filename);
  215.   k = 0;
  216.   for (i=0;i<j;i++) if (filename[i]=='/') k = i+1;
  217.   for (i=0;i<k;i++) direct[i]=filename[i]; direct[i]=0;
  218.   FITS_dir = MakeString(direct);
  219.   PaintImage(IDdata); /* draw image */
  220. } /* end of InitImage */
  221.  
  222.