-
Notifications
You must be signed in to change notification settings - Fork 16
/
AmrVisTool.cpp
759 lines (653 loc) · 25.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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
// ---------------------------------------------------------------
// AmrVisTool.cpp
// ---------------------------------------------------------------
#include <AMReX_ParallelDescriptor.H>
#include <AMReX_BLProfiler.H>
#include <stdio.h>
#if ! (defined(BL_OSF1) || defined(BL_Darwin) || defined(BL_AIX) || defined(BL_IRIX64) || defined(BL_CYGWIN_NT) || defined(BL_CRAYX1))
#include <endian.h>
#endif
// X/Motif headers
#include <Xm/Xm.h>
#include <Xm/FileSB.h>
#include <Xm/Form.h>
#include <X11/Xos.h>
// BoxLib has index member functions, Xos might define it (LessTif).
#undef index
#include <MessageArea.H>
#include <GraphicsAttributes.H>
#include <Palette.H>
#include <PltApp.H>
#include <GlobalUtilities.H>
#include <AMReX_ParmParse.H>
#include <AMReX_DataServices.H>
#include <PltAppState.H>
#ifdef BL_USE_PROFPARSER
#include <ProfApp.H>
#include <AMReX_DataServices.H>
#endif
#ifdef BL_VOLUMERENDER
#include <VolRender.H>
#endif
#ifdef BL_USE_ARRAYVIEW
#include <ArrayView.H>
#endif
using std::cout;
using std::cerr;
using std::endl;
using namespace amrex;
const int OPENITEM = 0;
const int QUITITEM = 1;
void CreateMainWindow(int argc, char *argv[]);
void BatchFunctions();
extern void PrintProfParserBatchUsage(std::ostream &os);
extern bool ProfParserBatchFunctions(int argc, char *argv[], bool runDefault,
bool &bParserProf);
// CallBack functions
void CBFileMenu(Widget, XtPointer, XtPointer);
void CBOpenPltFile(Widget, XtPointer, XtPointer);
XtAppContext app;
Widget wTopLevel, wTextOut, wDialog;
Widget wMainWindow, wMenuBar;
Arg args[amrex::Amrvis::MAXARGS];
cMessageArea messageText;
char buffer[amrex::Amrvis::BUFSIZE];
XmString sDirectory = XmStringCreateSimple(const_cast<char *>("none"));
list<PltApp *> pltAppList;
#ifdef BL_USE_PROFPARSER
list<ProfApp *> profAppList;
#endif
//--------------------------------------------------------------
void PrintMessage(const char *message) {
sprintf(buffer, "%s", message);
messageText.PrintText(buffer);
}
//--------------------------------------------------------------
int main(int argc, char *argv[]) {
amrex::Box comlineBox;
string comlineFileName;
bool useParmParse(false);
amrex::Initialize(argc, argv, useParmParse);
AVGlobals::GetDefaults("amrvis.defaults");
#ifdef BL_USE_PROFPARSER
amrex::BLProfiler::SetBlProfDirName("bl_prof_amrvis");
if(argc > 2 && AVGlobals::IsProfDirName(argv[argc - 1])) {
// ---- run the amrprofparser batch functions
amrex::DataServices::SetBatchMode();
bool runDefault(false), bParserProf(false), bAnyFunctionsRun;
bAnyFunctionsRun = ProfParserBatchFunctions(argc, argv, runDefault, bParserProf);
if( ! bAnyFunctionsRun) {
if(amrex::ParallelDescriptor::IOProcessor()) {
cout << '\n';
cout << "Usage: " << argv[0] << " [options] profddirname\n";
PrintProfParserBatchUsage(cout);
cout << endl;
}
}
if (!bParserProf){
amrex::BLProfiler::SetNoOutput();
}
amrex::Finalize();
return 0;
}
#endif
AVGlobals::ParseCommandLine(argc, argv);
amrex::AmrData::SetVerbose(AVGlobals::Verbose());
amrex::AmrData::SetSkipPltLines(AVGlobals::GetSkipPltLines());
amrex::AmrData::SetStaticBoundaryWidth(AVGlobals::GetBoundaryWidth());
if(AVGlobals::SleepTime() > 0) {
sleep(AVGlobals::SleepTime());
}
if(AVGlobals::GivenBox()) {
comlineBox = AVGlobals::GetBoxFromCommandLine();
}
if(AVGlobals::GetFabOutFormat() == 1) {
amrex::DataServices::SetFabOutSize(1);
}
if(AVGlobals::GetFabOutFormat() == 8) {
amrex::DataServices::SetFabOutSize(8);
}
if(AVGlobals::GetFabOutFormat() == 32) {
amrex::DataServices::SetFabOutSize(32);
}
bool bBatchMode(false);
if(AVGlobals::CreateSWFData() || AVGlobals::DumpSlices() ||
AVGlobals::GivenBoxSlice())
{
bBatchMode = true;
}
if(bBatchMode && AVGlobals::IsAnimation()) {
amrex::Abort("Batch mode and animation mode are incompatible.");
}
if(bBatchMode) {
amrex::DataServices::SetBatchMode();
BatchFunctions();
amrex::Finalize();
} else {
if(amrex::ParallelDescriptor::IOProcessor()) {
CreateMainWindow(argc, argv);
}
if(AVGlobals::IsAnimation()) {
BL_ASSERT(AVGlobals::GetFileCount() > 0);
bool bAmrDataOk(true);
amrex::Amrvis::FileType fileType = AVGlobals::GetDefaultFileType();
BL_ASSERT(fileType != amrex::Amrvis::INVALIDTYPE);
amrex::Vector<amrex::DataServices *> dspArray(AVGlobals::GetFileCount());
for(int nPlots = 0; nPlots < AVGlobals::GetFileCount(); ++nPlots) {
comlineFileName = AVGlobals::GetComlineFilename(nPlots);
dspArray[nPlots] = new amrex::DataServices(comlineFileName, fileType);
if(amrex::ParallelDescriptor::IOProcessor()) {
dspArray[nPlots]->IncrementNumberOfUsers();
}
if( ! dspArray[nPlots]->AmrDataOk()) {
bAmrDataOk = false;
}
}
if(amrex::ParallelDescriptor::IOProcessor()) {
if(bAmrDataOk) {
PltApp *temp = new PltApp(app, wTopLevel,
AVGlobals::GetComlineFilename(0),
dspArray, AVGlobals::IsAnimation());
if(temp == NULL) {
cerr << "Error: could not make a new PltApp." << endl;
for(int nPlots = 0; nPlots < AVGlobals::GetFileCount(); ++nPlots) {
dspArray[nPlots]->DecrementNumberOfUsers();
}
} else {
pltAppList.push_back(temp);
if(AVGlobals::GivenBox()) {
amrex::DataServices *dsp = temp->GetDataServicesPtr();
const amrex::AmrData &amrData = dsp->AmrDataRef();
amrex::Box bPD(amrData.ProbDomain()[amrData.FinestLevel()]);
amrex::Box itypComlineBox(bPD); // for correct box type
itypComlineBox.setSmall(comlineBox.smallEnd());
itypComlineBox.setBig(comlineBox.bigEnd());
amrex::Box comlineBoxErr(itypComlineBox);
itypComlineBox &= bPD;
if(itypComlineBox.ok()) {
SubregionPltApp(wTopLevel, comlineBox, comlineBox.smallEnd(),
temp, temp->GetPaletteName(), AVGlobals::IsAnimation(),
temp->GetPltAppState()->CurrentDerived(), comlineFileName);
CBQuitPltApp(NULL, temp, NULL);
} else {
cerr << "Error: bad subregion box on the command line: "
<< comlineBoxErr << endl;
}
}
}
} else {
if(amrex::ParallelDescriptor::IOProcessor()) {
for(int nPlots = 0; nPlots < AVGlobals::GetFileCount(); ++nPlots) {
dspArray[nPlots]->DecrementNumberOfUsers();
}
}
}
}
} else {
// loop through the command line list of plot files
amrex::Amrvis::FileType fileType = AVGlobals::GetDefaultFileType();
BL_ASSERT(fileType != amrex::Amrvis::INVALIDTYPE);
#ifdef BL_USE_PROFPARSER
if(fileType == amrex::Amrvis::PROFDATA) {
if(amrex::ParallelDescriptor::IOProcessor()) {
cout << "]]]]: fileType is amrex::Amrvis::PROFDATA." << endl;
PrintMessage("]]]]: fileType is amrex::Amrvis::PROFDATA.\n");
}
if(AVGlobals::GetFileCount() == 1) {
string dirName(AVGlobals::GetComlineFilename(0));
cout << "]]]]]]]]: dirName = " << dirName << endl;
amrex::Vector<amrex::DataServices *> pdspArray(AVGlobals::GetFileCount());
for(int nPlots(0); nPlots < AVGlobals::GetFileCount(); ++nPlots) {
comlineFileName = AVGlobals::GetComlineFilename(nPlots);
if(amrex::ParallelDescriptor::IOProcessor()) {
cout << endl << "FileName = " << comlineFileName << endl;
}
pdspArray[nPlots] = new amrex::DataServices(comlineFileName, fileType);
if(amrex::ParallelDescriptor::IOProcessor()) {
pdspArray[nPlots]->IncrementNumberOfUsers();
ProfApp *temp = new ProfApp(app, wTopLevel, comlineFileName,
pdspArray);
if(temp == nullptr) {
cerr << "Error: could not make a new ProfApp." << endl;
} else {
profAppList.push_back(temp);
}
}
}
} else {
amrex::Abort("**** Error: only a single bl_prof directory is supported.");
}
} else
#endif
{
amrex::Vector<amrex::DataServices *> dspArray(AVGlobals::GetFileCount());
for(int nPlots(0); nPlots < AVGlobals::GetFileCount(); ++nPlots) {
comlineFileName = AVGlobals::GetComlineFilename(nPlots);
if(amrex::ParallelDescriptor::IOProcessor()) {
cout << endl << "FileName = " << comlineFileName << endl;
}
dspArray[nPlots] = new amrex::DataServices(comlineFileName, fileType);
} // end for(nPlots...)
for(int nPlots(0); nPlots < AVGlobals::GetFileCount(); ++nPlots) {
if(amrex::ParallelDescriptor::IOProcessor()) {
if(dspArray[nPlots]->AmrDataOk()) {
amrex::Vector<amrex::DataServices *> dspArrayOne(1);
dspArrayOne[0] = dspArray[nPlots];
PltApp *temp = new PltApp(app, wTopLevel, dspArrayOne[0]->GetFileName(),
dspArrayOne, AVGlobals::IsAnimation());
if(temp == nullptr) {
cerr << "Error: could not make a new PltApp." << endl;
} else {
pltAppList.push_back(temp);
dspArray[nPlots]->IncrementNumberOfUsers();
if(AVGlobals::GivenBox()) {
amrex::DataServices *dsp = temp->GetDataServicesPtr();
const amrex::AmrData &amrData = dsp->AmrDataRef();
amrex::Box bPD(amrData.ProbDomain()[amrData.FinestLevel()]);
amrex::Box itypComlineBox(bPD); // for correct box type
itypComlineBox.setSmall(comlineBox.smallEnd());
itypComlineBox.setBig(comlineBox.bigEnd());
amrex::Box comlineBoxErr(itypComlineBox);
itypComlineBox &= bPD;
if(itypComlineBox.ok()) {
SubregionPltApp(wTopLevel, comlineBox, comlineBox.smallEnd(),
temp, temp->GetPaletteName(), AVGlobals::IsAnimation(),
temp->GetPltAppState()->CurrentDerived(), dsp->GetFileName());
CBQuitPltApp(NULL, temp, NULL);
} else {
cerr << "Error: bad subregion box on the command line: "
<< comlineBoxErr << endl;
}
}
}
}
}
} // end for(nPlots...)
}
} // end if(AVGlobals::IsAnimation())
if(amrex::ParallelDescriptor::IOProcessor()) {
XtAppMainLoop(app);
} else {
// all other processors wait for a request
amrex::DataServices::Dispatch(amrex::DataServices::InvalidRequestType, NULL, NULL);
}
} // end if(bBatchMode)
cout << amrex::ParallelDescriptor::MyProc() << "::]]]]: exiting main." << endl;
return 0;
} // end main()
// ---------------------------------------------------------------
void CreateMainWindow(int argc, char *argv[]) {
int i;
string comlineFileName;
String fallbacks[] = {const_cast<char *>("*fontList:variable=charset"),
NULL };
wTopLevel = XtVaAppInitialize(&app, "AmrVisTool", NULL, 0,
(int *) &argc, argv, fallbacks,
XmNx, 350,
XmNy, 10,
XmNwidth, 600,
XmNheight, 200,
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);
XmString sFile = XmStringCreateSimple(const_cast<char *>("File"));
XmString sOpen = XmStringCreateSimple(const_cast<char *>("Open..."));
XmString sQuit = XmStringCreateSimple(const_cast<char *>("Quit"));
wMenuBar = XmVaCreateSimpleMenuBar(wMainWindow, const_cast<char *>("menuBar"),
XmVaCASCADEBUTTON, sFile, 'F',
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNheight, 30,
NULL);
XmString sCtrlQ = XmStringCreateSimple(const_cast<char *>("Ctrl+Q"));
XmString sCtrlO = XmStringCreateSimple(const_cast<char *>("Ctrl+O"));
XmVaCreateSimplePulldownMenu(wMenuBar, const_cast<char *>("fileMenu"), 0,
(XtCallbackProc) CBFileMenu,
XmVaPUSHBUTTON, sOpen, 'O', "Ctrl<Key>O", sCtrlO,
XmVaPUSHBUTTON, sQuit, 'Q', "Ctrl<Key>Q", sCtrlQ,
NULL);
XmStringFree(sFile);
XmStringFree(sOpen);
XmStringFree(sQuit);
XmStringFree(sCtrlO);
XmStringFree(sCtrlQ);
XtManageChild(wMenuBar);
i = 0;
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, const_cast<char *>("textOut"), args, i);
XtManageChild(wTextOut);
messageText.Init(wTextOut);
XtRealizeWidget(wTopLevel);
} // end CreateMainWindow()
// ---------------------------------------------------------------
void BatchFunctions() {
string comlineFileName;
// loop through the command line list of plot files
for(int nPlots = 0; nPlots < AVGlobals::GetFileCount(); ++nPlots) {
comlineFileName = AVGlobals::GetComlineFilename(nPlots);
if(amrex::ParallelDescriptor::IOProcessor()) {
cout << "FileName = " << comlineFileName << endl;
}
amrex::Amrvis::FileType fileType = AVGlobals::GetDefaultFileType();
BL_ASSERT(fileType != amrex::Amrvis::INVALIDTYPE);
amrex::DataServices dataServices(comlineFileName, fileType);
string derived(AVGlobals::GetInitialDerived());
if( ! dataServices.CanDerive(derived)) {
if(amrex::ParallelDescriptor::IOProcessor()) {
cerr << "Unknown initial derived: " << derived << endl;
}
derived = dataServices.PlotVarNames()[0];
if(amrex::ParallelDescriptor::IOProcessor()) {
cerr << "Defaulting to: " << derived << endl;
}
AVGlobals::SetInitialDerived(derived);
}
#if (BL_SPACEDIM == 3)
#ifdef BL_VOLUMERENDER
if(AVGlobals::CreateSWFData()) {
amrex::AmrData &amrData = dataServices.AmrDataRef();
BL_ASSERT(dataServices.CanDerive(AVGlobals::GetInitialDerived()));
int minDrawnLevel = 0;
int maxDrawnLevel;
if(AVGlobals::UseMaxLevel()) {
maxDrawnLevel = max(0, min(AVGlobals::GetMaxLevel(), amrData.FinestLevel()));
} else {
maxDrawnLevel = amrData.FinestLevel();
}
if(amrex::ParallelDescriptor::IOProcessor()) {
cout << "_in BatchFunctions: using max level = " << maxDrawnLevel << endl;
}
amrex::Vector<amrex::Box> drawDomain = amrData.ProbDomain();
if(AVGlobals::GivenBox()) {
amrex::Box comlineBox = AVGlobals::GetBoxFromCommandLine();
int finelev(amrData.FinestLevel());
if(amrData.ProbDomain()[finelev].contains(comlineBox) == false) {
cerr << "Error: bad comlineBox: probDomain(finestLevel) = "
<< amrData.ProbDomain()[finelev] << endl;
amrex::Abort("Exiting.");
}
drawDomain[finelev] = comlineBox;
for(int ilev(amrData.FinestLevel() - 1); ilev >= 0; --ilev) {
int crr(amrex::CRRBetweenLevels(ilev, finelev, amrData.RefRatio()));
drawDomain[ilev] = drawDomain[finelev];
drawDomain[ilev].coarsen(crr);
}
}
int iPaletteStart(3);
int iPaletteEnd(AVGlobals::MaxPaletteIndex());
int iBlackIndex(0);
int iWhiteIndex(1);
int iColorSlots(AVGlobals::MaxPaletteIndex() + 1 - iPaletteStart);
Palette volPal(AVPalette::PALLISTLENGTH, AVPalette::PALWIDTH,
AVPalette::TOTALPALWIDTH, AVPalette::TOTALPALHEIGHT, 0);
if(amrex::ParallelDescriptor::IOProcessor()) {
cout << "_in BatchFunctions: palette name = "
<< AVGlobals::GetPaletteName() << endl;
}
volPal.ReadSeqPalette(AVGlobals::GetPaletteName(), false);
VolRender volRender(drawDomain, minDrawnLevel, maxDrawnLevel, &volPal,
AVGlobals::GetLightingFileName());
Real dataMin, dataMax;
if(AVGlobals::UseSpecifiedMinMax()) {
AVGlobals::GetSpecifiedMinMax(dataMin, dataMax);
} else {
amrData.MinMax(drawDomain[maxDrawnLevel], AVGlobals::GetInitialDerived(),
maxDrawnLevel, dataMin, dataMax);
}
volRender.MakeSWFData(&dataServices, dataMin, dataMax,
AVGlobals::GetInitialDerived(),
iPaletteStart, iPaletteEnd,
iBlackIndex, iWhiteIndex, iColorSlots,
PltApp::GetDefaultShowBoxes());
volRender.WriteSWFData(comlineFileName, AVGlobals::MakeSWFLight());
}
#endif
#endif
if(AVGlobals::DumpSlices()) {
if(AVGlobals::UseMaxLevel() == true) {
dataServices.SetWriteToLevel(AVGlobals::GetMaxLevel());
}
if(AVGlobals::SliceAllVars()) {
for(int slicedir(0); slicedir < AVGlobals::GetDumpSlices().size();
++slicedir)
{
for(list<int>::iterator li =
AVGlobals::GetDumpSlices()[slicedir].begin();
li != AVGlobals::GetDumpSlices()[slicedir].end();
++li)
{
int slicenum = *li;
amrex::DataServices::Dispatch(amrex::DataServices::DumpSlicePlaneAllVars,
&dataServices, slicedir, slicenum);
}
}
} else {
for(int slicedir(0); slicedir < AVGlobals::GetDumpSlices().size();
++slicedir)
{
for(list<int>::iterator li =
AVGlobals::GetDumpSlices()[slicedir].begin();
li != AVGlobals::GetDumpSlices()[slicedir].end();
++li)
{
int slicenum = *li;
amrex::DataServices::Dispatch(amrex::DataServices::DumpSlicePlaneOneVar,
&dataServices, slicedir, slicenum,
(void *) &derived);
}
}
}
} // end if(AVGlobals::DumpSlices())
if(AVGlobals::GivenBoxSlice()) {
if(AVGlobals::UseMaxLevel() == true) {
dataServices.SetWriteToLevel(AVGlobals::GetMaxLevel());
}
amrex::Box comLineBox(AVGlobals::GetBoxFromCommandLine());
BL_ASSERT(comLineBox.ok());
if(AVGlobals::SliceAllVars()) {
amrex::DataServices::Dispatch(amrex::DataServices::DumpSliceBoxAllVars,
&dataServices,
(void *) &comLineBox);
} else {
amrex::DataServices::Dispatch(amrex::DataServices::DumpSliceBoxOneVar,
&dataServices,
(void *) &comLineBox,
(void *) &derived);
}
} // end if(AVGlobals::GivenBoxSlice())
} // end for(nPlots...)
} // end BatchFunctions
// ---------------------------------------------------------------
void QuitAll() {
for(list<PltApp *>::iterator li = pltAppList.begin();
li != pltAppList.end(); ++li)
{
PltApp *obj = *li;
amrex::Vector<amrex::DataServices *> dataServicesPtr = obj->GetDataServicesPtrArray();
for(int ids(0); ids < dataServicesPtr.size(); ++ids) {
dataServicesPtr[ids]->DecrementNumberOfUsers();
}
delete obj;
}
pltAppList.clear();
amrex::DataServices::Dispatch(amrex::DataServices::ExitRequest, NULL);
}
// ---------------------------------------------------------------
void CBFileMenu(Widget, XtPointer client_data, XtPointer) {
int i(0);
unsigned long item = (unsigned long) client_data;
if(item == QUITITEM) {
QuitAll();
} else if(item == OPENITEM) {
i = 0;
amrex::Amrvis::FileType fileType(AVGlobals::GetDefaultFileType());
XmString sMask;
if(fileType == amrex::Amrvis::FAB) {
sMask = XmStringCreateSimple(const_cast<char *>("*.fab"));
} else if(fileType == amrex::Amrvis::MULTIFAB) {
sMask = XmStringCreateSimple(const_cast<char *>("*_H"));
#ifdef BL_USE_PROFPARSER
} else if(fileType == amrex::Amrvis::PROFDATA) {
sMask = XmStringCreateSimple(const_cast<char *>("bl_prof*"));
#endif
} else {
sMask = XmStringCreateSimple(const_cast<char *>("plt*"));
}
XmString sNone = XmStringCreateSimple(const_cast<char *>("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, const_cast<char *>("Open File"), args, i);
XtAddCallback(wDialog, XmNokCallback, (XtCallbackProc) 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;
}
amrex::Amrvis::FileType fileType(AVGlobals::GetDefaultFileType());
if(fileType == amrex::Amrvis::MULTIFAB) {
// delete the _H from the filename if it is there
const char *uH = "_H";
char *fm2 = filename + (strlen(filename) - 2);
if(strcmp(uH, fm2) == 0) {
filename[strlen(filename) - 2] = '\0';
}
}
char path[amrex::Amrvis::BUFSIZE];
strcpy(path, filename);
int pathPos(strlen(path) - 1);
while(pathPos > -1 && path[pathPos] != '/') {
--pathPos;
}
path[pathPos + 1] = '\0';
sDirectory = XmStringCreateSimple(path);
sprintf(buffer, "Selected file = %s\n", filename);
messageText.PrintText(buffer);
amrex::DataServices *dataServicesPtr = new amrex::DataServices();
dataServicesPtr->Init(filename, AVGlobals::GetDefaultFileType());
amrex::DataServices::Dispatch(amrex::DataServices::NewRequest, dataServicesPtr, NULL);
amrex::Vector<amrex::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.push_back(temp);
dspArray[0]->IncrementNumberOfUsers();
}
XtPopdown(XtParent(w));
}
// ---------------------------------------------------------------
void SubregionPltApp(Widget swTopLevel, const amrex::Box &trueRegion,
const amrex::IntVect &offset,
PltApp *pltparent,
const string &palfile, int isAnim,
const string ¤tderived, const string &file)
{
PltApp *temp = new PltApp(app, swTopLevel, trueRegion, offset,
pltparent, palfile, isAnim, currentderived, file);
if(temp == NULL) {
cerr << "Error in SubregionPltApp: could not make a new PltApp." << endl;
} else {
pltAppList.push_back(temp);
amrex::Vector<amrex::DataServices *> dataServicesPtr = temp->GetDataServicesPtrArray();
for(int ids(0); ids < dataServicesPtr.size(); ++ids) {
dataServicesPtr[ids]->IncrementNumberOfUsers();
}
}
}
#ifdef BL_USE_PROFPARSER
// ---------------------------------------------------------------
void SubregionProfApp(Widget swTopLevel, const amrex::Box &trueRegion,
const amrex::IntVect &offset,
ProfApp *profparent, const string &palfile,
const string &file)
{
ProfApp *temp = new ProfApp(app, swTopLevel, trueRegion, offset,
profparent, palfile, file);
cout << "_in SubregionProfApp: offset = " << offset << endl;
if(temp == NULL) {
cerr << "Error in SubregionProfApp: could not make a new ProfApp." << endl;
} else {
profAppList.push_back(temp);
//amrex::Vector<amrex::DataServices *> dataServicesPtr = temp->GetDataServicesPtrArray();
//for(int ids(0); ids < dataServicesPtr.size(); ++ids) {
//dataServicesPtr[ids]->IncrementNumberOfUsers();
//}
}
}
#endif
// ---------------------------------------------------------------
void CBQuitPltApp(Widget /*ofPltApp*/, XtPointer client_data, XtPointer) {
PltApp *obj = (PltApp *) client_data;
pltAppList.remove(obj);
amrex::Vector<amrex::DataServices *> &dataServicesPtr = obj->GetDataServicesPtrArray();
for(int ids(0); ids < dataServicesPtr.size(); ++ids) {
dataServicesPtr[ids]->DecrementNumberOfUsers();
amrex::DataServices::Dispatch(amrex::DataServices::DeleteRequest, dataServicesPtr[ids], NULL);
}
delete obj;
}
#ifdef BL_USE_PROFPARSER
// ---------------------------------------------------------------
void CBQuitProfApp(Widget /*ofProfApp*/, XtPointer client_data, XtPointer) {
ProfApp *obj = (ProfApp *) client_data;
profAppList.remove(obj);
amrex::Vector<amrex::DataServices *> &dataServicesPtr = obj->GetDataServicesPtrArray();
for(int ids(0); ids < dataServicesPtr.size(); ++ids) {
dataServicesPtr[ids]->DecrementNumberOfUsers();
amrex::DataServices::Dispatch(amrex::DataServices::DeleteRequest, dataServicesPtr[ids], NULL);
}
delete obj;
}
#endif
// ---------------------------------------------------------------
void CBQuitAll(Widget, XtPointer, XtPointer) {
QuitAll();
}
// ---------------------------------------------------------------
// ---------------------------------------------------------------