Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
readreg.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 Reads a proprietary .reg input file, a simple ASCII format,
55 and passes it to a blockConsumer. Returns an
56 error string on errors; returns NULL on sucess.
57 
58 Orion Sky Lawlor, olawlor@acm.org, 4/29/2002
59 */
60 #include <stdio.h>
61 #include "gridutil.h"
62 
63 const char *read_reg(const char *regFile,blockConsumer &dest)
64 {
65  //Open the input file
66  FILE *in=fopen(regFile,"r");
67  if (in==NULL) return "Couldn't open input .reg file";
68 
69  //Read the block size
70  int dimArr[3];
72  for (int axis=0;axis<3;axis++)
73  {
74  double m;
75  if (1!=fscanf(in,"%d",&dimArr[axis]))
76  return "Couldn't read block dimension";
77  if (1!=fscanf(in,"%lf",&m)) return "Couldn't read block min";
78  min[axis]=m;
79  if (1!=fscanf(in,"%lf",&m)) return "Couldn't read block max";
80  max[axis]=m;
81  }
82  fclose(in);
83 
84  //Allocate return grid
85  blockDim dim(dimArr[0],dimArr[1],dimArr[2]);
86  vector3d *locs=dest.allocateBlock(dim);
87 
88  //Fill in the grid
89  blockLoc i;
90  blockSpan s(blockLoc(0,0,0),dim);
91  BLOCKSPAN_FOR(i,s) {
92  vector3d v;
93  for (int axis=0;axis<3;axis++) {
94  double scl=i[axis]/(float)(dim[axis]-1);
95  v[axis]=min[axis]+scl*(max[axis]-min[axis]);
96  }
97  locs[dim[i]]=v;
98  }
99 
100  dest.consume(dim,locs);
101  dest.freeBlock(locs);
102 
103  return NULL; //Everything worked
104 }
105 
double s
Definition: blastest.C:80
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
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
const char * read_reg(const char *regFile, blockConsumer &dest)
Definition: readreg.cpp:63
virtual vector3d * allocateBlock(blockDim &dim)
Definition: read.cpp:146
#define BLOCKSPAN_FOR(i, span)
Definition: gridutil.h:230
virtual void freeBlock(vector3d *blk)
Definition: read.cpp:150
blockLoc i
Definition: read.cpp:79
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
virtual const char * consume(const blockDim &dim, vector3d *locs)=0
std::FILE * fopen(const char *const path, const char *const mode)
Open a file, and check for possible errors.
Definition: CImg.h:5494