forked from VirtualPlanetaryLaboratory/vplanet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvplanet.c
More file actions
164 lines (135 loc) · 4.59 KB
/
Copy pathvplanet.c
File metadata and controls
164 lines (135 loc) · 4.59 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
/**
@file vplanet.c
@brief The main entry point for the code. All the magic starts here.
@author Rory Barnes ([RoryBarnes](https://github.com/RoryBarnes/))
@date May 7 2014
*/
#include "vplanet.h"
/*
#ifdef DEBUG
#define _GNU_SOURCE
#include <fenv.h>
#endif
*/
/* Do not change these values */
const double dHUGE = DBL_MAX; // This is the largest possible double value according to <float.h>
const double dTINY = 1./DBL_MAX; // This is the smallest possibled double value according to <float.h>
/* Do not change these values */
/*! \brief Main function. All the magic happens here!
*/
int main(int argc,char *argv[]) {
#ifdef DEBUG
// feenableexcept(FE_INVALID | FE_OVERFLOW);
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID);
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_OVERFLOW);
#endif
struct timeval start, end;
/* Fix CPU time calculation someday
gettimeofday(&start, NULL);
time_t dStartTime;
dStartTime = time(NULL);
*/
int iOption,iVerbose,iQuiet,iOverwrite;
OPTIONS *options;
OUTPUT *output;
CONTROL control;
UPDATE *update;
BODY *body;
MODULE module;
FILES files;
SYSTEM system;
char infile[NAMELEN];
fnReadOption fnRead[MODULEOPTEND]; // XXX Pointers?
fnWriteOutput fnWrite[MODULEOUTEND];
fnUpdateVariable ***fnUpdate;
fnIntegrate fnOneStep;
#ifdef GITVERSION
strcpy(control.sGitVersion,GITVERSION);
#else
strcpy(control.sGitVersion,"Unknown");
#endif
/** Must initialize all options and outputs for all modules
independent of what is selected. This allows a complete
help screen as well as checks during ReadOptions. This
also requires the only modifications outside of module.c:
Add explicit references to all modules at the end of
options.c, output.c and util.c.
*/
options = malloc(MODULEOPTEND*sizeof(OPTIONS));
InitializeOptions(options,fnRead);
output = malloc(MODULEOUTEND*sizeof(OUTPUT));
InitializeOutput(output,fnWrite);
/* Set to IntegrationMethod to 0, so default can be
assigned if necessary */
control.Evolve.iOneStep = 0;
/* Copy executable file name to the files struct. */
strcpy(files.cExe,argv[0]);
if (argc == 1) {
fprintf(stderr,"Usage: %s [-v, -verbose] [-q, -quiet] [-h, -help] [-H, -Help] <file>\n",argv[0]);
exit(EXIT_EXE);
}
iVerbose=-1;
iQuiet=-1;
iOverwrite=-1;
control.Io.iVerbose=-1;
control.Io.bOverwrite=-1;
/* Check for flags */
for (iOption=1;iOption<argc;iOption++) {
if (memcmp(argv[iOption],"-v",2) == 0) {
control.Io.iVerbose = 5;
iVerbose=iOption;
}
if (memcmp(argv[iOption],"-q",2) == 0) {
control.Io.iVerbose = 0;
iQuiet=iOption;
}
if (memcmp(argv[iOption],"-f",2) == 0) {
control.Io.bOverwrite = 1;
iOverwrite=iOption;
}
if (memcmp(argv[iOption],"-h",2) == 0)
Help(options,output,files.cExe,0);
if (memcmp(argv[iOption],"-H",2) == 0)
Help(options,output,files.cExe,1);
}
if (iQuiet != -1 && iVerbose != -1) {
fprintf(stderr,"ERROR: -v and -q cannot be set simultaneously.\n");
exit(EXIT_EXE);
}
/* Now identify input file, usually vpl.in */
for (iOption=1;iOption<argc;iOption++) {
if (iOption != iVerbose && iOption != iQuiet && iOption != iOverwrite)
strcpy(infile,argv[iOption]);
}
/* Read input files */
ReadOptions(&body,&control,&files,&module,options,output,&system,&update,fnRead,infile);
if (control.Io.iVerbose >= VERBINPUT)
printf("Input files read.\n");
/* Check that user options are mutually compatible */
VerifyOptions(body,&control,&files,&module,options,output,&system,update,&fnOneStep,&fnUpdate);
if (control.Io.iVerbose >= VERBINPUT)
printf("Input files verified.\n");
control.Evolve.dTime=0;
control.Evolve.bFirstStep=1;
if (control.Io.bLog) {
WriteLog(body,&control,&files,&module,options,output,&system,update,fnUpdate,fnWrite,0);
if (control.Io.iVerbose >= VERBPROG)
printf("Log file written.\n");
}
/* Perform evolution */
if (control.Evolve.bDoForward || control.Evolve.bDoBackward) {
Evolve(body,&control,&files,&module,output,&system,update,fnUpdate,fnWrite,fnOneStep);
/* If evolution performed, log final system parameters */
if (control.Io.bLog) {
WriteLog(body,&control,&files,&module,options,output,&system,update,fnUpdate,fnWrite,1);
if (control.Io.iVerbose >= VERBPROG)
printf("Log file updated.\n");
}
}
//gettimeofday(&end, NULL);
if (control.Io.iVerbose >= VERBPROG) {
printf("Simulation completed.\n");
//printf("Total time: %.4e [sec]\n", difftime(end.tv_usec,start.tv_usec)/1e6);
}
exit(0);
}