-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcuggs.cpp
131 lines (116 loc) · 2.69 KB
/
cuggs.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "grains.h"
#include "visual.h"
void intro()
{
printf("cuggs :: cuda grain growth simulation\n");
printf("based on the monte carlo potts model\n");
printf("version 1.0 by torsten stoeter, sep 2010\n\n");
}
void usage()
{
printf("usage: ./cuggs [options]\n");
printf("default action without any options is to simulate\na random 2d grain distribution in visual mode\n\noptions:\n");
printf(" -help print this help screen\n");
printf(" -load <file> load <file> as initial grain distribution\n");
printf(" -kt <t> set simulation temperature <t> as decimal value\n");
printf(" -term <x> terminate simulation after <x> steps\n");
printf(" -save <file> save final grain distribution to <file> when terminating\n");
printf(" -stat <x> print statistics for grain distribution every <x> steps\n");
printf(" -verb print verbose data on grain distribution every <x> steps\n");
printf(" -dump <x> dump grain distribution to disk every <x> steps\n");
printf(" -visual enable visualization\n");
}
char *loadfile = NULL, *savefile = NULL;
int main(int argc, char *argv[])
{
intro();
if (argc == 1)
{
visual = 1;
}
else
{
int i = 0;
while (++i < argc)
{
if (strncmp(argv[i], "-help", 80) == 0)
{
usage();
exit(0);
}
else if (strncmp(argv[i], "-load", 80) == 0)
{
if (++i < argc)
loadfile = argv[i];
}
else if (strncmp(argv[i], "-save", 80) == 0)
{
if (++i < argc)
savefile = argv[i];
}
else if (strncmp(argv[i], "-kt", 80) == 0)
{
if (++i < argc)
kT = atof(argv[i]);
if (kT > 0)
{
printf("kT = %f\n", kT);
}
else
{
printf("bad kt: %f\n", kT);
exit(0);
}
}
else if (strncmp(argv[i], "-term", 80) == 0)
{
if (++i < argc)
term = atoi(argv[i]);
if (term < 0 && term > INT_MAX)
{
printf("bad term step: %d\n", term);
exit(0);
}
}
else if (strncmp(argv[i], "-stat", 80) == 0)
{
if (++i < argc)
stat = atoi(argv[i]);
if (stat < 0 && stat > INT_MAX)
{
printf("bad stat step: %d\n", stat);
exit(0);
}
}
else if (strncmp(argv[i], "-dump", 80) == 0)
{
if (++i < argc)
dump = atoi(argv[i]);
if (dump < 0 && dump > INT_MAX)
{
printf("bad dump step: %d\n", dump);
exit(0);
}
}
else if (strncmp(argv[i], "-verb", 80) == 0)
{
verb = 1;
}
else if (strncmp(argv[i], "-visual", 80) == 0)
{
visual = 1;
}
else
{
printf("bad option: %s\n", argv[i]);
exit(0);
}
}
}
run_cuggs(argc, argv, loadfile, savefile);
return 0;
}