13 #include <sys/types.h>
21 static int table_entire_mesh[] = {
69 static int subdir_on = 0;
85 static int is_entire_mesh(
int type) {
87 n =
sizeof(table_entire_mesh) /
sizeof(table_entire_mesh[0]);
89 for (i = 0; i < n; i++) {
90 if (table_entire_mesh[i] == type)
return 1;
97 static char *make_filename(
char *dir,
char *subdir,
char *prefix,
char *file,
98 char *suffix,
int myrank,
int flag_rank) {
104 if (dir && strlen(dir) > 0) {
112 if (subdir && strlen(subdir) > 0) {
123 if (prefix && strlen(prefix) > 0) {
145 sprintf(rank,
".%d",
myrank);
156 static char *make_filename_r(
char *dir,
char *subdir,
char *prefix,
char *file,
157 char *suffix,
int myrank,
int flag_rank,
165 if (dir && strlen(dir) > 0) {
168 if ((strlen(dir) + strlen(
separator)) > filename_len)
return NULL;
173 if (subdir && strlen(subdir) > 0) {
184 if (prefix && strlen(prefix) > 0) {
195 if ((strlen(
filename) + strlen(file)) > filename_len)
return NULL;
200 if ((strlen(
filename) + strlen(suffix)) > filename_len)
return NULL;
206 sprintf(rank,
".%d",
myrank);
208 if ((strlen(
filename) + strlen(rank)) > filename_len)
return NULL;
218 static void free_mesh_entry(
void) {
221 for (p = mesh_ent; p; p = q) {
231 static void free_mesh_grp_entry(
void) {
234 for (p = mesh_grp_ent; p; p = q) {
244 static void free_restart_entry(
void) {
247 for (p = restart_ent; p; p = q) {
257 static void free_result_entry(
void) {
260 for (p = result_ent; p; p = q) {
270 static void free_ctrl_entry(
void) {
273 for (p = ctrl_ent; p; p = q) {
290 for (p = mesh_ent; p; p = p->
next) {
302 for (p = mesh_grp_ent; p; p = p->
next) {
314 for (p = restart_ent; p; p = p->
next) {
324 for (p = restart_ent; p; p = p->
next) {
325 if (p->
io &
io)
return p;
336 for (p = result_ent; p; p = p->
next) {
348 for (p = ctrl_ent; p; p = p->
next) {
400 static int add_mesh_entry(
struct mesh_entry *mesh) {
404 for (p = mesh_ent; p; p = (q = p)->
next)
423 if (meshgrp ==
NULL) {
443 for (i = 0; i <
n_mesh; i++) {
444 meshgrp->
mesh[i] = get_mesh_entry(
mesh[i]);
446 if (meshgrp->
mesh[i] ==
NULL)
goto error;
466 for (p = mesh_grp_ent; p; p = (q = p)->
next)
485 if (result ==
NULL) {
521 static int add_result_entry(
struct result_entry *result) {
525 for (p = result_ent; p; p = (q = p)->
next)
544 if (restart ==
NULL) {
579 static int add_restart_entry(
struct restart_entry *restart) {
583 for (p = restart_ent; p; p = (q = p)->
next)
587 restart_ent = restart;
635 static int add_ctrl_entry(
struct ctrl_entry *ctrl) {
639 for (p = ctrl_ent; p; p = (q = p)->
next)
654 static void do_logging(
int loglv,
int msgno,
int add_location,
const char *fmt,
663 if (strlen(msg) > 0) s =
": ";
672 static void set_err(
int msgno,
const char *fmt, ...) {
679 static void set_err_token(
int token,
int msgno,
const char *fmt, ...) {
697 static int read_mesh_header(
void) {
718 static int read_mesh_head_param_name(
char *name) {
733 "NAME must begin with a letter or '_'");
747 if (get_mesh_entry(name) || get_mesh_grp_entry(name)) {
755 static int read_mesh_head_param_type(
int *type) {
795 static int read_mesh_head_param_io(
int *io) {
821 static int read_mesh_head_param_refine(
int *refine) {
844 static int read_mesh_data(
char *name,
int type,
int io,
int refine) {
866 if (mesh ==
NULL)
return -1;
869 if (add_mesh_entry(mesh))
return -1;
882 static int read_mesh(
void) {
896 ST_HEADER_LINE_PARAM,
899 state = ST_HEADER_LINE;
901 while (state != ST_FINISHED) {
902 if (state == ST_HEADER_LINE) {
903 if (read_mesh_header())
return -1;
906 state = ST_HEADER_LINE_PARAM;
908 }
else if (state == ST_HEADER_LINE_PARAM) {
913 if (read_mesh_head_param_name(name))
return -1;
919 if (read_mesh_head_param_type(&
type))
return -1;
925 if (read_mesh_head_param_io(&
io))
return -1;
931 if (read_mesh_head_param_refine(&
refine))
return -1;
956 state = ST_DATA_LINE;
958 }
else if (token ==
',') {
966 }
else if (state == ST_DATA_LINE) {
991 static int read_meshgrp_header(
void) {
1012 static int read_meshgrp_head_param_name(
char *name) {
1027 "NAME must begin with a letter or '_'");
1041 if (get_mesh_entry(name) || get_mesh_grp_entry(name)) {
1049 static int read_meshgrp_data(
char *name) {
1050 int i, token, n_mesh, n_mesh_max;
1086 if ((ment = get_mesh_entry(p)) ==
NULL) {
1091 if (!is_entire_mesh(ment->
type)) {
1096 if (n_mesh == n_mesh_max) {
1110 if (mesh[n_mesh] ==
NULL) {
1121 "',' or NL required after name_ID");
1127 meshgrp = make_mesh_group_entry(name, n_mesh, mesh);
1129 if (meshgrp ==
NULL)
return -1;
1132 if (add_mesh_group_entry(meshgrp))
return -1;
1134 for (i = 0; i < n_mesh; i++) {
1142 static int read_meshgrp(
void) {
1149 ST_HEADER_LINE_PARAM,
1152 state = ST_HEADER_LINE;
1154 while (state != ST_FINISHED) {
1155 if (state == ST_HEADER_LINE) {
1156 if (read_meshgrp_header())
return -1;
1159 state = ST_HEADER_LINE_PARAM;
1161 }
else if (state == ST_HEADER_LINE_PARAM) {
1166 if (read_meshgrp_head_param_name(name))
return -1;
1185 state = ST_DATA_LINE;
1187 }
else if (token ==
',') {
1195 }
else if (state == ST_DATA_LINE) {
1198 if (read_meshgrp_data(name))
return -1;
1200 state = ST_FINISHED;
1212 static int read_result_head(
void) {
1233 static int read_result_param_name(
char *name) {
1248 "NAME must begin with a letter or '_'");
1262 if (get_result_entry(name)) {
1270 static int read_result_param_io(
int *
io) {
1296 static int read_result_param_type(
int *fg_text) {
1327 if (strcmp(s,
"TEXT") == 0) {
1330 }
else if (strcmp(s,
"BINARY") == 0) {
1341 static int read_result_data(
char *name,
int io,
int fg_text) {
1360 result = make_result_entry(name,
io,
fg_text, p);
1362 if (result ==
NULL)
return -1;
1365 if (add_result_entry(result))
return -1;
1378 static int read_result(
void) {
1388 ST_HEADER_LINE_PARAM,
1392 state = ST_HEADER_LINE;
1394 while (state != ST_FINISHED) {
1395 if (state == ST_HEADER_LINE) {
1396 if (read_result_head())
return -1;
1398 state = ST_HEADER_LINE_PARAM;
1400 }
else if (state == ST_HEADER_LINE_PARAM) {
1405 if (read_result_param_name(name))
return -1;
1411 if (read_result_param_io(&
io))
return -1;
1417 if (read_result_param_type(&
fg_text))
return -1;
1440 state = ST_DATA_LINE;
1442 }
else if (token ==
',') {
1450 }
else if (state == ST_DATA_LINE) {
1453 if (read_result_data(name,
io,
fg_text))
return -1;
1455 state = ST_FINISHED;
1467 static int read_restart_head(
void) {
1488 static int read_restart_param_name(
char *name) {
1503 "NAME must begin with a letter or '_'");
1517 if (get_restart_entry(name)) {
1525 static int read_restart_param_io(
int *
io) {
1554 static int read_restart_data(
char *name,
int io) {
1573 restart = make_restart_entry(name,
io, p);
1575 if (restart ==
NULL)
return -1;
1578 if (add_restart_entry(restart))
return -1;
1591 static int read_restart(
void) {
1600 ST_HEADER_LINE_PARAM,
1603 state = ST_HEADER_LINE;
1605 while (state != ST_FINISHED) {
1606 if (state == ST_HEADER_LINE) {
1607 if (read_restart_head())
return -1;
1610 state = ST_HEADER_LINE_PARAM;
1612 }
else if (state == ST_HEADER_LINE_PARAM) {
1617 if (read_restart_param_name(name))
return -1;
1623 if (read_restart_param_io(&
io))
return -1;
1648 state = ST_DATA_LINE;
1650 }
else if (token ==
',') {
1658 }
else if (state == ST_DATA_LINE) {
1662 if (read_restart_data(name,
io))
return -1;
1664 state = ST_FINISHED;
1676 static int read_control_head(
void) {
1697 static int read_control_head_param_name(
char *name) {
1712 "NAME must begin with a letter or '_'");
1726 if (get_ctrl_entry(name)) {
1734 static int read_control_data(
char *name) {
1754 control = make_ctrl_entry(name, p);
1756 if (control ==
NULL) {
1761 if (add_ctrl_entry(control)) {
1776 static int read_control(
void) {
1783 ST_HEADER_LINE_PARAM,
1786 state = ST_HEADER_LINE;
1788 while (state != ST_FINISHED) {
1789 if (state == ST_HEADER_LINE) {
1790 if (read_control_head())
return -1;
1793 state = ST_HEADER_LINE_PARAM;
1795 }
else if (state == ST_HEADER_LINE_PARAM) {
1800 if (read_control_head_param_name(name))
return -1;
1819 state = ST_DATA_LINE;
1821 }
else if (token ==
',') {
1829 }
else if (state == ST_DATA_LINE) {
1832 if (read_control_data(name))
return -1;
1834 state = ST_FINISHED;
1846 static int read_subdir_head(
void) {
1867 static int read_subdir_head_param_limit(
void) {
1890 static int read_subdir(
void) {
1896 ST_HEADER_LINE_PARAM,
1899 state = ST_HEADER_LINE;
1901 while (state != ST_FINISHED) {
1902 if (state == ST_HEADER_LINE) {
1903 if (read_subdir_head())
return -1;
1906 state = ST_HEADER_LINE_PARAM;
1908 }
else if (state == ST_HEADER_LINE_PARAM) {
1922 if (read_subdir_head_param_limit())
return -1;
1938 state = ST_FINISHED;
1940 }
else if (token ==
',') {
1962 static struct read_func_table {
1965 } read_func_table[] = {
1974 #define N_READ_FUNC (sizeof(read_func_table) / sizeof(read_func_table[0]))
1977 static ReadFunc get_read_func(
int token) {
1981 if (token == read_func_table[i].token) {
1982 return read_func_table[i].func;
1991 static int parse(
void) {
1998 func = get_read_func(token);
2015 if ((*func)())
return -1;
2025 if (ctrlfile ==
NULL) {
2030 strcpy(ctrl_filename, ctrlfile);
2033 if ((fp = fopen(ctrl_filename,
"r")) ==
NULL) {
2060 free_mesh_grp_entry();
2061 free_result_entry();
2062 free_restart_entry();
2069 for (i = 0; i < meshfiles->
n_mesh; i++) {
2079 int flag_rank_none) {
2080 int i, flag_rank, nrank,
myrank, irank;
2087 if (files ==
NULL) {
2109 for (i = 0; i <
n_mesh; i++) {
2113 file->
io = ment->
io;
2116 if (flag_rank_none) {
2120 if (is_entire_mesh(file->
type)) {
2130 if (fname ==
NULL) {
2140 if (subdir_on && nrank > nlimit) {
2142 sprintf(prefix,
"TRUNK%d", irank);
2150 }
else if (subdir_on && nrank > 1) {
2160 if (retval ==
NULL) {
2174 int flag_rank_none) {
2178 mesh_grp = get_mesh_grp_entry(name_ID);
2181 files = make_meshfiles_struct(mesh_grp->
n_mesh, mesh_grp->
mesh, n_rank,
2182 i_rank, flag_rank_none);
2187 if (files ==
NULL) {
2188 mesh = get_mesh_entry(name_ID);
2191 files = make_meshfiles_struct(1, &mesh, n_rank, i_rank, flag_rank_none);
2197 if (files ==
NULL) {
2206 return get_meshfiles(name_ID, 0, 0, 0);
2210 return get_meshfiles(name_ID, 0, 0, 1);
2216 return get_meshfiles(name_ID, n_rank, i_rank, 0);
2222 return get_meshfiles(name_ID, n_rank, i_rank, 1);
2225 static char *get_result_file(
char *name_ID,
int istep,
int n_rank,
2226 int i_rank,
int *fg_text,
int flag_rank_none) {
2227 int nrank,
myrank, irank;
2228 char *fname, *retfname;
2230 char subname[10], prefix[10];
2231 result = get_result_entry(
name_ID);
2233 if (result ==
NULL) {
2248 if (subdir_on && !strcmp(
name_ID,
"vis_out")) {
2252 }
else if (subdir_on && nrank > nlimit) {
2253 sprintf(subname,
"STEP%d", istep);
2255 sprintf(prefix,
"TRUNK%d", irank);
2259 }
else if (subdir_on) {
2260 sprintf(subname,
"STEP%d", istep);
2269 if (fname ==
NULL) {
2276 if (retfname ==
NULL) {
2285 static char *get_filename_body(
char *file) {
2292 static char *get_result_filebody(
char *
name_ID) {
2294 char *fname, *retfname;
2296 result = get_result_entry(
name_ID);
2298 if (result ==
NULL) {
2304 fname = get_filename_body(result->
filename);
2308 if (retfname ==
NULL) {
2327 int n_rank,
int i_rank,
int *
fg_text) {
2328 return get_result_file(
name_ID, istep, n_rank, i_rank,
fg_text, 1);
2332 int n_rank,
int i_rank,
2334 return get_result_file(
name_ID, istep, n_rank, i_rank,
fg_text, 0);
2338 return get_result_filebody(
name_ID);
2342 int nrank,
myrank, irank;
2343 char *fname, *retfname;
2346 restart = get_restart_entry(
name_ID);
2348 if (restart ==
NULL) {
2357 if (subdir_on && nrank > nlimit) {
2359 sprintf(prefix,
"TRUNK%d", irank);
2363 }
else if (subdir_on) {
2371 if (fname ==
NULL) {
2378 if (retfname ==
NULL) {
2387 int nrank,
myrank, irank;
2388 char *fname, *retfname;
2391 p = get_restart_entry_by_io(
io);
2401 if (subdir_on && nrank > nlimit) {
2403 sprintf(prefix,
"TRUNK%d", irank);
2406 }
else if (subdir_on) {
2413 if (fname ==
NULL) {
2420 if (retfname ==
NULL) {
2431 ctrl = get_ctrl_entry(
name_ID);
2444 return get_ctrl_entry(
name_ID) ? 1 : 0;
2456 mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
2460 #if defined(__WIN32__) || defined(__WIN64__)
2463 sprintf(dirname,
"%s", token);
2466 token = strtok_r(fname,
separator, &saveptr);
2467 sprintf(dirname,
"%s", token);
2472 if ((dp = opendir(dirname)) ==
NULL) {
2475 if (mkdir(dirname, mode) != 0) {
2478 if (mkdir(dirname) != 0) {
2481 if (errno != EEXIST)
return -1;
2489 strcat(dirname, token);
2490 #if defined(__WIN32__) || defined(__WIN64__)
2557 int name_len,
int buf_len) {
2572 if (ret == 0)
return;
2578 int name_len,
int buf_len) {
2583 int name_len,
int buf_len) {
2588 int name_len,
int buf_len) {