-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathAmrVisTool.cpp
580 lines (500 loc) · 17.6 KB
/
AmrVisTool.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
//--------------------------------------------------------------
// AmrVisTool.cpp
//--------------------------------------------------------------
#ifdef BL_USE_NEW_HFILES
#include <strstream>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cerrno>
#else
#include <strstream.h>
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#endif
// X/Motif headers
#include <Xm.h>
#include <MainW.h>
#include <PushB.h>
#include <PushBG.h>
#include <FileSB.h>
#include <MessageB.h>
#include <Label.h>
#include <Text.h>
#include <RowColumn.h>
#include <Form.h>
#include <DrawingA.h>
#include <ToggleB.h>
#include <ToggleBG.h>
#include <Xos.h>
#include "MessageArea.H"
#include "GraphicsAttributes.H"
#include "Palette.H"
#include "PltApp.H"
#include "GlobalUtilities.H"
#include "ParmParse.H"
#include "ParallelDescriptor.H"
#include "DataServices.H"
#ifdef BL_VOLUMERENDER
#include "VolRender.H"
#endif
#ifdef BL_USE_ARRAYVIEW
#include "ArrayView.H"
#endif
const int OPENITEM = 0;
const int QUITITEM = 1;
//const int SETITEM = 0;
//const int HELPITEM = 0;
void CreateMainWindow(int argc, char *argv[]);
void BatchFunctions();
// CallBack functions
void CBFileMenu(Widget, XtPointer, XtPointer);
void CBOpenPltFile(Widget, XtPointer, XtPointer);
XtAppContext app;
Widget wTopLevel, wTextOut, wDialog;
Widget wMainWindow, wMenuBar;
XmString sFile, sOpen, sQuit;
Arg args[32];
cMessageArea messageText;
char buffer[BUFSIZ];
XmString sDirectory = XmStringCreateSimple("none");
List<PltApp *> pltAppList;
//--------------------------------------------------------------
void PrintMessage(char *message) {
sprintf(buffer, "%s", message);
messageText.PrintText(buffer);
}
//--------------------------------------------------------------
void main(int argc, char *argv[]) {
Box comlineBox;
aString comlineFileName;
#ifdef BL_USE_MPI
int nprocs = 1;
ParallelDescriptor::StartParallel(nprocs,&argc,&argv);
SetNProcs(ParallelDescriptor::NProcs());
#endif
ParmParse pp(0, argv, NULL, NULL);
GetDefaults("amrvis.defaults");
ParseCommandLine(argc, argv);
if(Verbose()) {
AmrData::SetVerbose(true);
}
AmrData::SetSkipPltLines(GetSkipPltLines());
AmrData::SetStaticBoundaryWidth(GetBoundaryWidth());
#ifndef BL_USE_MPI
ParallelDescriptor::StartParallel(NProcs(), &argc, &argv);
#endif
if(SleepTime() > 0) {
sleep(SleepTime());
}
if(GivenBox()) {
comlineBox = GetBoxFromCommandLine();
}
bool bBatchMode(false);
if(MakeSWFData() || DumpSlices() || GivenBoxSlice()) {
bBatchMode = true;
}
if(bBatchMode && IsAnimation()) {
ParallelDescriptor::Abort("Batch mode and animation mode are incompatible.");
}
if(GivenBox()) {
ParallelDescriptor::Abort("Command line subbox not supported yet.");
}
if(bBatchMode) {
DataServices::SetBatchMode();
BatchFunctions();
ParallelDescriptor::EndParallel();
} else {
if(ParallelDescriptor::IOProcessor()) {
CreateMainWindow(argc, argv);
}
if(IsAnimation()) {
assert(GetFileCount() > 0);
bool bAmrDataOk(true);
FileType fileType = GetDefaultFileType();
assert(fileType != INVALIDTYPE);
Array<DataServices *> dspArray(GetFileCount());
for(int nPlots = 0; nPlots < GetFileCount(); ++nPlots) {
comlineFileName = GetComlineFilename(nPlots);
dspArray[nPlots] = new DataServices(comlineFileName, fileType);
if(ParallelDescriptor::IOProcessor()) {
dspArray[nPlots]->IncrementNumberOfUsers();
}
if( ! dspArray[nPlots]->AmrDataOk()) {
bAmrDataOk = false;
}
}
if(ParallelDescriptor::IOProcessor()) {
if(bAmrDataOk) {
PltApp *temp = new PltApp(app, wTopLevel, GetComlineFilename(0),
dspArray, IsAnimation());
if(temp == NULL) {
cerr << "Error: could not make a new PltApp." << endl;
for(int nPlots = 0; nPlots < GetFileCount(); ++nPlots) {
dspArray[nPlots]->DecrementNumberOfUsers();
}
} else {
pltAppList.append(temp);
}
} else {
if(ParallelDescriptor::IOProcessor()) {
for(int nPlots = 0; nPlots < GetFileCount(); ++nPlots) {
dspArray[nPlots]->DecrementNumberOfUsers();
}
}
}
}
} else {
// loop through the command line list of plot files
FileType fileType = GetDefaultFileType();
assert(fileType != INVALIDTYPE);
for(int nPlots = 0; nPlots < GetFileCount(); ++nPlots) {
comlineFileName = GetComlineFilename(nPlots);
if(ParallelDescriptor::IOProcessor()) {
cout << "FileName = " << comlineFileName << endl;
}
Array<DataServices *> dspArray(1);
dspArray[0] = new DataServices(comlineFileName, fileType);
if(ParallelDescriptor::IOProcessor()) {
if(dspArray[0]->AmrDataOk()) {
PltApp *temp = new PltApp(app, wTopLevel, comlineFileName,
dspArray, IsAnimation());
if(temp == NULL) {
cerr << "Error: could not make a new PltApp." << endl;
} else {
pltAppList.append(temp);
dspArray[0]->IncrementNumberOfUsers();
}
}
}
} // end for(nPlots...)
} // end if(IsAnimation())
if(ParallelDescriptor::IOProcessor()) {
XtAppMainLoop(app);
} else {
// all other processors wait for a request
DataServices::Dispatch(DataServices::InvalidRequestType, NULL, NULL);
}
} // end if(bBatchMode)
//ParallelDescriptor::EndParallel();
} // end main()
// ---------------------------------------------------------------
void CreateMainWindow(int argc, char *argv[]) {
int i;
aString comlineFileName;
#ifdef CRAY
# if (BL_SPACEDIM == 2)
String fallbacks[6];
fallbacks[0] = "*fontList:7x13=charset";
fallbacks[1] = "*bottomShadowColor:gray";
fallbacks[2] = "*topShadowColor:gray";
fallbacks[3] = "*background:black";
fallbacks[4] = "*foreground:white";
fallbacks[5] = NULL;
# endif
# if (BL_SPACEDIM == 3)
//String fallbacks[6];
String fallbacks[4];
fallbacks[0] = "*fontList:7x13=charset";
fallbacks[1] = "*bottomShadowColor:yellow";
fallbacks[2] = "*topShadowColor:gray";
fallbacks[3] = NULL;
//fallbacks[3] = "*background:black";
//fallbacks[4] = "*foreground:white";
//fallbacks[5] = NULL;
//String fallbacks[] = {"*fontList:7x13=charset",
//"*background:black",
//"*foreground:white",
//"*bottomShadowColor:gray28",
//"*topShadowColor:gray42",
//NULL };
# endif
#else
#if (BL_SPACEDIM == 2)
String fallbacks[] = {"*fontList:7x13=charset", "*background:black",
"*foreground:white", "*bottomShadowColor:yellow",
"*topShadowColor:gray", NULL };
#endif
#if (BL_SPACEDIM == 3)
String fallbacks[] = {"*fontList:7x13=charset",
"*bottomShadowColor:black",
"*topShadowColor:gray",
NULL };
#endif
#endif
wTopLevel = XtVaAppInitialize(&app, "AmrVisTool", NULL, 0,
(int *) &argc, argv, fallbacks,
XmNx, 350,
XmNy, 10,
XmNwidth, 500,
XmNheight, 150,
NULL);
GraphicsAttributes *TheGAptr = new GraphicsAttributes(wTopLevel);
if(TheGAptr->PVisual() != XDefaultVisual(TheGAptr->PDisplay(),
TheGAptr->PScreenNumber() ) ){
Colormap colormap = XCreateColormap(TheGAptr->PDisplay(),
RootWindow(TheGAptr->PDisplay(),
TheGAptr->PScreenNumber()),
TheGAptr->PVisual(), AllocNone);
XtVaSetValues(wTopLevel, XmNvisual, TheGAptr->PVisual(), XmNdepth, 8,
XmNcolormap, colormap, NULL);
}
wMainWindow = XtVaCreateManagedWidget ("mainWindow",
xmFormWidgetClass, wTopLevel,
XmNscrollBarDisplayPolicy, XmAS_NEEDED,
XmNscrollingPolicy, XmAUTOMATIC,
NULL);
sFile = XmStringCreateSimple("File");
sOpen = XmStringCreateSimple("Open...");
sQuit = XmStringCreateSimple("Exit");
wMenuBar = XmVaCreateSimpleMenuBar(wMainWindow, "menuBar",
XmVaCASCADEBUTTON, sFile, 'F',
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNheight, 30,
NULL);
XmVaCreateSimplePulldownMenu(wMenuBar, "fileMenu", 0, CBFileMenu,
XmVaPUSHBUTTON, sOpen, 'O', NULL, NULL,
//XmVaSEPARATOR, // the separator is buggy in old versions of motif
XmVaPUSHBUTTON, sQuit, 'Q', NULL, NULL,
NULL);
XmStringFree(sFile);
XmStringFree(sOpen);
XmStringFree(sQuit);
XtManageChild(wMenuBar);
i = 0;
//XtSetArg(args[i], XmNrows, 20); i++;
//XtSetArg(args[i], XmNcolumns, 80); i++;
XtSetArg(args[i], XmNeditable, false); i++;
XtSetArg(args[i], XmNeditMode, XmMULTI_LINE_EDIT); i++;
XtSetArg(args[i], XmNwordWrap, true); i++;
XtSetArg(args[i], XmNscrollHorizontal, false); i++;
XtSetArg(args[i], XmNblinkRate, 0); i++;
XtSetArg(args[i], XmNautoShowCursorPosition, true); i++;
XtSetArg(args[i], XmNcursorPositionVisible, false); i++;
XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
XtSetArg(args[i], XmNtopWidget, wMenuBar); i++;
XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
XtSetArg(args[i], XmNbottomAttachment, XmATTACH_FORM); i++;
wTextOut = XmCreateScrolledText(wMainWindow, "textOut", args, i);
XtManageChild(wTextOut);
messageText.Init(wTextOut);
//XmMainWindowSetAreas(wMainWindow, wMenuBar, NULL, NULL, NULL, wTextOut);
XtRealizeWidget(wTopLevel);
} // end CreateMainWindow()
// ---------------------------------------------------------------
void BatchFunctions() {
aString comlineFileName;
// loop through the command line list of plot files
for(int nPlots = 0; nPlots < GetFileCount(); nPlots++) {
comlineFileName = GetComlineFilename(nPlots);
cout << "FileName = " << comlineFileName << endl;
FileType fileType = GetDefaultFileType();
assert(fileType != INVALIDTYPE);
DataServices dataServices(comlineFileName, fileType);
aString derived(GetInitialDerived());
if( ! dataServices.CanDerive(derived)) {
if(ParallelDescriptor::IOProcessor()) {
cerr << "Bad initial derived: cannot derive " << derived << endl;
}
derived = dataServices.PlotVarNames()[0];
if(ParallelDescriptor::IOProcessor()) {
cerr << "Defaulting to " << derived << endl;
}
SetInitialDerived(derived);
}
#if (BL_SPACEDIM == 3)
#ifdef BL_VOLUMERENDER
if(MakeSWFData()) {
AmrData &amrData = dataServices.AmrDataRef();
assert(dataServices.CanDerive(GetInitialDerived()));
int minDrawnLevel = 0;
int maxDrawnLevel;
if(UseMaxLevel()) {
maxDrawnLevel = Max(0, Min(GetMaxLevel(), amrData.FinestLevel()));
} else {
maxDrawnLevel = amrData.FinestLevel();
}
Array<Box> drawDomain = amrData.ProbDomain();
VolRender volRender(drawDomain, minDrawnLevel, maxDrawnLevel, NULL);
Real dataMin, dataMax;
if(UseSpecifiedMinMax()) {
GetSpecifiedMinMax(dataMin, dataMax);
} else {
amrData.MinMax(drawDomain[maxDrawnLevel], GetInitialDerived(),
maxDrawnLevel, dataMin, dataMax);
//bool minMaxValid;
//DataServices::Dispatch(DataServices::MinMaxRequest,
//&dataServices,
//drawDomain[maxDrawnLevel], GetInitialDerived(),
//maxDrawnLevel, dataMin, dataMax, minMaxValid);
}
int iPaletteStart = 2;
int iPaletteEnd = MaxPaletteIndex();
int iBlackIndex = 1;
int iWhiteIndex = 0;
int iColorSlots = MaxPaletteIndex() + 1 - iPaletteStart;
volRender.MakeSWFData(&dataServices, dataMin, dataMax, GetInitialDerived(),
iPaletteStart, iPaletteEnd,
iBlackIndex, iWhiteIndex, iColorSlots);
volRender.WriteSWFData(comlineFileName, MakeSWFLight());
}
#endif
#endif
if(DumpSlices()) {
if(SliceAllVars()) {
for(int slicedir=0; slicedir<GetDumpSlices().length(); ++slicedir) {
ListIterator<int> li(GetDumpSlices()[slicedir]);
while(li) {
int slicenum = li();
DataServices::Dispatch(DataServices::DumpSlicePlaneAllVars,
&dataServices,
slicedir, slicenum);
++li;
}
}
} else {
for(int slicedir=0; slicedir<GetDumpSlices().length(); slicedir++) {
ListIterator<int> li(GetDumpSlices()[slicedir]);
while(li) {
int slicenum = li();
DataServices::Dispatch(DataServices::DumpSlicePlaneOneVar,
&dataServices,
slicedir, slicenum, derived);
++li;
}
}
}
} // end if(DumpSlices())
if(GivenBoxSlice()) {
Box comLineBox(GetBoxFromCommandLine());
assert(comLineBox.ok());
if(SliceAllVars()) {
DataServices::Dispatch(DataServices::DumpSliceBoxAllVars,
&dataServices,
comLineBox);
} else {
DataServices::Dispatch(DataServices::DumpSliceBoxOneVar,
&dataServices,
comLineBox, derived);
}
} // end if(GivenBoxSlice())
} // end for(nPlots...)
} // end BatchFunctions
// ---------------------------------------------------------------
void CBFileMenu(Widget, XtPointer client_data, XtPointer) {
Arg args[MAXARGS];
int i = 0;
unsigned long item = (unsigned long) client_data;
if(item == QUITITEM) {
for(ListIterator<PltApp *> li(pltAppList); li; ++li) {
PltApp *obj = pltAppList[li];
Array<DataServices *> dataServicesPtr = obj->GetDataServicesPtrArray();
for(int ids = 0; ids < dataServicesPtr.length(); ++ids) {
dataServicesPtr[ids]->DecrementNumberOfUsers();
}
delete obj;
}
pltAppList.clear();
DataServices::Dispatch(DataServices::ExitRequest, NULL);
}
if(item == OPENITEM) {
i=0;
FileType fileType = GetDefaultFileType();
XmString sMask;
if(fileType==NEWPLT) {
sMask = XmStringCreateSimple("plt*");
} else if(fileType==FAB) {
sMask = XmStringCreateSimple("*.fab");
} else if(fileType==MULTIFAB) {
sMask = XmStringCreateSimple("*.multifab");
} else {
sMask = XmStringCreateSimple("*");
}
XmString sNone = XmStringCreateSimple("none");
if( ! XmStringCompare(sDirectory, sNone)) {
XtSetArg (args[i], XmNdirectory, sDirectory); i++;
}
XtSetArg (args[i], XmNpattern, sMask); i++;
XtSetArg (args[i], XmNfileTypeMask, XmFILE_ANY_TYPE); i++;
wDialog = XmCreateFileSelectionDialog(wTopLevel, "Open File", args, i);
XtAddCallback(wDialog, XmNokCallback, CBOpenPltFile, NULL);
XtAddCallback(wDialog, XmNcancelCallback,
(XtCallbackProc)XtUnmanageChild, NULL);
XmStringFree(sMask);
XmStringFree(sNone);
XtManageChild(wDialog);
XtPopup(XtParent(wDialog), XtGrabExclusive);
}
}
// ---------------------------------------------------------------
void CBOpenPltFile(Widget w, XtPointer, XtPointer call_data) {
char *filename = NULL;
if( ! XmStringGetLtoR(
((XmFileSelectionBoxCallbackStruct*) call_data)->value,
XmSTRING_DEFAULT_CHARSET,
&filename))
{
cerr << "CBOpenPltFile : system error" << endl;
return;
}
char path[BUFSIZ];
strcpy(path, filename);
int i = strlen(path) - 1;
while(i > -1 && path[i] != '/') {
--i;
}
path[i+1] = '\0';
sDirectory = XmStringCreateSimple(path);
sprintf(buffer, "Selected file = %s\n", filename);
messageText.PrintText(buffer);
DataServices *dataServicesPtr = new DataServices(filename, GetDefaultFileType());
DataServices::Dispatch(DataServices::NewRequest, dataServicesPtr, NULL);
Array<DataServices *> dspArray(1);
dspArray[0] = dataServicesPtr;
bool bIsAnim(false);
PltApp *temp = new PltApp(app, wTopLevel, filename, dspArray, bIsAnim);
if(temp == NULL) {
cerr << "Error: could not make a new PltApp." << endl;
} else {
pltAppList.append(temp);
dspArray[0]->IncrementNumberOfUsers();
}
XtPopdown(XtParent(w));
}
// ---------------------------------------------------------------
void SubregionPltApp(Widget wTopLevel, const Box &trueRegion,
const IntVect &offset,
AmrPicture *parentPicturePtr, PltApp *pltparent,
const aString &palfile, int isAnim,
const aString ¤tderived, const aString &file)
{
PltApp *temp = new PltApp(app, wTopLevel, trueRegion, offset, parentPicturePtr,
pltparent, palfile, isAnim, currentderived, file);
if(temp == NULL) {
cerr << "Error in SubregionPltApp: could not make a new PltApp." << endl;
} else {
pltAppList.append(temp);
Array<DataServices *> dataServicesPtr = temp->GetDataServicesPtrArray();
for(int ids = 0; ids < dataServicesPtr.length(); ++ids) {
dataServicesPtr[ids]->IncrementNumberOfUsers();
}
}
}
// ---------------------------------------------------------------
void CBQuitPltApp(Widget ofPltApp, XtPointer client_data, XtPointer) {
PltApp *obj = (PltApp *) client_data;
pltAppList.remove(obj);
Array<DataServices *> &dataServicesPtr = obj->GetDataServicesPtrArray();
for(int ids = 0; ids < dataServicesPtr.length(); ++ids) {
dataServicesPtr[ids]->DecrementNumberOfUsers();
DataServices::Dispatch(DataServices::DeleteRequest, dataServicesPtr[ids], NULL);
}
delete obj;
}
// ---------------------------------------------------------------
// ---------------------------------------------------------------