spirit-code / spirit

Atomistic Spin Simulation Framework
http://spirit-code.github.io
MIT License
116 stars 52 forks source link

Output fails if folder is not existent #34

Open GPMueller opened 7 years ago

GPMueller commented 7 years ago

Maybe this is not so doable currently.

The C++17 Filesystem TS might be a possibility...

GPMueller commented 7 years ago

Problematically, the code does not complain when a file cannot be written and just continues running. This is likely undesirable behaviour in most cases.

GPMueller commented 6 years ago

I think it is OK for the code to continue in case of an error, but maybe an input variable to set the level when the code should stop (i.e. warning, error or severe) would be a good idea?

Also, we could add an ifdef part which creates a folder using C++17, if available.

GPMueller commented 3 years ago

https://github.com/gulrak/filesystem could be used. It is absolutely sufficient for the use-cases of spirit and fortunately, it also works with emscripten 👍

If gulrak/filesystem should only be used when std::filesystem is not available, one can use the following code (though I would recommend against it because std::filesystem still requires some compiler flags depending on compiler versions, even in C++17 mode)

#if defined( __cplusplus ) && __cplusplus >= 201703L && defined( __has_include )
    #if __has_include( <filesystem>)
        #define GHC_USE_STD_FS
        #include <filesystem>
        namespace fs = std::filesystem;
    #endif
#endif
#ifndef GHC_USE_STD_FS
    #include <ghc/filesystem.hpp>
    namespace fs = ghc::filesystem;
#endif
GPMueller commented 3 years ago

https://github.com/gulrak/filesystem is already being used by the IMGUI on the feature-imgui branch. When the corresponding PR #583 is merged, it could be used by both ui-cpp and core (as is already done with fmt.

GPMueller commented 2 years ago

Improved file reading and writing with commits d1fe9f8909e5ec3169d0eed5a0fe06465b0d9848 and 18bf5d4cdd962389c110dd870ed0112a8b827b9b, respectively. There's now both a FilterFileHandle and OutFileHandle, for which it would make sense to use fs::exists, fs::is_directory/fs::is_regular_file, fs::create_directories.

One could even use fs::is_empty to detect when a file is being _over_written instead of just written. Note that fs::current_path gives the current working directory and that fs::weakly_canonical can be used for paths that might not exist (it resolves the absolute path as far as possible and keeps the non-existent parts as well).