void cal(int mode) // command cal { int k; int ix, iy, midxr, ixe; char txt[80]; double av; float wtt[NSPEC]; GdkColor color; if (mode == 0) { for (k = 0; k < d1.nfreq; k++) bbspec[k] = 0; zerospectra(0); d1.calon = 1; } if (mode == 1) for (k = 0; k < d1.nfreq; k++) bbspec[k] += spec[k]; if (mode == 2) { d1.calon = 0; for (k = 0; k < d1.nfreq; k++) { if (k > d1.f1 * d1.nfreq && k < d1.f2 * d1.nfreq) wtt[k] = 1; else wtt[k] = 0; } polyfitr(NPOLY, d1.nfreq, bbspec, wtt, bspec); // for(k=0;k < d1.nfreq; k++) bspec[k] = bbspec[k]; k = d1.fc * d1.nfreq; av = bspec[k]; for (k = 0; k < d1.nfreq; k++) bspec[k] = bspec[k] / av; d1.calpwr = av / d1.integ; // if(d1.yfac > 2) d1.tsys = 290.0 /(d1.yfac - 1.0); // put in manually d1.caldone = 1; printf("yfac %f tsys %f pwr %f pwrprev %f\n", d1.yfac, d1.tsys, pwr, pwrprev); if (d1.displ) { color.green = 0xffff; color.red = 0; color.blue = 0; gdk_color_parse("green", &color); gtk_widget_modify_bg(button_cal, GTK_STATE_NORMAL, &color); } } ix = midx * 1.55; ixe = midx * 0.4; midxr = midx * 2 - ix; sprintf(txt, "calibration in progress"); iy = midy * 0.1; if (d1.displ && mode) gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); iy = midy * 0.1; if (d1.displ && !mode) { gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); } if (d1.debug) printf("incal mode %d\n", mode); return; }
void cal(int mode) // command cal { int k; int ix, iy, midxr, ixe; char txt[80]; double av, max, maxf, p, a; float wtt[NSPEC]; GdkColor color; if (mode == 0) { for (k = 0; k < d1.nfreq; k++) bbspec[k] = 0; zerospectra(0); d1.calon = 1; d1.integ3 = 0; } if (mode == 1) { for (k = 0; k < d1.nfreq; k++) bbspec[k] += spec[k]; d1.integ3++; } if (mode == 2) { d1.calon = 0; max = -1e99; maxf = 0; for (k = 0; k < d1.nfreq; k++) { if (k > d1.f1 * d1.nfreq && k < d1.f2 * d1.nfreq) wtt[k] = 1; else wtt[k] = 0; if (spec[k] > max) { max = spec[k]; maxf = k * d1.bw / d1.nfreq + d1.efflofreq; } } if (d1.npoly > NPOLY) d1.npoly = NPOLY; polyfitr(d1.npoly, d1.nfreq, bbspec, wtt, bspec); // for(k=0;k<d1.nfreq;k+=10) printf("k %d wtt %f bbspec %f\n",k,wtt[k],bbspec[k]); if (d1.npoly == 1) for (k = 0; k < d1.nfreq; k++) bspec[k] = bbspec[k]; p = a = 0; for (k = 0; k < d1.nfreq; k++) { if (wtt[k]) { p += bspec[k]; a++; } } av = p / a; for (k = 0; k < d1.nfreq; k++) bspec[k] = bspec[k] / av; d1.calpwr = p / (a * d1.integ3); if (d1.yfac > 1.5 && d1.calmode == 20) d1.tsys = (d1.tcal - d1.yfac * 3.0) / (d1.yfac - 1.0); // put in Tsys assumes CMB of 3 K if (d1.calmode == 0) printf("yfac %f Tsys %f\n", d1.yfac, 290.0 / (d1.yfac - 1.0)); if (d1.caldone == 0 && d1.calmode != 2 && d1.calmode != 3) printf("yfac %f tsys %f pwr %f pwrprev %f calmode %d max_pwr %8.3f MHz\n", d1.yfac, d1.tsys, pwr, pwrprev, d1.calmode, maxf); d1.yfac = 0; // for next cal d1.caldone = 1; if (d1.displ) { color.green = 0xffff; color.red = 0; color.blue = 0; gdk_color_parse("green", &color); gtk_widget_modify_bg(button_cal, GTK_STATE_NORMAL, &color); } } ix = midx * 1.55; ixe = midx * 0.4; midxr = midx * 2 - ix; sprintf(txt, "calibration in progress"); iy = midy * 0.1; if (d1.displ && mode) gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); iy = midy * 0.1; if (d1.displ && !mode) { gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); } if (d1.debug) printf("incal mode %d\n", mode); return; }
int main(int argc, char *argv[]) { GtkWidget *window; GtkWidget *button_clear, *button_azel, *button_freq, *button_offset; GtkWidget *button_help; GdkColor color; int i, ii; int yr, da, hr, mn, sc; double secstart; char buf[64]; GdkGeometry geometry; GdkWindowHints geo_mask; // GdkRectangle update_rect; sprintf(d1.catnam, "srt.cat"); sprintf(d1.hlpnam, "srt.hlp"); for (i = 0; i < argc - 1; i++) { sscanf(argv[i], "%63s", buf); if (strstr(buf, "-c") && strlen(buf) == 2) sscanf(argv[i + 1], "%63s", d1.catnam); if (strstr(buf, "-h") && strlen(buf) == 2) sscanf(argv[i + 1], "%63s", d1.hlpnam); } // d1.azelport = 0x3f8; // com1 default for old SRT d1.ver = 4; // SRT software version d1.secs = readclock(); d1.run = 1; d1.record = 0; d1.entry1 = d1.entry2 = d1.entry3 = d1.entry5 = d1.entry6 = d1.entry8 = d1.helpwindow = d1.vwindow = 0; d1.plot = 0; d1.start_time = 0.0; d1.start_sec = 0.0; d1.speed_up = 0; d1.ppos = 0; d1.printout = 1; d1.debug = 0; d1.freq = 1420.4; // default d1.bw = 0; // set to 2.4 for TV dongle 10 MHz for ADC card in init d1.fbw = 0; // set in init or srt.cat d1.nblk = 5; // number of blocks in vspectra d1.record_int_sec = 0; d1.freqcorr = 0; // frequency correction for L.O. may be needed for TV dongle d1.freqchng = 0; d1.clearint = 0; d1.record_clearint = 0; d1.noclearint = 0; d1.nfreq = NSPEC; d1.plotsec = 1; d1.displ = 1; d1.noisecal = 0; // used for old SRT mount and controller // d1.ptoler = 1; // d1.countperstep = 10000; // default large number for no stepping // d1.elcounts_per_deg = (52.0 * 27.0 / 120.0); // default for H-180 // d1.azcounts_per_deg = 8.0 * 32.0 * 60.0 / (360.0 * 9.0); // default for CASSIMOUNT // d1.rod = 1; // default to rod as on CASSIMOUNT // d1.rod1 = 14.25; // rigid arm length // d1.rod2 = 16.5; // distance from pushrod upper joint to el axis // d1.rod3 = 2.0; // pushrod collar offset // d1.rod4 = 110.0; // angle at horizon // d1.rod5 = 30.0; // pushrod counts per inch d1.azelsim = d1.radiosim = d1.fftsim = 0; d1.mainten = 0; d1.stowatlim = 1; d1.rms = -1; // display max not rms d1.calcons = 1.0; d1.caldone = 0; d1.nrfi = 0; d1.rfisigma = 6; // level for RFI reporting to screen d1.tload = 300.0; d1.tspill = 20.0; d1.beamw = 5.0; d1.comerr = 0; d1.limiterr = 0; d1.restfreq = 1420.406; /* H-line restfreq */ d1.delay = 0; d1.azoff = 0.0; d1.eloff = 0.0; d1.drift = 0; d1.tstart = 0; d1.tsys = 100.0; // expected on cold sky d1.pwroff = 0.0; d1.tant = 100.0; d1.calpwr = 0; d1.yfac = 0; d1.calon = 0; d1.calmode = 0; d1.docal = 0; d1.tcal = 290; // absorber or bushes d1.sourn = 0; d1.track = 0; d1.scan = 0; d1.bsw = 0; d1.nbsw = 1; d1.obsn = 0; d1.stopproc = 0; d1.fstatus = 0; d1.cmdfl = 0; d1.south = 1; d1.hgt = 0; d1.dongle = 0; // set to zero initially - set to 1 in Init_Device if dongle d1.npoly = 25; // number of terms in polynomial fit of bandpass pwrst = pwrprev = 0.0; soutrack[0] = 0; sprintf(d1.cmdfnam, "cmd.txt"); sprintf(d1.datadir, "./"); // default to local directory if (!catfile()) return 0; d1.foutstatus = 0; // to get permission su root chown root srtn then chmod u+s srtn then exit if (!d1.azelsim) { if (d1.printout) printf("initializing antenna controller\n"); i = rot2(&d1.aznow, &d1.elnow, -1, buf); // initialize i = rot2(&d1.aznow, &d1.elnow, 1, buf); // read if (i < 0) { printf("Couldn't talk to antenna controller\n"); return 0; } } else { if (d1.stowatlim) { d1.azprev = d1.azlim1; d1.elprev = d1.ellim1; } else { d1.azprev = d1.stowaz; d1.elprev = d1.stowel; } } setgid(getgid()); setuid(getuid()); if (d1.mainten == 0) { if (d1.stowatlim) { d1.azcmd = d1.azlim1; d1.elcmd = d1.ellim1; } else { d1.azcmd = d1.stowaz; d1.elcmd = d1.stowel; } d1.azcount = 0; d1.elcount = 0; d1.stow = 1; } if (d1.azlim1 > d1.azlim2) { d1.south = 0; // dish pointing North for southern hemisphere if (d1.azlim2 < 360.0) d1.azlim2 += 360.0; } if (!d1.radiosim) Init_Device(0); if (d1.displ) { gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); geometry.min_width = 500; geometry.min_height = 300; geo_mask = GDK_HINT_MIN_SIZE; gtk_window_set_geometry_hints(GTK_WINDOW(window), window, &geometry, geo_mask); //Table size determines number of buttons across the top table = gtk_table_new(30, NUMBUTTONS, TRUE); drawing_area = gtk_drawing_area_new(); gtk_window_set_default_size(GTK_WINDOW(window), 800, 600); color.red = 0xffff; color.blue = 0xffff; color.green = 0xffff; gtk_widget_show(drawing_area); gtk_table_attach_defaults(GTK_TABLE(table), drawing_area, 0, NUMBUTTONS, 3, 30); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(quit), NULL); gtk_container_add(GTK_CONTAINER(window), table); g_signal_connect(G_OBJECT(drawing_area), "expose_event", (GtkSignalFunc) expose_event, NULL); g_signal_connect(G_OBJECT(drawing_area), "configure_event", (GtkSignalFunc) configure_event, NULL); g_signal_connect(G_OBJECT(drawing_area), "button_press_event", (GtkSignalFunc) button_press_event, NULL); gtk_widget_set_events(drawing_area, GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); button_clear = gtk_button_new_with_label("clear"); button_stow = gtk_button_new_with_label("stow"); button_azel = gtk_button_new_with_label("azel"); button_npoint = gtk_button_new_with_label("npoint"); button_bsw = gtk_button_new_with_label("beamsw"); button_freq = gtk_button_new_with_label("freq"); button_offset = gtk_button_new_with_label("offset"); button_record = gtk_button_new_with_label("record"); button_cmdfl = gtk_button_new_with_label("cmdfl"); button_cal = gtk_button_new_with_label("cal"); button_help = gtk_button_new_with_label("help"); button_exit = gtk_button_new_with_label("exit"); g_signal_connect(G_OBJECT(button_clear), "clicked", G_CALLBACK(button_clear_clicked), NULL); g_signal_connect(G_OBJECT(button_stow), "clicked", G_CALLBACK(button_stow_clicked), NULL); g_signal_connect(G_OBJECT(button_azel), "clicked", G_CALLBACK(button_azel_clicked), NULL); g_signal_connect(G_OBJECT(button_npoint), "clicked", G_CALLBACK(button_npoint_clicked), NULL); g_signal_connect(G_OBJECT(button_bsw), "clicked", G_CALLBACK(button_bsw_clicked), NULL); g_signal_connect(G_OBJECT(button_freq), "clicked", G_CALLBACK(button_freq_clicked), NULL); g_signal_connect(G_OBJECT(button_offset), "clicked", G_CALLBACK(button_offset_clicked), NULL); g_signal_connect(G_OBJECT(button_record), "clicked", G_CALLBACK(button_record_clicked), NULL); g_signal_connect(G_OBJECT(button_cmdfl), "clicked", G_CALLBACK(button_cmdfl_clicked), NULL); g_signal_connect(G_OBJECT(button_cal), "clicked", G_CALLBACK(button_cal_clicked), NULL); g_signal_connect(G_OBJECT(button_help), "clicked", G_CALLBACK(button_help_clicked), NULL); g_signal_connect(G_OBJECT(button_exit), "clicked", G_CALLBACK(button_exit_clicked), NULL); // test setting up tooltips instead of the "enter"/"leave" used below tooltips = gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips, button_clear, "click to clear integration and reset time plot to 1/4-scale", NULL); gtk_tooltips_set_tip(tooltips, button_stow, "click to stow antenna", NULL); gtk_tooltips_set_tip(tooltips, button_azel, "click to enter az el coordinates", NULL); gtk_tooltips_set_tip(tooltips, button_npoint, "click to start npoint scan", NULL); gtk_tooltips_set_tip(tooltips, button_bsw, "click to start beam switch", NULL); gtk_tooltips_set_tip(tooltips, button_freq, "click to enter new frequency in MHz [bandwidth] [nfreq]", NULL); gtk_tooltips_set_tip(tooltips, button_offset, "click to enter offsets", NULL); if (!d1.cmdfl) gtk_tooltips_set_tip(tooltips, button_cmdfl, "click to start cmd file", NULL); else gtk_tooltips_set_tip(tooltips, button_cmdfl, "click to stop cmd file", NULL); gtk_tooltips_set_tip(tooltips, button_cal, "click to start calibration", NULL); gtk_tooltips_set_tip(tooltips, button_help, "click to open help window", NULL); record_tooltip(); gtk_table_attach(GTK_TABLE(table), button_clear, 0, 1, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_stow, 1, 2, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_azel, 2, 3, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_npoint, 3, 4, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_bsw, 4, 5, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_freq, 5, 6, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_offset, 6, 7, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_record, 7, 8, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_cmdfl, 8, 9, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_cal, 9, 10, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_help, 10, 11, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_exit, 11, 12, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show(button_clear); gtk_widget_show(button_stow); gtk_widget_show(button_azel); gtk_widget_show(button_npoint); gtk_widget_show(button_bsw); gtk_widget_show(button_freq); gtk_widget_show(button_offset); gtk_widget_show(button_record); gtk_widget_show(button_cmdfl); gtk_widget_show(button_cal); gtk_widget_show(button_help); gtk_widget_show(button_exit); gtk_widget_show(table); gtk_widget_show(window); clearpaint(); } ii = 0; if (d1.printout) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource); } zerospectra(0); for (i = 0; i < d1.nfreq; i++) bspec[i] = 1; secstart = d1.nsecstart = -1; d1.secs = readclock(); while (d1.run) { zerospectra(1); if (d1.clearint) { if (d1.displ) cleararea(); zerospectra(0); d1.clearint = 0; } if (d1.freqchng) { if (d1.dongle) Init_Device(1); if (d1.printout) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource); } if (!d1.radiosim) { sleep(1); } zerospectra(0); d1.freqchng = 0; } if (d1.docal) { if (d1.docal == 1) { sprintf(d1.recnote, "* calibration started\n"); outfile(d1.recnote); } if (d1.bsw) { d1.bsw = 0; d1.azoff = 0.0; } if (d1.scan) { d1.scan = 0; d1.eloff = d1.azoff = 0.0; } if (d1.slew) d1.slew = 0; if (d1.docal == 1) cal(0); d1.docal = 2; cal(1); if (d1.integ >= NCAL) { cal(2); d1.docal = 0; } } if (d1.displ) cleararea(); azel(d1.azcmd, d1.elcmd); // allow time after cal if (d1.comerr == -1) return 0; if (!d1.slew) { pwr = 0.0; } if (!d1.slew) vspectra(); d1.secs = readclock(); aver(); d1.integ2++; if (d1.record_int_sec && d1.integ2 >= d1.record_int_sec) { outfile(" "); if (d1.record_clearint && d1.track && !d1.bsw && !d1.scan) d1.clearint = 1; d1.integ2 = 0; } if (d1.displ) { if (!d1.plot) Repaint(); while (gtk_events_pending() || d1.stopproc == 1) { gtk_main_iteration(); d1.plot = 0; } } if (!d1.displ && d1.domap) scanplot(); } return 0; }