3 #include "dataserv.bmp"
11 #define DATASPREAD (0.000001)
25 char *
months[] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
26 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" };
36 static char *spaces =
" ";
41 long frame_mask = KeyPressMask | ExposureMask | StructureNotifyMask;
62 {
"help", 0, 0, 0, 0, NULL, NULL, 4,
do_help,
"Displays this list"},
63 {
"quit", 0, 0, 0, 0, NULL, NULL, 4,
do_quit,
"Exit program"},
64 { NULL, 0, 0, 0, 0, NULL, NULL, 0, (
void *)0, NULL }
75 { XK_Up, 1,
"Up-Arrow",
"Move Integration Region Up" },
76 { XK_Down, 1,
"Down-Arrow",
"Move Integration Region Down" },
77 { XK_Up, 1,
"<Control> Up-Arrow",
"Move Upper Integration Channel Up" },
78 { XK_Down, 1,
"<Control> Down-Arrow",
"Move Upper Integration Channel Down" },
79 { XK_Up, 1,
"<shift> Up-Arrow",
"Move Lower Integration Channel Up" },
80 { XK_Down, 1,
"<shift> Down-Arrow",
"Move Lower Integration Channel Down" },
81 { XK_p, 1,
"<control> + p",
"Screen Capture Spectrum Plot" }
84 #define MAX_KEYSYMS (sizeof(keysyms) / sizeof(struct STURCT_KEYSYMS))
91 log_msg(
"To HELPER: '%s'", buf);
105 log_msg(
"To DATASERV: '%s'", buf);
127 sprintf(tbuf,
"Press the Following Keys in Either the OTF or Spectral Plot Windows\n");
129 printf(
"\n%s\n", tbuf);
139 sprintf(tbuf,
"Press %s key for %s", k->
key, k->
help);
140 printf(
"%s\n", tbuf);
146 sprintf(tbuf,
"Press the Following Keys Spectral Plot Windows\n");
148 printf(
"\n%s\n", tbuf);
158 sprintf(tbuf,
"Press %s key for %s", k->
key, k->
help);
159 printf(
"%s\n", tbuf);
176 cp = strtok(buf,
" \n\t");
178 sprintf(tbuf,
"Command Arguments\n");
179 printf(
"\n%s\n", tbuf);
183 for(p=parse_table;p->
msg;p++)
187 if(!strncmp(p->
msg, cp, strlen(cp)))
189 sprintf(tbuf,
"%s: %s", p->
msg, spaces);
190 strcpy(tbuf+18, p->
help);
191 printf(
"%s\n", tbuf);
198 sprintf(tbuf,
"%s: %s", p->
msg, spaces);
199 strcpy(tbuf+18, p->
help);
200 printf(
"%s\n", tbuf);
246 sprintf(tbuf,
"Chan: %4d; Intensity: %6.3fK", c, t);
261 XComposeStatus compose;
262 char buffer[1], tbuf[256];
263 char fname[256], sysBuf[256];
264 int bufsize=1, change = 0;
280 XLookupString((XKeyEvent *)event, buffer, bufsize, &keysym, &compose);
282 if(keysym == XK_p && event->xkey.state & ControlMask)
284 if(event->xkey.state & ControlMask)
286 sprintf(fname,
"SpectralPlot-%s.png",
getLogDate(0));
288 sprintf(sysBuf,
"import -w 0x%x %s", (
unsigned int)event->xany.window, fname);
294 printf(
"Created file: %s\n", fname);
298 if(keysym == XK_Up && event->xkey.state & ControlMask)
302 if(int_chans[1] > noint-1)
304 int_chans[1] = noint -1;
310 if(keysym == XK_Down && event->xkey.state & ControlMask)
314 if(int_chans[1] < int_chans[0])
316 int_chans[1] = int_chans[0];
322 if(keysym == XK_Up && event->xkey.state & ShiftMask)
326 if(int_chans[0] > int_chans[1])
328 int_chans[0] = int_chans[1];
334 if(keysym == XK_Down && event->xkey.state & ShiftMask)
351 if(int_chans[1] > noint-1)
353 int_chans[1] = noint -1;
356 if(int_chans[0] > int_chans[1])
358 int_chans[0] = int_chans[1];
364 if(keysym == XK_Down)
374 if(int_chans[1] < int_chans[0])
376 int_chans[1] = int_chans[0] +1;
389 sprintf(tbuf,
"otfchans %d %d", int_chans[0], int_chans[1]);
392 sprintf(tbuf,
"otf_bint_chan = %d /q", int_chans[0]);
394 sprintf(tbuf,
"otf_eint_chan = %d /q", int_chans[1]);
417 log_msg(
"doSpecPlotWinEvent()");
429 case ButtonPressMask:
442 if(
xgr_findWindow(event->xbutton.display, event->xbutton.window, &w))
444 log_msg(
"xgr_findWindow() returned Non Zero");
450 x = ((float)event->xbutton.x - (
float)w->
plotxb) / x - 0.5;
453 y = ((float)w->
plotye - (
float)
event->xbutton.y) / y - 0.5;
455 fchan = (float)im->
noint;
457 fchan = x * fchan + (fchan / 2.0);
466 if(chan > im->
noint-1)
473 log_msg(
"X = %f, Y = %f, Chan = %.2f, %d = %f", x, y, fchan, chan, im->
ydata[chan]);
483 char *
string, *last_token, *delim;
505 string[strlen(
string)+1] =
'\0';
507 }
else if(!last_token || !*last_token || !delim || !*delim)
511 ptr = last_token + strlen(last_token);
515 for(n=strlen(delim); *ptr; ptr++) {
516 for(i=0; i < n && *ptr != delim[i]; i++)
527 for( ; *ptr; ptr++) {
528 for(i=0; i < n && *ptr != delim[i]; i++)
544 static char cmdbuf[4096];
557 log_msg(
"readMail(): Got %d bytes, %s", len, buf);
559 if(buf || len <
sizeof(cmdbuf))
584 for(p=parse_table;p->
msg;p++)
586 if(!strncmp(p->
msg, buf, p->
len))
588 if(p->
log && strlen(buf) < 2048)
603 log_msg(
"Command %s NOT found", buf);
615 log_msg(
"Server %s caused IO Trap", DisplayString(display));
620 log_msg(
"Server: Unknown Server caused IO Trap");
634 log_msg(
"Server %s caused Xlib Error", DisplayString(display));
639 log_msg(
"Server: Unknown Server caused Xlib Error");
656 s = (
struct XGR_ *)p;
659 log_msg(
"Signal: Shuting Down Server %s", DisplayString(s->
dpy));
661 XCloseDisplay(s->
dpy);
669 log_msg(
"Exiting with status %d", status);
683 while(XPending(s->dpy))
685 XNextEvent(s->dpy, &event);
691 while (XCheckTypedWindowEvent(s->dpy, event.xany.window, Expose, &event))
700 case ConfigureNotify:
703 while (XCheckTypedWindowEvent(s->dpy, event.xany.window, ConfigureNotify, &event))
708 if(event.xconfigure.window && !event.xconfigure.send_event)
710 xgr_reSizeProc(event.xconfigure.window, event.xconfigure.width, event.xconfigure.height);
755 visual = DefaultVisual(display, DefaultScreen(display));
759 return((XImage *)NULL);
762 xi = XCreateImage(display, visual, (
unsigned int)depth, ZPixmap,0,
763 (
char *)NULL, (
unsigned int)w, (
unsigned int)h, 16, 0);
766 log_msg(
"XCreateImage failed");
767 return((XImage *)NULL);
770 ui = (unsigned)(xi->height*xi->bytes_per_line*
sizeof(
char));
771 if((xi->data=(
char *)malloc(ui))==NULL)
773 log_msg(
"Unable to malloc(%d) ximage in createXimage()", ui);
775 return((XImage *)NULL);
778 bzero((
char *)xi->data, xi->height * xi->bytes_per_line *
sizeof(
char));
808 log_msg(
"determine_min_max(): Scan #%7.2f is all %.4f", scan,
datamin);
823 char raStr[20], decStr[20], timeStr[20], mapStr[60], buf[256];
834 yr = (int)image->date;
835 mon = (
int)((image->date - (float)yr) * 100.0);
836 day = (int)((image->date - (
float)yr) * 10000.0 +0.5)-mon*100.0;
838 sprintf(buf,
"%16.16s %3d SCANS: %7.2f-%7.2f INT=%s DATE: %2d %s %2.2d",
843 timeStr, day,
months[mon-1], yr-2000);
849 sprintf(mapStr,
" Col %3d Row %3d ", image->col,image->row);
853 sprintf(mapStr,
"( %s %s )", raStr, decStr);
856 sprintf(buf,
"%s=%s %s %s CAL= %5.1f TSYS= %5.0f",
866 sprintf(buf,
"FREQ= %.2f SYN= %10.8f VEL= %7.1f DV= %6.2f FR= %4.0f SB= %d",
868 image->synfreq / 1000.0,
871 image->freqres * 1000.0,
875 sprintf(buf,
"Rms %8.3fK",image->rms);
884 float xb, xe, yb, ye;
898 data = &im->
ydata[0];
900 noint = (int)im->
noint;
917 if( (xdata = (
float *)malloc((
unsigned)(noint*
sizeof(
float)))) == NULL)
968 float xmin, xmax, ymin, ymax, yavg, xl, yt, xr, yb;
995 yavg = (ymax - ymin) / 15.0;
999 log_msg(
"Baselines: %d %d %d %d %d %d %d %d",
1012 if(im->baselines[i] > 0 && im->baselines[i+1] > 0 )
1014 xl = (float)im->baselines[i];
1015 xr = (
float)im->baselines[i+1];
1021 log_msg(
"Put Rectangles(): %f %f %f %f %f %f %f %f %f %f",
1022 startRes, im->freqres, xmin, xmax, ymin, ymax, xl, yt, xr, yb);
1030 if(im->int_beg >= 0 && im->int_end >= im->int_beg && im->int_end < im->noint-2)
1036 yavg = (ymax - ymin) / 15.0;
1038 xl = (float)im->int_beg;
1039 xr = (
float)im->int_end;
1062 int cw, ch, xpos, ypos, bg,
usPixmap, which;
1064 unsigned long value_mask;
1065 XSetWindowAttributes attr;
1066 XSizeHints size_hints;
1069 XTextProperty *wi, *ic;
1071 if((w = (
struct WINDOW *)calloc(1,
sizeof(
struct WINDOW ))) == NULL)
1073 log_msg(
"error in calloc for main Plot window");
1084 w->
win = XCreateSimpleWindow(s->dpy, RootWindow(s->dpy,s->scr_num),
1085 xpos, ypos, (
unsigned int)w->
canw,
1086 (
unsigned int)w->
canh,
1087 1, s->colors[
WHITE],
1093 if(!(w->
pixmap = XCreatePixmap(s->dpy, w->
win, (
unsigned int)w->
canw, (
unsigned int)w->
canh, s->depth)))
1102 XSelectInput(s->dpy,w->
win,
frame_mask | ButtonPressMask | Button1MotionMask);
1105 size_hints.flags = PPosition | PSize | PMinSize;
1106 size_hints.min_width = cw;
1107 size_hints.min_height = ch;
1108 size_hints.x = xpos;
1109 size_hints.y = ypos;
1111 w->
gc = XCreateGC(s->dpy, RootWindow(s->dpy, s->scr_num), (
unsigned long)0, (XGCValues *)NULL);
1115 w->
icon = XCreateBitmapFromData(s->dpy, w->
win, dataserv_bmp_bits,
1117 dataserv_bmp_height);
1119 XSetStandardProperties(s->dpy, w->
win,
1121 (
char **)NULL, 0, &size_hints);
1125 wm_hints.initial_state = NormalState;
1126 wm_hints.input = True;
1127 wm_hints.icon_pixmap = 0;
1128 wm_hints.flags = StateHint | InputHint | WindowGroupHint;
1129 wm_hints.window_group = w->
win;
1131 XSetWMProperties(s->dpy, w->
win, wi, ic, NULL, 0, &size_hints, &wm_hints, NULL);
1134 if(DoesBackingStore(XDefaultScreenOfDisplay(s->dpy)))
1138 log_msg(
"createWindow(): Setting Backing Store for Plot Window");
1141 value_mask = CWBackingStore;
1142 attr.backing_store = WhenMapped;
1143 XChangeWindowAttributes(s->dpy, w->
win, value_mask, &attr);
1146 XMapWindow(s->dpy, w->
win);
1149 XSetWindowBackground(s->dpy, w->
win, s->colors[w->
background]);
1150 XSetBackground(s->dpy, w->
gc, s->colors[w->
background]);
1151 XClearWindow(s->dpy, w->
win);
1163 int cw, ch, xpos, ypos, bg,
usPixmap;
1168 log_msg(
"DisplayInfo for %s - %s major %d minor %d release %d",
1169 DisplayString(s->dpy), ServerVendor(s->dpy), ProtocolVersion(s->dpy),
1170 ProtocolRevision(s->dpy), VendorRelease(s->dpy));
1172 s->xfd = XConnectionNumber(s->dpy);
1173 s->scr_num = DefaultScreen(s->dpy);
1176 s->windows.prev = s->windows.next = &s->windows;
1177 s->depth = XDefaultDepthOfScreen(XDefaultScreenOfDisplay(s->dpy));
1178 s->userXimage = NULL;
1198 static int block_for_event(
xfd, n)
1222 (*sock_callback)(
inMsg, len);
1243 s = (
struct XGR_ *)p;
1245 if(XPending(s->
dpy))
1258 f = (
struct XGR_ *)p2;
1263 xfd = block_for_event(xfds, n);
1267 f = (
struct XGR_ *)p2;
1271 if(XPending(f->
dpy) == 0)
1273 if(f->
dpy == server->
dpy)
1276 log_msg(
"Removeing %s in destoryFunc", DisplayString(f->
dpy));
1310 setpgid( (pid_t)0, (pid_t)0);
1315 signal(SIGTERM, (__sighandler_t)signalHandler);
1319 cp = getenv(
"LPSESSION");
1323 sprintf(
tfile,
"LOGDIR=/tmp/%s", cp);
1330 cp = getenv(
"DISPLAY");
1336 if((server=(
struct XGR_ *)calloc(1,
sizeof(
struct XGR_)))==NULL)
1338 log_msg(
"error in calloc for main server");
1351 if((server->
dpy = XOpenDisplay(
localHost)) == (Display *)NULL)
1365 strcpy(
title,
"Dataserv");
struct WINDOW_HEAD * prev
struct SOCK * last_msg(void)
int doSpecWinRepaint(void)
int xgr_drawBin(float *xdata, float *ydata, int n, int color)
int printKeySymHelp(void)
int xgr_drawBox(double x, double y, double x2, double y2, int color)
char * strcmprs(char *str)
int checkKeyPress(XEvent *event)
int deNewLineIt(char *buf)
int myErrorHandler(Display *display, XErrorEvent *myerr)
int log_perror(char *msg)
int xgr_drawText(double x, double y, char *msg, int clr, int f)
int determine_min_max(float *ydata, int dl, double scan)
struct WINDOW_HEAD windows
int log_eventdEnable(int enable)
char * getLogDate(int offset)
int xgr_freeWindows(struct XGR_ *s)
struct LP_IMAGE_INFO last_image
int display_image(double xb, double xe, double yb, double ye, struct DS_IMAGE_INFO *im)
int doSpecPlotWinEvent(XEvent *event, unsigned int mask)
struct MAIL_PARSE parse_table[]
struct OTF_STRUCT * myotf
int sexagesimal(double dang, char *str, int prec)
int sock_bufct(int bufct)
int log_msg(const char *fmt,...)
XImage * createXimage(Display *display, int w, int h, int depth)
int smart_log_open(char *name, int offset)
int sock_send(struct SOCK *s, char *message)
int putChanTemp(int c, double t)
struct STURCT_KEYSYMS keysyms[]
int xgr_findWindow(Display *dpy, Window win, struct WINDOW **w)
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_drawTextClear(double x, double y, char *msg, int clr, int f)
int xgr_eventProc(XEvent *event, Window window, unsigned int mask)
char * sock_name(struct SOCK *handle)
int xgr_setFont(struct XGR_ *s, int f)
int set_sock_callback(int(*call)(void))
float xdata[MAX_ATM_ELEMENTS]
int putHeader(struct DS_IMAGE_INFO *image)
int readMail(char *buf, int len)
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 doSpecPlot(struct DS_IMAGE_INFO *im)
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)
int xgr_mapUnmapWindow(char *name, int map)
int xgr_drawRectangle(double xmin, double xmax, double ymin, double ymax, double xl, double yt, double xr, double yb, int color, int bold)
int doSpecWinReSize(void)
int xgr_rePaintProc(Window window)
float ydata[MAX_DATA_CHANNELS]
int to_dataserv(char *buf)
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)