27 #include "dataserv.bmp"
28 #include "datagrid.bmp"
32 #define DATASPREAD 0.000001
80 static int block_for_event();
107 long frame_mask = KeyPressMask | ExposureMask | StructureNotifyMask;
114 static char *spaces =
" ";
133 {
"help", 0, 0, 0, 0, NULL, NULL, 4,
do_help,
"Displays this list"},
134 {
"quit", 0, 0, 0, 0, NULL, NULL, 4,
do_quit,
"Exit program"},
136 { NULL, 0, 0, 0, 0, NULL, NULL, 0, (
void *)0, NULL }
148 { XK_q, 1,
"q",
"Quit Program" },
149 { XK_p, 1,
"<control> + p",
"Screen Capture Window" }
152 #define MAX_KEYSYMS (sizeof(keysyms) / sizeof(struct STURCT_KEYSYMS))
162 log_msg(
"To HELPER: '%s'", buf);
176 log_msg(
"To XGRAPHIC: %s", buf);
191 sprintf(tbuf,
"Press the Following Keys in Either the OTF or Spectral Plot Windows\n");
193 printf(
"\n%s\n", tbuf);
203 sprintf(tbuf,
"Press %s key for %s", k->
key, k->
help);
204 printf(
"%s\n", tbuf);
210 sprintf(tbuf,
"Press the Following Keys Spectral Plot Windows\n");
212 printf(
"\n%s\n", tbuf);
222 sprintf(tbuf,
"Press %s key for %s", k->
key, k->
help);
223 printf(
"%s\n", tbuf);
240 cp = strtok(buf,
" \n\t");
242 sprintf(tbuf,
"Command Arguments\n");
243 printf(
"\n%s\n", tbuf);
247 for(p=parse_table;p->
msg;p++)
251 if(!strncmp(p->
msg, cp, strlen(cp)))
253 sprintf(tbuf,
"%s: %s", p->
msg, spaces);
254 strcpy(tbuf+18, p->
help);
255 printf(
"%s\n", tbuf);
262 sprintf(tbuf,
"%s: %s", p->
msg, spaces);
263 strcpy(tbuf+18, p->
help);
264 printf(
"%s\n", tbuf);
286 char *
string, *last_token, *delim;
308 string[strlen(
string)+1] =
'\0';
310 }
else if(!last_token || !*last_token || !delim || !*delim)
314 ptr = last_token + strlen(last_token);
318 for(n=strlen(delim); *
ptr; ptr++) {
319 for(i=0; i < n && *ptr != delim[i]; i++)
330 for( ; *
ptr; ptr++) {
331 for(i=0; i < n && *ptr != delim[i]; i++)
347 static char cmdbuf[4096];
353 log_msg(
"Got SPECDATA struct");
356 bcopy(buf, (
char *)&
sd, len);
371 log_msg(
"readMail(): Got %d bytes, %s", len, buf);
374 if(buf || len <
sizeof(cmdbuf))
399 for(p=parse_table;p->
msg;p++)
401 if(!strncmp(p->
msg, buf, p->
len))
403 if(p->
log && strlen(buf) < 2048)
418 log_msg(
"Command %s NOT found", buf);
512 char *cp,
tfile[256];
525 signal(SIGTERM, (__sighandler_t)signalHandler);
529 cp = getenv(
"LPSESSION");
533 sprintf(tfile,
"LOGDIR=/tmp/%s", cp);
539 fprintf(stderr,
"No SESSION defined\n");
546 setpgid( (pid_t)0, (pid_t)0);
550 cp = getenv(
"TOPDIR");
556 cp = getenv(
"FIXDAT");
560 sprintf(
fixeddir,
"/home/data4/fixed");
562 cp = getenv(
"_3DDIR");
566 sprintf(
_3ddir,
"/home/data1/3d");
568 cp = getenv(
"DISPLAY");
577 if((server=(
struct XGR_ *)calloc(1,
sizeof(
struct XGR_)))==NULL)
579 log_msg(
"error in calloc for main server");
592 if((server->
dpy = XOpenDisplay(
localHost)) == (Display *)NULL)
609 strcpy(title,
"Specdata");
633 log_msg(
"Server %s caused IO Trap", DisplayString(display));
638 log_msg(
"Server: Unknown Server caused IO Trap");
652 log_msg(
"Server %s caused Xlib Error", DisplayString(display));
657 log_msg(
"Server: Unknown Server caused Xlib Error");
673 s = (
struct XGR_ *)p;
676 log_msg(
"Signal: Shuting Down Server %s", DisplayString(s->
dpy));
678 XCloseDisplay(s->
dpy);
687 log_msg(
"Exiting with status %d", status);
701 XComposeStatus compose;
705 if(event->type == KeyPress)
707 XLookupString((XKeyEvent *)event, buffer, bufsize, &keysym, &compose);
709 if(keysym == XK_p && event->xkey.state == ControlMask)
711 log_msg(
"Stand-by, Making Copy of SpecData Window.");
720 #define WINDOW_PLOT 1
728 int cw, ch, xpos, ypos, bg,
usPixmap, which;
730 unsigned long value_mask;
731 XSetWindowAttributes attr;
732 XSizeHints size_hints;
735 XTextProperty *wi, *ic;
737 if((w = (
struct WINDOW *)calloc(1,
sizeof(
struct WINDOW ))) == NULL)
739 log_msg(
"error in calloc for main Plot window");
750 w->
win = XCreateSimpleWindow(s->dpy, RootWindow(s->dpy,s->scr_num),
751 xpos, ypos, (
unsigned int)w->
canw,
752 (
unsigned int)w->
canh,
759 if(!(w->
pixmap = XCreatePixmap(s->dpy, w->
win, (
unsigned int)w->
canw, (
unsigned int)w->
canh, s->depth)))
771 size_hints.flags = PPosition | PSize | PMinSize;
772 size_hints.min_width = cw;
773 size_hints.min_height = ch;
777 w->
gc = XCreateGC(s->dpy, RootWindow(s->dpy, s->scr_num), (
unsigned long)0, (XGCValues *)NULL);
783 w->
icon = XCreateBitmapFromData(s->dpy, w->
win, dataserv_bmp_bits,
785 dataserv_bmp_height);
789 w->
icon = XCreateBitmapFromData(s->dpy, w->
win, datagrid_bmp_bits,
791 datagrid_bmp_height);
794 XSetStandardProperties(s->dpy, w->
win,
796 (
char **)NULL, 0, &size_hints);
801 wm_hints.initial_state = NormalState;
802 wm_hints.input = True;
803 wm_hints.icon_pixmap = 0;
804 wm_hints.flags = StateHint | InputHint | WindowGroupHint;
805 wm_hints.window_group = w->
win;
807 XSetWMProperties(s->dpy, w->
win, wi, ic, NULL, 0, &size_hints, &wm_hints, NULL);
810 if(DoesBackingStore(XDefaultScreenOfDisplay(s->dpy)))
814 log_msg(
"createWindow(): Setting Backing Store for Plot Window");
817 value_mask = CWBackingStore;
818 attr.backing_store = WhenMapped;
819 XChangeWindowAttributes(s->dpy, w->
win, value_mask, &attr);
822 XMapWindow(s->dpy, w->
win);
825 XSetWindowBackground(s->dpy, w->
win, s->colors[w->
background]);
826 XSetBackground(s->dpy, w->
gc, s->colors[w->
background]);
827 XClearWindow(s->dpy, w->
win);
838 int cw, ch, xpos, ypos, bg,
usPixmap;
843 log_msg(
"DisplayInfo for %s - %s major %d minor %d release %d",
844 DisplayString(s->dpy), ServerVendor(s->dpy), ProtocolVersion(s->dpy),
845 ProtocolRevision(s->dpy), VendorRelease(s->dpy));
847 s->xfd = XConnectionNumber(s->dpy);
848 s->scr_num = DefaultScreen(s->dpy);
851 s->windows.prev = s->windows.next = &s->windows;
852 s->depth = XDefaultDepthOfScreen(XDefaultScreenOfDisplay(s->dpy));
853 s->userXimage = NULL;
887 return(strncmp(s1, s2, l1) == 0);
894 fprintf(stderr,
"\nUsage of '%s' command line arguments: \n", progname);
895 fprintf(stderr,
"-ws x y Set Window size to x y\n");
896 fprintf(stderr,
"-nopixmap Set dataserv in non-pixmap mapping mode\n");
897 fprintf(stderr,
"-obs initials Set initials to display; defaults to current observer\n");
898 fprintf(stderr,
"-ver n dir Set datafile ver to n, located on disk dir;\n");
899 fprintf(stderr,
" defaults to current observers version\n");
900 fprintf(stderr,
"-maxcolors [16|32|64|128] Set max colors of image display; default 64\n");
901 fprintf(stderr,
"-color [GRAY|PSEUDO|FLAME] Set color mode of image display; default PSEUDO\n");
902 fprintf(stderr,
"-usage This message\n");
957 log_msg(
"To Monitor: %s", buf);
1021 log_msg(
"No structure sent yet");
1037 log_msg(
"Looking for scan %.2f in %s", scan, cp);
1042 log_msg(
"Scan %.2f, not found in %s", scan, cp);
1057 log_msg(
"Scan is OTF: Loading Off Scan %.2f", scan);
1062 log_msg(
"Off Scan %.2f, not found in %s", scan, cp);
1071 log_msg(
"Loading Gains Scan %.2f", scan);
1076 log_msg(
"Gains Scan %.2f, not found in %s", scan, cp);
1090 int ret, be, modeid;
1142 s = (
struct XGR_ *)p;
1144 if(XPending(s->
dpy))
1157 f = (
struct XGR_ *)p2;
1162 xfd = block_for_event(xfds, n);
1166 f = (
struct XGR_ *)p2;
1170 if(XPending(f->
dpy) == 0)
1172 if(f->
dpy == server->
dpy)
1175 log_msg(
"Removeing %s in destoryFunc", DisplayString(f->
dpy));
1195 while(XPending(s->dpy))
1197 XNextEvent(s->dpy, &event);
1199 switch( event.type )
1203 while (XCheckTypedWindowEvent(s->dpy, event.xany.window, Expose, &event))
1212 case ConfigureNotify:
1215 while (XCheckTypedWindowEvent(s->dpy, event.xany.window, ConfigureNotify, &event))
1220 if(event.xconfigure.window && !event.xconfigure.send_event)
1222 xgr_reSizeProc(event.xconfigure.window, event.xconfigure.width, event.xconfigure.height);
1260 static int block_for_event(
xfd, n)
1284 (*sock_callback)(
inMsg, len);
1309 s = (
struct XGR_ *)p;
1311 XSynchronize(s->
dpy, v);
1327 visual = DefaultVisual(display, DefaultScreen(display));
1331 return((XImage *)NULL);
1334 xi = XCreateImage(display, visual, (
unsigned int)depth, ZPixmap,0,
1335 (
char *)NULL, (
unsigned int)w, (
unsigned int)h, 16, 0);
1338 log_msg(
"XCreateImage failed");
1339 return((XImage *)NULL);
1342 ui = (unsigned)(xi->height*xi->bytes_per_line*
sizeof(
char));
1343 if((xi->data=(
char *)malloc(ui))==NULL)
1345 log_msg(
"Unable to malloc(%d) ximage in createXimage()", ui);
1347 return((XImage *)NULL);
1350 bzero((
char *)xi->data, xi->height * xi->bytes_per_line *
sizeof(
char));
1379 log_msg(
"determine_min_max(): Scan #%7.2f is all %.4f", scan,
datamin);
1394 log_msg(
"Freeing Data Pointers");
1422 float f, *xArray, *yArray;
1423 float xb, xe, yb, ye;
1427 xb = 0.05; xe = 0.995;
1428 yb = 0.05; ye = 1.000;
1432 log_msg(
"Requested spectra > numOfSpectra");
1435 if((xArray = (
float *)malloc((
unsigned)(
otf.
noint*
sizeof(
float))))==NULL)
1437 log_msg(
"Unable to malloc(%d) xArray in displaySingleOtfSpectra()",
otf.
noint*
sizeof(
float));
1440 if((yArray = (
float *)malloc((
unsigned)(
otf.
noint*
sizeof(
float))))==NULL)
1442 log_msg(
"Unable to malloc(%d) yArray in displaySingleOtfSpectra()",
otf.
noint*
sizeof(
float));
1443 free((
char *)xArray);
1491 free((
char *)xArray);
1496 free((
char *)yArray);
1510 dl = (int)datalen / (
sizeof(
float) * ( (int)noint +5));
1518 float xb, xe, yb, ye;
1522 float scale, dec_slope, ra_slope;
1523 float a1, b1, siga1, sigb1, chi2_1, q1 = 0;
1528 if((xdata = (
float *)malloc((
unsigned)(
otf.
numSpectra*
sizeof(
float))))==NULL)
1535 xdata[i] = (
float)i;
1537 if((ydata = (
float *)malloc((
unsigned)(
otf.
numSpectra*
sizeof(
float))))==NULL)
1540 free((
char *)xdata);
1553 lsqfit(xdata,ydata, 0, i, sig, 0, &b1, &a1, &sigb1, &siga1, &chi2_1, &q1);
1561 lsqfit(xdata,ydata, 0, i, sig, 0, &b1, &a1, &sigb1, &siga1, &chi2_1, &q1);
1564 if((fabs(ra_slope) < fabs(dec_slope)))
1568 sprintf(temp,
"R.A. Array");
1573 sprintf(temp,
"Dec. Array");
1580 sprintf(temp,
"Time Array");
1585 sprintf(temp,
"R.A. Array");
1590 sprintf(temp,
"Dec. Array");
1594 sprintf(temp,
"Az. Array");
1598 sprintf(temp,
"El. Array");
1601 free((
char *)xdata);
1602 free((
char *)ydata);
1617 free((
char *)xdata);
1618 free((
char *)ydata);
1627 float xb, xe, yb, ye;
1634 float *x, *y, *w, *o, *g;
1644 if((xdata = (
float *)malloc((
unsigned)(
otf.
numSpectra*
sizeof(
float))))==NULL)
1650 if((ydata = (
float *)malloc((
unsigned)(
otf.
numSpectra*
sizeof(
float))))==NULL)
1653 free((
char *)xdata);
1668 *y = ((*w - *o) / *o) * *g;
1679 dtemp += ydata[i+j];
1693 free((
char *)xdata);
1694 free((
char *)ydata);
1706 free((
char *)xdata);
1707 free((
char *)ydata);
1716 float *xArray, *yArray;
1718 int i, j, plotStart, indx;
1739 if( (accum = (
double *)malloc((
unsigned)(
otf.
noint*
sizeof(
double)))) == NULL)
1741 log_msg(
"Unable to malloc(%d) accum in stuffOtf()",
otf.
noint*
sizeof(
double));
1778 free((
char *)accum);
1789 float xb=0.050, xe=0.995, yb=0.50, ye=1.0;
1790 float scale, delta, dxb[12], dxe[12];
1792 int arraySize, indx;
1793 float *xArray, *yArray;
1815 delta = (xe - xb ) / (
float)
otf.
plots;
1817 sprintf(temp,
"Scan %7.2f:", head->scan);
1823 if((xArray = (
float *)malloc((
unsigned)(arraySize*
sizeof(
float))))==NULL)
1825 log_msg(
"Unable to malloc(%d) xdata in do_otf()", arraySize*
sizeof(
float));
1830 if((yArray = (
float *)malloc((
unsigned)(arraySize*
sizeof(
float))))==NULL)
1832 log_msg(
"Unable to malloc(%d) ydata in do_otf()", arraySize*
sizeof(
float));
1833 free((
char *)xArray);
1842 dxb[i] = xb + (float)i*delta;
1844 if(
stuffOtf(i, &indx, xArray, yArray) < 0)
1848 free((
char *)xArray);
1853 free((
char *)yArray);
1864 free((
char *)xArray);
1869 free((
char *)yArray);
1906 free((
char *)xArray);
1911 free((
char *)yArray);
1926 log_msg(
"Doing Total Map Off Plot");
1952 log_msg(
"Doing Default Spectral Plot");
1966 xmin = xscale / -2.0;
1973 data[i] += (xmin + (xscale * (float)i));
1981 data[i] -= (xmin + (xscale * (float)i));
2007 #define SQR(a) (sqrarg=(a),sqrarg*sqrarg)
2009 int lsqfit(x, y,
bdata, ndata, sig, mwt, a, b, siga, sigb, chi2, q)
2010 float x[],y[],sig[],*a,*b,*siga,*sigb,*chi2,*q;
2011 int bdata,ndata,mwt;
2014 float wt, t, sxoss, sx = 0.0, sy = 0.0, st2 = 0.0,
ss, sigdat;
2022 for(i=bdata;i<ndata;i++)
2024 wt = 1.0 /
SQR(sig[i]);
2032 for(i=bdata;i<ndata;i++)
2045 for(i=bdata;i<ndata;i++)
2047 t = (x[i] - sxoss) / sig[i];
2049 *b += t * y[i] / sig[i];
2054 for(i=bdata;i<ndata;i++)
2063 *a = (sy - sx * (*b)) /
ss;
2064 *siga = sqrt((1.0 + sx * sx / (
ss * st2)) /
ss);
2065 *sigb = sqrt(1.0 / st2);
2070 for(i=bdata;i<ndata;i++)
2072 *chi2 +=
SQR(y[i] - (*a) - (*b) * x[i]);
2076 sigdat = sqrt((*chi2) / (ndata - bdata - 2));
struct WINDOW_HEAD * prev
struct SOCK * last_msg(void)
int xgr_drawBin(float *xdata, float *ydata, int n, int color)
int printKeySymHelp(void)
#define MAX_DATA_CHANNELS
int xgr_drawBox(double x, double y, double x2, double y2, int color)
int deNewLineIt(char *buf)
int myErrorHandler(Display *display, XErrorEvent *myerr)
int to_monitor(char *buf)
int xgr_drawText(double x, double y, char *msg, int clr, int f)
int freeDataPointers(void)
int determine_min_max(float *ydata, int dl, double scan)
struct WINDOW_HEAD windows
int verifyScanDone(int scn)
int xgr_freeWindows(struct XGR_ *s)
int stuffOtf(int plot, int *indxX, float *xArray, float *yArray)
int mainFrameRepaint(void)
struct MAIL_PARSE parse_table[]
int dummieEventProc(XEvent *event)
int getNumSpectra(double datalen, double noint)
int log_msg(const char *fmt,...)
XImage * createXimage(Display *display, int w, int h, int depth)
int found_scans[MAX_BACKENDS *MAX_PARTS]
int lsqfit(float x[], float y[], int bdata, int ndata, float sig[], int mwt, float *a, float *b, float *siga, float *sigb, float *chi2, float *q)
int displaySingleOtfSpectra(void)
int smart_log_open(char *name, int offset)
int do_linetotalmapoff(void)
int sock_send(struct SOCK *s, char *message)
struct STURCT_KEYSYMS keysyms[]
int checkIgnoreScans(int v, double s)
int displayArrayGraph(double xb, double xe, double yb, double ye)
int subtractPredictedRA(float *data)
int xgr_graphInit(struct XGR_ *s)
int xgr_reSizeProc(Window window, int width, int height)
int sock_sel(char *message, int *l, int *p, int n, int tim, int rd_in)
int xgr_eventProc(XEvent *event, Window window, unsigned int mask)
int displaySingleChan(double xb, double xe, double yb, double ye)
int do_toggleFixData(char *buf)
char * sock_name(struct SOCK *handle)
int argmatch(char *s1, char *s2, int atleast)
int set_sock_callback(int(*call)(void))
float bdata[MAX_ATM_ELEMENTS]
float xdata[MAX_ATM_ELEMENTS]
int readMail(char *buf, int len)
int do_otf(float *data, struct HEADER *head, float *offdata, float *gainsdata)
int peekScan(double scan, char *filename, int *be, int *modeid, struct HEADER *head)
struct BOUND * sock_bind(char *mbname)
int xgr_pixmapToWindow(char *name)
int myIOErrorHandler(Display *display, XErrorEvent *myerr)
struct SOCK * sock_connect(char *mbname)
int setCactusEnvironment(void)
char ** findFixedFonts(Display *dpy, int *num)
char * vxstrtok(char *string, char *last_token, char *delim)
int to_xgraphic(char *buf)
float ydata[MAX_ATM_ELEMENTS]
struct WINDOW * createWindow(struct XGR_ *s, char *title, int cw, int ch, int xpos, int ypos, int bg, int usPixmap, int which)
struct MAP_SCANS * map_scans_head
struct OTF_GRID ** gridArray
int scaleData(float *data)
#define PLOT_INT_INTENSITY
int xgr_mapUnmapWindow(char *name, int map)
int xgr_rePaintProc(Window window)
int xgr_checkForEvents(void)
int createWindows(struct XGR_ *s, char *title, int cw, int ch, int xpos, int ypos, int bg, int usPixmap)
int xgr_clearScreen(void)
int processEvent(struct XGR_ *s)
int xgr_setCurWindow(int win, int which)