-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.c
2581 lines (2234 loc) · 86.5 KB
/
options.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
/**************************************************************************
* options.c *
* *
* Written by Rory Barnes *
* *
* This file contains subroutines related to reading and verifying the *
* input options. *
* *
**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include "eqtide.h"
#include "options.h"
#include "output.h"
void ExitMultipleOptions(char infile[],char name[],int line1,int line2,int iExit) {
fprintf(stderr,"ERROR: Multiple occurences of option %s found.\n",name);
fprintf(stderr,"\t%s, lines: %d and %d\n",infile,line1,line2);
exit(iExit);
}
void AddOptionBool(char infile[], char name[], int *param, int *nline, int iExit,int iVerbose) {
FILE *fp;
char *line,*word,*cTmp;
int n=0,done=0,iLen;
iLen=strlen(name);
word = InitializeString(OPTLEN);
cTmp = InitializeString(OPTLEN);
line = InitializeString(LINELEN);
fp=fopen(infile,"r");
if (fp == NULL) {
fprintf(stderr,"ERROR: Unable to open %s.\n",infile);
exit(iExit);
}
// Memory leak -- if EOF reached, line is set to NULL and cannot be freed
while(fgets(line,LINELEN,fp) != NULL) {
/* Check for # sign */
if (memcmp(line,"#",1) != 0) {
/* Check for desired parameter */
sprintf(word,"null");
sscanf(line,"%s",word);
if (memcmp(word,name,iLen) == 0) {
/* Parameter Found! */
if (done)
ExitMultipleOptions(infile,name,*nline+1,n+1,iExit);
sscanf(line,"%s %s",cTmp,word);
*param=atoi(word);
done=1;
*nline=n;
}
}
n++;
}
if (done) {
if (*param == 0 || *param == 1) {
return;
} else {
fprintf(stderr,"ERROR: Option %s must be 0 or 1.\n",name);
LineExit(infile,*nline,iExit,iVerbose);
}
}
free(word);
free(cTmp);
free(line);
fclose(fp);
}
void AddOptionInt(char infile[], char name[], int *param, int *nline, int iExit) {
FILE *fp;
char line[LINELEN],*word,*cTmp;
int n=0,done=0,iLen;
iLen=strlen(name);
word = InitializeString(OPTLEN);
cTmp = InitializeString(OPTLEN);
fp=fopen(infile,"r");
if (fp == NULL) {
fprintf(stderr,"ERROR: Unable to open %s.\n",infile);
exit(iExit);
}
// Memory leak -- if EOF reached, line is set to NULL and cannot be freed
while(fgets(line,LINELEN,fp) != NULL) {
/* Check for # sign */
if (memcmp(line,"#",1) != 0) {
/* Check for desired parameter */
sprintf(word,"null");
sscanf(line,"%s",word);
if (memcmp(word,name,iLen) == 0) {
/* Parameter Found! */
if (done)
ExitMultipleOptions(infile,name,*nline+1,n+1,iExit);
sscanf(line,"%s %s",cTmp,word);
*param=atoi(word);
done=1;
*nline=n;
}
}
n++;
}
free(word);
free(cTmp);
fclose(fp);
}
void AddOptionDouble(char infile[], char name[], double *param,int *nline, int iExit) {
FILE *fp;
char line[LINELEN],*word,*cTmp;
int n=0,done=0,iLen;
iLen=strlen(name);
word = InitializeString(OPTLEN);
cTmp = InitializeString(OPTLEN);
fp=fopen(infile,"r");
if (fp == NULL) {
fprintf(stderr,"ERROR: Unable to open %s.\n",infile);
exit(iExit);
}
// Memory leak -- if EOF reached, line is set to NULL and cannot be freed
while(fgets(line,LINELEN,fp) != NULL) {
/* Check for # sign */
if (memcmp(line,"#",1) != 0) {
/* Check for desired parameter */
sprintf(word,"null");
sscanf(line,"%s",word);
if (memcmp(word,name,iLen) == 0) {
/* Parameter Found! */
if (done)
ExitMultipleOptions(infile,name,*nline+1,n+1,iExit);
sscanf(line,"%s %s",cTmp,word);
*param=atof(word);
done=1;
*nline=n;
}
}
n++;
}
free(word);
free(cTmp);
fclose(fp);
}
void AddOptionString(char infile[], char name[],char *param, int *nline, int iExit) {
FILE *fp;
char line[LINELEN],*word,*cTmp;
int n=0,done=0,iLen;
iLen=strlen(name);
word = InitializeString(OPTLEN);
cTmp = InitializeString(OPTLEN);
fp=fopen(infile,"r");
if (fp == NULL) {
fprintf(stderr,"ERROR: Unable to open %s.\n",infile);
exit(iExit);
}
// Memory leak -- if EOF reached, line is set to NULL and cannot be freed
while(fgets(line,LINELEN,fp) != NULL) {
/* Check for # sign */
if (memcmp(line,"#",1) != 0) {
/* Check for desired parameter */
sprintf(word,"null");
sscanf(line,"%s",word);
if (memcmp(word,name,iLen) == 0) {
/* Parameter Found! */
if (done)
ExitMultipleOptions(infile,name,*nline+1,n+1,iExit);
sscanf(line,"%s %s",cTmp,param);
done=1;
*nline=n;
}
}
n++;
}
free(word);
free(cTmp);
fclose(fp);
}
int GetNumOut(char infile[],char name[],int iLen,int *nline,int iExit) {
char line[LINELEN],*word;
int i,j,istart,ok,done=0,n=0,num;
FILE *fp;
word = InitializeString(OPTLEN);
fp=fopen(infile,"r");
if (fp == NULL) {
fprintf(stderr,"Unable to open %s.\n",infile);
exit(iExit);
}
while(fgets(line,LINELEN,fp) != NULL) {
/* Check for # sign */
if (memcmp(line,"#",1) != 0) {
/* Check for desired parameter */
sscanf(line,"%s",word);
if (memcmp(word,name,iLen) == 0) {
/* Parameter Found! */
if (done) {
fprintf(stderr,"ERROR: Multiple occurences of parameter %s found.\n",name);
fprintf(stderr,"\t%s, lines: %d and %d\n",infile,*nline,n);
exit(iExit);
}
done=1;
*nline=n;
num=0;
istart=0;
ok=1;
for (i=1;i<LINELEN;i++) { /* Ignore first character, as it makes conditional well-defined */
/* printf("%d ",line[i]); */
if (ok) {
if (line[i] == 35) {
/* Pound sign! */
ok=0;
num++;
}
if (isspace(line[i]) && !isspace(line[i-1]))
num++;
}
}
}
}
n++;
for (i=0;i<LINELEN;i++)
line[i]=0;
}
/* Lose the input parameter */
num--;
free(word);
fclose(fp);
return num;
}
int AddOutputOrder(char infile[], char name[], int iLen,char *param[NUMOUT],int *nline,OUTPUT *output,int iVerbose,int iExit) {
FILE *fp;
char line[LINELEN],*word,*cTmp,*opt[NUMOUT],*input[NUMOUT],*base,*out[NUMOUT];
int i=0,count=0,n=0,istart=0,j=0,nl=0,k=0,bNeg=0,iOut=0;
int foo;
word = InitializeString(OPTLEN);
cTmp = InitializeString(OPTLEN);
for (i=0;i<NUMOUT;i++) {
opt[i] = InitializeString(OPTLEN);
input[i] = InitializeString(OPTLEN);
out[i] = InitializeString(OPTLEN);
param[i] = InitializeString(OPTLEN);
}
fp=fopen(infile,"r");
if (fp == NULL) {
fprintf(stderr,"Unable to open %s.\n",infile);
exit(iExit);
}
rewind(fp);
/* Variables:
n = Counter of Output; at end is total #
count = Number of matches to output.cParam
word = string to search for option in input file
name = name of option in input file
input[n] = Verbatim string from input stream
base = Dummy copy of input, to allow for capitalization manipulation
output.cParam = Output option string
cTmp = Dummy copy of output.cParam, to allow for capitalization manipulation
opt = array of possible output options
param = Output option with capitalization (¶m->cOutputOrder)
out = Dummy of param
bNeg = Negative sign in front of option?
iOut = ID of output struct that matches an output parameter
istart = index of line at end of last parameter
*/
// Memory leak -- if EOF reached, line is set to NULL and can't be freed
while(fgets(line,LINELEN,fp) != NULL) {
/* Check for # sign */
foo = strlen(line);
if (memcmp(line,"#",1) != 0) {
/* Check for desired parameter */
sprintf(word,"null");
sscanf(line,"%s",word);
if (memcmp(word,name,iLen) == 0) {
/* Parameter Found! */
n=0;
*nline=nl;
istart=0;
base = InitializeString(OPTLEN);
// Read in output parameters, one character at a time
for (i=0;i<LINELEN;i++) {
/* printf("%d ",line[i]); */
/* If this character is not white space, #, or the last line,
then read in the character
*/
if (isspace(line[i]) || line[i] == 35 || i == strlen(line)-1 ) {
for (j=0;j<(i-istart);j++) {
/* printf("%d ",line[istart+j]); */
// Check if the first character is a negative sign
if (line[istart+j] == 45) {
bNeg = 1;
// Place characters in string one at a time
} else if (!iscntrl(line[istart+j]) && line[istart+j] != 35)
/* if (line[istart+j] != 10) */
input[n][j-bNeg] = line[istart+j];
}
/* Dump string into buffer. This is to maintain
capitalization in original input. */
for (k=0;k<OPTLEN;k++)
base[k]=input[n][k];
/* Don't include name of parameter, e.g. OutputOrder */
if (memcmp(input[n],name,iLen)) { // returns 0 if the two strings match
/* Check for ambiguity */
count=0; /* How many possibilities? */
for (j=0;j<NUMOUT;j++) {
for (k=0;k<OPTLEN;k++)
/* Maintain capitalization in output.cParam */
cTmp[k]=output->cParam[j][k];
//printf("%d %s %s %d %d\n",n,base,cTmp,i,istart);
//fflush(stdout);
//if (memcmp(lower(base),lower(cTmp),(i-istart)) == 0) {
if (memcmp(lower(base),lower(cTmp),strlen(base)) == 0) {
/* Valid output option found */
for (k=0;k<OPTLEN;k++)
opt[count][k]=output->cParam[j][k];
count++;
iOut=j;
}
}
if (count > 1) {
/* More than one possibility */
if (iVerbose >= VERBERR) {
fprintf(stderr,"ERROR: Output option \"%s\" is ambiguous. Options are ",input[n]);
for (k=0;k<count;k++) {
fprintf(stderr,"%s",opt[k]);
if (k < count-1)
fprintf(stderr,", ");
}
fprintf(stderr,".\n");
}
LineExit(infile,nl,iExit,iVerbose);
}
if (!count) {
/* Option not found */
if (iVerbose >= VERBERR)
fprintf(stderr,"ERROR: Unknown option %s listed in %s.\n",input[n],name);
LineExit(infile,nl,iExit,iVerbose);
}
if (count == 1) {
/* Unique option */
param[n-1] = InitializeString(OPTLEN);
for (k=0;k<OPTLEN;k++) {
/* n-1 because n=0 is name */
param[n-1][k]=opt[0][k];
out[n-1][k]=param[n-1][k];
}
output->iNeg[iOut]=bNeg;
if (bNeg && iVerbose >= VERBUNITS)
fprintf(stderr,"WARNING: Output option %s is negative, output units will be %s\n",param[n-1],output->cNeg[iOut]);
bNeg=0;
}
}
while (isspace(line[i])) i++;
istart=i;
n++; /*?*/
}
}
}
}
for (j=0;j<LINELEN;j++) line[j]=0;
nl++;
}
/* First check redundancy */
for (i=1;i<n;i++) { // n-1 because n=0 is Option name
for (k=0;k<i;k++) { // n-1 because n=0 is Option name
//printf("%d %d %s %s\n",i,k,param[i],param[k]);
//fflush(stdout);
//if (memcmp(param[i],param[k],strlen(param[i]-1)) == 0) {
if (strcmp(param[i],param[k]) == 0) {
/* Match */
if (iVerbose >= VERBERR)
fprintf(stderr,"ERROR: Same option listed multiple times in %s: %s.\n",name,param[k]);
LineExit(infile,nl,iExit,iVerbose);
}
}
}
// Release memory mallocked in InitializeString
free(word);
free(cTmp);
for (i=0;i<NUMOUT;i++) {
free(opt[i]);
free(input[i]);
free(out[i]);
}
fclose(fp);
// Return number of output columns. If no output requested, returns -1
return n-1;
}
int iGetNumLines(char infile[],int iExit) {
int n=0;
FILE *fp;
char line[LINELEN];
fp=fopen(infile,"r");
if (fp == NULL) {
fprintf(stderr,"Unable to open %s.\n",infile);
exit(iExit);
}
// Memory leak -- if EOF reached, line is set to NULL and can't be freed
while(fgets(line,LINELEN,fp) != NULL) {
n++;
}
return n;
}
void InitializeInput(char infile[],int iNumLines,int iLineOK[],int iExit) {
int n,i,bad;
FILE *fp;
char line[LINELEN];
fp=fopen(infile,"r");
if (fp == NULL) {
fprintf(stderr,"Unable to open %s.\n",infile);
exit(iExit);
}
for (n=0;n<iNumLines;n++) {
/* Initialize iLineOK */
iLineOK[n] = 0;
for (i=0;i<LINELEN;i++) line[i]=32;
fgets(line,LINELEN,fp);
/* Check for # sign or blank line */
if (!memcmp(line,"#",1)) {
/* Line is OK */
iLineOK[n] = 1;
} else {
bad=0;
for (i=0;i<LINELEN;i++) {
if (!isspace(line[i]) && line[i] != '\0') {
bad=1;
}
}
if (!bad) iLineOK[n] = 1;
}
}
}
void InitializeOptions(OPTIONS *options) {
int i;
for (i=0;i<NUMOPT;i++)
sprintf(options->cParam[i],"null");
/* Do System Name first as it is used by other options. */
sprintf(options->cParam[OPT_SYSTEMNAME],"sSystemName");
sprintf(options->cDescr[OPT_SYSTEMNAME],"System Name");
sprintf(options->cDefault[OPT_SYSTEMNAME],"None - must be supplied");
options->iType[OPT_SYSTEMNAME] = 3;
/*
*
* A
*
*/
sprintf(options->cParam[OPT_AGE],"dAge");
sprintf(options->cDescr[OPT_AGE],"System Age");
sprintf(options->cDefault[OPT_AGE],"0");
options->iType[OPT_AGE] = 2;
/*
*
* B
*
*/
sprintf(options->cParam[OPT_BACK],"bDoBackward");
sprintf(options->cDescr[OPT_BACK],"Do Backward Integration?");
sprintf(options->cDefault[OPT_BACK],"No");
options->iType[OPT_BACK] = 0;
sprintf(options->cParam[OPT_BACKFILE],"sBackwardFile");
sprintf(options->cDescr[OPT_BACKFILE],"Name of Backward Integration Output File");
sprintf(options->cDefault[OPT_BACKFILE],"%s.backward",options->cParam[OPT_SYSTEMNAME]);
options->iType[OPT_BACKFILE] = 3;
sprintf(options->cParam[OPT_BACKOUTPUTTIME],"dBackwardOutputTime");
sprintf(options->cDescr[OPT_BACKOUTPUTTIME],"Output Interval for Backward Intgeration");
sprintf(options->cDefault[OPT_BACKOUTPUTTIME],"1");
options->iType[OPT_BACKOUTPUTTIME] = 2;
sprintf(options->cParam[OPT_BACKSTOPTIME],"dBackwardStopTime");
sprintf(options->cDescr[OPT_BACKSTOPTIME],"Stop Time for Backward Integration");
sprintf(options->cDefault[OPT_BACKSTOPTIME],"10");
options->iType[OPT_BACKSTOPTIME] = 2;
sprintf(options->cParam[OPT_BACKTIMESTEP],"dBackwardTimeStep");
sprintf(options->cDescr[OPT_BACKTIMESTEP],"Timestep for Backward Integration");
sprintf(options->cDefault[OPT_BACKTIMESTEP],"1");
options->iType[OPT_BACKTIMESTEP] = 2;
/*
*
* D
*
*/
sprintf(options->cParam[OPT_DISCRETEROT],"bDiscreteRot");
sprintf(options->cDescr[OPT_DISCRETEROT],"Use Discrete Rotation Model (Phase lag only)");
sprintf(options->cDefault[OPT_DISCRETEROT],"1");
options->iType[OPT_DISCRETEROT] = 0;
/*
* FORWARD
*
*/
sprintf(options->cParam[OPT_FORW],"bDoForward");
sprintf(options->cDescr[OPT_FORW],"Do Forward Integration?");
sprintf(options->cDefault[OPT_FORW],"0");
options->iType[OPT_FORW] = 0;
sprintf(options->cParam[OPT_FORWFILE],"sForwardFile");
sprintf(options->cDescr[OPT_FORWFILE],"Name of Forward Integration Output File");
sprintf(options->cDefault[OPT_FORWFILE],"%s.forward",options->cParam[OPT_SYSTEMNAME]);
options->iType[OPT_FORWFILE] = 3;
sprintf(options->cParam[OPT_FORWOUTPUTTIME],"dForwardOutputTime");
sprintf(options->cDescr[OPT_FORWOUTPUTTIME],"Output Interval for Forward Integration");
sprintf(options->cDefault[OPT_FORWOUTPUTTIME],"1");
options->iType[OPT_FORWOUTPUTTIME] = 2;
sprintf(options->cParam[OPT_FORWSTOPTIME],"dForwardStopTime");
sprintf(options->cDescr[OPT_FORWSTOPTIME],"Stop Time for Forward Integration");
sprintf(options->cDefault[OPT_FORWSTOPTIME],"10");
options->iType[OPT_FORWSTOPTIME] = 2;
sprintf(options->cParam[OPT_FORWTIMESTEP],"dForwardTimeStep");
sprintf(options->cDescr[OPT_FORWTIMESTEP],"Timestep for Forward Integration");
sprintf(options->cDefault[OPT_FORWTIMESTEP],"1");
options->iType[OPT_FORWTIMESTEP] = 2;
/*
*
* HALT
*
*/
sprintf(options->cParam[OPT_HALTDBLSYNC],"bHaltDblSync");
sprintf(options->cDescr[OPT_HALTDBLSYNC],"Halt at Double Synchronous State?");
sprintf(options->cDefault[OPT_HALTDBLSYNC],"0");
options->iType[OPT_HALTDBLSYNC] = 0;
sprintf(options->cParam[OPT_HALTMAXECC],"dHaltMaxEcc");
sprintf(options->cDescr[OPT_HALTMAXECC],"Maximum Eccentricity Value that Halts Integration");
sprintf(options->cDefault[OPT_HALTMAXECC],"1");
options->iType[OPT_HALTMAXECC] = 2;
sprintf(options->cParam[OPT_HALTMERGE],"bHaltMerge");
sprintf(options->cDescr[OPT_HALTMERGE],"Halt at Merge");
sprintf(options->cDefault[OPT_HALTMERGE],"1");
options->iType[OPT_HALTMERGE] = 0;
sprintf(options->cParam[OPT_HALTMINECC],"dHaltMinEcc");
sprintf(options->cDescr[OPT_HALTMINECC],"Minimum Eccentricity Value that Halts Integration");
sprintf(options->cDefault[OPT_HALTMINECC],"0");
options->iType[OPT_HALTMINECC] = 2;
sprintf(options->cParam[OPT_HALTMINPRIOBL],"dHaltMinPriObl");
sprintf(options->cDescr[OPT_HALTMINPRIOBL],"Primary's Minimum Obliquity Value that Halts Integration");
sprintf(options->cDefault[OPT_HALTMINPRIOBL],"0");
options->iType[OPT_HALTMINPRIOBL] = 2;
sprintf(options->cParam[OPT_HALTMINSECOBL],"dHaltMinSecObl");
sprintf(options->cDescr[OPT_HALTMINSECOBL],"Secondary's Minimum Obliquity Value that Halts Integration");
sprintf(options->cDefault[OPT_HALTMINSECOBL],"0");
options->iType[OPT_HALTMINSECOBL] = 2;
sprintf(options->cParam[OPT_HALTMINSEMI],"dHaltMinSemi");
sprintf(options->cDescr[OPT_HALTMINSEMI],"Minimum Semi-Major Axis Value that Halts Integration");
sprintf(options->cDefault[OPT_HALTMINSEMI],"0");
options->iType[OPT_HALTMINSEMI] = 2;
sprintf(options->cParam[OPT_HALTPOSDEDT],"bHaltPosDeDt");
sprintf(options->cDescr[OPT_HALTPOSDEDT],"Halt if de/dt > 0?");
sprintf(options->cDefault[OPT_HALTPOSDEDT],"0");
options->iType[OPT_HALTPOSDEDT] = 0;
sprintf(options->cParam[OPT_HALTPRILOCK],"bHaltPriLock");
sprintf(options->cDescr[OPT_HALTPRILOCK],"Halt if Primary Becomes Tide-Locked?");
sprintf(options->cDefault[OPT_HALTPRILOCK],"0");
options->iType[OPT_HALTPRILOCK] = 0;
sprintf(options->cParam[OPT_HALTSECLOCK],"bHaltSecLock");
sprintf(options->cDescr[OPT_HALTSECLOCK],"Halt if Secondary Becomes Tide-Locked?");
sprintf(options->cDefault[OPT_HALTSECLOCK],"0");
options->iType[OPT_HALTSECLOCK] = 0;
sprintf(options->cParam[OPT_HALTSECSYNC],"bHaltSecSync");
sprintf(options->cDescr[OPT_HALTSECSYNC],"Halt if Secondary's rotation becomes syncrhonous?");
sprintf(options->cDefault[OPT_HALTSECSYNC],"0");
options->iType[OPT_HALTSECSYNC] = 0;
/*
*
* I
*
*/
sprintf(options->cParam[OPT_INTEGRATION],"sIntegration");
sprintf(options->cDescr[OPT_INTEGRATION],"Integration method (Euler or RungeKutta4");
sprintf(options->cDefault[OPT_INTEGRATION],"RungeKutta4");
options->iType[OPT_INTEGRATION] = 3;
/*
*
* L
*
*/
sprintf(options->cParam[OPT_LOG],"bDoLog");
sprintf(options->cDescr[OPT_LOG],"Write Log File?");
sprintf(options->cDefault[OPT_LOG],"0");
options->iType[OPT_LOG] = 0;
sprintf(options->cParam[OPT_LOGFILE],"sLogFile");
sprintf(options->cDescr[OPT_LOGFILE],"Log File Name");
sprintf(options->cDefault[OPT_LOGFILE],"tide.log");
options->iType[OPT_LOGFILE] = 3;
/*
*
* M
*
*/
sprintf(options->cParam[OPT_MINVALUE],"dMinValue");
sprintf(options->cDescr[OPT_MINVALUE],"Minimum Non-Zero Value of Eccentricity and Obliquities");
sprintf(options->cDefault[OPT_MINVALUE],"0");
options->iType[OPT_MINVALUE] = 2;
/*
*
* O
*
*/
sprintf(options->cParam[OPT_OUTDIGITS],"iDigits");
sprintf(options->cDescr[OPT_OUTDIGITS],"Number of Digits After Decimal Point");
sprintf(options->cDefault[OPT_OUTDIGITS],"4");
options->iType[OPT_OUTDIGITS] = 1;
sprintf(options->cParam[OPT_OUTPUTORDER],"sOutputOrder");
sprintf(options->cDescr[OPT_OUTPUTORDER],"Output Parameter(s)");
sprintf(options->cDefault[OPT_OUTPUTORDER],"None");
options->iType[OPT_OUTPUTORDER] = 4;
sprintf(options->cParam[OPT_OUTSCINOT],"iSciNot");
sprintf(options->cDescr[OPT_OUTSCINOT],"Logarithm to Change from Standard to Scientific Notation");
sprintf(options->cDefault[OPT_OUTSCINOT],"4");
options->iType[OPT_OUTSCINOT] = 1;
/*
*
* ORBIT
*
*/
sprintf(options->cParam[OPT_ORBECC],"dEcc");
sprintf(options->cDescr[OPT_ORBECC],"Orbital Eccentricity");
sprintf(options->cDefault[OPT_ORBECC],"0");
options->iType[OPT_ORBECC] = 2;
sprintf(options->cParam[OPT_ORBMEANMOTION],"dMeanMotion");
sprintf(options->cDescr[OPT_ORBMEANMOTION],"Orbital Mean Motion");
sprintf(options->cDefault[OPT_ORBMEANMOTION],"1");
options->iType[OPT_ORBMEANMOTION] = 2;
sprintf(options->cParam[OPT_ORBPER],"dPeriod");
sprintf(options->cDescr[OPT_ORBPER],"Orbital Period");
sprintf(options->cDefault[OPT_ORBPER],"1");
options->iType[OPT_ORBPER] = 2;
sprintf(options->cParam[OPT_ORBSEMI],"dSemi");
sprintf(options->cDescr[OPT_ORBSEMI],"Semi-Major Axis");
sprintf(options->cDefault[OPT_ORBSEMI],"1");
options->iType[OPT_ORBSEMI] = 2;
/*
*
* P
*
*/
sprintf(options->cParam[OPT_PRIFORCEEQSPIN],"bPrimaryForceEqSpin");
sprintf(options->cDescr[OPT_PRIFORCEEQSPIN],"Force Primary's Spin Rate to Equilibrium");
sprintf(options->cDefault[OPT_PRIFORCEEQSPIN],"0");
options->iType[OPT_PRIFORCEEQSPIN] = 0;
sprintf(options->cParam[OPT_PRIK2],"dPrimaryK2");
sprintf(options->cDescr[OPT_PRIK2],"Love Number of Degree 2 of Primary");
sprintf(options->cDefault[OPT_PRIK2],"1");
options->iType[OPT_PRIK2] = 2;
sprintf(options->cParam[OPT_PRIMASS],"dPrimaryMass");
sprintf(options->cDescr[OPT_PRIMASS],"Mass of Primary");
sprintf(options->cDefault[OPT_PRIMASS],"1");
options->iType[OPT_PRIMASS] = 2;
sprintf(options->cParam[OPT_PRIMASSRAD],"sPrimaryMassRad");
sprintf(options->cDescr[OPT_PRIMASSRAD],"Mass-Radius Relationship for Central Body: GS99 RH00 BO06 Sotin07 ");
sprintf(options->cDefault[OPT_PRIMASSRAD],"None");
options->iType[OPT_PRIMASSRAD] = 3;
sprintf(options->cParam[OPT_PRIMAXLOCKDIFF],"dPrimaryMaxLockDiff");
sprintf(options->cDescr[OPT_PRIMAXLOCKDIFF],"Maximum relative difference between primary's spin and equilibrium spin rates to force equilibrium spin rate");
sprintf(options->cDefault[OPT_PRIMAXLOCKDIFF],"0");
options->iType[OPT_PRIMAXLOCKDIFF] = 3;
sprintf(options->cParam[OPT_PRIOBL],"dPrimaryObliquity");
sprintf(options->cDescr[OPT_PRIOBL],"Obliquity of Primary");
sprintf(options->cDefault[OPT_PRIOBL],"0");
options->iType[OPT_PRIOBL] = 2;
sprintf(options->cParam[OPT_PRIQ],"dPrimaryQ");
sprintf(options->cDescr[OPT_PRIQ],"Tidal Quality Factor of Primary");
sprintf(options->cDefault[OPT_PRIQ],"1e6");
options->iType[OPT_PRIQ] = 2;
sprintf(options->cParam[OPT_PRIRAD],"dPrimaryRadius");
sprintf(options->cDescr[OPT_PRIRAD],"Radius of Primary");
sprintf(options->cDefault[OPT_PRIRAD],"1");
options->iType[OPT_PRIRAD] = 2;
sprintf(options->cParam[OPT_PRIRG],"dPrimaryRadGyra");
sprintf(options->cDescr[OPT_PRIRG],"Radius of Gyration of Primary");
sprintf(options->cDefault[OPT_PRIRG],"0.5");
options->iType[OPT_PRIRG] = 2;
sprintf(options->cParam[OPT_PRISPINPER],"dPrimarySpinPeriod");
sprintf(options->cDescr[OPT_PRISPINPER],"Rotation Period of Primary");
sprintf(options->cDefault[OPT_PRISPINPER],"1");
options->iType[OPT_PRISPINPER] = 2;
sprintf(options->cParam[OPT_PRISPINRATE],"dPrimarySpinRate");
sprintf(options->cDescr[OPT_PRISPINRATE],"Rotational Angular Frequency of Primary");
sprintf(options->cDefault[OPT_PRISPINRATE],"1");
options->iType[OPT_PRISPINRATE] = 2;
sprintf(options->cParam[OPT_PRITAU],"dPrimaryTau");
sprintf(options->cDescr[OPT_PRITAU],"Time Lag of Primary");
sprintf(options->cDefault[OPT_PRITAU],"1");
options->iType[OPT_PRITAU] = 2;
sprintf(options->cParam[OPT_PRIVROT],"dPrimaryRotVel");
sprintf(options->cDescr[OPT_PRIVROT],"Rotational Velocity of Primary");
sprintf(options->cDefault[OPT_PRIVROT],"None");
options->iType[OPT_PRIVROT] = 2;
/*
*
* S
*
*/
sprintf(options->cParam[OPT_SECK2],"dSecondaryK2");
sprintf(options->cDescr[OPT_SECK2],"Love Number of Degree 2 of Secondary");
sprintf(options->cDefault[OPT_SECK2],"1");
options->iType[OPT_SECK2] = 2;
sprintf(options->cParam[OPT_SECK2],"dSecondaryK2");
sprintf(options->cDescr[OPT_SECK2],"Love Number of Degree 2 of Secondary");
sprintf(options->cDefault[OPT_SECK2],"1");
options->iType[OPT_SECK2] = 2;
sprintf(options->cParam[OPT_SECFORCEEQSPIN],"bSecondaryForceEqSpin");
sprintf(options->cDescr[OPT_SECFORCEEQSPIN],"Force Secondary's Spin Rate to Equilibrium");
sprintf(options->cDefault[OPT_SECFORCEEQSPIN],"0");
options->iType[OPT_SECFORCEEQSPIN] = 0;
sprintf(options->cParam[OPT_SECMASS],"dSecondaryMass");
sprintf(options->cDescr[OPT_SECMASS],"Mass of Secondary");
sprintf(options->cDefault[OPT_SECMASS],"1");
options->iType[OPT_SECMASS] = 2;
sprintf(options->cParam[OPT_SECMASSRAD],"sSecondaryMassRad");
sprintf(options->cDescr[OPT_SECMASSRAD],"Mass-Radius Relationship for Secondary: GS99 RH00 BO06 Sotin07");
sprintf(options->cDefault[OPT_SECMASSRAD],"None");
options->iType[OPT_SECMASSRAD] = 3;
sprintf(options->cParam[OPT_SECMAXLOCKDIFF],"dSecondaryMaxLockDiff");
sprintf(options->cDescr[OPT_SECMAXLOCKDIFF],"Maximum relative difference between secondary's spin and equilibrium spin rates to force equilibrium spin rate");
sprintf(options->cDefault[OPT_SECMAXLOCKDIFF],"0");
options->iType[OPT_SECMAXLOCKDIFF] = 3;
sprintf(options->cParam[OPT_SECOBL],"dSecondaryObl");
sprintf(options->cDescr[OPT_SECOBL],"Obliquity of Secondary");
sprintf(options->cDefault[OPT_SECOBL],"0");
options->iType[OPT_SECOBL] = 2;
sprintf(options->cParam[OPT_SECQ],"dSecondaryQ");
sprintf(options->cDescr[OPT_SECQ],"Tidal Quality Factor of Secondary");
sprintf(options->cDefault[OPT_SECQ],"100");
options->iType[OPT_SECQ] = 2;
sprintf(options->cParam[OPT_SECRAD],"dSecondaryRadius");
sprintf(options->cDescr[OPT_SECRAD],"Radius of Secondary");
sprintf(options->cDefault[OPT_SECRAD],"1");
options->iType[OPT_SECRAD] = 2;
sprintf(options->cParam[OPT_SECRG],"dSecondaryRadGyra");
sprintf(options->cDescr[OPT_SECRG],"Radius of Gyration of Secondary");
sprintf(options->cDefault[OPT_SECRG],"0.5");
options->iType[OPT_SECRG] = 2;
sprintf(options->cParam[OPT_SECSPINPER],"dSecondarySpinPer");
sprintf(options->cDescr[OPT_SECSPINPER],"Rotational Period of Secondary");
sprintf(options->cDefault[OPT_SECSPINPER],"0");
options->iType[OPT_SECSPINPER] = 2;
sprintf(options->cParam[OPT_SECSPINRATE],"dSecondarySpinRate");
sprintf(options->cDescr[OPT_SECSPINRATE],"Rotational Angular Frequency of Secondary");
sprintf(options->cDefault[OPT_SECSPINRATE],"0");
options->iType[OPT_SECSPINRATE] = 2;
sprintf(options->cParam[OPT_SECSYNCECC],"dSecondarySyncEcc");
sprintf(options->cDescr[OPT_SECSYNCECC],"Secondary's Rotation is synchronous below this value");
sprintf(options->cDefault[OPT_SECSYNCECC],"0");
options->iType[OPT_SECSYNCECC] = 2;
sprintf(options->cParam[OPT_SECTAU],"dSecondaryTau");
sprintf(options->cDescr[OPT_SECTAU],"Time Lag for Secondary");
sprintf(options->cDefault[OPT_SECTAU],"1");
options->iType[OPT_SECTAU] = 2;
sprintf(options->cParam[OPT_SECVROT],"dSecondaryRotVel");
sprintf(options->cDescr[OPT_SECVROT],"Rotational Velocity of Secondary");
sprintf(options->cDefault[OPT_SECVROT],"1");
options->iType[OPT_SECVROT] = 2;
/*
*
* T
*
*/
sprintf(options->cParam[OPT_TIMESTEPCOEFF],"dTimestepCoeff");
sprintf(options->cDescr[OPT_TIMESTEPCOEFF],"Coefficient to scale the timestep");
sprintf(options->cDefault[OPT_TIMESTEPCOEFF],"1");
options->iType[OPT_TIMESTEPCOEFF] = 2;
sprintf(options->cParam[OPT_TIDEMODEL],"sTideModel");
sprintf(options->cDescr[OPT_TIDEMODEL],"Tidal Model: p2 [constant-phase-lag, 2nd order] t8 [constant-time-lag, 8th order]");
sprintf(options->cDefault[OPT_TIDEMODEL],"p2");
options->iType[OPT_TIDEMODEL] = 3;
/*
*
* UNITS
*
*/
sprintf(options->cParam[OPT_UNITANGLE],"sUnitAngle");
sprintf(options->cDescr[OPT_UNITANGLE],"Angle Units: Degrees Radians");
sprintf(options->cDefault[OPT_UNITANGLE],"Radians");
options->iType[OPT_UNITANGLE] = 3;
sprintf(options->cParam[OPT_UNITLENGTH],"sUnitLength");
sprintf(options->cDescr[OPT_UNITLENGTH],"Length Units: cm m km Solar Earth Jupiter AU");
sprintf(options->cDefault[OPT_UNITLENGTH],"cm");
options->iType[OPT_UNITLENGTH] = 3;
sprintf(options->cParam[OPT_UNITMASS],"sUnitMass");
sprintf(options->cDescr[OPT_UNITMASS],"Mass Units: Grams Kilograms Solar Earth Jupiter Saturn");
sprintf(options->cDefault[OPT_UNITMASS],"grams");
options->iType[OPT_UNITMASS] = 3;
sprintf(options->cParam[OPT_UNITTIME],"sUnitTime");
sprintf(options->cDescr[OPT_UNITTIME],"Time Units: Seconds, Days Years Myr Gyr");
sprintf(options->cDefault[OPT_UNITTIME],"Seconds");
options->iType[OPT_UNITTIME] = 3;
/*
*
* V
*
*/
sprintf(options->cParam[OPT_VARDT],"bVarDt");
sprintf(options->cDescr[OPT_VARDT],"Use variable timestep for Backward Integration?");
sprintf(options->cDefault[OPT_VARDT],"No");
options->iType[OPT_VARDT] = 0;
sprintf(options->cParam[OPT_VERBOSE],"iVerbose");
sprintf(options->cDescr[OPT_VERBOSE],"Verbosity Level: 1-5");
sprintf(options->cDefault[OPT_VERBOSE],"3");
options->iType[OPT_VERBOSE] = 1;
}
void Unrecognized(char infile[],int iNumLines,int *iLineOK,int iExit) {
FILE *fp;
char line[LINELEN],word[16];
/* foo is a placeholder for calls to EqSpinRate_CTL */
int i,iBad=0,foo; /* Assume don't exit */
fp=fopen(infile,"r");
for (i=0;i<iNumLines;i++) {
fgets(line,LINELEN,fp);
if (!iLineOK[i]) {
/* Bad line */
sscanf(line,"%s",word);
fprintf(stderr,"ERROR: Unrecognized parameter \"%s\" in %s, line %d.\n",word,infile,i+1);
iBad++;
}
}
if (iBad) {
fprintf(stderr,"%d bad line(s) in %s.\n",iBad,infile);
exit(iExit);
}
}
void VerifyOptions(PARAM *param,PRIMARY *pri,SECONDARY *sec,INPUT input,OPTIONS options,LINE line,char infile[],IO *io) {
/* foo is a placeholder for calls to EqSpinRate_CTL */
int foo;
if (sec->dSemi == 0 && sec->dMeanMotion == 0 && input.dPeriod == 0) {
fprintf(stderr,"ERROR: dSemi, dMeanMotion, or dPeriod are not set.\n");
exit(io->exit_param);
}
if (sec->dSemi != 0 && sec->dMeanMotion != 0 && input.dPeriod != 0) {
fprintf(stderr,"ERROR: dSemi (line %d), dMeanMotion (line %d) and dPeriod (line %d) are all set! Only one is allowed.\n",line.lSemi,line.lMeanMotion,line.lPeriod);
exit(io->exit_param);
}
if (sec->dSemi != 0 && sec->dMeanMotion != 0) {
fprintf(stderr,"ERROR: dSemi (line %d), dMeanMotion (line %d) are both set! Only one is allowed.\n",line.lSemi,line.lMeanMotion);
exit(io->exit_param);
}
if (sec->dSemi != 0 && input.dPeriod != 0) {
fprintf(stderr,"ERROR: dSemi (line %d) and dPeriod (line %d) are both set! Only one is allowed.\n",line.lSemi,line.lPeriod);
exit(io->exit_param);
}
if (sec->dMeanMotion != 0 && input.dPeriod != 0) {
fprintf(stderr,"ERROR: dMeanMotion (line %d) and dPeriod (line %d) are all set! Only one is allowed.\n",line.lMeanMotion,line.lPeriod);
exit(io->exit_param);
}
/*
* Only one of semi-major axis, period and mean motion are set, now
* assign dSemi and dMeanMotion.
*/
if (sec->dSemi != 0) {
input.dPeriod=a2p(sec->dSemi,(sec->dMass + pri->dMass));
sec->dMeanMotion=dPerToFreq(input.dPeriod);
} else if (sec->dMeanMotion != 0) {
input.dPeriod=dFreqToPer(sec->dMeanMotion);
sec->dSemi=p2a(input.dPeriod,(sec->dMass + pri->dMass));
} else if (input.dPeriod != 0) {
sec->dMeanMotion = dPerToFreq(input.dPeriod);
sec->dSemi = p2a(input.dPeriod,(pri->dMass+sec->dMass));
}
/*
* Primary Mass and Radius
*/
if (pri->dMass == 0) {
if (pri->dRadius > 0 && pri->iMassRad > 0) {