files.c 4.2 KB
Newer Older
Cassio Kirch's avatar
Cassio Kirch committed
1
2
#include <stdio.h>
#include <time.h>
3
//#include <sys/stat.h>
Cassio Kirch's avatar
Cassio Kirch committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

#include "define.h"
#include "files.h"

char dateString[DATE_SIZE];

char*
getDate()
{
  return dateString;
}

void
setDate ()
{
  time_t now = time(NULL);
  struct tm* tmP = localtime(&now);
21
  strftime(dateString, DATE_SIZE, "%Y%m%d_%Hh%Mmin%Ssec", tmP);
Cassio Kirch's avatar
Cassio Kirch committed
22
23
24
25
26
}

void
putParametersToFile(FILE* file)
{
27
28
29
  fprintf(file, "#Modo 'um sistema' com alpha e beta fixos.\n"          \
          "#Compiled at %s %s\n"                                        \
          "#Runned at\t%s\n"                                            \
Cassio Kirch's avatar
Cassio Kirch committed
30
31
32
33
34
35
36
          "#ALPHA11 = %lf\n"                                            \
          "#ALPHA12 = %lf\n"                                            \
          "#ALPHA22 = %lf\n"                                            \
          "#BETA11  = %lf\n"                                            \
          "#BETA12  = %lf\n"                                            \
          "#BETA22  = %lf\n"                                            \
          "#N   =     %d\n"                                             \
Cassio Kirch's avatar
Cassio Kirch committed
37
          "#ENDOPROP = %lf\n"                                           \
Cassio Kirch's avatar
Cassio Kirch committed
38
39
40
41
42
43
44
45
46
47
48
49
          "#ETA =     %lf\n"                                            \
          "#V0  =     %lf\n"                                            \
          "#R0  =     %lf\n"                                            \
          "#DT  =     %lf\n"                                            \
          "#CORE_RADIUS =      %lf\n"                                   \
          "#ELASTIC_DISTANCE = %lf\n"                                   \
          "#INFINITE FORCE   = %lf\n"                                   \
          "#RANGE =  %lf\n"                                             \
          "#PROP  =  %lf\n"                                             \
          "#SEED  =  %u\n"                                              \
          "#BOXES =  %u\n"                                              \
          "#BOXES_IN_EDGE =    %u\n"                                    \
Cassio Kirch's avatar
Cassio Kirch committed
50
51
          "#STEPS =  %llu\n"                                            \
          "#EXIT_INTERVAL = %llu\n#\n"                                  \
52
53
54
          "#THREADS: %u\n",                                             \
          __DATE__, __TIME__, dateString,                               \
          ALPHA11, ALPHA12, ALPHA22,                                    \
Cassio Kirch's avatar
Cassio Kirch committed
55
          BETA11, BETA12, BETA22,                                       \
Cassio Kirch's avatar
Cassio Kirch committed
56
          N, ENDOPROP, ETA, V0,                                         \
Cassio Kirch's avatar
Cassio Kirch committed
57
58
59
          NEIGHBOR_DISTANCE, DT,                                        \
          CORE_RADIUS, ELASTIC_DISTANCE,                                \
          INFINITE_FORCE, RANGE,                                        \
Cassio Kirch's avatar
Cassio Kirch committed
60
61
62
          PROP, SEED, BOXES,                                            \
          BOXES_IN_EDGE, STEPS,                                         \
          EXIT_INTERVAL, NUM_THREADS);
Cassio Kirch's avatar
Cassio Kirch committed
63
64
65
}

FILE*
66
initializeGodFile ()
Cassio Kirch's avatar
Cassio Kirch committed
67
68
69
70
71
72
73
74
75
76
77
78
79
{
  FILE* dat;
  char fileName[FILENAME_SIZE];
  sprintf(fileName, "one_system_%s.dat", dateString);
  dat = fopen (fileName, "w");
  putParametersToFile(dat);
  return dat;
}

FILE*
initializeGammaFile()
{
  FILE* gammaFile;
80
  char fileName[FILENAME_SIZE];
Cassio Kirch's avatar
Cassio Kirch committed
81
82
83
84
85
86
  sprintf(fileName, "gamma_%s.dat", dateString);
  gammaFile = fopen(fileName, "w");
  putParametersToFile(gammaFile);
  return gammaFile;
}

87
88
89
90
91
92
93
94
95
96
97
98
99
#ifdef COUNT_NEIGHBORS
FILE*
initializeAverageNeighborsFile ()
{
  FILE* myFile;
  char fileName[FILENAME_SIZE];
  sprintf(fileName, "avgNeighbors_%s.dat", dateString);
  myFile = fopen(fileName, "w");
  putParametersToFile(myFile);
  return myFile;
}
#endif

Cassio Kirch's avatar
Cassio Kirch committed
100
101
102
103
104
105
106
107
108
109
FILE*
initializeStepAndTypeFile (const unsigned long long int step,   \
                           const cellType type)
{
  static FILE* dat;
  static char fileName[FILENAME_SIZE];
  sprintf(fileName, "%llu_%u.dat", step, type);
  dat = fopen(fileName, "w");
  return dat;
}
110
111
112
113
114
115
116
117
118
119
120

FILE* initializeFinalConfigurationFile()
{
  FILE* finalConfigurationFile;
  char fileName[FILENAME_SIZE];
  sprintf(fileName, "final_%s.dat", dateString);
  finalConfigurationFile = fopen(fileName, "w");
  putParametersToFile(finalConfigurationFile);
  return finalConfigurationFile;
}

Cassio Kirch's avatar
Cassio Kirch committed
121
122
123
124
125
void
printParameters()
{
  putParametersToFile(stdout);
}