files.c 3.9 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
          "#ALPHA11 = %lf\n"                                            \
          "#ALPHA12 = %lf\n"                                            \
          "#ALPHA22 = %lf\n"                                            \
          "#BETA11  = %lf\n"                                            \
          "#BETA12  = %lf\n"                                            \
          "#BETA22  = %lf\n"                                            \
          "#N   =     %d\n"                                             \
          "#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"                                    \
          "#STEPS =  %u\n"                                              \
          "#EXIT_INTERVAL = %d\n#\n"                                    \
51
52
53
          "#THREADS: %u\n",                                             \
          __DATE__, __TIME__, dateString,                               \
          ALPHA11, ALPHA12, ALPHA22,                                    \
Cassio Kirch's avatar
Cassio Kirch committed
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
          BETA11, BETA12, BETA22,                                       \
          (unsigned int)N, ETA, V0,                                     \
          NEIGHBOR_DISTANCE, DT,                                        \
          CORE_RADIUS, ELASTIC_DISTANCE,                                \
          INFINITE_FORCE, RANGE,                                        \
          PROP, (unsigned int)SEED, (unsigned int)BOXES,                \
          (unsigned int)BOXES_IN_EDGE, (unsigned int)STEPS,             \
          (unsigned int)EXIT_INTERVAL, (unsigned int)NUM_THREADS);
}

FILE*
initializeSingleFile ()
{
  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;
79
  char fileName[FILENAME_SIZE];
Cassio Kirch's avatar
Cassio Kirch committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  sprintf(fileName, "gamma_%s.dat", dateString);
  gammaFile = fopen(fileName, "w");
  putParametersToFile(gammaFile);
  return gammaFile;
}

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;
}
96
97
98
99
100
101
102
103
104
105
106

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
107
108
109
110
111
void
printParameters()
{
  putParametersToFile(stdout);
}