forked from ajmas/NewSRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmdfl.c
230 lines (225 loc) · 9 KB
/
cmdfl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include "d1cons.h"
#include "d1proto.h"
#include "d1typ.h"
#include "d1glob.h"
double cmdfile(void)
// reads command file
/* drives the schedule with stop time yyyy:ddd:hh:mm:ss
or LST:hh:mm:ss or just : for immediate scheduling
or :n for scheduling for n secs - will wait for source to be within limits
followed by keywords:
sourcename (any name in catalog)
stow
calibrate
quit
vplot // makes postscript of current integration
clearint // clears intergation
record (turns on data file if not already on) [filename] [recmode]
roff (turns off data file)
freq fcenter_MHz [bandwidth_MHz]
mode n for 25 point b for beamswitch
*/
{
double secs, secnow, lst, freq, bw;
int i, j, n, line, yr, day, hr, min, se, ss;
int da, mn, sc;
int ix, iy;
char str[256], txt[256];
char *p, *k;
FILE *file1;
GdkColor color;
if ((file1 = fopen(d1.cmdfnam, "r")) == NULL) {
printf(" Unable to open %s\n", d1.cmdfnam);
return 0.0;
}
secs = secnow = d1.secs;
i = 1;
line = 0;
ss = 0;
k = 0;
str[255] = 0;
while ((k = fgets(str, 80, file1)) != 0 && i == 1) {
line++;
// printf("line %d %s",line,str);
if (str[0] != '*' && str[0] != ' ' && str[0] != '#' && strlen(str) > 2 && line > d1.cmdfline) {
if (str[0] != 'L' && str[0] != ':') { // yyyy:ddd:hh:mm:ss
sscanf(str, "%d:%d:%d:%d:%d", &yr, &day, &hr, &min, &se);
secs = tosecs(yr, day, hr, min, se);
}
// d.dtext(440.0, ylim + 40.0, gg, Color.red, "cmd err " + str);
if (str[0] == 'L' && strstr(str, "LST")) { // "LST:%2d:%2d:%2d",&hr,&min,&sec
hr = min = se = 0;
sscanf(str, "LST:%d:%d:%d", &hr, &min, &se);
lst = gst(secnow) - d1.lon;
secs = hr * 3600.0 + min * 60.0 + se - lst * 86400.0 / (PI * 2.0);
if (secs < 0)
secs += 86400.0;
if (secs > 86400.0)
secs -= 86400.0;
if (secs < 0)
secs += 86400.0;
if (secs > 86400.0)
secs -= 86400.0;
secs += secnow;
}
// d.dtext(440.0, ylim + 40.0, gg, Color.red, "cmd err " + str);
if (str[0] == ':' && str[1] != ' ') {
ss = 0;
sscanf(str, ":%d", &ss);
secs += ss;
}
// d.dtext(440.0, ylim + 40.0, gg, Color.red, "cmd err " + str);
for (n = 0; n < (int) strlen(str); n++)
if (str[n] == '\n')
str[n] = ' ';
if (secs >= secnow) {
// System.out.println("secs "+secs+" secnow "+secnow);
for (j = 0; j < d1.nsou; j++) {
if ((p = strstr(str, sounam[j]))) {
strncpy(soutrack, sounam[j], sizeof(soutrack) - 1);
if (ss < 2)
secs += 2; // add time
d1.track = 1;
d1.bsw = 0;
d1.azoff = 0;
d1.eloff = 0;
// check for mode
if (p && *p) { // note p before *p
p = strchr(p, ' ');
if (p && *p) {
if (strchr(p, 'n')) {
d1.scan = 1;
}
if (strchr(p, 'b')) {
d1.bsw = 1;
}
}
}
if (!d1.noclearint && !d1.scan && !d1.bsw)
d1.clearint = 1; // clear integration on source change
}
}
if (strstr(str, "azel")) {
j = sscanf(str, "%*s %*s %lf %lf", &d1.azcmd, &d1.elcmd);
if (j == 2) {
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);
printf("cmdf %s", str);
}
if (ss < 2)
secs += 2; // add time
d1.track = 0;
soutrack[0] = 0;
}
}
if (strstr(str, "offset")) {
sscanf(str, "%*s %*s %lf %lf", &d1.azoff, &d1.eloff);
sprintf(d1.recnote, "* entered azoff %lf eloff %lf\n", d1.azoff, d1.eloff);
outfile(d1.recnote);
}
if (strstr(str, "stow")) {
if (d1.stowatlim) {
d1.azcmd = d1.azlim1;
d1.elcmd = d1.ellim1;
} else {
d1.azcmd = d1.stowaz;
d1.elcmd = d1.stowel;
}
soutrack[0] = 0;
d1.stow = 1;
}
if (strstr(str, "calibrate"))
d1.docal = 1;
if (strstr(str, "record")) {
d1.record = 1;
if (sscanf(str, "%*s %*s %255s", d1.filname) == 1)
d1.foutstatus = 1;
}
if (strstr(str, "quit") && d1.stow == -1) {
d1.run = 0;
gtk_exit(0);
}
if (strstr(str, "roff")) {
d1.record = 0;
if (d1.displ) {
color.green = 0xffff;
color.red = 0xffff;
color.blue = 0xffff;
gtk_widget_modify_bg(button_record, GTK_STATE_NORMAL, &color);
}
}
if (strstr(str, "vplot")) {
velspec();
button_psw_clicked();
}
if (strstr(str, "clearint"))
d1.clearint = 1;
if (strstr(str, "freq")) {
bw = d1.bw;
sscanf(str, "%*s %*s %lf %lf", &freq, &bw);
if (bw > 0 && bw <= 10.0)
if (freq > 1200.0 && freq < 1800.0) {
d1.freq = freq;
d1.f1 = 0.5 - bw * 0.5;
d1.f2 = 0.5 + bw * 0.5;
d1.fc = (d1.f1 + d1.f2) * 0.5;
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);
printf("new freq %f %f\n", d1.freq, d1.freq);
}
sprintf(d1.recnote, "* entered freq %lf nfreq %d\n", d1.freq, d1.nfreq);
outfile(d1.recnote);
d1.freqchng = 1;
}
}
}
i = 0;
ix = midx * 1.05;
iy = midy * 0.99;
if (d1.displ && str[0]) {
color.red = 0;
color.green = 0xffff;
color.blue = 0;
gdk_color_parse("green", &color);
gtk_widget_modify_fg(drawing_area, GTK_STATE_NORMAL, &color);
gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix,
iy - midy * 0.04, midx * 0.4, midy * 0.05);
sprintf(txt, "line %2d %s", line, str);
gdk_draw_text(pixmap, fixed_font, drawing_area->style->fg_gc[GTK_STATE_NORMAL], ix,
iy, txt, strlen(txt) - 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);
printf("line %2d %s\n", line, str);
}
}
}
d1.cmdfline = line;
fclose(file1);
if (k == 0) {
if (d1.displ) {
ix = midx * 1.05;
iy = midy * 0.99;
color.red = 0;
color.green = 0xffff;
color.blue = 0;
gdk_color_parse("green", &color);
gtk_widget_modify_fg(drawing_area, GTK_STATE_NORMAL, &color);
gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix,
iy - midy * 0.04, midx * 0.4, midy * 0.05);
sprintf(txt, "line %2d : end_of_file", line);
gdk_draw_text(pixmap, fixed_font, drawing_area->style->fg_gc[GTK_STATE_NORMAL], ix,
iy, txt, strlen(txt) - 1);
}
d1.cmdfl = 0;
d1.cmdfline = 0;
}
return secs;
}