MIDAS  0.75
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
module_t3d.cpp
Go to the documentation of this file.
1 #include "module_t3d.h"
2 #include "problem.h"
3 
4 #include "librw.h"
5 #include "gelib.h"
6 
7 #ifdef __T3D_MODULE
8 #include "t3d.h"
9 #endif
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <time.h>
15 
16 
17 namespace midaspace {
18 
19 void mesh_generate_T3d (const Problem *pd, const char *solver, const char *options_string)
20 {
21  char *auxch;
22 
23  //double sec = clock();
24  //Pd->sodriver()->print_info_message (SODE_start_blue_arrow, "Model[%ld] - mesh generation by T3d", this->give_ID());
25 
28 
30  fflush(stdout);
31  //fpos_t pos; fgetpos(stdout, &pos); // kdyz to oddebuguju, tak se zde promenna pos nezmeni, tim padem mi to dole ...
32  int fd_out = dup(fileno(stdout));
33  freopen(auxch = strdupl(pd->give_OUT_moFILE()->give_name(), ".T3d.log.stdout"), "w", stdout);
34  delete [] auxch;
35 
37  fflush(stderr);
38  //fpos_t pos; fgetpos(stderr, &pos); // kdyz to oddebuguju, tak se zde promenna pos nezmeni, tim padem mi to dole ...
39  int fd_err = dup(fileno(stderr));
40  freopen(auxch = strdupl(pd->give_OUT_moFILE()->give_name(), ".T3d.log.stderr"), "w", stderr);
41  delete [] auxch;
42 
43 
44  int status;
46  if (solver) {
47  char cmd[1000];
48  sprintf(cmd, "%s %s", solver, options_string);
49  //fprintf (stdout,"%s\n", cmd);
50 
51  fprintf (stdout,"\n");
52  fflush(stdout); fflush(stderr);
53  status = system(cmd);
54  fprintf(stdout,"\n");
55  }
56  else {
57 #ifdef __T3D_MODULE
58  try {
59  t3d_main (NULL, (char *)options_string);
60  status = 0;
61  }
62  catch (...){
63  status = 1;
64  }
65 #else
66  _errorr("T3d binary is given as \"-\", however the module __T3D_MODULE is not linked. Activate the module in Makefile please.");
67 #endif
68  }
69 
72  fflush(stdout);
73  dup2(fd_out, fileno(stdout));
74  close(fd_out);
75  clearerr(stdout);
76  //fsetpos(stdout, &pos); // ... rve, ze pos neni inicializovana, proto tento radek zatim zakomentovavam
77 
79  fflush(stderr);
80  dup2(fd_err, fileno(stderr));
81  close(fd_err);
82  clearerr(stderr);
83  //fsetpos(stderr, &pos); // ... rve, ze pos neni inicializovana, proto tento radek zatim zakomentovavam
84 
85  if (status) _errorr("T3d ma problemy Houstone");
86  //print_info_message_timeok ((clock() - sec) / (double)CLOCKS_PER_SEC);
87 }
88 
89 } // namespace midaspace
90 
91 // these functions are have to be outside of midspace
92 // nejaky problemy s t3d funkcema, casem to oprav aby to tady nebylo
93 void print_message(FILE *stream, char *buffer)
94 {
95  fprintf (stream, "%s", buffer);
96 }
97 void exit_termination(int exit_code)
98 {
99  fflush (stdout);
100  CHANGE_CONSOLE_COLOUR(stderr, TC_D_RED); fprintf (stderr,"\n\n T3d ERROR: exit code %d", exit_code);
101  CHANGE_CONSOLE_COLOUR(stderr, TC_DEFAULT); fprintf (stderr," !!!\n\n");
102 }
103 void process_exit(int exit_code)
104 {
105  throw 0;
106 }
char * strdupl(const char *src)
standard strdup - Memory for the new string is obtained with malloc(3), and can be freed with free(3)...
Definition: librw.cpp:53
void exit_termination(int exit_code)
Definition: module_t3d.cpp:97
#define CHANGE_CONSOLE_COLOUR(_1, _2)
Definition: gelib.h:126
#define TC_D_RED
Definition: gelib.h:71
General functions.
Input / output function.
Interface to library T3D.
const char * give_name(void) const
Definition: taux.h:146
void process_exit(int exit_code)
Definition: module_t3d.cpp:103
const FiLe * give_OUT_moFILE(void) const
Definition: problem.h:201
#define _errorr(_1)
Definition: gelib.h:151
void print_message(FILE *stream, char *buffer)
Definition: module_t3d.cpp:93
#define TC_DEFAULT
Definition: gelib.h:85
void mesh_generate_T3d(const Problem *pd, const char *solver, const char *options_string)
Definition: module_t3d.cpp:19
Problem description.
Definition: problem.h:74
Class Problem.