FrontISTR 5.2.0
Large-scale structural analysis program with finit element method
Loading...
Searching...
No Matches
hecmw_res_type_conv.c
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright (c) 2019 FrontISTR Commons
3 * This software is released under the MIT License, see LICENSE.txt
4 *****************************************************************************/
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <errno.h>
9#include "hecmw_struct.h"
10#include "hecmw_result.h"
11#include "hecmw_util.h"
12#include "hecmw_io.h"
13
14int strid = 1;
15int endid = 1;
16int intid = 1;
17char out_file[HECMW_NAME_LEN + 1] = "";
18
19void help(void) {
20 printf(" HECMW Result File Type Converter\n");
21 printf("usage) rconv [options]\n");
22 printf("[option]\n");
23 printf(" -h : help\n");
24 printf(" -o [file] : output file name without rank and step number\n");
25 printf(" -s [step] : start step number (default:%d)\n", strid);
26 printf(" -e [step] : end step number (default:%d)\n", endid);
27 printf(" -i [step] : interval step number (default:%d)\n", intid);
28}
29
30int set_params(int argc, char **argv) {
31 int i;
32
33 for (i = 1; i < argc; i++) {
34 if (strcmp(argv[i], "-h") == 0) {
35 help();
36 return -1;
37 } else if (strcmp(argv[i], "-o") == 0) {
38 if (argc == i + 1) {
39 fprintf(stderr, "Error : paramter required after %s\n", argv[i]);
40 return -1;
41 }
42 i++;
43 strcpy(out_file, argv[i]);
44 } else if (strcmp(argv[i], "-s") == 0) {
45 if (argc == i + 1) {
46 fprintf(stderr, "Error : paramter required after %s\n", argv[i]);
47 return -1;
48 }
49 i++;
50 if (sscanf(argv[i], "%d", &strid) != 1) {
51 fprintf(
52 stderr,
53 "Error : parameter %s cannot be converted to start step number\n",
54 argv[i]);
55 return -1;
56 }
57 } else if (strcmp(argv[i], "-e") == 0) {
58 if (argc == i + 1) {
59 fprintf(stderr, "Error : paramter required after %s\n", argv[i]);
60 return -1;
61 }
62 i++;
63 if (sscanf(argv[i], "%d", &endid) != 1) {
64 fprintf(stderr,
65 "Error : parameter %s cannot be converted to end step number\n",
66 argv[i]);
67 return -1;
68 }
69 } else if (strcmp(argv[i], "-i") == 0) {
70 if (argc == i + 1) {
71 fprintf(stderr, "Error : paramter required after %s\n", argv[i]);
72 return -1;
73 }
74 i++;
75 if (sscanf(argv[i], "%d", &intid) != 1) {
76 fprintf(stderr,
77 "Error : parameter %s cannot be converted to interval step "
78 "number\n",
79 argv[i]);
80 return -1;
81 }
82 } else {
83 fprintf(stderr, "Error : invalid parameter %s\n", argv[i]);
84 help();
85 return -1;
86 }
87 }
88
89 return 0;
90}
91
92int main(int argc, char **argv) {
94 char *fileheader, resultfile[HECMW_FILENAME_LEN + 1];
95 char header[HECMW_HEADER_LEN + 1];
96 char comment[HECMW_MSG_LEN + 1];
97 char dirname[HECMW_HEADER_LEN + 1];
98 char buff[HECMW_HEADER_LEN + 1];
99 char *ptoken, *ntoken;
100 int n_node, n_elem, rcode, fg_text;
101 int i, mynode;
102
103 if (HECMW_init(&argc, &argv)) {
105 }
106
107 if (set_params(argc, argv)) {
109 }
110
111 mynode = HECMW_comm_get_rank();
112
113 for (i = strid; i <= endid; i++) {
114 if ((i % intid) != 0 && i != endid) continue;
115
116 fileheader =
117 HECMW_ctrl_get_result_fileheader("fstrRES", i, &fg_text);
118 sprintf(resultfile, "%s.%d.%d", fileheader, mynode, i);
119 fprintf(stdout, "Input file : %s\n", resultfile);
120 data = HECMW_result_read_by_fname(resultfile);
121 if (!data) {
123 }
124
125 if (out_file[0]) {
126 strcpy(buff, resultfile);
127 strcpy(dirname, "");
128 ptoken = strtok(buff, "/");
129 ntoken = strtok(NULL, "/");
130 while (ntoken) {
131 strcat(dirname, ptoken);
132 strcat(dirname, "/");
133 ptoken = ntoken;
134 ntoken = strtok(NULL, "/");
135 }
136 sprintf(resultfile, "%s%s.%d.%d", dirname, out_file, mynode, i);
137 }
138 fprintf(stdout, "Output file : %s\n", resultfile);
139
140 n_node = HECMW_result_get_nnode();
141 n_elem = HECMW_result_get_nelem();
144 rcode = HECMW_result_write_txt_ST_by_fname(resultfile, data, n_node, n_elem,
145 header, comment);
146 if (rcode) {
148 }
149
153 }
154
156
157 return 0;
158}
HECMW_Comm HECMW_comm_get_comm(void)
Definition: hecmw_comm.c:699
int HECMW_comm_get_rank(void)
Definition: hecmw_comm.c:707
#define HECMW_FILENAME_LEN
Definition: hecmw_config.h:72
#define HECMW_MSG_LEN
Definition: hecmw_config.h:74
#define HECMW_HEADER_LEN
Definition: hecmw_config.h:68
#define HECMW_NAME_LEN
Definition: hecmw_config.h:70
char * HECMW_ctrl_get_result_fileheader(char *name_ID, int istep, int *fg_text)
int HECMW_finalize(void)
Definition: hecmw_finalize.c:9
int HECMW_init(int *argc, char ***argv)
Definition: hecmw_init.c:24
#define NULL
void help(void)
int endid
int intid
int set_params(int argc, char **argv)
char out_file[HECMW_NAME_LEN+1]
int strid
char * HECMW_result_get_header(char *buff)
Definition: hecmw_result.c:207
int HECMW_result_get_nnode(void)
Definition: hecmw_result.c:203
void HECMW_result_free_nodeID(void)
Definition: hecmw_result.c:233
int HECMW_result_get_nelem(void)
Definition: hecmw_result.c:205
struct hecmwST_result_data * HECMW_result_read_by_fname(char *filename)
Definition: hecmw_result.c:168
char * HECMW_result_get_comment(char *buff)
Definition: hecmw_result.c:212
void HECMW_result_free(struct hecmwST_result_data *result)
Definition: hecmw_result.c:25
void HECMW_result_free_elemID(void)
Definition: hecmw_result.c:238
int HECMW_result_write_txt_ST_by_fname(char *filename, struct hecmwST_result_data *result, int n_node, int n_elem, char *header, char *comment)
void HECMW_abort(HECMW_Comm comm)
Definition: hecmw_util.c:88
CNFData data
int main()
Definition: varray_test.c:10