#include <perms.h>
int _imp_mainep(int _imp_argc, char **_imp_argv) {
  void Emas3(_imp_string * Comms, _imp_string * Parms, int *Flag);
  void Emas3itos(int *K, _imp_string *S);
  void Volumes(double Ti, double A, double T, double Theta, double Dthetatd, double *Va, double *Vd, double *Dvadt,
               double *Dvddt);
  void Define(int *Chan, _imp_string *Text);
  double Sattemp(double S, double P);
  double Latheat(double S, double T);
  double Htcond(int I, double Th, double T, double L, double D, double Nf, double Hf);
  void Readline(_imp_string * Text);
  void Emas3prompt(_imp_string * Text);
  double Dens[21 /*0:20*/][21 /*0:20*/];
  _imp_string File;
  _imp_string No;
  int I;
  int J;
  int Flag;
  int K;
  double R;
  double Va;
  double Vb;
  double Vc;
  double Vd;
  double Dvadt;
  double Dvddt;
  double Pa;
  double Pb;
  double Pc;
  double Pd;
  double Twb;
  double Twc;
  double Tsatb;
  double Hco;
  double Latb;
  double Mb;
  double Mass;
  double Dth;
  double Th;
  double Avep;
  double Power;
  double Vmin;
  double Vmax;
  double Ratio;
  double Ideal;
  double Still;
  double Cons[8 /*1:8*/];
  double Y[15 /*1:15*/];
  Cons[1] = 0.5;
  Cons[2] = 8;
  Cons[5] = 5000;
  File = _imp_str_literal("t#out");
  Define(5, _imp_str_literal("emct12:general.densities"));
  Define(2, _imp_str_literal("emct12:mk3.result"));
  Define(3, File);
  Define(60, _imp_str_literal("prod"));
  Selectinput(5);
  for (I = 0; I <= 17; I++)
    for (J = 0; J <= 8; J++) Read(Dens[J][I]);
  Vmin = 0;
  Vmax = 0;
  R = 461.889;
  Flag = 0;
  Volumes(0, Cons[1], Cons[2], 0, 0, Still, Still, Dvadt, Dvddt);
  Selectoutput(3);
  Selectinput(2);
  Closestream;
  Avep = 0;
  Mass = 0;
  for (I = 1; I <= 6000; I++) {
    for (J = 1; J <= 15; J++) {
      Read(Y[J]);
      if (Y[J] == 101010.10) {
        Flag = 1;
        break;
      }
    }
    if (Flag == 1) break;
    Volumes(Y[1], Cons[1], Cons[2], 0, 0, Ideal, Vd, Dvadt, Dvddt);
    Volumes(Y[1], Cons[1], Cons[2], Y[2], Y[3], Va, Vd, Dvadt, Dvddt);
    Th = Cons[1] * Sin(2 * Pi * Y[1] / Cons[2]);
    Dth = (Cons[1] * 2 * Pi / Cons[2]) * Cos(2 * Pi * Y[1] / Cons[2]);
    Vb = 45;
    Vc = 45;
    Pa = Y[8] * R * (Y[4] + 273) / Va;
    Pa = Pa / 1 @5;
    Pb = Y[9] * R * (Y[5] + 273) / Vb;
    Pb = Pb / 1 @5;
    Pc = Y[10] * R * (Y[6] + 273) / Vc;
    Pc = Pc / 1 @5;
    Pd = Y[11] * R * (Y[7] + 273) / Vd;
    Pd = Pd / 1 @5;
    Vmax += (Ideal - Still) * 2;
    Vmin += (Va - Still) * 2;
    Ratio = Sqrt(Vmin / Vmax);
    Twb = Y[12] - 0.25 * (Y[12] - Y[13]);
    Twc = Y[13] + 0.25 * (Y[12] - Y[13]);
    Hco = Htcond(1, Y[5], Twb, 3, 2.5, 0, 0) / 1000;
    Tsatb = Sattemp(0, Pb);
    Latb = Latheat(0, Tsatb);
    Mb = Hco * Cons[5] * (Y[5] - Twb) / Latb;
    Power = -(Pa - Pd) * Dvadt * 100;
    Avep += Power;
    Mass += Mb;
    Print(Y[1], 2, 2);
    Print(Pa, 3, 3);
    Print(Pb, 3, 3);
    Print(Pc, 3, 3);
    Print(Pa - Pd, 3, 3);
    Print(Va, 3, 3);
    Newline();
  }
  Mass = Mass / I;
  Avep = Avep / I;
  Selectinput(0);
  Selectoutput(0);
  Closestream;
  Closestream;
  Selectoutput(60);
  Printstring(_imp_str_literal("The average mass flowrate of condensate is "));
  Print(Mass, 2, 2);
  Printstring(_imp_str_literal(" kg/s."));
  Newline();
  Printstring(_imp_str_literal("Mean Power input ="));
  Print(Avep, 3, 3);
  Printstring(_imp_str_literal("kW"));
  Newline();
  Printstring(_imp_str_literal("Mean SEC ="));
  Print(Avep / Mass, 3, 3);
  Printstring(_imp_str_literal("kJ/kg"));
  Newline();
  Printstring(_imp_str_literal("Ratio of swept volume to ideal volume = "));
  Print(Ratio, 3, 3);
  Selectoutput(0);
  Closestream;
  exit(0);
  return (1);
}
