Select Git revision
Callbacks.cpp
Forked from
gmsh / gmsh
Source project has a limited visibility.
-
Christophe Geuzaine authoredChristophe Geuzaine authored
PViewIO.cpp 7.46 KiB
// Gmsh - Copyright (C) 1997-2009 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>.
#include "GmshConfig.h"
#include "GmshMessage.h"
#include "PView.h"
#include "PViewDataList.h"
#include "PViewDataGModel.h"
#include "StringUtils.h"
bool PView::readPOS(std::string fileName, int fileIndex)
{
FILE *fp = fopen(fileName.c_str(), "rb");
if(!fp){
Msg::Error("Unable to open file '%s'", fileName.c_str());
return false;
}
char str[256] = "XXX";
double version;
int format, size, index = -1;
while(1) {
while(str[0] != '$'){
if(!fgets(str, sizeof(str), fp) || feof(fp))
break;
}
if(feof(fp))
break;
if(!strncmp(&str[1], "PostFormat", 10)) {
if(!fscanf(fp, "%lf %d %d\n", &version, &format, &size)){
Msg::Error("Read error");
return false;
}
if(version < 1.0) {
Msg::Error("Post-processing file too old (ver. %g < 1.0)", version);
return false;
}
if(size == sizeof(double))
Msg::Debug("Data is in double precision format (size==%d)", size);
else {
Msg::Error("Unknown data size (%d) in post-processing file", size);
return false;
}
}
else if(!strncmp(&str[1], "View", 4)){
index++;
if(fileIndex < 0 || fileIndex == index){
PViewDataList *d = new PViewDataList();
if(!d->readPOS(fp, version, format ? true : false)){
Msg::Error("Could not read data in list format");
delete d;
return false;
}
else{
d->setFileName(fileName);
d->setFileIndex(index);
new PView(d);
}
}
}