HydroCODE_2D 0.1
This is a implementation of fully explict forward Euler scheme for 2-D Euler equations of motion on Eulerian coordinate
sys_pro.c
浏览该文件的文档.
1
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <math.h>
10
11/*
12 * To realize cross-platform programming.
13 * MKDIR: Create a subdirectory.
14 * ACCESS: Determine access permissions for files or folders.
15 * - mode=0: Test for existence.
16 * - mode=2: Test for write permission.
17 * - mode=4: Test for read permission.
18 */
19#ifdef _WIN32
20#include <io.h>
21#include <direct.h>
22#define ACCESS(path,mode) _access((path),(mode))
23#define MKDIR(path) _mkdir((path))
24#elif __linux__
25#include <unistd.h>
26#include <sys/stat.h>
27#define ACCESS(path,mode) access((path),(mode))
28#define MKDIR(path) mkdir((path), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
29#endif
30
31
37void DispPro(const double pro, const int step)
38{
39 int j;
40 static double pro_print = 0.0;
41 const double dpro_print = 0.1; // Print-out interval of percentage point.
42 if (pro >= pro_print)
43 {
44 for (j = 0; j < 77; j++)
45 putchar('\b'); // Clears the current line to display the latest progress bar status.
46 for (j = 0; j < lround(pro/2); j++)
47#ifdef _WIN32
48 putchar('+'); // Print the part of the progress bar that has been completed, denoted by '+'.
49#elif __linux__
50 printf("\x1b[45m \x1b[0m");
51#endif
52 for (j = 1; j <= 50-lround(pro/2); j++)
53#ifdef _WIN32
54 putchar('-'); // Print how much is left on the progress bar.
55#elif __linux__
56 printf("\x1b[47m \x1b[0m");
57#endif
58 fprintf(stdout, " %6.2f%% STEP=%-8d", pro, step);
59 fflush(stdout);
60 pro_print += dpro_print;
61 }
62}
63
72int CreateDir(const char * pPath)
73{
74 if(0 == ACCESS(pPath,2))
75 return -1;
76
77 const char* pCur = pPath;
78 char tmpPath[FILENAME_MAX+40];
79 memset(tmpPath,0,sizeof(tmpPath));
80
81 int pos = 0;
82 while(*pCur++!='\0')
83 {
84 tmpPath[pos++] = *(pCur-1);
85
86 if(*pCur=='/' || *pCur=='\0')
87 {
88 if(0!=ACCESS(tmpPath,0) && strlen(tmpPath)>0)
89 {
90 MKDIR(tmpPath);
91 }
92 }
93 }
94 if(0 == ACCESS(pPath,2))
95 return 0;
96 else
97 return 1;
98}
99
100
107void init_mem(double * p[], const int n, int ** cell_pt)
108{
109 for(int k = 0; k < n; ++k)
110 {
111 p[k] = (double *)calloc(cell_pt[k][0], sizeof(double));
112 if(p[k] == NULL)
113 {
114 printf("Initialize memory fail! DOUBLE data at grid cell points.\n");
115 for(int j = 0; j < k; j++)
116 {
117 free(p[k]);
118 p[k] = NULL;
119 }
120 exit(5);
121 }
122 }
123}
124
125
132void init_mem_int(int * p[], const int n, int ** cell_pt)
133{
134 for(int k = 0; k < n; ++k)
135 {
136 p[k] = (int *)malloc(cell_pt[k][0] * sizeof(int));
137 if(p[k] == NULL)
138 {
139 printf("Initialize memory fail! INT data at grid cell points.\n");
140 for(int j = 0; j < k; j++)
141 {
142 free(p[k]);
143 p[k] = NULL;
144 }
145 exit(5);
146 }
147 }
148}
void init_mem_int(int *p[], const int n, int **cell_pt)
This is a function that initializes memory for integer data.
Definition: sys_pro.c:132
int CreateDir(const char *pPath)
This is a function that recursively creates folders.
Definition: sys_pro.c:72
void init_mem(double *p[], const int n, int **cell_pt)
This is a function that initializes memory for double-precision floating-point data.
Definition: sys_pro.c:107
void DispPro(const double pro, const int step)
This function print a progress bar on one line of standard output.
Definition: sys_pro.c:37