-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.c
More file actions
executable file
·2531 lines (2435 loc) · 70.4 KB
/
Copy pathgui.c
File metadata and controls
executable file
·2531 lines (2435 loc) · 70.4 KB
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* gui.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include "display.h"
#include "version.h"
#include "sysres.h"
#include "sio.h"
#include "fk.h"
#ifndef WIN32
#define _strdup strdup
#endif
#define MAXNF 256
double eval_f(char *);
double gr_etime(void);
double resp_rms(double *, double *);
int access(char *, int);
int alloc_mem(int);
int chk_overwrite(char *);
int describe_position(char *, int, int);
int display_wave(float *, int, int, double, PLTFMT *);
int eval_i(char *);
int getnum(char *, double *, char *);
int get_usr_var(char *, double *, char *);
int gr_can_print(void);
int gr_edit(char *);
int gr_find(char *, char *, int);
int gr_pbstr(char *);
int print_screen(char *, char *, int, int);
int read_config(char *, char *, PGMCFG *);
int read_data_ascii(char *, char *, PGMCFG *);
int read_data_mat(char *, char *, PGMCFG *);
int read_stim_mat(char *, char *, PGMCFG *);
int set_usr_var(char *, char *, char *);
int spectral_average(int);
int stim_compute(int, char *);
int write_config(char *, char *, PGMCFG *);
int write_data_ascii(char *, char *, PGMCFG *);
int write_data_mat(char *, char *, PGMCFG *);
int write_stim_mat(char *, char *, PGMCFG *);
void cal_create(char *);
void cal_read(char *);
void cal_tones(double, double, char *);
void clr_all(void);
void clr_hist(void);
void dp_cp(char *);
void dp_mp(char *);
void display_fft(float *, PLTFMT *, int);
void display_frame(PGMCFG *, PLTFMT *, char *, int);
void display_rte(float *, int, int, double, PLTFMT *);
void dp_compute(void);
void dp_stim(char *);
void drop_suid(void);
void dump_hist(FILE *);
void free_mem(void);
void gr_beep(void);
void gr_close(void);
void gr_exit_incl(void);
void gr_get_cwd(char *, int);
void gr_getline(char *, char *, int);
void gr_getprompt(char *, char *, int);
void gr_init(void);
void gr_prcl(char *);
void gr_set_cwd(char *);
void gr_sleep(double);
void log_file(int);
void masking_msg(char *, char *);
void prn_devlst(void);
void prn_help(void);
void prn_msg(char *);
void prn_msg2(char *);
void prn_top(PGMCFG *, char *);
void resp_bp(int);
void resp_ft(int);
void resp_norm(void);
void resp_vpu(void);
void set_ic(int);
void stim_ft(int);
void stim_scale(int);
void test_tone(char *msg);
void write_help(char *, char *);
void write_nfo_file(char *);
extern char *no_dev;
extern double reject_thresh, dpn_sb, splref, stime, samp_val;
extern double tone_attn1, tone_attn2, tone_attn3, swpskp;
extern float *st, *rt, *sf, *rf;
extern int dc_remove, nsab, logflg, debug;
extern int nrej, reject_mode, wtav_mode;
extern int nsch, nrch, nrcp, sio_present, inclev, ntwb;
extern FILE *lfp[8];
extern PGMCFG cf;
extern PLTFMT pf;
extern int ycmd, xpix, ypix, cw, ch;
static char cfgfn[80] = "";
static char comment[80] = "";
static char crn[20] = "";
static char datfn[80] = "";
static char *def_ascfn = "sysres.txt";
static char *def_cfgfn = "sysres.cfg";
static char *def_datfn = "sysres.mat";
static char *def_nrmfn = "sysres.mat";
static char *def_prnfn = "sysres.prn";
static char *help_fn = "help.txt";
static char idstr[20] = "";
static char lstfn[80] = "";
static char msg[300] = "";
static char nrmfn[80] = "";
static char *po[2] = {"Landscape", "Portrait"};
static char *pt[3] = {"PostScript", "PCL", "Color PostScript"};
static char *ramp_name[] = {
"None", "Linear", "Cosine", "Blackman", "Exponential",
"Lissajous", "Proscan", "Nuttall"
};
static char nfofn[80] = DEFNFO;
static char stmfn[80] = "";
static int nrt = sizeof(ramp_name) / sizeof(ramp_name[0]);
static double ad_atten = 0;
static double da_atten = 0;
void
init_sio(char *s)
{
prn_msg("locate sio device...");
sio_set_device(SIO_PREF_SYNC); // look for a 24-bit card
prn_msg("open sio...");
sio_set_channel_offset(cf.choi, cf.choo);
sio_present = sio_open();
if (sio_present) {
sio_get_device(s);
} else {
strcpy(s,"No sio device.");
}
stim_compute(2, msg); // zero stimulus
play_zero(8);
}
void
newext(char *f, char *e)
{
char *s = f;
while (*s >= ' ') /* locate end of filename */
s++;
while (*s != '\\' && *s != '/' && s > f) /* backup to start of name */
s--;
while (*s >= ' ' && *s != '.') /* locate end of name */
s++;
while (*e >= ' ') /* copy extension */
*s++ = *e++;
*s = '\0';
}
int
hasext(char *f)
{
char *s = f;
int e = 0;
while (*s >= ' ') /* locate end of filename */
s++;
while (*s != '\\' && *s != '/' && s > f) { /* backup to start of name */
s--;
if (*s == '.')
e++;
}
return (e);
}
void
trim(char *s)
{
char *p;
for (p = s; *p >= ' '; p++) /* locate end of string */
continue;
while (p > s && p[-1] <= ' ') /* backup over trailing spaces */
p--;
if (*p)
*p = '\0'; /* truncate string */
}
void
strip_comment(char *s)
{
char *p;
for (p = s; *p && *p != ';'; p++) /* locate comment or EOL */
continue;
while (p > s && p[-1] <= ' ') /* backup over trailing spaces */
p--;
if (*p)
*p = '\0'; /* truncate string */
}
void
defext(char *f, char *e)
{
trim(f);
if (!hasext(f))
newext(f, e);
}
void
basename(char *b, char *f, int n)
{
char *s = f;
while (*s >= ' ') /* locate end of filename */
s++;
while (*s != '\\' && *s != '/' && s > f) /* backup to start of name */
s--;
while (*s == '\\' && *s == '/') /* advance past slash */
s++;
f = s;
while (*f >= ' ' && *f != '.' && (f - s) < n) /* copy name */
*b++ = *f++;
*b = '\0';
}
int
read_list(char *msg)
{
lfp[inclev] = fopen(lstfn, "rt");
if (lfp[inclev] == NULL) {
sprintf(msg, "Can't read list file (%s).", lstfn);
return (0);
}
inclev++;
return (1);
}
void
write_list(char *msg)
{
FILE *fp;
static char *fn = "sysres.lst";
fp = fopen(fn, "wt");
if (fp == NULL) {
sprintf(msg, "Can't open list file for writing (%s).", fn);
}
dump_hist(fp);
fclose(fp);
sprintf(msg, "Wrote command list to file (%s).", fn);
}
void
exit_list(void)
{
while (inclev > 0) {
fclose(lfp[--inclev]);
}
}
void
masking_query(char *s)
{
int c, d, e;
double v;
c = s[1];
d = s[2];
e = s[3];
if (e == '=') {
v = eval_f(s + 4);
switch(c) {
case 'a':
if (d == '1') {
tone_attn1 = v;
} else if (d == '2') {
tone_attn2 = v;
}
break;
case 'f':
if (d == '1') {
cf.f1 = v;
} else if (d == '2') {
cf.f2 = v;
}
break;
case 'm':
if (d == 'r') {
tm.mr = v;
} else if (d == 's') {
tm.ms = v;
} else if (d == 'd') {
tm.md = v;
}
break;
case 'p':
if (d == 'g') {
tm.pg = v;
} else if (d == 'd') {
tm.pd = v;
}
break;
case 't':
if (d == 'v') {
tm.tv = v;
} else if (d == 'd') {
tm.td = v;
}
break;
}
} else if (c == 's' && d <= ' ') {
cf.f1 = 4000;
cf.f2 = 4000;
cf.f3 = 0;
tm.mr = 2;
tm.pd = 2;
swpskp = 0;
}
}
static double
adjust_f(double f)
{
int n;
if (cf.rate > 0 && cf.ncal > 0) {
n = (int) (cf.ncal * f / cf.rate + 0.5);
f = n * cf.rate / cf.ncal;
}
return (f);
}
static void
attn_msg(int flg)
{
if (flg == 3 || cf.f3 > 0)
sprintf(msg, "att1=%.1f att2=%.1f att3=%.1f (dB)",
tone_attn1, tone_attn2, tone_attn3);
else
sprintf(msg, "att1=%.1f att2=%.1f (dB)", tone_attn1, tone_attn2);
prn_msg(msg);
}
static void
cho_msg(void)
{
sprintf(msg, "channel offset: in=%d out=%d", cf.choi, cf.choo);
prn_msg(msg);
sio_set_channel_offset(cf.choi, cf.choo);
sio_present = sio_open();
}
static void
cd_msg(char *s)
{
int n;
static int m = 58;
n = strlen(s);
if (n > m) {
strcpy(s, "...");
strcat(s, s + (n - m + 4));
}
sprintf(msg, "current directory = %.*s", n, s);
prn_msg(msg);
}
static void
freq_msg(int flg)
{
if (flg == 3 || cf.f3 > 0) {
sprintf(msg, "f1=%.0f f2=%.0f f3=%.0f Hz",
cf.f1, cf.f2, cf.f3);
} else {
sprintf(msg, "f1=%.0f f2=%.0f Hz", cf.f1, cf.f2);
}
prn_msg(msg);
}
static void
levl_msg(int flg)
{
if (flg == 3 || cf.f3 > 0)
sprintf(msg, "levl1=%.1f levl2=%.1f levl3=%.1f (dB)",
cf.l1, cf.l2, cf.l3);
else
sprintf(msg, "levl1=%.1f levl2=%.1f (dB)", cf.l1, cf.l2);
prn_msg(msg);
}
void
l1eq(char *s, int set)
{
char *p;
double a0, a1;
int i;
static double c[4] = {0};
static int o = 0;
if (strlen(s) > 0) {
for (i = 0; i < 4; i++)
c[i] = 0;
o = 0;
p = s;
while (*p && o < 4) {
while (*p == ' ' || *p == '+')
p++;
c[o++] = eval_f(p);
while (*p && *p != ' ' && *p != '+')
p++;
}
}
if (set && o) {
a0 = cf.l2;
a1 = cf.lpma[1];
cf.l1 = c[0] + c[1] * a0;
cf.lpma[0] = c[1] * a1;
cf.lpmb[0] = c[2];
cf.lpmc[0] = c[3];
cf.lpnc[0] = cf.lpnc[1];
cf.lpph[0] = cf.lpph[1];
}
sprintf(msg, "L1 =");
for (i = 0; i < o; i++) {
sprintf(msg + strlen(msg), " %.3g", c[i]);
}
prn_msg(msg);
}
void
l3eq(char *s, int set)
{
char *p;
double a0, a1;
int i;
static double c[4] = {0};
static int o = 0;
if (strlen(s) > 0) {
for (i = 0; i < 4; i++)
c[i] = 0;
o = 0;
p = s;
while (*p && o < 4) {
while (*p == ' ' || *p == '+')
p++;
c[o++] = eval_f(p);
while (*p && *p != ' ' && *p != '+')
p++;
}
}
if (set && o) {
a0 = cf.l2;
a1 = cf.lpma[1];
cf.l3 = c[0] + c[1] * a0;
cf.lpma[2] = c[1] * a1;
cf.lpmb[2] = c[2];
cf.lpmc[2] = c[3];
cf.lpnc[2] = cf.lpnc[1];
cf.lpph[2] = cf.lpph[1];
}
sprintf(msg, "L3 =");
for (i = 0; i < o; i++) {
sprintf(msg + strlen(msg), " %.3g", c[i]);
}
prn_msg(msg);
}
static void
lp_msg(int mpi)
{
sprintf(msg,
"Lissajous path %d: nc=%.0f ph=%.0f (deg) ma,mb,mc=%.0f,%.0f,%.0f (dB)",
mpi + 1, cf.lpnc[mpi], cf.lpph[mpi],
cf.lpma[mpi], cf.lpmb[mpi], cf.lpmc[mpi]);
prn_msg(msg);
}
static void
am_msg(void)
{
sprintf(msg,
"amplitude modulation: in=%.2f %.2f %.2f; nc=%.0f %.0f %.0f (Hz)",
cf.amin[0], cf.amin[1], cf.amin[2],
cf.amnc[0], cf.amnc[1], cf.amnc[2]);
prn_msg(msg);
}
static void
dbms_msg(int flg)
{
if (flg == 3 || cf.f3 > 0)
sprintf(msg, "dbms = %.4f, %.4f, %.4f dB/msec",
cf.dbms[0], cf.dbms[1], cf.dbms[2]);
else
sprintf(msg, "dbms = %.4f, %.4f msec", cf.dbms[0], cf.dbms[1]);
prn_msg(msg);
}
static void
dpon_msg(void)
{
int n;
static char *dpon_name[8] = {
"6*F1-5*F2", "5*F1-4*F2", "4*F1-3*F2", "3*F1-2*F2",
"2*F1-F2", "F2-F1", "2*F2-F1", "3*F2-2*F1"
};
n = limit(-5, pf.dpon, 2) + 5;
sprintf(msg, "DP order number = %d (%s)", pf.dpon, dpon_name[n]);
prn_msg(msg);
}
static void
edit_fn(char *fn)
{
if (!gr_edit(fn))
prn_msg("Can't edit file.");
}
static void
list_fn(char *s)
{
char fn[80];
double to = 0;
int nf, c;
for (nf = 0; nf < MAXNF && gr_find(s, fn, nf); nf++) {
c = gr_getkey(fn, to);
if (c == CTRL_C || c == ESC)
break;
}
}
static void
dp_exp_fit_msg(char *fn, double dbmx, double dbrn, int dpon)
{
char bn[80];
double t;
if (pf.dpef <= 0)
return;
if (pf.dpef == 1) {
pf.efc[3] = 0.00;
pf.efc[4] = 0.001;
} else if (pf.efc[2] > pf.efc[4]) { /* put smallest time-constant first */
t = pf.efc[1];
pf.efc[1] = pf.efc[3];
pf.efc[3] = t;
t = pf.efc[2];
pf.efc[2] = pf.efc[4];
pf.efc[4] = t;
t = pf.efc[7];
pf.efc[7] = pf.efc[8];
pf.efc[8] = t;
}
strcpy(bn, fn);
newext(bn, "");
if (pf.dpfc) {
sprintf(msg, "dpenv('%s', [%.2f %.3f %.2f %.3f %.2f %.4f %.4f %.4f]"
", %.0f, %.0f, %d, '%s.txt')",
bn, pf.efc[1], pf.efc[2], pf.efc[3], pf.efc[4], pf.efc[0],
pf.efc[7], pf.efc[8], pf.efc[6], dbmx, dbrn, dpon, bn);
} else {
sprintf(msg, "dpenv('%s', [%.2f %.3f %.2f %.3f %.2f]"
", %.0f, %.0f, %d, '%s.txt')",
bn, pf.efc[1], pf.efc[2], pf.efc[3], pf.efc[4], pf.efc[0],
dbmx, dbrn, dpon, bn);
}
prn_msg(msg);
if (pf.dpef == 1) {
sprintf(msg, "DP exp fit: %.2f, %.2f dB"
"; %.3f sec (VAF=%.3f,SNR=%.1fdB)",
pf.efc[1], pf.efc[0], pf.efc[2], pf.efc[5], pf.efc[9]);
} else if (pf.dpef == 2) {
sprintf(msg, "DP exp fit: %.2f, %.2f, %.2f dB"
"; %.3f, %.3f sec (VAF=%.3f,SNR=%.1fdB)",
pf.efc[1], pf.efc[3], pf.efc[0], pf.efc[2], pf.efc[4],
pf.efc[5], pf.efc[9]);
}
prn_msg(msg);
if (pf.dpfc) {
if (pf.dpef == 1) {
sprintf(msg, " phase: %.4f, %.4f cyc",
pf.efc[7], pf.efc[6]);
} else if (pf.dpef == 2) {
sprintf(msg, " phase: %.4f, %.4f, %.4f cyc",
pf.efc[7], pf.efc[8], pf.efc[6]);
}
prn_msg2(msg);
}
}
void
dp_dsp_msg(void)
{
sprintf(msg, "DP display = %d %d %d %d %d",
pf.dp_dsp[0], pf.dp_dsp[1], pf.dp_dsp[2],
pf.dp_dsp[3], pf.dp_dsp[4]);
prn_msg(msg);
}
double
db_ref(void)
{
double dbref;
if (cf.sens_mp > 0) {
dbref = (cf.ntone > 0) ? 20 * log10(cf.sens_mp * splref) : -20 * log10(cf.sens_mp) ;
} else {
dbref = (cf.ntone > 0) ? 10 * log10(2.0) : 0;
}
return (dbref);
}
void
db_msg(void)
{
char *units, msg[80];
double dbmin, dbmax;
if (cf.sens_mp > 0) {
units = (cf.ntone > 0) ? "dBSPL" : "dBvpp";
} else {
units = (cf.ntone > 0) ? "dBV" : "dB";
}
dbmax = pf.dbvref - db_ref();
dbmin = dbmax - pf.dbrange;
sprintf(msg, "dBmax=%.0f dBmin=%.0f (%s) ", dbmax, dbmin, units);
prn_msg(msg);
}
static void
response_msg(char *msg1, int tf)
{
char *tfstr, *units, *rmsfmt, msg[320];
int i, n;
double vrms[MAXNDC], msgd[MAXNDC], rms[MAXNDC], dbr, maxrms = 0;
resp_rms(vrms, msgd);
tfstr = tf ? "frequency" : "time";
if (tf) {
tfstr = "frequency";
if (cf.sens_mp > 0) {
dbr = 20 * log10(cf.sens_mp * splref / sqrt(2.0));
} else if (cf.ntone > 0) {
dbr = 0;
} else {
dbr = -10 * log10(cf.nsamp);
}
for (i = 0; i < nrch; i++)
rms[i] = (vrms[i] > 0) ? 20 * log10(vrms[i]) - dbr : -300;
units = (cf.sens_mp > 0) ? "dBSPL" : (cf.ntone > 0) ? " dBV" : " dB";
} else {
tfstr = "time";
for (i = 0; i < nrch; i++) {
rms[i] = (cf.sens_mp > 0) ? vrms[i] / cf.sens_mp :
(cf.ntone > 0) ? vrms[i] : vrms[i] * sqrt(cf.nsamp);
if (maxrms < rms[i])
maxrms = rms[i];
}
if (maxrms < 1e-3) {
for (i = 0; i < nrch; i++)
rms[i] *= 1e6;
units = (cf.sens_mp > 0) ? "uPa" : (cf.ntone > 0) ? " uV" : "";
} else if (maxrms < 1) {
for (i = 0; i < nrch; i++)
rms[i] *= 1e3;
units = (cf.sens_mp > 0) ? "mPa" : (cf.ntone > 0) ? " mV" : "";
} else {
units = (cf.sens_mp > 0) ? "Pa" : (cf.ntone > 0) ? " V" : "";
}
}
sprintf(msg, "%s response: %s", tfstr, msg1);
n = strlen(msg);
if (nrch == 1) {
rmsfmt = tf ? "; rms=%.2f%s" : "; rms=%.4g%s";
sprintf(msg + n, rmsfmt, rms[0], units);
if (cf.ntone == 0) {
n = strlen(msg);
sprintf(msg + n, "; gd=%.3g%s", msgd[0], "ms");
}
} else {
rmsfmt = tf ? "; rms=%.2f, %.2f%s" : "; rms=%.4g, %.4g%s";
sprintf(msg + n, "; rms=%.4g, %.4g%s", rms[0], rms[1], units);
if (cf.ntone == 0) {
n = strlen(msg);
sprintf(msg + n, "; gd=%.3g, %.3g%s", msgd[0], msgd[1], "ms");
}
}
prn_msg(msg);
}
int
ndp(double z)
{
int d = 0;
if (z == 0)
d = 0;
else if (z < 1)
d = 3;
else if (z < 10)
d = 2;
else if (z < 100)
d = 1;
return (d);
}
void
zf_msg(void)
{
sprintf(msg, "zf1=%.*f zf2=%.*f (Hz) zoom=%s",
ndp(pf.zf1), pf.zf1,
ndp(pf.zf2), pf.zf2,
pf.zoom ? "on" : "off");
prn_msg(msg);
}
void
zt_msg(void)
{
sprintf(msg, "zt1=%.3f zt2=%.3f (sec) zoom=%s",
pf.zt1, pf.zt2, pf.zoom ? "on" : "off");
prn_msg(msg);
}
void
set_crn_line(char *s)
{
char *c;
// remove leading spaces
while (*s == ' ')
s++;
// remove comment
c = strchr(s, ';');
if (c != NULL)
*c = '\0';
// remove trailing blanks
c = s + strlen(s);
while (c[-1] == ' ')
c--;
*c = '\0';
// save corner label
strncpy(crn, s, 19);
}
void
get_crn_line(char *s)
{
if (crn[0] == '\0') {
strcpy(s, "SysRes");
} else if (strncmp(crn, "$fn", 3) == 0) {
basename(s, datfn, 20);
} else {
strncpy(s, crn, 20);
}
}
void
delay_set_msg(void)
{
sprintf(msg, "delay_max=%g delay_range=%g delay_off=%g (ms)",
pf.delay_max, pf.delay_range, pf.delay_off);
prn_msg(msg);
}
void
optlev_fit_msg(void)
{
sprintf(msg, "optlev fit: snr=%g min=%d ord=%d",
cf.olsnr, cf.olmin, cf.olord);
prn_msg(msg);
}
void
optlev_lst_msg(void)
{
sprintf(msg, "optlev lst: avt=%g beg=%g inc=%g nlv=%g num=%d snr=%g rep=%d ",
cf.lsavt, cf.lsbeg, cf.lsinc, cf.lsnlv, cf.lsnum, cf.lssnr, cf.lsrep);
prn_msg(msg);
}
void
lst_sup_msg(void)
{
sprintf(msg, "optlev lst suppressor: f3=%g L3a=%g L3b=%g",
cf.lsf3, cf.lsl3a, cf.lsl3b);
prn_msg(msg);
}
void
ncal_set_msg(void)
{
char msg[80];
double ms;
int nm;
ms = pf.ofst * 1000.0 / cf.rate;
sprintf(msg, "ncal=%d ofst=%d (%.3g msec)", cf.ncal, pf.ofst, ms);
if (pf.npfit > 0) {
nm = strlen(msg);
ms = pf.npfit * 1000.0 / cf.rate;
sprintf(msg + nm, " npfit=%d (%.3g msec)", pf.npfit, ms);
}
prn_msg(msg);
}
void
phase_set_msg(void)
{
sprintf(msg, "phase_max=%g phase_range=%g phase_off=%g (cyc)",
pf.phase_max, pf.phase_range, pf.phase_off);
prn_msg(msg);
}
void
ramp_msg(void)
{
char typ[20];
int n;
n = cf.rmp_typ;
if (n < 0)
sprintf(typ, "%s (f3 only)", ramp_name[-n]);
else
sprintf(typ, "%s", ramp_name[n]);
sprintf(msg, "Ramp: bd,ed,od = %.1f, %.1f, %.1f msec; type=%s",
cf.beg_dur, cf.end_dur, cf.rmp_dur, typ);
prn_msg(msg);
}
void
mouse_msg(void)
{
#ifdef WIN32
int x, y;
mouse_position(&x, &y);
if (describe_position(msg, x, y))
prn_msg(msg);
#endif // WIN32
}
static void
expand_id(char *datfn)
{
char *s, *t;
s = strchr(datfn, '$');
if (s) {
if (strncmp(s, "$id", 3) == 0) {
t = _strdup(s + 3);
sprintf(s, "%s%s", idstr, t);
free(t);
}
}
}
int
get_tokens(char *s, char **left, char **right, int *eq)
{
int nch = 0;
while (*s && *s <= ' ') // skip over leading blanks
s++;
*left = s;
while (isalnum(*s)) // skip over first token
s++;
while (*s == '?')
s++;
nch = (int) (s - *left);
while (*s && *s <= ' ') // skip over trailing blanks
s++;
if (*s == '=') { // if next character is equals, skip over it
s++;
while (*s && *s <= ' ')
s++;
*eq = 1;
} else {
*eq = 0;
}
*right = s;
return (nch);
}
int
lookup(char *string, int e)
{
int i, rval = 0, c = 0;
static char *commands[] = {
// Configuration commands #0-21
"ad", "da", "dc", "ia", "na", "ns", "oa", "sr", "st",
"vo", "f1", "f2", "fc", "fi", "ft", "fp", "fn", "fu", "fr", "nf",
"no", "sa",
// Plot commands #22-46
"cs", "crn", "dr", "dn", "do", "eml", "pl", "pm", "pn",
"po", "pr", "ps", "shd", "shp", "tr", "ts", "td", "te", "vr", "SR",
"zf1", "zf2", "zt1", "zt2", "zo",
// File commands #47-58
"lf", "ra", "rc", "rd", "rl", "rs", "sv", "wa", "wc", "wd", "wh", "ws",
// printer commands #59-63
"PL", "PN", "PO", "PS", "PT",
// DPOAE commands #64-82
"avm", "ca", "cn", "dp", "dpbw", "dpdp", "dpef", "dpen", "dpfc",
"dpft", "dpno", "dpon", "dpsb", "dpt1", "om", "os", "rjm", "rjn",
"rjt",
// Masking commands #83-94
"ma1", "ma2", "mf1", "mf2", "mmd", "mmr", "mms", "mpd", "mpg", "ms",
"mtd", "mtv",
// Other commands, #95-119
"a1", "a2", "be", "bp", "bd", "cd", "co", "di", "ed", "et", "ga",
"go", "l1", "l2", "ls", "sm", "od", "pa", "pg", "q", "rt", "sk", "sl",
"to", "vn",
// other commands that aren't in the help #120-140
"at", "a3", "de", "dm", "dptw", "ex", "fz", "f3", "h", "help", "ic",
"kc", "l3", "pe", "quit", "wl", "?", "ct", "nt", "dpch", "cach",
// new commands #141-150
"dpst", "dprm", "dpsf", "dpfd", "dbms1", "dbms2", "dbms3", "ow", "dbg",
"edit",
// new commands #151-167
"lpma1", "lpma2", "lpma3", "lpmb1", "lpmb2", "lpmb3",
"lpmc1", "lpmc2", "lpmc3", "lpnc1", "lpnc2", "lpnc3",
"lpph1", "lpph2", "lpph3", "l1eq", "acsf",
// new commands #168-196
"lpol", "lsol", "olmin", "olord", "olsnr",
"lsavt", "lsbeg", "lsinc", "lsnlv", "lsnum", "lssnr", "l3eq",
"dpcp", "dpmp", "wci", "msg",
"amin1", "amin2", "amin3", "amnc1", "amnc2", "amnc3",
"after", "id", "ckfn", "lsrep", "lsf3", "lsl3a", "lsl3b",
// new commands #197-203
"dl", "late", "rp", "oi", "oo", "pef", "pes"
};
static int numcom = sizeof(commands) / sizeof(commands[0]);
for (i = 0; (i < numcom); i++) {
c = strlen(commands[i]);
if((c == e) && !strncmp(commands[i],string, e)) {
rval = i;
break;
}
}
if (i == numcom)
rval = -1;
return rval;
}
int
prepare_stimulus(char *msg)
{
if (cf.stm_typ == 6) {
if (!*stmfn) {
sprintf(msg, "Please use 'rs' to specify stimulus file name.");
return (0);
}
if (!read_stim_mat(msg, stmfn, &cf)) {
return (0);
}
stim_scale(0);
stim_ft(nsch);
cf.da_mode = (1 << nsch) - 1;
}
if (!stim_compute(cf.stm_typ, msg)) {
return (0);
}
return (1);
}
int
set_stimulus(int stmtyp, char *msg)
{
cf.stm_typ = stmtyp;
prn_top(&cf, comment);
if (!prepare_stimulus(msg)) {
return (0);
}
return (1);
}
void
gui(void)
{
char s[256], *tu;
char *right;
char *left;
double ms, sm, sr = 0, ss, t1, t2, dbmx, f, v;
int gc = 1, n = 0, ical, avcnt = 0, eq = 0;
int stmtyp = 0;
int command, nch, c;