ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ERF_ReadCustomBinaryIC.H File Reference
#include "ERF_DataStruct.H"
Include dependency graph for ERF_ReadCustomBinaryIC.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ReadCustomBinaryIC (const std::string filename, amrex::Vector< amrex::Real > &xvec_h, amrex::Vector< amrex::Real > &yvec_h, amrex::Vector< amrex::Real > &zvec_h, amrex::Vector< amrex::Real > &rho_h, amrex::Vector< amrex::Real > &uvel_h, amrex::Vector< amrex::Real > &vvel_h, amrex::Vector< amrex::Real > &wvel_h, amrex::Vector< amrex::Real > &theta_h, amrex::Vector< amrex::Real > &qv_h, amrex::Vector< amrex::Real > &qc_h, amrex::Vector< amrex::Real > &qr_h)
 

Function Documentation

◆ ReadCustomBinaryIC()

void ReadCustomBinaryIC ( const std::string  filename,
amrex::Vector< amrex::Real > &  xvec_h,
amrex::Vector< amrex::Real > &  yvec_h,
amrex::Vector< amrex::Real > &  zvec_h,
amrex::Vector< amrex::Real > &  rho_h,
amrex::Vector< amrex::Real > &  uvel_h,
amrex::Vector< amrex::Real > &  vvel_h,
amrex::Vector< amrex::Real > &  wvel_h,
amrex::Vector< amrex::Real > &  theta_h,
amrex::Vector< amrex::Real > &  qv_h,
amrex::Vector< amrex::Real > &  qc_h,
amrex::Vector< amrex::Real > &  qr_h 
)
inline
24 {
25  int nx, ny, nz, ndata;
26  float value;
27 
28  // Open the binary file in input mode
29  std::ifstream infile(filename, std::ios::binary);
30  if (!infile) {
31  std::cerr << "Error: Could not open file " << filename << std::endl;
32  }
33 
34  // Read the four integers
35  infile.read(reinterpret_cast<char*>(&nx), sizeof(int));
36  infile.read(reinterpret_cast<char*>(&ny), sizeof(int));
37  infile.read(reinterpret_cast<char*>(&nz), sizeof(int));
38  infile.read(reinterpret_cast<char*>(&ndata), sizeof(int));
39 
40  for(int i=0; i<nx; i++) {
41  infile.read(reinterpret_cast<char*>(&value), sizeof(float));
42  xvec_h.emplace_back(value);
43  }
44 
45  for(int j=0; j<ny; j++) {
46  infile.read(reinterpret_cast<char*>(&value), sizeof(float));
47  yvec_h.emplace_back(value);
48  }
49 
50  for(int k=0; k<nz; k++) {
51  infile.read(reinterpret_cast<char*>(&value), sizeof(float));
52  zvec_h.emplace_back(value);
53  }
54 
55  amrex::Vector<amrex::Real>* data_h = nullptr; // Declare pointer outside the loop
56 
57  // Read the file
58  for(int idx=0; idx<ndata; idx++){
59  if(idx == 0){
60  data_h = &rho_h;
61  } else if (idx==1) {
62  data_h = &uvel_h;
63  } else if (idx==2) {
64  data_h = &vvel_h;
65  } else if (idx==3) {
66  data_h = &wvel_h;
67  } else if(idx==4) {
68  data_h = &theta_h;
69  } else if(idx==5) {
70  data_h = &qv_h;
71  } else if(idx==6) {
72  data_h = &qc_h;
73  } else if(idx==7) {
74  data_h = &qr_h;
75  }
76  for(int k=0; k<nz; k++) {
77  for(int j=0; j<ny; j++) {
78  for(int i=0; i<nx; i++) {
79  infile.read(reinterpret_cast<char*>(&value), sizeof(float));
80  data_h->emplace_back(value);
81  }
82  }
83  }
84  }
85  infile.close();
86 }

Referenced by ERF::init_coarse_weather_data().

Here is the caller graph for this function: