libode
Easy to compile, fast ODE integrators as C++ classes
Loading...
Searching...
No Matches
ode_io.cc
Go to the documentation of this file.
1
2
3#include "ode_io.h"
4
5namespace ode {
6
7void ode_check_write (const char *fn) {
8
9 //try to open the file
10 FILE *ofile = fopen(fn, "wb");
11 //raise an error if needed
12 if (ofile == NULL) ode_print_exit("cannot open file, ensure the requisite directories exist (like the output directory)");
13 //close
14 fclose(ofile);
15}
16
17void ode_print_exit (const char *msg) {
18
19 //print the given message
20 printf("\nODE FAILURE: %s\n\n", msg);
21 //cancel the program
22 exit(EXIT_FAILURE);
23}
24
25std::string ode_int_to_string (long i) {
26
27 // https://www.geeksforgeeks.org/converting-string-to-number-and-vice-versa-in-c/
28 std::ostringstream str;
29 str << i;
30 std::string out = str.str();
31 return(out);
32}
33
34} // namespace ode
void ode_check_write(const char *fn)
check if a file can be written (opened in write mode)
Definition ode_io.cc:7
void ode_print_exit(const char *msg)
print a message and exit with failure
Definition ode_io.cc:17
std::string ode_int_to_string(long i)
converts an integer into a string
Definition ode_io.cc:25