Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
write.cpp File Reference
#include <stdio.h>
#include <strings.h>
#include "adj.h"
#include "util.h"
#include "FC.h"
Include dependency graph for write.cpp:

Go to the source code of this file.

Typedefs

typedef double REAL
 
typedef void(* fn_fortran_write )(int *block, int *ni, int *nj, int *nk, REAL *x, REAL *y, REAL *z, const char *fName)
 

Functions

void FC_GLOBAL (write_msh, WRITE_MSH)(int *block
 
void FC_GLOBAL (write_grda, WRITE_GRDA)(int *block
 
void FC_GLOBAL (write_grdb, WRITE_GRDB)(int *block
 
static void write_fortran (int block, blockDim dim, const vector3d *locs, const char *fName, fn_fortran_write writeFn)
 
void vecMax (const vector3d &a, vector3d &dest)
 
void vecMin (const vector3d &a, vector3d &dest)
 
void write_bounds (const blockDim &dim, const vector3d *locs, const char *filename_base)
 
const char * write_hdf (const blockDim &dim, const vector3d *locs, const char *filename)
 
const char * writeBlocks (vector< block * > &blocks, const char *outMesh)
 

Variables

void int * ni
 
void int int * nj
 
void int int int * nk
 
void int int int REALx
 
void int int int REAL REALy
 
void int int int REAL REAL REALz
 
void int int int REAL REAL
REAL const char * 
fName
 

Typedef Documentation

typedef void(* fn_fortran_write)(int *block, int *ni, int *nj, int *nk, REAL *x, REAL *y, REAL *z, const char *fName)

Definition at line 70 of file write.cpp.

typedef double REAL

Definition at line 67 of file write.cpp.

Function Documentation

void FC_GLOBAL ( write_msh  ,
WRITE_MSH   
)
void FC_GLOBAL ( write_grda  ,
WRITE_GRDA   
)
void FC_GLOBAL ( write_grdb  ,
WRITE_GRDB   
)
void vecMax ( const vector3d a,
vector3d dest 
)

Definition at line 109 of file write.cpp.

References vector3d::x, vector3d::y, and vector3d::z.

Referenced by write_bounds().

110 {
111  if (a.x>dest.x) dest.x=a.x;
112  if (a.y>dest.y) dest.y=a.y;
113  if (a.z>dest.z) dest.z=a.z;
114 }
real x
Definition: vector3d.h:88
real y
Definition: vector3d.h:88
real z
Definition: vector3d.h:88

Here is the caller graph for this function:

void vecMin ( const vector3d a,
vector3d dest 
)

Definition at line 115 of file write.cpp.

References vector3d::x, vector3d::y, and vector3d::z.

Referenced by write_bounds().

116 {
117  if (a.x<dest.x) dest.x=a.x;
118  if (a.y<dest.y) dest.y=a.y;
119  if (a.z<dest.z) dest.z=a.z;
120 }
real x
Definition: vector3d.h:88
real y
Definition: vector3d.h:88
real z
Definition: vector3d.h:88

Here is the caller graph for this function:

void write_bounds ( const blockDim dim,
const vector3d locs,
const char *  filename_base 
)

Definition at line 122 of file write.cpp.

References cimg_library::cimg::fclose(), cimg_library::cimg::fopen(), i, max(), min(), vecMax(), vecMin(), vector3d::x, vector3d::y, and vector3d::z.

124 {
125  char filename[1024];
126  sprintf(filename,"%s.bounds",filename_base);
127  FILE *f=fopen(filename,"w");
128  if (f==NULL) return;
129  //Find the bounds of all locations
130  double big=1.0e25;
131  vector3d max(-big,-big,-big),min(big,big,big);
132  blockLoc i;
133  for (i[2]=0; i[2]<dim[2]; i[2]++)
134  for (i[1]=0; i[1]<dim[1]; i[1]++)
135  for (i[0]=0; i[0]<dim[0]; i[0]++) {
136  vecMax(locs[dim[i]],max);
137  vecMin(locs[dim[i]],min);
138  }
139  fprintf(f,"%f %f %f %f %f %f\n",min.x,max.x,min.y,max.y,min.z,max.z);
140  fclose(f);
141 }
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
int fclose(std::FILE *file)
Close a file, and check for possible errors.
Definition: CImg.h:5507
void vecMin(const vector3d &a, vector3d &dest)
Definition: write.cpp:115
void vecMax(const vector3d &a, vector3d &dest)
Definition: write.cpp:109
blockLoc i
Definition: read.cpp:79
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
std::FILE * fopen(const char *const path, const char *const mode)
Open a file, and check for possible errors.
Definition: CImg.h:5494

Here is the call graph for this function:

static void write_fortran ( int  block,
blockDim  dim,
const vector3d locs,
const char *  fName,
fn_fortran_write  writeFn 
)
static

Definition at line 85 of file write.cpp.

References fortranifyString(), blockDim::getSize(), i, x, vector3d::x, y, vector3d::y, z, and vector3d::z.

Referenced by writeBlocks().

87 {
88  //Copy the data from C array to fortran arrays
89  int len=dim.getSize();
90  REAL *x=new REAL[len];
91  REAL *y=new REAL[len];
92  REAL *z=new REAL[len];
93  blockLoc i;
94  for (i[2]=0; i[2]<dim[2]; i[2]++)
95  for (i[1]=0; i[1]<dim[1]; i[1]++)
96  for (i[0]=0; i[0]<dim[0]; i[0]++)
97  { //Copy data into fortran array
98  int c_i=dim[i], f_i=dim[i];
99  x[f_i]=locs[c_i].x;
100  y[f_i]=locs[c_i].y;
101  z[f_i]=locs[c_i].z;
102  }
103 
104  //Send the data off to fortran (JB: added block)
105  (writeFn)(&block,&dim[0],&dim[1],&dim[2],x,y,z,fortranifyString(fName));
106  delete[] x; delete[] y; delete[] z;
107 }
void int int REAL REAL * y
Definition: read.cpp:74
double REAL
Definition: read.cpp:70
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
Definition: adj.h:203
void int int int REAL REAL REAL * z
Definition: write.cpp:76
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
int getSize(void) const
Definition: gridutil.h:126
const char * fortranifyString(const char *src)
real z
Definition: vector3d.h:88

Here is the call graph for this function:

Here is the caller graph for this function:

const char* write_hdf ( const blockDim dim,
const vector3d locs,
const char *  filename 
)

Definition at line 77 of file writehdf.cpp.

References chk, blockDim::getSize(), i, cimg_library::cimg::time(), x, vector3d::x, y, vector3d::y, z, and vector3d::z.

Referenced by writeBlocks().

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 }
void int int REAL REAL * y
Definition: read.cpp:74
double REAL
Definition: read.cpp:70
real x
Definition: vector3d.h:88
real y
Definition: vector3d.h:88
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

Here is the call graph for this function:

Here is the caller graph for this function:

const char* writeBlocks ( vector< block * > &  blocks,
const char *  outMesh 
)

Definition at line 147 of file write.cpp.

References endsWith(), FC_GLOBAL, i, incrementAscii(), write_fortran(), write_grda(), write_grdb(), write_hdf(), and write_msh().

Referenced by main().

149 {
150  char oName[1024];
151  bool isFortran=false, isHDF=false;
152  bool incrementFilenames=true;
153  fn_fortran_write writeFn=NULL;
154  strcpy(oName,outMesh);
155  if (endsWith(outMesh,".msh"))
156  { //Write .msh files:
157  isFortran=true;
158  writeFn=FC_GLOBAL(write_msh,WRITE_MSH);
159  }
160  else if (endsWith(outMesh,"1")||
161  endsWith(outMesh,".grda")||
162  endsWith(outMesh,".grdb"))
163  { //Probably a grda or grdb file:
164  isFortran=true;
165  incrementFilenames=false; //Same filename every time
166  char tmp[1024];
167  strcpy(tmp,outMesh);
168  //Clip off any trailing numbers:
169  int endIdx=strlen(tmp)-1;
170  while (endIdx>0&&(isdigit(tmp[endIdx])||(tmp[endIdx]=='_')))
171  tmp[endIdx--]=0;
172  if (endsWith(tmp,".grda"))
173  writeFn=FC_GLOBAL(write_grda,WRITE_GRDA);
174  else if (endsWith(tmp,".grdb"))
175  writeFn=FC_GLOBAL(write_grdb,WRITE_GRDB);
176  else return "Unrecognized output mesh extension! (2)";
177  }
178 #ifdef USE_HDF
179  else if (endsWith(outMesh,".hdf"))
180  {
181  isHDF=true;
182  }
183 #endif
184  else if (endsWith(outMesh,".null"))
185  {/*Just skip output*/}
186  else
187  return "Unrecognized output mesh file extension! (1)";
188 
189 
190  for (unsigned int i=0;i<blocks.size();i++) {
191  const blockDim &dim=blocks[i]->getDim();
192  const vector3d *locs=&blocks[i]->getLoc(blockLoc(0,0,0));
193 
194  if (isFortran)
195  if (i+1==blocks.size())
196  { /* Last time around, pass a negative block number
197  so fortran code can close its file. */
198  write_fortran(-(i+1),dim,locs,oName,writeFn);
199  } else {
200  write_fortran( i+1 ,dim,locs,oName,writeFn);
201  }
202 
203 #ifdef USE_HDF
204  else if (isHDF)
205  write_hdf(dim,locs,oName);
206 #endif
207 
208  printf("."); fflush(stdout);
209  if (incrementFilenames) {
210  if (!incrementAscii(oName))
211  return "Cannot increment output filename! Use something like 'foo_0001.msh'\n";
212  }
213  }
214  printf("\n");
215 
216  return NULL;
217 }
bool incrementAscii(char *cur)
subroutine write_grda(iblock, ni, nj, nk, x, y, z, F_name)
Definition: writegrda.f90:64
subroutine write_grdb(iblock, ni, nj, nk, x, y, z, F_name)
Definition: writegrdb.f90:64
void(* fn_fortran_write)(int *block, int *ni, int *nj, int *nk, REAL *x, REAL *y, REAL *z, const char *fName)
Definition: write.cpp:70
bool endsWith(const char *a, const char *suffix)
subroutine write_msh(iblock, ni, nj, nk, x, y, z, F_name)
Definition: writemsh.f90:58
blockLoc i
Definition: read.cpp:79
#define FC_GLOBAL(name, NAME)
Definition: FC.h:5
const char * write_hdf(const blockDim &dim, const vector3d *locs, const char *filename)
Definition: writehdf.cpp:77
static void write_fortran(int block, blockDim dim, const vector3d *locs, const char *fName, fn_fortran_write writeFn)
Definition: write.cpp:85

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

void int int int REAL REAL REAL const char * fName

Definition at line 76 of file write.cpp.

Referenced by writeMblock().

void int* ni

Definition at line 76 of file write.cpp.

void int int* nj

Definition at line 76 of file write.cpp.

void int int int* nk

Definition at line 76 of file write.cpp.

void int int int REAL* x

Definition at line 76 of file write.cpp.

void int int int REAL REAL* y

Definition at line 76 of file write.cpp.

void int int int REAL REAL REAL * z

Definition at line 76 of file write.cpp.

Referenced by __scalegrd.f90__(), CImgList< uintT >::_atN(), CImgList< uintT >::_atNX(), CImgList< uintT >::_atNXY(), CImg< uintT >::_atX(), CImg< uintT >::_atXY(), CImg< uintT >::_atXYZ(), CImg< uintT >::_atXYZV(), CImg< uintT >::_autocrop(), CImg< uintT >::_cubic_atX(), CImg< uintT >::_cubic_atXY(), CImg< uintT >::_display_object3d(), CImg< uintT >::_draw_line(), CImg< uintT >::_draw_object3d(), CImg< uintT >::_draw_point(), CImg< uintT >::_draw_polygon(), CImg< uintT >::_draw_spline(), CImg< uintT >::_get_permute_axes(), CImg< uintT >::_linear_atX(), CImg< uintT >::_linear_atXY(), CImg< uintT >::_linear_atXYZ(), CImg< uintT >::_linear_atXYZV(), CImg< uintT >::_load_raw(), CImg< uintT >::_save_ascii(), CImg< uintT >::_save_dlm(), CImg< uintT >::_save_inr(), CImg< uintT >::_save_raw(), Rocblas::acos(), Rocblas::add_scalar(), CImgList< uintT >::atN(), CImgList< uintT >::atNX(), CImgList< uintT >::atNXY(), CImg< uintT >::atX(), CImg< uintT >::atXY(), CImg< uintT >::atXYZ(), CImg< uintT >::atXYZV(), Rocblas::axpy(), Rocblas::axpy_scalar(), PointS3< FT >::bbox(), CImg< uintT >::blur_anisotropic(), CImg< uintT >::blur_bilateral(), GeoPrim::C3Centroid(), C3Plane::C3Plane(), Rocblas::calcChoose(), VectorS3< FT >::cartesian(), PointS3< FT >::cartesian(), GeoPrim::Centroid(), circumcenter(), CImgList< uintT >::contains(), CImgList< uintT >::containsNXYZV(), Rocblas::copy(), Rocblas::copy_helper(), Rocblas::copy_scalar(), CPlane::CPlane(), CImg< uintT >::cross(), CImg< uintT >::cubic_atX(), CImg< uintT >::cubic_atXY(), CImg< uintT >::deriche(), CImg< uintT >::distance_hamilton(), Rocblas::div_scalar(), Rocblas::dot_MPI(), Rocblas::dot_scalar_MPI(), CImg< uintT >::draw_fill(), CImg< uintT >::draw_gaussian(), CImg< uintT >::draw_image(), CImg< uintT >::draw_line(), CImg< uintT >::draw_rectangle(), CImg< uintT >::edge_tensors(), entropy_corr1(), entropy_corr2(), CImg< T >::_cimg_math_parser::eval(), CImg< uintT >::eval(), CImg< uintT >::FFT(), CImg< uintT >::fill(), for(), Rocblas::gen2arg(), CImg< uintT >::get_BayertoRGB(), CImg< uintT >::get_blur_median(), CImg< uintT >::get_blur_patch(), CImg< uintT >::get_correlate(), CImg< uintT >::get_crop(), CImg< uintT >::get_dilate(), CImg< uintT >::get_displacement_field(), CImg< uintT >::get_distance(), CImg< uintT >::get_erode(), CImg< uintT >::get_gradient(), CImg< uintT >::get_haar(), CImg< uintT >::get_hessian(), CImg< uintT >::get_index(), CImg< uintT >::get_matrix_at(), CImg< uintT >::get_norm(), CImg< uintT >::get_projections2d(), CImg< uintT >::get_resize(), CImg< uintT >::get_resize_doubleXY(), CImg< uintT >::get_resize_halfXY(), CImg< uintT >::get_resize_tripleXY(), CImg< uintT >::get_RGBtoBayer(), CImg< uintT >::get_rotate(), CImg< uintT >::get_structure_tensor(), CImg< uintT >::get_tensor_at(), CImg< uintT >::get_vector_at(), CImg< uintT >::get_warp(), setup_py::grid(), SerialProgram::HigherOrderTets(), init_crds1_tet_unstr_2(), Mesh::NodalCoordinates::init_node(), KNN_Grid< Tri >::k_nearest(), CImg< uintT >::linear_atX(), CImg< uintT >::linear_atXY(), CImg< uintT >::linear_atXYZ(), CImg< uintT >::linear_atXYZV(), main(), CImg< uintT >::max(), Rocblas::max_MPI(), Rocblas::maxof_scalar(), midpoint(), CImg< uintT >::min(), Rocblas::min_MPI(), CImg< uintT >::mirror(), Rocblas::mul_scalar(), Rocblas::neg(), CImg< uintT >::normalize(), CImg< uintT >::offset(), CImg< uintT >::operator%=(), CImg< uintT >::operator&=(), CImg< uintT >::operator()(), CImgList< uintT >::operator()(), VectorS3< FT >::operator*(), CImg< uintT >::operator*=(), VectorS3< FT >::operator+(), CImg< uintT >::operator+=(), VectorS3< FT >::operator-(), CImg< uintT >::operator-=(), VectorS3< FT >::operator/(), CImg< uintT >::operator/=(), VectorS3< FT >::operator==(), PointS3< FT >::operator==(), operator>>(), CImg< uintT >::operator^=(), CImg< uintT >::operator|=(), tpz_ordered::parse_data(), plag_writetecplotascii(), PointS3< FT >::PointS3(), CImg< uintT >::pow(), principal_stress(), projection(), CImg< uintT >::ptr(), Rocblas::rand(), Rocblas::rand_scalar(), read_msh(), rescale_object(), rflu_modbilinearpatch::rflu_blin_findclosestpoint(), rflu_modexactflow::rflu_computeexactflowculick(), rflu_computeexactflowerror(), rflu_modexactflow::rflu_computeexactflowpacoust(), rflu_computeexactflowprobeerror(), rflu_modplottingvars::rflu_computeplottingvarsgraderr(), rflu_modweights::rflu_computewtsx2c_1d(), rflu_modoles::rflu_definecorrelation221(), rflu_modoles::rflu_definecorrelation32(), rflu_modoles::rflu_definecorrelation431(), rflu_modoles::rflu_definecorrelation432(), rflu_modoles::rflu_definecorrelation541(), rflu_modoles::rflu_definecorrelation542(), rflu_modrocstartools::rflu_genx_constraindisp(), rflu_modrocstartools::rflu_genx_initbflag(), rflu_modincelltest::rflu_ict_testfacequadbilinear(), rflu_initflowhardcode(), rflu_modexactflow::rflu_setexactflowlinear(), rflu_modexactflow::rflu_setexactflowtrig(), rflu_settransportvars(), rflu_modtimezoom::rflu_timezoomcomputebulkvars(), rflu_modtimezoom::rflu_timezoomsumaddsource(), rflu_modtimezoom::rflu_timezoomsumresiduals(), rflu_user_getdeformation(), rs(), CImg< uintT >::save_tiff(), scalerotatevector(), CImg< uintT >::set_linear_atXY(), CImg< uintT >::set_linear_atXYZ(), CImg< uintT >::set_matrix_at(), CImg< uintT >::set_tensor_at(), CImg< uintT >::set_vector_at(), BoundingBox::setCoordinates(), CImg< uintT >::sharpen(), smallestelement(), CImg< uintT >::sphere3d(), Rocblas::sqrt(), Rocblas::sub_scalar(), Rocblas::sum_MPI(), CImg< uintT >::SVD(), CImg< uintT >::torus3d(), tql2(), Transfer_base::transfer_2n(), CImg< uintT >::translate(), GeoPrim::Transpose(), CImg< uintT >::transpose(), tred2(), VectorS3< FT >::VectorS3(), vol_elem_mat_ortho(), MeshImpl::vtk_create_structured_elems(), MeshImpl::write_exodus(), write_fortran(), write_grda(), write_grdb(), write_hdf(), write_msh(), TecplotOrderedWriter::writePoints(), writetecplotbinary(), Vector_3< Real >::z(), Point_3< Real >::z(), and zn_gen_grid().