Write options to file
| 712 | |
| 713 | /// Write options to file |
| 714 | void OptionsNetCDF::write(const Options& options, const std::string& time_dim) { |
| 715 | Timer timer("io"); |
| 716 | |
| 717 | // Check the file mode to use |
| 718 | auto ncmode = NcFile::replace; |
| 719 | if (file_mode == FileMode::append) { |
| 720 | // NetCDF doesn't have a "read-write, create if exists" mode, so |
| 721 | // we need to check ourselves if the file already exists; if it |
| 722 | // doesn't, tell NetCDF to create it |
| 723 | std::ifstream file(filename); |
| 724 | ncmode = file.good() ? NcFile::FileMode::write : NcFile::FileMode::newFile; |
| 725 | } |
| 726 | |
| 727 | if (not data_file) { |
| 728 | data_file = std::make_unique<netCDF::NcFile>(filename, ncmode); |
| 729 | } |
| 730 | |
| 731 | if (data_file->isNull()) { |
| 732 | throw BoutException("Could not open NetCDF file '{:s}' for writing", filename); |
| 733 | } |
| 734 | |
| 735 | writeGroup(options, *data_file, time_dim); |
| 736 | |
| 737 | data_file->sync(); |
| 738 | } |
| 739 | |
| 740 | } // namespace bout |
| 741 |
nothing calls this directly
no test coverage detected