gmsh-TingyuanDoc
0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
|
Go to the documentation of this file.
6 #include "GmshConfig.h"
21 FILE *fp =
Fopen(fileName.c_str(),
"rb");
23 Msg::Error(
"Unable to open file '%s'", fileName.c_str());
27 char str[256] =
"XXX";
29 int format = -1, size = -1, index = -1;
32 while(str[0] !=
'$') {
33 if(!fgets(str,
sizeof(str), fp) || feof(fp))
break;
38 if(!strncmp(&str[1],
"PostFormat", 10)) {
39 if(!fscanf(fp,
"%lf %d %d\n", &version, &format, &size)) {
45 Msg::Error(
"Post-processing file too old (ver. %g < 1.0)", version);
49 if(size ==
sizeof(
double))
50 Msg::Debug(
"Data is in double precision format (size==%d)", size);
52 Msg::Error(
"Unknown data size (%d) in post-processing file", size);
57 else if(!strncmp(&str[1],
"View", 4)) {
59 if(fileIndex < 0 || fileIndex == index) {
61 if(!d->
readPOS(fp, version, format ?
true :
false)) {
62 Msg::Error(
"Could not read data in list format");
76 if(!fgets(str,
sizeof(str), fp) || feof(fp))
break;
77 }
while(str[0] !=
'$');
87 FILE *fp =
Fopen(fileName.c_str(),
"rb");
89 Msg::Error(
"Unable to open file '%s'", fileName.c_str());
95 Msg::Error(
"Model is empty: please load a mesh before loading the dataset");
100 char str[256] =
"XXX";
102 bool binary =
false,
swap =
false;
105 while(str[0] !=
'$') {
106 if(!fgets(str,
sizeof(str), fp) || feof(fp))
break;
111 if(!strncmp(&str[1],
"MeshFormat", 10)) {
113 if(!fgets(str,
sizeof(str), fp)) {
118 if(sscanf(str,
"%lf %d %d", &version, &format, &size) != 3) {
126 if(fread(&one,
sizeof(
int), 1, fp) != 1) {
132 Msg::Debug(
"Swapping bytes from binary file");
136 else if(!strncmp(&str[1],
"InterpolationScheme", 19)) {
138 if(!fgets(str,
sizeof(str), fp)) {
143 Msg::Debug(
"Reading interpolation scheme '%s'", name.c_str());
146 if(fscanf(fp,
"%d", &numTypes) != 1) {
150 for(
int i = 0; i < numTypes; i++) {
151 int type, numMatrices;
152 if(fscanf(fp,
"%d %d", &type, &numMatrices) != 2) {
156 for(
int j = 0; j < numMatrices; j++) {
158 if(fscanf(fp,
"%d %d", &m, &n) != 2) {
163 for(
int k = 0; k < m; k++) {
164 for(
int l = 0; l < n; l++) {
166 if(fscanf(fp,
"%lf", &d) != 1) {
177 else if(!strncmp(&str[1],
"NodeData", 8) ||
178 !strncmp(&str[1],
"ElementData", 11) ||
179 !strncmp(&str[1],
"ElementNodeData", 15)) {
181 if(fileIndex < 0 || fileIndex == index) {
183 if(!strncmp(&str[1],
"NodeData", 8))
185 else if(!strncmp(&str[1],
"ElementData", 11))
191 std::string viewName, interpolationScheme;
192 if(!fgets(str,
sizeof(str), fp)) {
196 if(sscanf(str,
"%d", &numTags) != 1) {
200 for(
int i = 0; i < numTags; i++) {
201 if(!fgets(str,
sizeof(str), fp)) {
212 if(!fgets(str,
sizeof(str), fp)) {
216 if(sscanf(str,
"%d", &numTags) != 1) {
220 for(
int i = 0; i < numTags; i++) {
221 if(!fgets(str,
sizeof(str), fp)) {
226 if(sscanf(str,
"%lf", &time) != 1) {
233 int timeStep = 0, numComp = 0, numEnt = 0, partition = 0;
234 long int blocksize = 0;
235 if(!fgets(str,
sizeof(str), fp)) {
239 if(sscanf(str,
"%d", &numTags) != 1) {
243 for(
int i = 0; i < numTags; i++) {
244 if(!fgets(str,
sizeof(str), fp)) {
249 if(sscanf(str,
"%d", &timeStep) != 1) {
255 if(sscanf(str,
"%d", &numComp) != 1) {
261 if(sscanf(str,
"%d", &numEnt) != 1) {
267 if(sscanf(str,
"%d", &partition) != 1) {
273 if(sscanf(str,
"%ld", &blocksize) != 1) {
279 if(partitionToRead == -1 || partitionToRead == partition) {
288 bool create = d ? false :
true;
290 if(!d->
readMSH(viewName, fileName, fileIndex, fp, binary,
swap,
291 timeStep, time, partition, numComp, numEnt,
292 interpolationScheme)) {
293 Msg::Error(
"Could not read data in msh file");
302 if(create)
new PView(d);
306 else if(blocksize > 0 && partitionToRead != partition) {
310 fseek(fp, blocksize, SEEK_CUR);
316 if(!fgets(str,
sizeof(str), fp) || feof(fp))
break;
317 }
while(str[0] !=
'$');
324 #if defined(HAVE_MED)
326 extern std::vector<std::string> medGetFieldNames(
const std::string &fileName);
330 std::vector<std::string> fieldNames = medGetFieldNames(fileName);
332 for(std::size_t index = 0; index < fieldNames.size(); index++) {
333 if(fileIndex < 0 || (
int)index == fileIndex) {
339 bool create = d ? false :
true;
341 if(!d->
readMED(fileName, index)) {
342 Msg::Error(
"Could not read data in MED file");
347 if(create)
new PView(d);
359 Msg::Error(
"Gmsh must be compiled with MED support to read '%s'",
373 d->
readPCH(fileName, fileIndex);
378 bool PView::write(
const std::string &fileName,
int format,
bool append)
384 case 0: ret =
_data->
writePOS(fileName,
false,
false, append);
break;
385 case 1: ret =
_data->
writePOS(fileName,
true,
false, append);
break;
386 case 2: ret =
_data->
writePOS(fileName,
false,
true, append);
break;
398 case 7: ret =
writeX3D(fileName);
break;
404 else if(ext ==
".stl")
406 else if(ext ==
".msh")
413 else if(ext ==
".med")
415 else if(ext ==
".x3d")
427 if(ret)
Msg::StatusBar(
true,
"Done writing '%s'", fileName.c_str());
434 bool isBinary,
int adaptLev,
double adaptErr,
int npart,
439 adaptLev, adaptErr, npart, isBinary);
virtual bool writeSTL(const std::string &fileName)
std::vector< std::string > SplitFileName(const std::string &fileName)
void set(int r, int c, scalar v)
virtual bool writeTXT(const std::string &fileName)
static PView * getViewByName(const std::string &name, int timeStep=-1, int partition=-1, const std::string &fileName="")
bool readPCH(const std::string &fileName, int fileIndex)
static void Info(const char *fmt,...)
static void Debug(const char *fmt,...)
static void Error(const char *fmt,...)
static void StatusBar(bool log, const char *fmt,...)
static bool readPOS(const std::string &fileName, int fileIndex=-1)
virtual bool writePOS(const std::string &fileName, bool binary=false, bool parsed=true, bool append=false)
virtual bool writeMED(const std::string &fileName)
virtual void setFileName(const std::string &val)
FILE * Fopen(const char *f, const char *mode)
bool readPOS(FILE *fp, double version, bool binary)
void swap(double &a, double &b)
virtual void sendToServer(const std::string &name)
PViewData * getData(bool useAdaptiveIfAvailable=false)
static void addMatrixToInterpolationScheme(const std::string &name, int type, fullMatrix< double > &mat)
static bool writeX3D(const std::string &fileName)
virtual bool writeMSH(const std::string &fileName, double version=2.2, bool binary=false, bool saveMesh=true, bool multipleView=false, int partitionNum=-1, bool saveInterpolationMatrices=true, bool forceNodeData=false, bool forceElementData=false)
int saveInterpolationMatrices
virtual void setName(const std::string &val)
std::string ExtractDoubleQuotedString(const char *str, int len)
static void removeInterpolationScheme(const std::string &name)
void sendToServer(const std::string &name)
bool write(const std::string &fileName, int format, bool append=false)
static bool readMED(const std::string &fileName, int fileIndex=-1)
bool readMED(const std::string &fileName, int fileIndex)
static bool readMSH(const std::string &fileName, int fileIndex=-1, int partitionToRead=-1)
static bool readPCH(const std::string &fileName, int fileIndex=-1)
virtual void setFileIndex(int val)
void saveAdaptedViewForVTK(const std::string &guifileName, int useDefaultName, int step, int level, double tol, int npart, bool isBinary)
bool writeAdapt(const std::string &fileName, int useDefaultName, bool isBinary, int adaptLev, double adaptErr, int npart, bool append=false)
static GModel * current(int index=-1)
bool readMSH(const std::string &viewName, const std::string &fileName, int fileIndex, FILE *fp, bool binary, bool swap, int step, double time, int partition, int numComp, int numNodes, const std::string &interpolationScheme)