Modernise the terrafit file handling code.
This commit is contained in:
parent
71306b371f
commit
afe4be595f
1 changed files with 17 additions and 31 deletions
|
@ -54,6 +54,8 @@
|
||||||
#include <Prep/Terra/Mask.h>
|
#include <Prep/Terra/Mask.h>
|
||||||
|
|
||||||
using std::istream;
|
using std::istream;
|
||||||
|
using simgear::Dir;
|
||||||
|
using simgear::PathList;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Benchmark: Processing 800 individual buckets:
|
* Benchmark: Processing 800 individual buckets:
|
||||||
|
@ -143,37 +145,20 @@ bool endswith(const std::string& s1, const std::string& suffix) {
|
||||||
return s1.compare(s1len-sufflen,sufflen,suffix)==0;
|
return s1.compare(s1len-sufflen,sufflen,suffix)==0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fit_file(const std::string& path) {
|
void fit_file(const SGPath& path) {
|
||||||
|
|
||||||
SG_LOG(SG_GENERAL, SG_INFO,"Working on file '" << path << "'");
|
SG_LOG(SG_GENERAL, SG_INFO,"Working on file '" << path << "'");
|
||||||
|
|
||||||
std::string infile,outfile;
|
SGPath outPath(path.dir());
|
||||||
if (endswith(path,".arr.gz")) {
|
outPath.append(path.file_base() + ".fit.gz");
|
||||||
infile=path.substr(0,path.size()-7);
|
|
||||||
} else if (endswith(path,".arr")) {
|
|
||||||
infile=path.substr(0,path.size()-4);
|
|
||||||
} else {
|
|
||||||
/* actually should not happen */
|
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "unknown input file extension = " << path);
|
|
||||||
throw sg_exception("unknown input file extension!");
|
|
||||||
}
|
|
||||||
|
|
||||||
outfile=infile+".fit.gz";
|
if (outPath.exists() && (path.modTime() < outPath.modTime())) {
|
||||||
|
SG_LOG(SG_GENERAL, SG_INFO ,"Skipping " << outPath << ", source " << path << " is older");
|
||||||
struct stat statbuf;
|
|
||||||
if (stat(path.c_str(),&statbuf)!=0) {
|
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT ,"ERROR: Unable to stat '" << path << "':" << strerror(errno));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
time_t src_mtime=statbuf.st_mtime;
|
|
||||||
|
|
||||||
if (stat(outfile.c_str(),&statbuf)==0 && statbuf.st_mtime>src_mtime) {
|
|
||||||
SG_LOG(SG_GENERAL, SG_INFO ,"Skipping " << outfile << ", source " << path << " is older");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SGBucket bucket(0,0); // dummy bucket
|
SGBucket bucket(0,0); // dummy bucket
|
||||||
TGArray inarray(infile);
|
TGArray inarray(path.dir() + "/" + path.file_base());
|
||||||
inarray.parse(bucket);
|
inarray.parse(bucket);
|
||||||
inarray.close();
|
inarray.close();
|
||||||
|
|
||||||
|
@ -186,8 +171,8 @@ void fit_file(const std::string& path) {
|
||||||
greedy_insertion(mesh);
|
greedy_insertion(mesh);
|
||||||
|
|
||||||
gzFile fp;
|
gzFile fp;
|
||||||
if ( (fp = gzopen( outfile.c_str(), "wb9" )) == NULL ) {
|
if ( (fp = gzopen( outPath.c_str(), "wb9" )) == NULL ) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: opening " << outfile << " for writing!");
|
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: opening " << outPath << " for writing!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,6 +196,7 @@ void fit_file(const std::string& path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void walk_path(const SGPath& path) {
|
void walk_path(const SGPath& path) {
|
||||||
|
|
||||||
if (!path.exists()) {
|
if (!path.exists()) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT ,"ERROR: Unable to stat '" << path.str() << "':" << strerror(errno));
|
SG_LOG(SG_GENERAL, SG_ALERT ,"ERROR: Unable to stat '" << path.str() << "':" << strerror(errno));
|
||||||
return;
|
return;
|
||||||
|
@ -219,9 +205,9 @@ void walk_path(const SGPath& path) {
|
||||||
if ((path.lower_extension() == "arr") || (path.complete_lower_extension() == "arr.gz")) {
|
if ((path.lower_extension() == "arr") || (path.complete_lower_extension() == "arr.gz")) {
|
||||||
fit_file(path.str());
|
fit_file(path.str());
|
||||||
} else if (path.isDir()) {
|
} else if (path.isDir()) {
|
||||||
simgear::Dir d(path);
|
Dir d(path);
|
||||||
simgear::PathList subdirs = d.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT);
|
int flags = Dir::TYPE_DIR | Dir::TYPE_FILE | Dir::NO_DOT_OR_DOTDOT;
|
||||||
BOOST_FOREACH(const SGPath& p, subdirs) {
|
BOOST_FOREACH(const SGPath& p, d.children(flags)) {
|
||||||
walk_path(p);
|
walk_path(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue