Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
writehdf.cpp
Go to the documentation of this file.
1 /* *******************************************************************
2  * Illinois Open Source License *
3  * *
4  * University of Illinois/NCSA *
5  * Open Source License *
6  * *
7  * Copyright@2008, University of Illinois. All rights reserved. *
8  * *
9  * Developed by: *
10  * *
11  * Center for Simulation of Advanced Rockets *
12  * *
13  * University of Illinois *
14  * *
15  * www.csar.uiuc.edu *
16  * *
17  * Permission is hereby granted, free of charge, to any person *
18  * obtaining a copy of this software and associated documentation *
19  * files (the "Software"), to deal with the Software without *
20  * restriction, including without limitation the rights to use, *
21  * copy, modify, merge, publish, distribute, sublicense, and/or *
22  * sell copies of the Software, and to permit persons to whom the *
23  * Software is furnished to do so, subject to the following *
24  * conditions: *
25  * *
26  * *
27  * @ Redistributions of source code must retain the above copyright *
28  * notice, this list of conditions and the following disclaimers. *
29  * *
30  * @ Redistributions in binary form must reproduce the above *
31  * copyright notice, this list of conditions and the following *
32  * disclaimers in the documentation and/or other materials *
33  * provided with the distribution. *
34  * *
35  * @ Neither the names of the Center for Simulation of Advanced *
36  * Rockets, the University of Illinois, nor the names of its *
37  * contributors may be used to endorse or promote products derived *
38  * from this Software without specific prior written permission. *
39  * *
40  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
41  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
42  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
43  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
44  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
45  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
46  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
47  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
48  *********************************************************************
49  * Please acknowledge The University of Illinois Center for *
50  * Simulation of Advanced Rockets in works and publications *
51  * resulting from this software or its derivatives. *
52  *********************************************************************/
53 /*
54 Writes out a CSAR rocket .hdf output file, an HDF4 format.
55 
56 Orion Sky Lawlor, olawlor@acm.org, 6/8/2001
57 */
58 #include <stdio.h>
59 #include "gridutil.h"
60 
61 /*HDF4 include file*/
62 #include "mfhdf.h"
63 
64 //HDF data type
65 typedef double REAL;
66 
67 #define chk(x) checkHDFerr(x,__FILE__,__LINE__)
68 static int checkHDFerr(int errCode,const char *fName,int lineNo) {
69  if (errCode==-1) {
70  fprintf(stderr,"HDF I/O Error in (%s:%d)\n",
71  fName,lineNo);
72  exit(23);
73  }
74  return errCode;
75 }
76 
77 const char *write_hdf(const blockDim &dim,const vector3d *locs,
78  const char *filename)
79 {
80  const int dataType=6;//double precision float
81  REAL time=0.0;
82  int32 timeLen=1;
83  chk(DFSDsetdims(1,&timeLen));
84  chk(DFSDsetNT(dataType));
85  chk(DFSDputdata(filename, 1, &timeLen, &time));
86 
87  //Copy the data from C++ array to C arrays
88  int len=dim.getSize();
89  REAL *x=new REAL[len];
90  REAL *y=new REAL[len];
91  REAL *z=new REAL[len];
92  blockLoc i;
93  for (i[2]=0; i[2]<dim[2]; i[2]++)
94  for (i[1]=0; i[1]<dim[1]; i[1]++)
95  for (i[0]=0; i[0]<dim[0]; i[0]++)
96  { //Copy data into separate, coordinate-wise arrays
97  int c_i=dim[i], f_i=dim[i];
98  x[f_i]=locs[c_i].x;
99  y[f_i]=locs[c_i].y;
100  z[f_i]=locs[c_i].z;
101  }
102 
103  //Send the data off to HDF
104  int32 dSize[3]; //Swap dimensions
105  dSize[0]=dim[2]; dSize[1]=dim[1]; dSize[2]=dim[0];
106  chk(DFSDsetdims(3,dSize));
107  chk(DFSDsetNT(dataType));
108  chk(DFSDadddata(filename, 3, dSize, x));
109  chk(DFSDadddata(filename, 3, dSize, y));
110  chk(DFSDadddata(filename, 3, dSize, z));
111 
112  //Clean up output arrays
113  delete[] x; delete[] y; delete[] z;
114 
115  return NULL;
116 }
117 
118 
void int int REAL REAL * y
Definition: read.cpp:74
double REAL
Definition: read.cpp:70
static int checkHDFerr(int errCode, const char *fName, int lineNo)
Definition: writehdf.cpp:68
real x
Definition: vector3d.h:88
real y
Definition: vector3d.h:88
void int int int REAL REAL REAL const char * fName
Definition: write.cpp:76
void int int int REAL REAL REAL * z
Definition: write.cpp:76
#define chk(x)
Definition: writehdf.cpp:67
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
unsigned long time()
Get the value of a system timer with a millisecond precision.
Definition: CImg.h:4605
int getSize(void) const
Definition: gridutil.h:126
real z
Definition: vector3d.h:88
const char * write_hdf(const blockDim &dim, const vector3d *locs, const char *filename)
Definition: writehdf.cpp:77