ReFRACtor
hdf_file_generating.cc
Go to the documentation of this file.
1 #include "hdf_file_generating.h"
2 
3 using namespace FullPhysics;
4 
5 //-----------------------------------------------------------------------
9 //-----------------------------------------------------------------------
10 
12 {
13  if(hdf_file_) {
14  hdf_file_->close();
15  hdf_file_.reset();
16  int status = rename((fname + ".generating").c_str(), fname.c_str());
17  if(status != 0)
18  throw Exception("Trouble renaming the file " + fname +
19  ".generating to " + fname);
20  }
21 }
22 
24 {
25  if(!hdf_file_) {
26  // Ok if this fails, we just want to remove any file that might be
27  // in the way
28  remove(fname.c_str());
29  // Create with ".generating", which we remove when done creating file.
30  hdf_file_.reset(new HdfFile(fname + ".generating", HdfFile::CREATE));
31  }
32  return *hdf_file_;
33 }
34 
35 //-----------------------------------------------------------------------
38 //-----------------------------------------------------------------------
39 
41 {
42  if(hdf_file_) {
43  // Try to close first, but don't fail if closing fails.
44  try {
45  hdf_file_->close();
46  } catch(...) {
47  }
48  hdf_file_.reset();
49  // Don't bother checking return code, if removing fails we don't
50  // have anything else to try.
51  remove((fname + ".generating").c_str());
52  }
53 }
54 
55 void HdfFileGenerating::print(std::ostream& Os) const
56 {
57  Os << "HdfFileGenerating: \n"
58  << " File name: " << fname << "\n";
59 }
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
void abandon()
Abandon a file and clean it up.
void close()
Close a file, changing the name to the final name.
This class reads and writes a HDF5 file.
Definition: hdf_file.h:39
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
void print(std::ostream &Os) const

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11