Salome HOME
Imported using TkCVS
[plugins/ghs3dprlplugin.git] / src / tepal2med / tepal2med.cxx
1 /*
2 ** prog principal de test de ghs3dprl
3 */
4
5 #include <stdio.h> /* printf clrscr fopen fread fwrite fclose */
6 #include <string>
7 #include <cstring>
8 #include <iostream>
9 #include <fstream>
10 #include "ghs3dprl_msg_parser.h"
11
12 #include <qtextstream.h>
13 #include <qstring.h>
14 #include <qxml.h>
15 #include <qwindowdefs.h>
16
17
18 #include <qapplication.h>
19 #include "dlg_ghs3dmain.h"
20
21 using namespace std;
22 using namespace med_2_2;
23
24 //************************************
25 int main(int argc, char **argv)
26 {
27    bool ok,is_test,is_menu,is_launchtepal;
28    int nbfiles,nbelem_limit_swap,verbose;
29    QString casename,casenamemed,tmp,cmd,format;
30    QString version="V0.1 beta";
31
32
33    if ((argc > 11)||(argc < 2))
34    {
35       cerr<<"tepal2med "<<version<<endl;
36       cerr<<"Usage: "<<argv[0]<<" CaseNameTepal NumberOfFiles [LimitSwap] [Verbose[0->6]] [Test|noTest] [Menu|noMenu] [LaunchTepal|noLaunchTepal] CaseNameMed\n";
37       return 1;
38    }
39    casename=argv[1];
40    tmp=argv[2];
41    nbfiles=tmp.toLong(&ok,10);
42    if (!ok)
43    {
44       cerr<<"NumberOfFiles: an integer is expected\n\n";
45       return 1;
46    }
47    if (nbfiles<=0)
48    {
49       cerr<<"NumberOfFiles: a positive integer is expected\n\n";
50       return 1;
51    }
52    if (nbfiles>512) //delirium in 2007
53    {
54       cerr<<"NumberOfFiles: a positive integer <= 512 is expected\n\n";
55       return 1;
56    }
57
58    //default 1GOctet/8(for double)/10(for arrays in memory at the same time)
59    nbelem_limit_swap=1000000000/8/10;
60    if (argc > 3)
61    {
62       tmp=argv[3];
63       nbelem_limit_swap=tmp.toLong(&ok,10);
64       if (!ok)
65       {
66          cerr<<"LimitSwap: an integer is expected\n\n";
67          return 1;
68       }
69       if (nbelem_limit_swap<=0)
70       {
71          cerr<<"LimitSwap: a positive integer is expected\n\n";
72          return 1;
73       }
74    }
75
76    verbose=1; //default
77    if (argc > 4)
78    {
79       tmp=argv[4];
80       verbose=tmp.toLong(&ok,10);
81       if (!ok)
82       {
83          cerr<<"Verbose: an integer is expected\n\n";
84          return 1;
85       }
86       if (verbose<0)
87       {
88          cerr<<"Verbose: a positive integer is expected\n\n";
89          return 1;
90       }
91    }
92
93    is_test=FALSE; //default
94    if (argc > 5)
95    {
96       tmp=argv[5];
97       if (tmp=="Test") is_test=TRUE;
98    }
99
100    is_menu=FALSE; //default
101    if (argc > 6)
102    {
103       tmp=argv[6];
104       if (tmp=="Menu") is_menu=TRUE;
105    }
106
107    is_launchtepal=FALSE; //default
108    if (argc > 7)
109    {
110       tmp=argv[7];
111       if (tmp=="LaunchTepal") is_launchtepal=TRUE;
112    }
113
114    casenamemed=casename;
115    if (argc > 8)
116    {
117       casenamemed=argv[8];
118    }
119
120    // We must always have an application
121    if (is_menu)
122    {
123    QApplication a(argc,argv);
124    dlg_ghs3dmain *m = new dlg_ghs3dmain();
125    a.setMainWidget(m);      // It is our main widget
126    m->setCaption("tepal2med "+version);
127    m->show();               // Show it...
128    a.exec();                // And run!
129    cout<<"parameters "<<m->value_KeepFiles<<" "<<m->value_NbPart<<endl;
130    //cancel if close widget without Ok button
131    if (!m->value_Ok) return 1;
132    nbfiles=m->value_NbPart;
133    }
134
135    QString path;
136    int n=casenamemed.contains('/');
137    if (n>0)
138       path=casenamemed.section('/',-n-1,-2)+"/";
139    else
140       path="./";
141    casenamemed=casenamemed.section('/',-1);
142    if (casenamemed.length()>20)
143    {
144       cerr<<"CaseNameMed truncated (no more 20 characters)"<<endl;
145       casenamemed.truncate(20);
146    }
147
148    /*cout<<"CaseNameMed="<<casenamemed<<endl;
149    cout<<"PathMed="<<path<<endl;*/
150
151    //verbose=5;
152    if (verbose>0)
153    cout<<"CaseNameTepal="<<casename<<
154          " NumberOfFiles="<<nbfiles<<
155          " LimitSwap="<<nbelem_limit_swap<<
156          " Verbose="<<verbose<<
157          " Test="<<is_test<<
158          " Menu="<<is_menu<<
159          " LaunchTepal="<<is_launchtepal<<
160          " CaseNameMed="<<path+casenamemed<<
161          "\n";
162
163    //"tepal -f exemple1 -n 4"
164    if (is_launchtepal)
165    {
166    cmd="tepal -f "+casename+" -n "+cmd.sprintf("%d",nbfiles)+" > "+path+"tepal.out";
167    cout<<"LaunchTepal Command = "<<cmd<<endl;
168    system( (const char *) cmd ); // run
169    }
170
171    ghs3dprl_mesh_wrap *mymailw=new ghs3dprl_mesh_wrap;
172    //no constructor, later maybe
173    mymailw->nbfiles=0;
174    mymailw->nbelem_limit_swap=nbelem_limit_swap; //for huge cases big array swap in huge binary files
175    mymailw->verbose=verbose;
176    mymailw->casename=casenamemed;
177    mymailw->path=path;
178
179    ghs3dprl_msg_parser handler;
180    //constructor later maybe
181    //handler.verbose=TRUE;
182    handler.mailw=mymailw;
183
184    QXmlSimpleReader reader;
185    reader.setContentHandler(&handler);
186    format=format.sprintf("%d",nbfiles);
187    int nbf=format.length();
188    format=format.sprintf(".%%.%dd.%%.%dd",nbf,nbf);
189    //read files .msg
190    for (int i=1; i<=nbfiles; i++)
191    {
192       mymailw->nofile=i;
193       //tmp=casename+tmp.sprintf(".%d.%d.msg",nbfiles,i);
194       tmp=casename+tmp.sprintf(format,nbfiles,i)+".msg";
195       if (verbose>0) cout<<"FileName="<<tmp<<endl;
196       QFile File(tmp);
197       QXmlInputSource source(&File);
198       reader.parse(source);
199       File.close();
200    }
201    if (verbose>0)
202       cout<<"NumberOfFilesMSGAcquired="<<mymailw->nbfiles<<"\n";
203    if (mymailw->nbfiles != nbfiles)
204    {
205       cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n";
206       return 1;
207    }
208
209    if (is_test)
210    {
211       ok=mymailw->test_msg_wrap();
212       if (ok)
213       {
214          if (verbose>0) cout<<"\nResult_test_msg_wrap=ok\n\n";
215       }
216       else
217       {
218          cerr<<"\nResult_test_msg_wrap=NO_OK!\n\n";
219          return 1;
220       }
221    }
222
223    //after verification remove unusued data
224    //"NE0 FI" for/from <version>1.0</version>
225    //after verification remove duplicates data
226    //for debug but don't do that because reliability
227    // and locality of datas files
228    //" RE " for duplicates <receive>
229    //int nb=mymailw->remove_key_mesh_wrap(QRegExp("( NE0 | RE)",TRUE,FALSE));
230
231    //because <send> equals <receive>
232    int nb=0;
233    nb=mymailw->remove_key_mesh_wrap(QRegExp("RE",TRUE,FALSE));
234    if (verbose>3) cout<<"NumberOfKeysRemoved="<<nb<<endl;
235    if (verbose>3) ok=mymailw->list_keys_mesh_wrap();
236
237    //test read files .noboiteb
238    //tmp=casename+".noboiteb";
239    //ok=mymailw->ReadFileNOBOITEB(tmp);
240
241    //read files .noboite
242    //supposed big files
243    mymailw->nbfiles=0;
244    for (int i=1; i<=nbfiles; i++)
245    {
246       mymailw->nofile=i;
247       tmp=casename+tmp.sprintf(format,nbfiles,i)+".noboite";
248       if (verbose>0) cout<<"FileName="<<tmp<<endl;
249       ok=mymailw->ReadFileNOBOITE(tmp);
250       //mymailw->SwapOutOfMemory_key_mesh_wrap(QRegExp("NB",TRUE,FALSE));
251    }
252    if (verbose>0)
253       cout<<"NumberOfFilesNOBOITEAcquired="<<mymailw->nbfiles<<"\n";
254    if (mymailw->nbfiles != nbfiles)
255    {
256       cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n";
257       return 1;
258    }
259
260    if (is_test)
261    {
262       ok=mymailw->test_vertices_wrap();
263       if (ok)
264       {
265          if (verbose>0) cout<<"\nResult_test_vertices_wrap=ok\n\n";
266       }
267       else
268       {
269          cerr<<"\nResult_test_vertices_wrap=NO_OK!\n\n";
270          return 1;
271       }
272    }
273
274    //read files .faces
275    mymailw->nbfiles=0;
276    for (int i=1; i<=nbfiles; i++)
277    {
278       mymailw->nofile=i;
279       tmp=casename+tmp.sprintf(format,nbfiles,i)+".faces";
280       if (verbose>0) cout<<"FileName="<<tmp<<endl;
281       ok=mymailw->ReadFileFACES(tmp);
282    }
283    if (verbose>0)
284       cout<<"NumberOfFilesFACESAcquired="<<mymailw->nbfiles<<"\n\n";
285    if (mymailw->nbfiles != nbfiles)
286    {
287       cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n\n";
288       return 1;
289    }
290
291    //read files .points
292    mymailw->nbfiles=0;
293    for (int i=1; i<=nbfiles; i++)
294    {
295       mymailw->nofile=i;
296       tmp=casename+tmp.sprintf(format,nbfiles,i)+".points";
297       if (verbose>0) cout<<"FileName="<<tmp<<endl;
298       ok=mymailw->ReadFilePOINTS(tmp);
299    }
300    if (verbose>0)
301       cout<<"NumberOfFilesPOINTSAcquired="<<mymailw->nbfiles<<"\n\n";
302    if (mymailw->nbfiles != nbfiles)
303    {
304       cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n\n";
305       return 1;
306    }
307
308    //read files .glo
309    //supposed big files big arrays so don't read with parser
310    mymailw->nbfiles=0;
311    for (int i=1; i<=nbfiles; i++)
312    {
313       mymailw->nofile=i;
314       tmp=casename+tmp.sprintf(format,nbfiles,i)+".glo";
315       if (verbose>0) cout<<"FileName="<<tmp<<endl;
316       ok=mymailw->ReadFileGLO(tmp);
317       //mymailw->SwapOutOfMemory_key_mesh_wrap(QRegExp("GL",TRUE,FALSE));
318    }
319    if (verbose>0)
320       cout<<"NumberOfFilesGLOAcquired="<<mymailw->nbfiles<<"\n\n";
321    if (mymailw->nbfiles != nbfiles)
322    {
323       cerr<<"NumberOfFiles != NumberOfFilesAcquired is unexpected\n\n";
324       return 1;
325    }
326
327    /*exemples
328    ok=mymailw->list_keys_mesh_wrap();
329    tmp="FA RE NE4 FI1";
330    ok=mymailw->list_onekey_mesh_wrap(tmp);
331    tmp="FA SE NE4 FI1";
332    ok=mymailw->list_onekey_mesh_wrap(tmp);
333    tmp="FA RE NE1 FI4";
334    ok=mymailw->list_onekey_mesh_wrap(tmp);
335    tmp="FA SE NE1 FI4";
336    ok=mymailw->list_onekey_mesh_wrap(tmp);
337
338    tmp="FA RE NE4 FI1";
339    ok=mymailw->list_onekey_mesh_wrap(tmp);*/
340
341    //test remove points (type 3)
342    //nb=mymailw->remove_key_mesh_wrap(QRegExp("PO",TRUE,FALSE));
343    //cout<<"***remove_key_mesh_wrap*** remove nb="<<nb<<endl;
344    //ok=mymailw->list_keys_mesh_wrap();
345
346    ok=mymailw->Write_MEDfiles();
347    //int nb=mymailw->remove_key_mesh_wrap(QRegExp(".",TRUE,FALSE));
348    nb=mymailw->remove_all_keys_mesh_wrap();
349    if (verbose>3)
350       cout<<"***remove_all_key_mesh_wrap*** "<<nb<<" keys removed\n";
351    cout<<endl<<"===end of "<<argv[0]<<"==="<<endl;
352    return 0; //ok
353 }
354