forked from HartmutBorth/PLASIM
-
Notifications
You must be signed in to change notification settings - Fork 4
/
most.c
5001 lines (4270 loc) · 123 KB
/
most.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
/*
MOST - Model Starter
---------------------------------------------------------------------------
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
---------------------------------------------------------------------------
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#define INT int
#define LINEMAX 256
typedef char String[LINEMAX];
String Buffer;
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#define FULLARC (360 * 64)
#define WINDOW_WIDTH 820
/* Models */
#define PUMA 0
#define SAM 1
#define CAT 2
#define PLASIM 3
#define MODELS 4
/* Resolutions */
#define RES_T15 0
#define RES_T21 1
#define RES_T31 2
#define RES_T42 3
#define RES_T63 4
#define RESOLUTIONS 5
int PlasimSteps[RESOLUTIONS] =
{
60, // T15
45, // T21
30, // T31
20, // T42
10 // T63
};
int PumaSteps[RESOLUTIONS] =
{
60, // T15
60, // T21
45, // T31
30, // T42
15 // T63
};
int ResLat[RESOLUTIONS] =
{
24,
32,
48,
64,
96
};
int Resolution = -1;
char *ShortModelName[MODELS] =
{
"puma",
"sam",
"cat",
"plasim"
};
char *FullModelName[MODELS] =
{
"PUMA",
"SAM",
"CAT",
"Planet Simulator"
};
int Model = PUMA;
#define ALL -1
#define EARTH 0
#define MARS 1
#define EXO 2
#define PLANETS 3
char *PlanetName[PLANETS] =
{
"Earth",
"Mars",
"Exo"
};
int Planet = EARTH;
double *OroEarth; // Earth Orography T42 (128 x 64)
double *OroMars; // Mars Orography T42 (128 x 64)
double *OroPrep; // Preprocessed Orography
Pixmap OpmEarth;
Pixmap OpmMars;
Pixmap OpmPrep;
double RevGra = 1.0 / 9.81;
/* Object types */
#define SEL_TEXT 1
#define SEL_CHECK 2
#define SEL_INT 3
#define SEL_REAL 4
#define SEL_TEVA 5
#define SEL_PLANET 6
struct ItemStruct
{
char list[80]; // Name of namelist
char name[80]; // Name of variable
char text[80]; // Text value
float pvec[PLANETS]; // Planetary parameter
double rval; // Real value
int ival; // Integer value
int model; // Model
int flag; // Flag
};
struct SelStruct
{
struct SelStruct *Next; // Link to next Sel
struct SelStruct *Prev; // Link to previous Sel
struct ItemStruct *Item; // Link to item
int type; // Type (TEXT,CHECK,INT,REAL)
int x; // x coordinate of box
int y; // y coordinate of box
int h; // height of box
int w; // width of box
int xo; // x offset
int xt; // x coordinate for text
int yt; // y coordinate for text
int lt; // length of text
int iv; // integer value of box content
int div; // default integer value
int no; // 1: not selectable
int teco; // text colour
int edco; // edit column (cursor)
int hide; // 1: don't show
float fv; // floating value of box content
float dfv; // default floating value
float fpl[PLANETS]; // planet dependent floats
int *piv; // pointer to linked integer variable
float *pfv; // pointer to linked float variable
char text[80]; // text to display
char teva[16]; // box content
};
struct SelStruct SelStart;
struct SelStruct SelModels[MODELS];
struct SelStruct *CursorSel;
struct SelStruct *ComEnd;
struct SelStruct *SelAno;
struct SelStruct *SelTgr;
struct SelStruct *SelOro;
struct SelStruct *SelMod;
struct SelStruct *SelRes;
struct SelStruct *SelOce;
struct SelStruct *SelLsg;
struct SelStruct *SelIce;
struct SelStruct *SelAnn;
struct SelStruct *SelPlanet[PLANETS];
struct SelStruct *SelSYear;
struct SelStruct *SelCPU;
struct SelStruct *SelMulti;
struct SelStruct *SelLat2;
// Title lines for the entry of resolution
char *DimText1;
char *DimText2;
char *DimText3;
#define DIMLOGO 4
struct SymbolStruct
{
int x; // x pos
int y; // y pos
int w; // width
int h; // height
int b; // background color
int f; // foreground color
char **i; // image
char *d; // image data
XImage *X; // X-Image
char t[2][80]; // caption
} Logo[DIMLOGO];
int Logos;
struct ColorStrip
{
double Lo;
double Hi;
char *Name;
unsigned long pixel;
};
unsigned long WinBG = 0; // Black background
unsigned long TextC = 0; // Text color
unsigned long HeadC = 0; // Heading color
#define DIMFRAME 3
int Frames;
struct FrameStruct
{
void (*Action)();
Pixmap pixmap; // pixmap
int x; // x pos
int y; // y pos
int w; // width
int h; // height
int b; // background color
int f; // foreground color
int xs; // x pos selection
int ys; // y pos selection
int ws; // width selection
int hs; // height selection
char t[3][80]; // text
} Frame[DIMFRAME];
int FrameNo;
int Buttons;
int Button1Down = 1;
#define DIMBUTTON 5
struct ButtonStruct
{
void (*Action)();
int x; // x pos
int y; // y pos
int w; // width
int h; // height
int b; // background color
int f; // foreground color
char t[3][80]; // text
} Button[DIMBUTTON];
int Buttons;
/* Coordinates */
int opbox_x;
int opbox_y;
int opbox_w;
int opbox_h;
int nlbox_x;
int nlbox_y;
int nlbox_w;
int nlbox_h;
int nlpos_x;
int nledi_x;
int sfbox_x;
int sfbox_y;
int sfbox_w;
int sfbox_h;
int sfbox_b;
int bubox_x;
int bubox_y;
int bubox_w;
int bubox_h;
int CursorCol;
int LastSel;
int EdiKeyCode;
#define NL_MAX_ITEMS 100
int NL_items = 0;
struct ItemStruct NL_list[NL_MAX_ITEMS];
int BigEndian;
int Oce;
int Ice;
int Lsg;
int SimStart;
int SimYears;
int nreadsr;
int noutput;
int ndebug;
int nprec;
int ngui;
int noro = 1;
int OroAno;
int OroClear;
int OroAqua;
int TgrAno;
int nac;
int Preprocessed;
int SAMindex;
int ScreenHeight;
int Expert = 1;
int SuperExpert = 0;
int PumaEnabled;
int CatEnabled;
int SamEnabled;
int LsgEnabled;
int ModeRadiusSq;
int ForceRebuild;
int dxsh;
int dxs2;
int Yoden; // PUMA setup for Yoden experiment
int CatSim = 51; // simulation setup number for CAT
/* Special parameter */
int Latitudes = 32; // Number of latitudes in atmosphere
int Latitude2 = 32; // Number of latitudes for 2nd. instance
int Levels = 10; // Number of levels in atmosphere
int Cores = 1; // Number of cores for parallel version
int Multirun = 1; // Number of coupled runs
int MultirunEnabled = 0; // Multirun module present?
int Truncation = 21; // Spectral truncation computed from Latitudes
unsigned Seed;
char cfg_file[256] = "most_last_used.cfg";
char exec_name[256] = "most_puma.x";
char exec_nam2[256] = "most_puma.x"; // 2nd. instance
char exec_ppp[256] = "most_ppp.x";
char oro_name[256] = "N064_surf_0129.sra"; // Orography in T42 resolution
char namelist_name[256] = "puma_namelist";
char diag_name[256] = "puma_diag";
char outp_name[256] = "puma_output";
char build_name[256] = "most_puma_build";
char build_ppp[256] = "most_ppp_build";
char run_name[256] = "most_puma_run";
char run_ppp[256] = "most_ppp_run";
char res_name[256] = "resmod.f90";
char hostname[256] = "localhost";
char mpirun[256] = "mpirun"; // "openmpirun" for Open MPI
int ScreenN;
time_t CurrentDate;
Display *display;
unsigned int ScreenW,ScreenH;
int SmallScreen = 1;
static char *progname = "Most";
int DimX;
int DimY;
int DimTr = 21;
int DimSH = 11 * 23;
int DimSE = 11 * 23 + 2;
int ScreenD;
int OffX;
int OffY = 0;
int WinXSize;
int WinYSize;
int WhitePix;
int BlackPix;
int *Ampli;
int *ModeX;
int *ModeY;
int *ModeM;
int *ModeN;
int x11flag = 1;
Colormap colormap;
XColor xcolor1,xcolor2;
XColor Red,Green,Blue,Grey,LightRed,DarkRed,LightBlue,DarkBlue;
XColor LightGreen,DarkGreen,Yellow,Cyan,Dummy;
Window Cow; // Control bar
XTextProperty WinconName1;
XEvent WinEvent;
XSizeHints CowSizeHints;
int count;
XEvent report;
GC gc;
char ModFontName[80] = "-misc-fixed-bold-r-normal--15-*-*-*-*-*-*-*";
char FixFontName[80] = "-misc-fixed-bold-r-normal--15-*-*-*-*-*-*-*";
char BigFontName[80] = "-misc-fixed-medium-r-normal--20-*-*-*-*-*-*-*";
//char ModFontName[80] = "9x15bold";
//char FixFontName[80] = "9x15bold";
//char BigFontName[80] = "10x20";
XFontStruct *ModFont;
XFontStruct *FixFont;
XFontStruct *BigFont;
XFontStruct *SamFont;
int ModFontHeight;
int FixFontHeight;
int BigFontHeight;
int ModFontWidth;
int FixFontWidth;
int BigFontWidth;
int ModFontAscent;
int FixFontAscent;
int BigFontAscent;
int EdiFirstKey;
int EdiLastKey;
int EdiSymsPerKey;
int NumLockMask;
int ModeSwitchMask;
int Debug = 0;
KeySym *EdiKeymap;
XModifierKeymap *Mok;
char *display_name = NULL;
XWMHints wm_hints;
XClassHint class_hints;
Atom Delwin;
char *mona[12] =
{
"Jan","Feb","Mar",
"Apr","May","Jun",
"Jul","Aug","Sep",
"Oct","Nov","Dec"
};
char datch[32];
struct MapImageStruct
{
char *d; // Bitmap data
int w; // Image width
int h; // Image height
int f; // Rotation factor
float l; // Reference longitude
float r; // Rotation speed [deg/step]
XImage *X; // XImage structure
};
struct MapImageStruct MapHRE; // Hires (2560x1280) Earth image
struct MapImageStruct MapHRM; // Hires ( ) Mars image
struct MapImageStruct MapLRE; // Lores azimuthal Earth image
struct MapImageStruct MapLRM; // Lores azimuthal Mars image
struct MapImageStruct MapLRK; // Lores azimuthal Kepler-16
struct MapImageStruct MapLRL; // Lores azimuthal Kepler-186b
/* Isoarea data */
#define TOLELO 0x0001
#define TOLEHI 0x0002
#define TORILO 0x0004
#define TORIHI 0x0008
#define BOLELO 0x0010
#define BOLEHI 0x0020
#define BORILO 0x0040
#define BORIHI 0x0080
#define TOLEIN 0x0100
#define TOREIN 0x0200
#define BOLEIN 0x0400
#define BOREIN 0x0800
#define IPX(l,m,h) (VGAX * (x + (l-m) / (l-h)))
#define IPY(l,m,h) (VGAY * (y + (l-m) / (l-h)))
int nlon = 128;
int nlat = 64;
int nlev = 5;
int *Flag;
double VGAX;
double VGAY;
Pixmap pix;
/* Orography units are [m2/s2] */
struct ColorStrip OroStrip[] =
{
{-99999.0, 80.0,"DarkBlue"},
{ 80.0, 800.0,"green"},
{ 800.0, 1600.0,"brown"},
{ 1600.0, 2400.0,"orange"},
{ 2400.0,99999.0,"white"},
{ 0.0, 0.0,NULL}
};
struct ColorStrip OroMarsStrip[] =
{
{-99999.0,-16000.0,"yellow"},
{-16000.0,-12000.0,"RoyalBlue4"},
{-12000.0, -8000.0,"RoyalBlue3"},
{ -8000.0, -4000.0,"RoyalBlue2"},
{ -4000.0, 0.0,"RoyalBlue1"},
{ 0.0, 4000.0,"dark green"},
{ 4000.0, 8000.0,"light green"},
{ 8000.0, 12000.0,"brown"},
{ 12000.0, 16000.0,"orange"},
{ 16000.0, 99999.0,"white"},
{ 0.0, 0.0,NULL}
};
struct ColorStrip GibbStrip[] =
{
{-99999.0, 0.0,"DarkBlue"},
{ 0.0,99999.0,"green"},
{ 0.0, 0.0,NULL}
};
struct ColorStrip TStrip[] =
{
{-99.0,-15.0,"RoyalBlue4"},
{-15.0,-20.0,"RoyalBlue3"},
{-10.0, -5.0,"RoyalBlue2"},
{ -5.0, -0.1,"RoyalBlue1"},
{ -0.1, 0.1,"yellow"},
{ 0.1, 5.0,"IndianRed1"},
{ 5.0, 10.0,"IndianRed2"},
{ 10.0, 15.0,"IndianRed3"},
{ 15.0, 20.0,"IndianRed4"},
{ 20.0,999.0,"red"},
{ 0.0, 0.0,NULL}
};
void DoNothing(void)
{
printf("Do nothing\n");
}
void ChangeModel(int NewMo)
{
int i;
struct SelStruct *Sel;
if (NewMo < 0) // locate active model
{
NewMo = PUMA; // default if none is specified
for (i=0 , Sel = SelMod ; i < MODELS; ++i , Sel = Sel->Next)
{
if (Sel->iv == 1) NewMo = i;
}
}
ComEnd->Next = &SelModels[NewMo];
ComEnd->Next->Prev = ComEnd;
for (i=0 , Sel = SelMod ; i < MODELS; ++i , Sel = Sel->Next)
{
if (i == NewMo) Sel->iv = 1;
else Sel->iv = 0;
}
if (NewMo == PUMA || NewMo == SAM)
{
SelAno->hide = 0;
SelAnn->no = 0;
SelOce->no = 1;
SelIce->no = 1;
SelOro->no = 0;
SelSYear->no = 1;
if (SelLsg) SelLsg->no = 1;
for (i=0 ; i < PLANETS ; ++i) SelPlanet[i]->no = 1;
}
if (NewMo == PLASIM)
{
SelAno->hide = 1;
SelAnn->no = 1;
SelOro->no = 1;
SelSYear->no = 0;
if (Expert)
{
SelOce->no = 0;
SelIce->no = 0;
if (SelLsg) SelLsg->no = 0;
for (i=0 ; i < PLANETS ; ++i) SelPlanet[i]->no = 0;
}
}
if (SuperExpert)
{
if (NewMo == CAT)
{
strcpy(DimText1,"NGX ");
strcpy(DimText2,"NGY ");
}
else
{
strcpy(DimText1,"Latitudes #1 ");
strcpy(DimText2,"Latitudes #2 ");
}
}
else
{
if (NewMo == CAT)
{
strcpy(DimText1,"[ 64 x 64 ]");
strcpy(DimText2,"[ 256 x 256 ]");
strcpy(DimText3,"[1024 x 1024]");
}
else
{
strcpy(DimText1,"T21 [64x32]");
strcpy(DimText2,"T31 [96x48]");
strcpy(DimText3,"T42 [128x64]");
}
}
Model = NewMo;
}
void WriteSettings(void)
{
int mxtl;
char tb[80];
FILE *fp;
struct SelStruct *Sel;
fp = fopen("most_last_used.cfg","w");
if (!fp) return;
fprintf(fp,"[MoSt 17 - configuration file] created %s\n",ctime(&CurrentDate));
mxtl = 0;
for (Sel = &SelStart ; Sel ; Sel = Sel->Next)
{
if (Sel->type != SEL_TEXT ) mxtl = MAX(mxtl,strlen(Sel->text));
}
for (Sel = &SelStart ; Sel ; Sel = Sel->Next)
{
if (Sel->type == SEL_TEXT ) fprintf(fp,"\n[%s]\n",Sel->text);
else
{
memset(tb,' ',sizeof(tb));
strncpy(tb,Sel->text,strlen(Sel->text));
tb[mxtl] = 0;
fprintf(fp,"%s = ",tb);
}
if (Sel->type == SEL_CHECK) fprintf(fp,"%6d\n",Sel->iv);
else if (Sel->type == SEL_INT ) fprintf(fp,"%6d\n",Sel->iv);
else if (Sel->type == SEL_TEVA ) fprintf(fp,"%s\n",Sel->teva);
else if (Sel->type == SEL_REAL || Sel->type == SEL_PLANET)
{
if (Sel->type == SEL_PLANET) Sel->fv = Sel->fpl[Planet];
if (fabs(Sel->fv) >= 1.0 && fabs(Sel->fv) < 9000.0) fprintf(fp,"%10.4f\n",Sel->fv);
else fprintf(fp,"%10.4e\n",Sel->fv);
}
}
fclose(fp);
}
void FormatReal(float fv, char *text)
{
if (fv == 0.0 ||
(fv > 0.001 && fv < 99999.0) ||
(fv > -9999.0 && fv < -0.001))
{
sprintf(text,"%11.4f",fv);
if (!strcmp(text+8,"000")) text[ 8] = 0;
else if (!strcmp(text+9,"00" )) text[ 9] = 0;
else if (text[10] == '0') text[10] = 0;
}
else
{
sprintf(text,"%11.4e",fv);
}
}
void UpdateSelections(struct SelStruct *Sel)
{
char text[80];
int selx;
selx = 0;
for (; Sel ; Sel = Sel->Next)
{
if (Sel == ComEnd->Next) selx = 1;
if (selx) Sel->x = nledi_x;
if (Sel->type == SEL_INT )
{
sprintf(text,"%10d",Sel->iv);
strcpy(Sel->teva,text+10-Sel->edco);
if (Sel->piv) *Sel->piv = Sel->iv;
}
if (Sel->type == SEL_REAL || Sel->type == SEL_PLANET)
{
if (Sel->type == SEL_PLANET) Sel->fv = Sel->fpl[Planet];
FormatReal(Sel->fv,text);
strcpy(Sel->teva,text);
}
}
// if (SelLat2) SelLat2->no = (SelMulti->iv != 2) ;
}
void ChangePlanet(int NewPlanet)
{
struct SelStruct *Sel;
SelPlanet[Planet]->iv = 0;
Planet = NewPlanet;
SelPlanet[Planet]->iv = 1;
strcpy(SelModels[PLASIM].text,PlanetName[Planet]);
SelModels[PLASIM].lt = strlen(PlanetName[Planet]);
for (Sel = &SelStart ; Sel ; Sel = Sel->Next)
{
if (Sel->type == SEL_PLANET)
{
Sel->fv = Sel->fpl[Planet];
}
}
UpdateSelections(ComEnd->Next);
}
int ReadSettings(char *fn)
{
int pl;
char tb[80];
char *eq;
FILE *fp;
struct SelStruct *Sel;
fp = fopen(fn,"r");
if (!fp)
{
printf("\nUsing default configuration\n");
return 0;
}
fgets(tb,sizeof(tb),fp);
if (strncmp(tb,"[MoSt",5))
{
printf("\nFileheader is: %s\n",tb);
printf("Expected : [MoSt ...]\n");
printf("Using default configuration\n");
fclose(fp);
return 0;
}
while (!feof(fp))
{
eq = strchr(tb,'=');
if (eq)
{
for (Sel = &SelStart ; Sel ; Sel = Sel->Next)
{
if (!strncmp(tb,Sel->text,strlen(Sel->text)))
{
if (!isalnum(tb[strlen(Sel->text)]))
{
if (Sel->type == SEL_REAL || Sel->type == SEL_PLANET)
{
Sel->fv = atof(eq+1);
if (Sel->pfv) *Sel->pfv = Sel->fv;
if (Sel->type == SEL_PLANET) Sel->fpl[Planet] = Sel->fv;
}
else
{
Sel->iv = atoi(eq+1);
if (Sel->piv) *Sel->piv = Sel->iv;
}
}
}
}
}
else if (!strncmp(tb,"[Modules]",9)) ChangeModel(-1);
else
{
for (pl=0 ; pl < PLANETS ; ++pl)
{
if (!strncmp(tb+1,PlanetName[pl],strlen(PlanetName[pl])) && pl != Planet)
ChangePlanet(pl);
}
}
fgets(tb,sizeof(tb),fp);
}
fclose(fp);
return 1;
}
void Exit(void)
{
int i;
WriteSettings();
// XNextEvent(display,&WinEvent);
// XCloseDisplay(display);
exit(0);
}
void AbortMessage(char *s)
{
printf("\n\n%s\n",s);
exit(1);
}
void Abort(void)
{
Exit();
}
void InitNextSelection(struct SelStruct *Sel, int dy, char *t)
{
Sel->type = Sel->Prev->type;
Sel->y = Sel->Prev->y + dy;
Sel->h = Sel->Prev->h;
Sel->w = Sel->Prev->w;
Sel->xo = Sel->Prev->xo;
Sel->yt = Sel->Prev->yt + dy;
strcpy(Sel->text,t);
Sel->lt = strlen(Sel->text);
Sel->teco = Sel->Prev->teco;
Sel->edco = Sel->Prev->edco;
}
void CursorOn(void)
{
int x,y,w,h;
if (CursorSel)
{
x = CursorSel->x + CursorCol * FixFontWidth;
y = CursorSel->y;
w = CursorSel->w;
h = CursorSel->h;
XSetForeground(display,gc,Red.pixel);
XDrawRectangle(display,Cow,gc,x,y,FixFontWidth,h);
XDrawRectangle(display,Cow,gc,x-1,y-1,FixFontWidth+2,h+2);
}
}
void RemoveBlanks(char *p)
{
int l;
l = strlen(p);
while (l && p[l-1] == ' ') p[--l] = 0;
}
struct SelStruct *NewSel(struct SelStruct *OldSel)
{
struct SelStruct *Sel;
Sel = calloc(1,sizeof(struct SelStruct));
OldSel->Next = Sel;
Sel->Prev = OldSel;
return Sel;
}
void NL_i(int m, char *list, char *name, int i)
{
if (NL_items > NL_MAX_ITEMS-2)
{
printf("\n*** Error ***\n");
printf("Number of namelist items exceeds %d \n",NL_MAX_ITEMS);
printf("Increase NL_MAX_ITEMS in most,c\n");
exit(1);
}
NL_list[NL_items].model = m;
strcpy(NL_list[NL_items].list,list);
strcpy(NL_list[NL_items].name,name);
NL_list[NL_items].flag = SEL_INT;
NL_list[NL_items].ival = i;
NL_list[NL_items].rval = 0.0;
NL_list[NL_items].text[0] = 0;
NL_items++;
}
void NL_r(int m, char *list, char *name, double r)
{
if (NL_items > NL_MAX_ITEMS-2)
{
printf("\n*** Error ***\n");
printf("Number of namelist items exceeds %d \n",NL_MAX_ITEMS);
printf("Increase NL_MAX_ITEMS in most,c\n");
exit(1);
}
NL_list[NL_items].model = m;
strcpy(NL_list[NL_items].list,list);
strcpy(NL_list[NL_items].name,name);
NL_list[NL_items].flag = SEL_REAL;
NL_list[NL_items].ival = 0;
NL_list[NL_items].rval = r;
NL_list[NL_items].text[0] = 0;
NL_items++;
}
void NL_p(char *name, float r[])
{
if (NL_items > NL_MAX_ITEMS-2)
{
printf("\n*** Error ***\n");
printf("Number of namelist items exceeds %d \n",NL_MAX_ITEMS);
printf("Increase NL_MAX_ITEMS in most,c\n");
exit(1);
}
NL_list[NL_items].model = PLASIM;
strcpy(NL_list[NL_items].list,"planet");
strcpy(NL_list[NL_items].name,name);
NL_list[NL_items].flag = SEL_PLANET;
NL_list[NL_items].ival = 0;
NL_list[NL_items].rval = 0.0;
NL_list[NL_items].text[0] = 0;
memcpy(NL_list[NL_items].pvec,r,sizeof(float) * PLANETS);
NL_items++;
}
void NL_t(int m, char *list, char *name, char *t)
{
if (NL_items > NL_MAX_ITEMS-2)
{
printf("\n*** Error ***\n");
printf("Number of namelist items exceeds %d \n",NL_MAX_ITEMS);
printf("Increase NL_MAX_ITEMS in most,c\n");
exit(1);
}
NL_list[NL_items].model = m;
strcpy(NL_list[NL_items].list,list);
strcpy(NL_list[NL_items].name,name);
NL_list[NL_items].flag = SEL_TEVA;
NL_list[NL_items].ival = 0;
NL_list[NL_items].rval = 0.0;
strcpy(NL_list[NL_items].text,t);
NL_items++;
}
// Earth Mars Exo
float eccen_vec[PLANETS] = { 0.016715, 0.09341233, 0.0};
float mvelp_vec[PLANETS] = { 102.7 , 336.04084 , 0.0};
float obliq_vec[PLANETS] = { 23.44 , 25.19 , 0.0};
float gsol0_vec[PLANETS] = {1367.0 , 595.0 ,1000.0};
void InitNamelist(void)
{
// Planet Simulator