-
Notifications
You must be signed in to change notification settings - Fork 0
/
eme.c
1709 lines (1636 loc) · 38.5 KB
/
eme.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
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
// Copyright (c) <2012> <Leif Asbrink>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify,
// merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include <ctype.h>
#include "globdef.h"
#include "uidef.h"
#include "screendef.h"
#include "keyboard_def.h"
#include "rusage.h"
#include "thrdef.h"
extern void users_eme(void);
#define MAX_EMEPARM 4
extern char *eme_own_info_filename;
extern char *eme_allcalls_filename;
extern char *eme_emedta_filename;
extern char *eme_dirskd_filename;
extern char *eme_dxdata_filename;
extern char *eme_call3_filename;
extern char *eme_error_report_file;
#define EGH 18
#define DX_SEARCH_LINES 2
int eg_old_y1;
int eg_old_y2;
int eg_old_x1;
int eg_old_x2;
void make_eme_graph(int clear_old);
int eme_graph_scro;
int emeparm_int[MAX_EMEPARM];
float *emeparm_float;
char *emeparm_text[MAX_EMEPARM+1]={"Auto init", //0
"UTC correction", //1
"Latitude (+ for N)", //2
"Longitude (+ for E)", //3
"Locator"};
char tmp_locator[7];
char dx_locator[7];
int dx_no;
FILE *locerr_file;
float cos_laref;
float sin_laref;
float cos_dxlat;
float sin_dxlat;
void locator_to_latlong(void);
void dist_az(float *dist, float *azimuth, float lat, float lon,
float dxlat, float dxlon);
void latlong_to_locator(float lon, float lat);
float dx_lat;
float tmp_lat;
float dx_lon;
float tmp_lon;
float dx_dist;
float dx_az;
int dxflag;
#define MAX_SUGGESTED 6
int eg_move_flag;
int suggested_calls[MAX_SUGGESTED];
int suggested_calls_counter;
char dx_callsign[EG_DX_CHARS+1];
#define MAX_DXCALLS 10000
#define RAD (PI_L/180)
void check_eg_borders(void)
{
current_graph_minh=eg_vsiz;
current_graph_minw=eg_hsiz;
check_graph_placement((void*)(&eg));
set_graph_minwidth((void*)(&eg));
}
void clear_search_result_box(void)
{
lir_fillbox(eg.xleft+1,egbutt[EG_DX].y1+3+text_height,
eg.xright-eg.xleft-1,eg.ybottom-egbutt[EG_DX].y1-3-text_height,0);
settextcolor(10);
lir_pixwrite(egbutt[EG_DX].x1+text_width/2,egbutt[EG_DX].y1+2,dx_callsign);
settextcolor(7);
}
void show_dx_location(void)
{
char s[80];
settextcolor(10);
lir_pixwrite(egbutt[EG_LOC].x1+text_width/2,egbutt[EG_LOC].y1+2,dx_locator);
sprintf(s,"%d ",(int)(dx_az/RAD));
s[3]=0;
lir_pixwrite(eg.xleft+text_width/2,egbutt[EG_LOC].y1+2,s);
sprintf(s,"%d ",(int)(dx_dist));
s[6]=0;
lir_pixwrite(egbutt[EG_LOC].x2+text_width/2,egbutt[EG_LOC].y1+2,s);
settextcolor(7);
clear_search_result_box();
}
void new_eme_loc(void)
{
int i;
for(i=0; i<6; i++)tmp_locator[i]=numinput_txt[i];
locator_to_latlong();
for(i=0; i<6; i++)dx_locator[i]=tmp_locator[i];
dx_locator[6]=0;
dx_lat=tmp_lat;
dx_lon=tmp_lon;
dxflag=1;
eme_time=0;
cos_dxlat=cos(RAD*dx_lat);
sin_dxlat=sin(RAD*dx_lat);
dist_az(&dx_dist, &dx_az, emeparm_float[2],emeparm_float[3], dx_lat, dx_lon);
suggested_calls_counter=1;
show_dx_location();
numinput_flag=-1;
}
void clear_dx(void)
{
char s[80];
int i;
for(i=0; i<EG_DX_CHARS; i++)s[i]=' ';
s[EG_DX_CHARS]=0;
lir_pixwrite(egbutt[EG_DX].x1+text_width/2,egbutt[EG_DX].y1+2,s);
dxflag=0;
}
void new_dx_result(void)
{
char s[256];
int i, j, k, m;
int line, pos;
if(suggested_calls_counter == 0)
{
clear_dx();
return;
}
if(suggested_calls_counter == 1)
{
for(i=0; i<EG_DX_CHARS; i++)dx_callsign[i]=dx[suggested_calls[0]].call[i];
tmp_lon=-dx[suggested_calls[0]].lon;
tmp_lat=dx[suggested_calls[0]].lat;
latlong_to_locator(tmp_lon,tmp_lat);
for(i=0; i<6; i++)numinput_txt[i]=tmp_locator[i];
new_eme_loc();
}
else
{
for(i=0; i<EG_DX_CHARS; i++)
{
dx_callsign[i]=' ';
}
}
dx_callsign[EG_DX_CHARS]=0;
k=0;
for(j=0; j<DX_SEARCH_LINES; j++)
{
for(i=0; i<EGH-1; i++)
{
s[k]=' ';
k++;
}
s[k]=0;
k++;
}
if(suggested_calls_counter > 1)
{
line=0;
pos=0;
for(i=0; i<suggested_calls_counter; i++)
{
k=suggested_calls[i];
j=0;
while(dx[k].call[j] != ' ')j++;
if(dx[k].call[j] == ' ')j--;
if(pos+j >= EGH-1)
{
pos=0;
line++;
if(line >= DX_SEARCH_LINES)
{
j=0;
goto nomore;
}
}
m=0;
while(m <= j)
{
s[EGH*line+pos]=dx[k].call[m];
m++;
pos++;
}
pos++;
}
nomore:;
if(j==0)settextcolor(13);
}
clear_search_result_box();
for(i=0; i<DX_SEARCH_LINES; i++)
{
lir_pixwrite(eg.xleft+text_width/2,egbutt[EG_DX].y1+3+(i+1)*text_height,
&s[i*EGH]);
}
if(j==0)settextcolor(7);
}
void star_match_dx_a(void)
{
int i, j, k, ia, ib, ib0;
// The first character is a star.
// Find the length of the fragment.
ib0=1;
while( ib0 < numinput_curpos && numinput_txt[ib0] != '*')ib0++;
// Search for calls containing the string.
for(i=0; i<dx_no; i++)
{
ia=1;
j=0;
ib=ib0;
get_string:;
while(dx[i].call[j] != numinput_txt[ia] && j < CALLSIGN_CHARS )j++;
if(j < CALLSIGN_CHARS)
{
// We have found the first character.
for(k=ia+1; k<ib; k++)
{
j++;
if(j >= CALLSIGN_CHARS)goto fail;
if(dx[i].call[j] != numinput_txt[k] && numinput_txt[k] != '?')goto fail;
}
// The string matches.
// If there no more '*' in the search string, decide if sucess or fail.
if(ib==numinput_curpos)
{
j++;
if(j == CALLSIGN_CHARS)goto sucess;
if(dx[i].call[j] == ' ')goto sucess;
goto fail;
}
ib++;
if(ib==numinput_curpos)goto sucess;
ia=ib;
while( ib < numinput_curpos && numinput_txt[ib] != '*')ib++;
goto get_string;
sucess:;
suggested_calls[suggested_calls_counter]=i;
suggested_calls_counter++;
if(suggested_calls_counter >= MAX_SUGGESTED)goto maxsug;
}
fail:;
}
maxsug:;
new_dx_result();
}
void star_match_dx_b(void)
{
int i, j, k, ia, ib, ib0;
// The first character is not a star.
// Find the length of the fragment.
ib0=1;
while( ib0 < numinput_curpos && numinput_txt[ib0] != '*')ib0++;
// Search for calls beginning with the fragment string.
for(i=0; i<dx_no; i++)
{
for(k=0; k<ib0; k++)
{
if(dx[i].call[k] != numinput_txt[k] && numinput_txt[k] != '?')goto fail;
}
ib=ib0+1;
if(ib==numinput_curpos)goto sucess;
j=0;
get_string:;
ia=ib;
while( ib < numinput_curpos && numinput_txt[ib] != '*')ib++;
while(dx[i].call[j] != numinput_txt[ia] && j < CALLSIGN_CHARS )j++;
if(j < CALLSIGN_CHARS)
{
// We have found the first character.
for(k=ia+1; k<ib; k++)
{
j++;
if(j >= CALLSIGN_CHARS)goto fail;
if(dx[i].call[j] != numinput_txt[k] && numinput_txt[k] != '?')goto fail;
}
// The string matches.
// If there no more '*' in the search string, decide if sucess or fail.
if(ib==numinput_curpos)
{
j++;
if(j == CALLSIGN_CHARS)goto sucess;
if(dx[i].call[j] == ' ')goto sucess;
goto fail;
}
ib++;
if(ib==numinput_curpos)goto sucess;
goto get_string;
sucess:;
suggested_calls[suggested_calls_counter]=i;
suggested_calls_counter++;
if(suggested_calls_counter >= MAX_SUGGESTED)goto maxsug;
}
fail:;
}
maxsug:;
new_dx_result();
}
void new_eme_dx(void)
{
int i,j,k;
pause_thread(THREAD_SCREEN);
hide_mouse(eg.xleft,eg.xright,eg.ytop,eg.ybottom);
// Search the data base for the call sign in numinput_txt.
// Just return if we have 2 or less characters
numinput_flag=-1;
suggested_calls_counter=0;
// There may be '*' and '?' in the call.
// Clean up the search string in case '?' are next to '*'
// or there are multiple '*'.
i=0;
while(i<numinput_curpos)
{
if(numinput_txt[i]=='*')
{
while(i>0 && numinput_txt[i-1] == '*')i--;
while(i>0 && numinput_txt[i-1] == '?')
{
i--;
k=i;
while(k<numinput_curpos)
{
numinput_txt[k]=numinput_txt[k+1];
k++;
}
numinput_curpos--;
if(i>0)i--;
}
}
if(numinput_txt[i]=='*')
{
while(i<numinput_curpos-1 &&
(numinput_txt[i+1] == '?' || numinput_txt[i+1] == '*'))
{
k=i+1;
while(k<numinput_curpos)
{
numinput_txt[k]=numinput_txt[k+1];
k++;
}
numinput_curpos--;
}
}
i++;
}
if(numinput_curpos<=2)
{
clear_dx();
goto new_eme_dx_x;
}
// If the first character is '*' call a special routine.
if(numinput_txt[0] == '*')
{
star_match_dx_a();
goto new_eme_dx_x;
}
// If there is any '*' at all, call another special routine
for(i=0; i<numinput_curpos; i++)
{
if(numinput_txt[i] == '*')
{
star_match_dx_b();
goto new_eme_dx_x;
}
}
// Search for matching calls with fixed positions for the
// characters.
for(i=0; i<dx_no; i++)
{
j=0;
while(j<numinput_curpos &&
(numinput_txt[j] == '?' || numinput_txt[j]==dx[i].call[j]) )j++;
if(j == numinput_curpos &&
(dx[i].call[j] == ' ' || numinput_curpos >= CALLSIGN_CHARS) )
{
suggested_calls[suggested_calls_counter]=i;
suggested_calls_counter++;
if(suggested_calls_counter >= MAX_SUGGESTED)goto maxsug;
}
}
maxsug:;
new_dx_result();
new_eme_dx_x:;
resume_thread(THREAD_SCREEN);
}
void help_on_eme_graph(void)
{
int msg_no;
int event_no;
// Set msg invalid in case we are not in any select area.
msg_no=-1;
for(event_no=0; event_no<MAX_EGBUTT; event_no++)
{
if( egbutt[event_no].x1 <= mouse_x &&
egbutt[event_no].x2 >= mouse_x &&
egbutt[event_no].y1 <= mouse_y &&
egbutt[event_no].y2 >= mouse_y)
{
switch (event_no)
{
case EG_TOP:
case EG_BOTTOM:
case EG_LEFT:
case EG_RIGHT:
msg_no=101;
break;
case EG_MINIMISE:
msg_no=70;
break;
case EG_LOC:
msg_no=71;
break;
case EG_DX:
msg_no=72;
break;
}
}
}
help_message(msg_no);
}
void mouse_continue_eme_graph(void)
{
int i, j;
switch (mouse_active_flag-1)
{
case EG_TOP:
if(eg.ytop!=mouse_y)goto egm;
break;
case EG_BOTTOM:
if(eg.ybottom!=mouse_y)goto egm;
break;
case EG_LEFT:
if(eg.xleft!=mouse_x)goto egm;
break;
case EG_RIGHT:
if(eg.xright==mouse_x)break;
egm:;
pause_screen_and_hide_mouse();
graph_borders((void*)&eg,0);
eg_move_flag=1;
if(eg_oldx==-10000)
{
eg_oldx=mouse_x;
eg_oldy=mouse_y;
}
else
{
i=mouse_x-eg_oldx;
j=mouse_y-eg_oldy;
eg_oldx=mouse_x;
eg_oldy=mouse_y;
eg.ytop+=j;
eg.ybottom+=j;
eg.xleft+=i;
eg.xright+=i;
check_eg_borders();
}
graph_borders((void*)&eg,15);
resume_thread(THREAD_SCREEN);
break;
default:
goto await_release;
}
if(leftpressed == BUTTON_RELEASED)goto finish;
return;
await_release:;
if(leftpressed != BUTTON_RELEASED) return;
switch (mouse_active_flag-1)
{
case EG_MINIMISE:
eg.minimise^=1;
break;
case EG_LOC:
for(i=0; i<EG_DX_CHARS; i++) dx_callsign[i]=' ';
mouse_active_flag=1;
numinput_chars=EG_LOC_CHARS;
numinput_xpix=egbutt[EG_LOC].x1+text_width/2;
numinput_ypix=egbutt[EG_LOC].y1+2;
erase_numinput_txt();
numinput_flag=TEXT_PARM;
par_from_keyboard_routine=new_eme_loc;
return;
case EG_DX:
mouse_active_flag=1;
numinput_chars=EG_DX_CHARS;
numinput_xpix=egbutt[EG_DX].x1+text_width/2;
numinput_ypix=egbutt[EG_DX].y1+2;
erase_numinput_txt();
numinput_flag=TEXT_PARM;
par_from_keyboard_routine=new_eme_dx;
return;
default:
lirerr(872);
break;
}
finish:;
leftpressed=BUTTON_IDLE;
mouse_active_flag=0;
make_eme_graph(TRUE);
if(eg.minimise==0)calculate_moon_data();
eg_oldx=-10000;
}
void mouse_on_eme_graph(void)
{
int event_no;
// First find out is we are on a button or border line.
for(event_no=0; event_no<MAX_EGBUTT; event_no++)
{
if( egbutt[event_no].x1 <= mouse_x &&
egbutt[event_no].x2 >= mouse_x &&
egbutt[event_no].y1 <= mouse_y &&
egbutt[event_no].y2 >= mouse_y)
{
eg_old_y1=eg.ytop;
eg_old_y2=eg.ybottom;
eg_old_x1=eg.xleft;
eg_old_x2=eg.xright;
mouse_active_flag=1+event_no;
current_mouse_activity=mouse_continue_eme_graph;
return;
}
}
// Not button or border.
// Do nothing.
current_mouse_activity=mouse_nothing;
mouse_active_flag=1;
}
void make_eme_graph(int clear_old)
{
int xj,xi,yj,yi;
pause_thread(THREAD_SCREEN);
if(clear_old)
{
hide_mouse(eg_old_x1,eg_old_x2,eg_old_y1,eg_old_y2);
lir_fillbox(eg_old_x1,eg_old_y1,eg_old_x2-eg_old_x1+1,
eg_old_y2-eg_old_y1+1,0);
}
eg_move_flag=0;
if(eg.minimise == 0 && eme_flag == 2)
{
eg_hsiz=EGH*text_width;
eg_vsiz=(4+DX_SEARCH_LINES)*text_height+3;
eme_active_flag=1;
cos_laref=cos(RAD*emeparm_float[2]);
sin_laref=sin(RAD*emeparm_float[2]);
}
else
{
eg_hsiz=2*text_width-1;
eg_vsiz=1.5*text_height-1;
eme_active_flag=0;
}
eg_flag=1;
check_eg_borders();
clear_button(egbutt, MAX_EGBUTT);
hide_mouse(eg.xleft,eg.xright,eg.ytop,eg.ybottom);
scro[eme_graph_scro].no=EME_GRAPH;
scro[eme_graph_scro].x1=eg.xleft;
scro[eme_graph_scro].x2=eg.xright;
scro[eme_graph_scro].y1=eg.ytop;
scro[eme_graph_scro].y2=eg.ybottom;
egbutt[EG_LEFT].x1=eg.xleft;
egbutt[EG_LEFT].x2=eg.xleft+2;
egbutt[EG_LEFT].y1=eg.ytop;
egbutt[EG_LEFT].y2=eg.ybottom;
egbutt[EG_RIGHT].x1=eg.xright-2;
egbutt[EG_RIGHT].x2=eg.xright;
egbutt[EG_RIGHT].y1=eg.ytop;
egbutt[EG_RIGHT].y2=eg.ybottom;
egbutt[EG_TOP].x1=eg.xleft;
egbutt[EG_TOP].x2=eg.xright;
egbutt[EG_TOP].y1=eg.ytop;
egbutt[EG_TOP].y2=eg.ytop+2;
egbutt[EG_BOTTOM].x1=eg.xleft;
egbutt[EG_BOTTOM].x2=eg.xright;
egbutt[EG_BOTTOM].y1=eg.ybottom-2;
egbutt[EG_BOTTOM].y2=eg.ybottom;
// Draw the border lines
graph_borders((void*)&eg,7);
eg_oldx=-10000;
settextcolor(7);
xj=eg.xleft+text_width-1;
if(eme_active_flag != 0)
{
xi=xj+3.5*text_width;
yi=eg.ytop+2*text_height;
egbutt[EG_LOC].x1=xi;
egbutt[EG_LOC].x2=xi+text_width*(EG_LOC_CHARS+0.5);
egbutt[EG_LOC].y1=yi;
yi+=text_height;
xi-=2*text_width;
egbutt[EG_LOC].y2=yi;
lir_hline(egbutt[EG_LOC].x1,egbutt[EG_LOC].y1,egbutt[EG_LOC].x2,7);
if(kill_all_flag) return;
lir_hline(egbutt[EG_LOC].x1,egbutt[EG_LOC].y2,egbutt[EG_LOC].x2,7);
if(kill_all_flag) return;
lir_line(egbutt[EG_LOC].x1,egbutt[EG_LOC].y1,egbutt[EG_LOC].x1,
egbutt[EG_LOC].y2,7);
if(kill_all_flag) return;
lir_line(egbutt[EG_LOC].x2,egbutt[EG_LOC].y1,egbutt[EG_LOC].x2,
egbutt[EG_LOC].y2,7);
if(kill_all_flag) return;
yi+=2;
yj=yi+text_height/2;
egbutt[EG_DX].x1=xi;
egbutt[EG_DX].x2=xi+text_width*(EG_DX_CHARS+0.5);
egbutt[EG_DX].y1=yi;
yi+=text_height;
egbutt[EG_DX].y2=yi;
yi+=2;
if(dxflag != 0)
{
show_dx_location();
}
lir_hline(egbutt[EG_DX].x1,egbutt[EG_DX].y1,egbutt[EG_DX].x2,7);
if(kill_all_flag) return;
lir_hline(egbutt[EG_DX].x1,egbutt[EG_DX].y2,egbutt[EG_DX].x2,7);
if(kill_all_flag) return;
lir_line(egbutt[EG_DX].x1,egbutt[EG_DX].y1,egbutt[EG_DX].x1,
egbutt[EG_DX].y2,7);
if(kill_all_flag) return;
lir_line(egbutt[EG_DX].x2,egbutt[EG_DX].y1,egbutt[EG_DX].x2,
egbutt[EG_DX].y2,7);
if(kill_all_flag) return;
}
else
{
yj=eg.ybottom-text_height/2-1;
}
make_button(xj,yj,egbutt,EG_MINIMISE,'X');
resume_thread(THREAD_SCREEN);
make_modepar_file(GRAPHTYPE_EG);
}
void init_eme_graph(void)
{
FILE *file;
int i, j, k;
char s[80];
// In case we process saved data from disk, the real time
// moon window is useless, just skip it.
if(savefile_parname[0] != 0)return;
s[0]=0;
if (read_modepar_file(GRAPHTYPE_EG) == 0)
{
eg.xleft=15*text_width;
eg.xright=17*text_width;
eg.ybottom=0.7*screen_height;
eg.ytop=eg.ybottom-1.5*text_height;
eg.minimise=1;
}
dxflag=0;
if(eme_flag == 2)
{
if(dx!=NULL)
{
lirerr(81975);
return;
}
file = fopen(eme_dxdata_filename, "r");
if(file == NULL)
{
lirerr(1130);
return;
}
k=fread(s,1,1,file);
j=0;
while(k!=0 && s[j] != 10 && s[j] != 13)
{
j++;
k=fread(&s[j],1,1,file);
if(j >= 80)
{
err1131:;
lirerr(1131);
return;
}
}
if(j == 0 || k == 0)goto err1131;
s[j]=0;
sscanf(s,"%d",&dx_no);
if(dx_no > MAX_DXCALLS)goto err1131;
dx=malloc(dx_no*sizeof(DXDATA));
if(dx == NULL)
{
lirerr(1132);
return;
}
i=0;
read_dx:;
k=fread(s,1,1,file);
j=0;
while(k!=0 && (s[j] == 10 || s[j] == 13)) k=fread(s,1,1,file);
if(k == 0)
{
lirerr(1131);
return;
}
while(k!=0 && s[j] != 10 && s[j] != 13)
{
j++;
k=fread(&s[j],1,1,file);
if(j >= 80)
{
lirerr(1131);
return;
}
}
if(j == 0 || k == 0)
{
lirerr(1131);
return;
}
s[j]=0;
for(k=0; k<CALLSIGN_CHARS; k++)dx[i].call[k]=s[k];
sscanf(&s[CALLSIGN_CHARS],"%f %f",&dx[i].lat,&dx[i].lon);
i++;
if(i<dx_no)goto read_dx;
fclose(file);
}
eme_graph_scro=no_of_scro;
make_eme_graph(FALSE);
no_of_scro++;
if(no_of_scro >= MAX_SCRO)lirerr(89);
}
void dist_az(float *dist, float *azimuth, float lat, float lon,
float dxlat, float dxlon)
{
float sin_dxl, cos_dxl;
float sin_lat, cos_lat;
float t1,t2,t3;
cos_dxl=cos(PI_L*dxlat/180);
sin_dxl=sin(PI_L*dxlat/180);
cos_lat=cos(PI_L*lat/180);
sin_lat=sin(PI_L*lat/180);
t1=PI_L*(lon-dxlon)/180;
t2=sin_dxl*sin_lat+cos_dxl*cos_lat*cos(t1);
if(fabs(t2)>1)t2=1;
t2=atan2(sqrt(1-t2*t2),t2);
dist[0]=t2*6366;
if(dist[0] < 5)
{
dist[0]=0;
azimuth[0]=0;
return;
}
if(t1<-PI_L)t1+=2*PI_L;
if(t1> PI_L)t1-=2*PI_L;
t3=(sin_dxl-sin_lat*cos(t2))/(cos_lat*sin(t2));
if(fabs(t3) > 1)t3=1;
azimuth[0]=atan2(sqrt(1-t3*t3),t3);
if(t1 == 0)
{
if(dxlat < lat)
{
azimuth[0]=PI_L;
}
else
{
azimuth[0]=2*PI_L;
}
}
else
{
if(t1 > 0)azimuth[0]=2*PI_L-azimuth[0];
}
}
void check_latest_dx(void)
{
char s[80];
int i, j, k;
float dist, az;
// Check that the latest call sign is not already in the data base.
for(i=0; i<dx_no; i++)
{
j=0;
while(j<CALLSIGN_CHARS && dx[i].call[j] == dx[dx_no].call[j])j++;
if(j==CALLSIGN_CHARS)
{
// We have located a duplicate call sign.
// Just ignore it in case the location is the same (or close to)
// If longitude or latitude is 1000 for one, use the other.
if(dx[i].lon == 1000)dx[i].lon=dx[dx_no].lon;
if(dx[i].lat == 1000)dx[i].lat=dx[dx_no].lat;
if(dx[dx_no].lon == 1000)dx[dx_no].lon=dx[i].lon;
if(dx[dx_no].lat == 1000)dx[dx_no].lat=dx[i].lat;
if(fabs(dx[i].lon-dx[dx_no].lon) > 0.1 ||
fabs(dx[i].lat-dx[dx_no].lat) > 0.1)
{
dist_az(&dist, &az, dx[i].lon,dx[i].lat,dx[dx_no].lon,dx[dx_no].lat);
if(dist > 200)
{
if(locerr_file == NULL)
{
locerr_file = fopen(eme_error_report_file, "w");
if(locerr_file == NULL)
{
lirerr(1133);
return;
}
}
for(k=0; k<CALLSIGN_CHARS; k++)s[k]=dx[i].call[k];
s[CALLSIGN_CHARS]=0;
fprintf(locerr_file,
"%s %d km lon %.2f lat %.2f [lon %.2f lat %.2f]\n",
s, (int)(dist), dx[i].lon, dx[i].lat,
dx[dx_no].lon, dx[dx_no].lat);
}
}
dx[i].lon=0.5*(dx[i].lon+dx[dx_no].lon);
dx[i].lat=0.5*(dx[i].lat+dx[dx_no].lat);
dx_no--;
}
}
}
void latlong_to_locator(float lon, float lat)
{
int i;
float t1,t2;
t1=lon;
t2=lat;
t1+=180;
i=t1/20;
t1=t1-20*i;
tmp_locator[0]=i+'A';
i=t1/2;
t1=t1-2*i;
tmp_locator[2]=i+'0';
t1*=12;
tmp_locator[4]=t1+'a';
t2+=90;
i=t2/10;
t2=t2-10*i;
tmp_locator[1]=i+'A';
i=t2;
tmp_locator[3]=i+'0';
t2-=i;
t2*=24;
tmp_locator[5]=t2+'a';
}
void locator_to_latlong(void)
{
int flg;
float lat, lon;
tmp_locator[0]=toupper(tmp_locator[0]);
tmp_locator[1]=toupper(tmp_locator[1]);
tmp_locator[4]=tolower(tmp_locator[4]);
tmp_locator[5]=tolower(tmp_locator[5]);
flg=0;
if(tmp_locator[0]<'A')
{
tmp_locator[0]='A';
flg=1;
}
if(tmp_locator[0]>'R')
{
tmp_locator[0]='R';
flg=1;
}
if(tmp_locator[1]<'A')
{
tmp_locator[1]='A';
flg=1;
}
if(tmp_locator[1]>'R')
{
tmp_locator[1]='R';
flg=1;
}
if(tmp_locator[2]<'0' || tmp_locator[2]>'9')flg=1;
if(tmp_locator[3]<'0' || tmp_locator[3]>'9')flg=1;
if(flg != 0)
{
tmp_locator[2]='4';
tmp_locator[3]='4';
tmp_locator[4]='a';
tmp_locator[5]='a';
}
if( tmp_locator[4]<'a' ||
tmp_locator[4]>'x' ||
tmp_locator[5]<'a' ||
tmp_locator[5]>'x' )
{
tmp_locator[4]='l';
tmp_locator[5]='l';
}
lon=tmp_locator[4]-'a'+0.5;
lon/=12;
lon-=180;
lon+=(tmp_locator[2]-'0')*2;
lon+=(tmp_locator[0]-'A')*20;
if(fabs(lon)>180.001)lon=0;
lat=tmp_locator[5]-'a'+0.5;
lat/=24;
lat-=90;
lat+=(tmp_locator[3]-'0');
lat+=(tmp_locator[1]-'A')*10;
if(fabs(lat)>90.001)lat=0;
tmp_lon=lon;
tmp_lat=lat;
}
// eme_flag=0 Nothing loaded. Load all data in case the first parameter =1
// eme_flag=1 Nothing loaded. Load all data unconditionally.
// eme_flag=2 Database loaded. Ask if it should be changed.
void read_eme_database(void)
{
int i, j, k, m;
char s[80];
FILE *own_file;
char *tmpbuf;
emeparm_float=(float*)((void*)(emeparm_int));
// Set flag to zero if file is empty
own_file = fopen(eme_own_info_filename, "r");
if(own_file == NULL)
{
eme_flag=0;
return;
}
// Allocate a lot of scratch memory.
// No processing arrays are allocated this early in program
// execution so there should be plenty of memory available.
tmpbuf=malloc(131072);
for(i=0;i<4096; i++)tmpbuf[i]=0;