-
Notifications
You must be signed in to change notification settings - Fork 16
/
PltAppOutput.cpp
347 lines (298 loc) · 12.2 KB
/
PltAppOutput.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
// ---------------------------------------------------------------
// PltAppOutput.cpp
// ---------------------------------------------------------------
#include <AMReX_ParallelDescriptor.H>
#include <Xm/Xm.h>
#include <Xm/SelectioB.h>
#include <Xm/ToggleB.h>
#include <Xm/Text.h>
#include <PltApp.H>
#include <PltAppState.H>
#include <AMReX_DataServices.H>
#include <ProjectionPicture.H>
#include <Output.H>
#include <XYPlotWin.H>
using std::cout;
using std::cerr;
using std::endl;
using std::strcpy;
using namespace amrex;
// -------------------------------------------------------------------
void PltApp::DoOutput(Widget w, XtPointer data, XtPointer) {
amrex::ignore_unused(w);
int i;
static Widget wGetFileName;
XmString sMessage;
sMessage = XmStringCreateSimple(const_cast<char *>("Please enter a filename base:"));
i=0;
XtSetArg(args[i], XmNselectionLabelString, sMessage); ++i;
XtSetArg(args[i], XmNautoUnmanage, false); ++i;
XtSetArg(args[i], XmNkeyboardFocusPolicy, XmPOINTER); ++i;
wGetFileName = XmCreatePromptDialog(wAmrVisTopLevel, const_cast<char *>("Save as"), args, i);
XmStringFree(sMessage);
unsigned long which = (unsigned long) data;
switch(which) {
case 0:
AddStaticCallback(wGetFileName, XmNokCallback,&PltApp::DoCreatePSFile);
break;
case 1:
AddStaticCallback(wGetFileName, XmNokCallback,&PltApp::DoCreateRGBFile);
break;
case 2:
AddStaticCallback(wGetFileName, XmNokCallback,&PltApp::DoCreateFABFile);
break;
default:
cerr << "Error in PltApp::DoOutput: bad selection = " << data << endl;
return;
}
XtAddCallback(wGetFileName, XmNcancelCallback,
(XtCallbackProc)XtDestroyWidget, NULL);
XtSetSensitive(XmSelectionBoxGetChild(wGetFileName,
XmDIALOG_HELP_BUTTON), false);
char tempstr[Amrvis::BUFSIZE], tempfilename[Amrvis::BUFSIZE];
if(animating2d) {
strcpy(tempfilename, AVGlobals::StripSlashes(fileNames[currentFrame]).c_str());
} else {
strcpy(tempfilename, AVGlobals::StripSlashes(fileNames[0]).c_str());
}
sprintf(tempstr, "%s_%s", pltAppState->CurrentDerived().c_str(), tempfilename);
XmTextSetString(XmSelectionBoxGetChild(wGetFileName, XmDIALOG_TEXT), tempstr);
XtManageChild(wGetFileName);
XtPopup(XtParent(wGetFileName), XtGrabNone);
} // end DoOutput
// -------------------------------------------------------------------
void PltApp::DoCreatePSFile(Widget w, XtPointer, XtPointer call_data) {
XmSelectionBoxCallbackStruct *cbs = (XmSelectionBoxCallbackStruct *) call_data;
char psfilename[Amrvis::BUFSIZE];
char *fileNameBase;
int imageSizeX, imageSizeY;
XImage *printImage;
if(animating2d) {
ResetAnimation();
}
XmStringGetLtoR(cbs->value, XmSTRING_DEFAULT_CHARSET, &fileNameBase);
// write the Amrvis::ZPLANE picture
sprintf(psfilename, "%s_XY.ps", fileNameBase);
printImage = amrPicturePtrArray[Amrvis::ZPLANE]->GetPictureXImage();
imageSizeX = amrPicturePtrArray[Amrvis::ZPLANE]->ImageSizeH();
imageSizeY = amrPicturePtrArray[Amrvis::ZPLANE]->ImageSizeV();
WritePSFile(psfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
#ifdef AMREX_DEBUG
/*
{
int minDrawnLevel(pltAppState->MinDrawnLevel());
int maxDrawnLevel(pltAppState->MaxDrawnLevel());
const AmrData &amrData = dataServicesPtr[currentFrame]->AmrDataRef();
sprintf(psfilename, "%s_XY_new.ps", fileNameBase);
bool bDrawBoxesIntoImage(false);
printImage = amrPicturePtrArray[Amrvis::ZPLANE]->GetPictureXImage(bDrawBoxesIntoImage);
Vector< Vector<GridBoxes> > gridBoxes;
amrPicturePtrArray[Amrvis::ZPLANE]->GetGridBoxes(gridBoxes, minDrawnLevel, maxDrawnLevel);
WriteNewPSFile(psfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr,
amrData, minDrawnLevel, maxDrawnLevel, gridBoxes);
}
*/
#endif
#if (BL_SPACEDIM==3)
int minDrawnLevel(pltAppState->MinDrawnLevel());
int maxDrawnLevel(pltAppState->MaxDrawnLevel());
// write the Amrvis::YPLANE picture
sprintf(psfilename, "%s_XZ.ps", fileNameBase);
printImage = amrPicturePtrArray[Amrvis::YPLANE]->GetPictureXImage();
imageSizeX = amrPicturePtrArray[Amrvis::YPLANE]->ImageSizeH();
imageSizeY = amrPicturePtrArray[Amrvis::YPLANE]->ImageSizeV();
WritePSFile(psfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
// write the Amrvis::XPLANE picture
sprintf(psfilename, "%s_YZ.ps", fileNameBase);
printImage = amrPicturePtrArray[Amrvis::XPLANE]->GetPictureXImage();
imageSizeX = amrPicturePtrArray[Amrvis::XPLANE]->ImageSizeH();
imageSizeY = amrPicturePtrArray[Amrvis::XPLANE]->ImageSizeV();
WritePSFile(psfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
// write the iso picture
#ifdef BL_VOLUMERENDER
if( ! (XmToggleButtonGetState(wAutoDraw) || showing3dRender ) ) {
printImage = projPicturePtr->DrawBoxesIntoPixmap(minDrawnLevel, maxDrawnLevel);
} else {
printImage = projPicturePtr->GetPictureXImage();
}
#else
printImage = projPicturePtr->DrawBoxesIntoPixmap(minDrawnLevel, maxDrawnLevel);
#endif
sprintf(psfilename, "%s_XYZ.ps", fileNameBase);
imageSizeX = projPicturePtr->ImageSizeH();
imageSizeY = projPicturePtr->ImageSizeV();
WritePSFile(psfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
# endif
// write the palette
sprintf(psfilename, "%s_pal.ps", fileNameBase);
printImage = pltPaletteptr->GetPictureXImage();
imageSizeX = pltPaletteptr->PaletteWidth();
imageSizeY = pltPaletteptr->PaletteHeight();
const Vector<Real> &pValueList = pltPaletteptr->PaletteDataList();
string pNumFormat(pltPaletteptr->PaletteNumberFormat());
WritePSPaletteFile(psfilename, printImage, imageSizeX, imageSizeY,
pValueList, pNumFormat, *pltPaletteptr);
XtFree(fileNameBase);
XtDestroyWidget(w);
} // end DoCreatePSFile
// -------------------------------------------------------------------
void PltApp::DoCreateRGBFile(Widget w, XtPointer, XtPointer call_data) {
XmSelectionBoxCallbackStruct *cbs = (XmSelectionBoxCallbackStruct *) call_data;
char rgbfilename[Amrvis::BUFSIZE];
char *fileNameBase;
int imageSizeX, imageSizeY;
XImage *printImage;
if(animating2d) {
ResetAnimation();
}
XmStringGetLtoR(cbs->value, XmSTRING_DEFAULT_CHARSET, &fileNameBase);
// write the Amrvis::ZPLANE picture
char suffix[4];
if(AVGlobals::IsSGIrgbFile()) {
strcpy(suffix, "rgb");
} else {
strcpy(suffix, "ppm");
}
sprintf(rgbfilename, "%s_XY.%s", fileNameBase,suffix);
printImage = amrPicturePtrArray[Amrvis::ZPLANE]->GetPictureXImage();
imageSizeX = amrPicturePtrArray[Amrvis::ZPLANE]->ImageSizeH();
imageSizeY = amrPicturePtrArray[Amrvis::ZPLANE]->ImageSizeV();
if(AVGlobals::IsSGIrgbFile()) {
WriteRGBFile(rgbfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
} else {
WritePPMFile(rgbfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
}
#if (BL_SPACEDIM==3)
// write the Amrvis::YPLANE picture
sprintf(rgbfilename, "%s_XZ.%s", fileNameBase, suffix);
printImage = amrPicturePtrArray[Amrvis::YPLANE]->GetPictureXImage();
imageSizeX = amrPicturePtrArray[Amrvis::YPLANE]->ImageSizeH();
imageSizeY = amrPicturePtrArray[Amrvis::YPLANE]->ImageSizeV();
if(AVGlobals::IsSGIrgbFile()) {
WriteRGBFile(rgbfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
} else {
WritePPMFile(rgbfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
}
// write the Amrvis::XPLANE picture
sprintf(rgbfilename, "%s_YZ.%s", fileNameBase, suffix);
printImage = amrPicturePtrArray[Amrvis::XPLANE]->GetPictureXImage();
imageSizeX = amrPicturePtrArray[Amrvis::XPLANE]->ImageSizeH();
imageSizeY = amrPicturePtrArray[Amrvis::XPLANE]->ImageSizeV();
if(AVGlobals::IsSGIrgbFile()) {
WriteRGBFile(rgbfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
} else {
WritePPMFile(rgbfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
}
// write the iso picture
int minDrawnLevel(pltAppState->MinDrawnLevel());
int maxDrawnLevel(pltAppState->MaxDrawnLevel());
#ifdef BL_VOLUMERENDER
if( ! (XmToggleButtonGetState(wAutoDraw) || showing3dRender )) {
printImage = projPicturePtr->DrawBoxesIntoPixmap(minDrawnLevel, maxDrawnLevel);
} else {
printImage = projPicturePtr->GetPictureXImage();
}
#else
printImage = projPicturePtr->DrawBoxesIntoPixmap(minDrawnLevel, maxDrawnLevel);
#endif
sprintf(rgbfilename, "%s_XYZ.%s", fileNameBase, suffix);
imageSizeX = projPicturePtr->ImageSizeH();
imageSizeY = projPicturePtr->ImageSizeV();
if(AVGlobals::IsSGIrgbFile()) {
WriteRGBFile(rgbfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
} else {
WritePPMFile(rgbfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
}
# endif
// write the palette
sprintf(rgbfilename, "%s_pal.%s", fileNameBase, suffix);
printImage = pltPaletteptr->GetPictureXImage();
imageSizeX = pltPaletteptr->PaletteWidth();
imageSizeY = pltPaletteptr->PaletteHeight();
if(AVGlobals::IsSGIrgbFile()) {
WriteRGBFile(rgbfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
} else {
WritePPMFile(rgbfilename, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
}
XtFree(fileNameBase);
XtDestroyWidget(w);
} // end DoCreateRGBFile
// -------------------------------------------------------------------
void PltApp::DoCreateFABFile(Widget w, XtPointer, XtPointer call_data) {
XmSelectionBoxCallbackStruct *cbs = (XmSelectionBoxCallbackStruct *) call_data;
char fabfilename[Amrvis::BUFSIZE];
char *fileNameBase;
XmStringGetLtoR(cbs->value, XmSTRING_DEFAULT_CHARSET, &fileNameBase);
sprintf(fabfilename, "%s.fab", fileNameBase);
string fabFileName(fabfilename);
int maxDrawnLevel(pltAppState->MaxDrawnLevel());
string derivedQuantity(pltAppState->CurrentDerived());
Vector<Box> bx = amrPicturePtrArray[0]->GetSubDomain();
DataServices::Dispatch(DataServices::WriteFabOneVar,
dataServicesPtr[currentFrame],
(void *) &fabFileName,
(void *) &(bx[maxDrawnLevel]),
maxDrawnLevel,
(void *) &derivedQuantity);
XtFree(fileNameBase);
XtDestroyWidget(w);
} // end DoCreateFABFile
// -------------------------------------------------------------------
void PltApp::DoCreateAnimRGBFile() {
char outFileName[Amrvis::BUFSIZE];
int imageSizeX, imageSizeY;
XImage *printImage;
ResetAnimation();
char suffix[32];
if(AVGlobals::IsSGIrgbFile()) {
strcpy(suffix, "rgb");
} else {
strcpy(suffix, "ppm");
}
sprintf(outFileName, "%s_%s.F%05i.%s", pltAppState->CurrentDerived().c_str(),
AVGlobals::StripSlashes(fileNames[currentFrame]).c_str(),
currentFrame, suffix);
cout << "******* Creating file: " << outFileName << endl;
// write the picture
printImage = amrPicturePtrArray[Amrvis::ZPLANE]->GetPictureXImage();
imageSizeX = amrPicturePtrArray[Amrvis::ZPLANE]->ImageSizeH();
imageSizeY = amrPicturePtrArray[Amrvis::ZPLANE]->ImageSizeV();
if(AVGlobals::IsSGIrgbFile()) {
WriteRGBFile(outFileName, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
} else {
if(AVGlobals::IsAnnotated()) {
const AmrData &amrData = dataServicesPtr[currentFrame]->AmrDataRef();
Real time(amrData.Time());
WritePPMFileAnnotated(outFileName, printImage, imageSizeX, imageSizeY,
*pltPaletteptr, currentFrame, time, gaPtr,
AVGlobals::StripSlashes(fileNames[currentFrame]),
pltAppState->CurrentDerived());
} else {
WritePPMFile(outFileName, printImage, imageSizeX, imageSizeY, *pltPaletteptr);
}
}
#if (BL_SPACEDIM == 2)
for(int dim(0); dim < BL_SPACEDIM; ++dim) {
if(XYplotwin[dim]) {
if(dim == 0) {
strcpy(suffix, "X.dat");
} else {
strcpy(suffix, "Y.dat");
}
sprintf(outFileName, "%s_%s.%s", pltAppState->CurrentDerived().c_str(),
AVGlobals::StripSlashes(fileNames[currentFrame]).c_str(),
suffix);
cout << "******* Creating xyline file: " << outFileName << endl;
FILE *fs = fopen(outFileName, "w");
if(fs == NULL) {
cerr << "*** Error: could not open file: " << outFileName << endl;
} else {
XYplotwin[dim]->DoASCIIDump(fs, outFileName);
fclose(fs);
}
}
}
#endif
} // end DoCreateAnimRGBFile
// -------------------------------------------------------------------
// -------------------------------------------------------------------