Canoe
Comprehensive Atmosphere N' Ocean Engine
fits.cpp
Go to the documentation of this file.
1 
5 // C/C++
6 #include <iomanip>
7 #include <iostream>
8 #include <sstream>
9 #include <stdexcept>
10 #include <string>
11 
12 // athena
13 #include <athena/athena.hpp>
14 #include <athena/mesh/mesh.hpp>
15 #include <athena/outputs/user_outputs.hpp>
16 
17 // canoe
18 #include <impl.hpp>
19 
20 // inversion
21 #include <inversion/inversion.hpp>
22 
23 #ifdef FITSOUTPUT
24 extern "C" {
25 #include <fitsio.h>
26 }
27 
28 FITSOutput::FITSOutput(OutputParameters oparams) : OutputType(oparams) {}
29 
30 void FITSOutput::WriteOutputFile(Mesh *pm, ParameterInput *pin, bool flag) {
31  // TODO : saftgard for pfit == null
32  // create filename: "file_basename"+"."+"file_id"+"."+XXXXX+".fits",
33  // where XXXXX = 5-digit file_number
34  if (output_params.file_number > 0) {
35  std::string fname = "!"; // clobber
36  char number[6];
37  int err;
38  snprintf(number, sizeof(number), "%05d", output_params.file_number);
39 
40  fname.append(output_params.file_basename);
41  fname.append(".");
42  fname.append(output_params.file_id);
43  fname.append(".");
44  fname.append(number);
45  fname.append(".fits");
46 
47  for (int i = 0; i < pm->nblocal; ++i) {
48  MeshBlock *pmb = pm->my_blocks(i);
49  auto &pfit = pmb->pimpl->all_fits.back();
50  pfit->MakeMCMCOutputs(fname);
51  pfit->ResetChain();
52  }
53  }
54 
55  // increment counters
56  output_params.file_number++;
57  output_params.next_time += output_params.dt;
58  pin->SetInteger(output_params.block_name, "file_number",
59  output_params.file_number);
60  pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
61 }
62 
63 #endif // FITSOUTPUT