00001
00002
00003
00004
00005
00006 #ifndef AMROC_F77_FILEINPUT_H
00007 #define AMROC_F77_FILEINPUT_H
00008
00016 #include "FileInput.h"
00017 #include "F77Interfaces/F77FileOutput.h"
00018
00019 template <class VectorType, int dim>
00020 class F77InBase {
00021 typedef typename VectorType::InternalDataType DataType;
00022 typedef GridFunction<VectorType,dim> vec_grid_fct_type;
00023 typedef GridFunction<DataType,dim> grid_fct_type;
00024 typedef generic_fortran_func generic_func_type;
00025 public:
00026 typedef void (*in_1_func_type) ( FI(1,DataType), FI(1,VectorType), BI, const INTEGER& meqn,
00027 const INTEGER& cnt, const DOUBLE& t );
00028 typedef void (*in_2_func_type) ( FI(2,DataType), FI(2,VectorType), BI, const INTEGER& meqn,
00029 const INTEGER& cnt, const DOUBLE& t );
00030 typedef void (*in_3_func_type) ( FI(3,DataType), FI(3,VectorType), BI, const INTEGER& meqn,
00031 const INTEGER& cnt, const DOUBLE& t );
00032
00033 F77InBase(generic_func_type in) : f_in(in), _Equations(VectorType::Length()) {}
00034
00035 virtual ~F77InBase() {}
00036
00037 virtual void Transform(grid_fct_type& work, vec_grid_fct_type& u, const int Time, const int& Level,
00038 const int cnt, const double& t) {
00039 if (!f_in) return;
00040 forall(u,Time,Level,c)
00041 BBox bb = u.interiorbbox(Time,Level,c);
00042 if (dim == 1)
00043 ((in_1_func_type) f_in)(FA(1,work(Time,Level,c)),FA(1,u(Time,Level,c)),
00044 BOUNDING_BOX(bb),_Equations,cnt,t);
00045 else if (dim == 2)
00046 ((in_2_func_type) f_in)(FA(2,work(Time,Level,c)),FA(2,u(Time,Level,c)),
00047 BOUNDING_BOX(bb),_Equations,cnt,t);
00048 else if (dim == 3)
00049 ((in_3_func_type) f_in)(FA(3,work(Time,Level,c)),FA(3,u(Time,Level,c)),
00050 BOUNDING_BOX(bb),_Equations,cnt,t);
00051 end_forall
00052 }
00053
00054 inline void SetInFunc(generic_func_type in) { f_in = in; }
00055 generic_func_type GetInFunc() const { return f_in; }
00056
00057 protected:
00058 generic_func_type f_in;
00059 int _Equations;
00060 };
00061
00062
00074 template <class VectorType, int dim>
00075 class F77FileInput : public F77OutBase<VectorType,dim>, public F77InBase<VectorType,dim>,
00076 public FileInput<VectorType,dim> {
00077 typedef typename VectorType::InternalDataType DataType;
00078 typedef FileInput<VectorType,dim> base;
00079 typedef F77OutBase<VectorType,dim> out_base;
00080 typedef F77InBase<VectorType,dim> in_base;
00081 public:
00082 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00083 typedef typename base::grid_fct_type grid_fct_type;
00084 typedef typename base::grid_data_type grid_data_type;
00085 typedef typename out_base::generic_func_type generic_func_type;
00086
00087 F77FileInput(generic_func_type in) :
00088 out_base(0), in_base(in), base() {}
00089
00090 F77FileInput(generic_func_type out, generic_func_type in) :
00091 out_base(out), in_base(in), base() {}
00092
00093 virtual ~F77FileInput() {}
00094
00095 virtual void ReadIn(vec_grid_fct_type& u, grid_fct_type& IOfunc) {
00096 if (!out_base::f_out && !in_base::f_in) return;
00097 for (int cnt=1; cnt<=base::Ncnt(); cnt++) {
00098 if (base::CompName[cnt-1].c_str()[0] == '-')
00099 continue;
00100 int lev;
00101 double t;
00102 if (GetOutFunc())
00103 for (lev=0; lev<=FineLevel(base::GH()); lev++) {
00104 int Time = CurrentTime(base::GH(),lev);
00105 t = GetPhysicalTime(u,Time,lev);
00106 ((out_base*) this)->Transform(u,IOfunc,Time,lev,cnt,t);
00107 }
00108 ReadIn(IOfunc,base::CompName[cnt-1].c_str());
00109 if (GetInFunc())
00110 for (lev=0; lev<=FineLevel(base::GH()); lev++) {
00111 int Time = CurrentTime(base::GH(),lev);
00112 t = GetPhysicalTime(u,Time,lev);
00113 ((in_base*) this)->Transform(IOfunc,u,Time,lev,cnt,t);
00114 }
00115 #ifndef DAGH_NO_MPI
00116 MPI_Barrier(comm_service::comm());
00117 #endif
00118 }
00119 }
00120
00121 virtual void ReadIn(grid_fct_type& IOfunc, const char* name)
00122 { base::ReadIn(IOfunc,name); }
00123
00124 virtual void ReadIn(grid_fct_type& IOfunc, const char* name,
00125 const int& Time, const int& Level)
00126 { base::ReadIn(IOfunc,name,Time,Level); }
00127
00128 virtual void ReadIn(grid_data_type& IOdata, const char* name,
00129 const int& Time, const int& Level) {
00130 base::ReadIn(IOdata,name,Time,Level);
00131 }
00132
00133 inline void SetInFunc(generic_func_type in) { in_base::SetInFunc(in); }
00134 generic_func_type GetInFunc() const { return in_base::GetInFunc(); }
00135 inline void SetOutFunc(generic_func_type out) { out_base::SetOutFunc(out); }
00136 generic_func_type GetOutFunc() const { return out_base::GetOutFunc(); }
00137 };
00138
00139 #endif