double VCS_SPECIES_THERMO::GStar_R_calc(size_t kglob, double TKelvin,
                                        double pres)
{
    double fe = G0_R_calc(kglob, TKelvin);
    double T = TKelvin;
    if (UseCanteraCalls) {
        if (m_VCS_UnitsFormat != VCS_UNITS_MKS) {
            throw CanteraError("VCS_SPECIES_THERMO::GStar_R_calc",
                               "Possible inconsistency");
        }
        size_t kspec = IndexSpeciesPhase;
        OwningPhase->setState_TP(TKelvin, pres);
        fe = OwningPhase->GStar_calc_one(kspec);
        double R = vcsUtil_gasConstant(m_VCS_UnitsFormat);
        fe /= R;
    } else {
        double pref = SS0_Pref;
        switch (SSStar_Model) {
        case VCS_SSSTAR_CONSTANT:
            break;
        case VCS_SSSTAR_IDEAL_GAS:
            fe += T * log(pres/ pref);
            break;
        default:
            throw CanteraError("VCS_SPECIES_THERMO::GStar_R_calc",
                               "unknown SSStar model");
        }
    }
    return fe;
}
/**************************************************************************
 *
 * GStar_R_calc();
 *
 *  This function calculates the standard state Gibbs free energy
 *  for species, kspec, at the solution temperature TKelvin and
 *  solution pressure, Pres.
 *  
 *
 *  Input
 *   kglob = species global index.
 *   TKelvin = Temperature in Kelvin
 *   pres = pressure is given in units specified by if__ variable.
 *
 *
 * Output
 *    return value = standard state free energy in units of Kelvin.
 */
double VCS_SPECIES_THERMO::GStar_R_calc(size_t kglob, double TKelvin,
					double pres)
{
  char yo[] = "VCS_SPECIES_THERMO::GStar_R_calc ";
  double fe, T;
  fe = G0_R_calc(kglob, TKelvin);
  T = TKelvin;
  if (UseCanteraCalls) {
    AssertThrowVCS(m_VCS_UnitsFormat == VCS_UNITS_MKS, "Possible inconsistency");
    size_t kspec = IndexSpeciesPhase;
    OwningPhase->setState_TP(TKelvin, pres);
    fe = OwningPhase->GStar_calc_one(kspec);
    double R = vcsUtil_gasConstant(m_VCS_UnitsFormat);
    fe /= R;
  } else {
    double pref = SS0_Pref;
    switch(SSStar_Model) {
    case VCS_SSSTAR_CONSTANT:
      break;
    case VCS_SSSTAR_IDEAL_GAS:
      fe += T * log( pres/ pref );	 
      break;
    default:
      plogf("%sERROR: unknown SSStar model\n", yo);
      exit(EXIT_FAILURE);
    }
  }
  return fe;
}
/**************************************************************************
 *
 * G0_R_calc:
 *
 *  This function calculates the naught state Gibbs free energy
 *  for species, kspec, at the temperature TKelvin
 *
 *  Input
 *   kglob = species global index.
 *   TKelvin = Temperature in Kelvin
 *
 * Output
 *    return value = naught state free energy in Kelvin.
 */
double VCS_SPECIES_THERMO::G0_R_calc(size_t kglob, double TKelvin)
{
#ifdef DEBUG_MODE
  char yo[] = "VS_SPECIES_THERMO::G0_R_calc ";
#endif
  double fe, H, S;
  if (SS0_Model == VCS_SS0_CONSTANT) {
    fe = SS0_feSave;  
    return fe;
  }
  if (TKelvin == SS0_TSave) {
    fe = SS0_feSave;
    return fe;
  }
  if (UseCanteraCalls) {
    AssertThrowVCS(m_VCS_UnitsFormat == VCS_UNITS_MKS, "Possible inconsistency");
    size_t kspec = IndexSpeciesPhase;
    OwningPhase->setState_T(TKelvin);
    fe = OwningPhase->G0_calc_one(kspec);
    double R = vcsUtil_gasConstant(m_VCS_UnitsFormat);
    fe /= R;
  } else {
    switch (SS0_Model) {
    case VCS_SS0_CONSTANT:
      fe = SS0_feSave;
      break;
    case VCS_SS0_CONSTANT_CP:
      H  = SS0_H0 + (TKelvin - SS0_T0) * SS0_Cp0;
      S  = SS0_Cp0 + SS0_Cp0 * log((TKelvin / SS0_T0));
      fe = H - TKelvin * S;
      break;
    default:
#ifdef DEBUG_MODE
      plogf("%sERROR: unknown model\n", yo);
#endif
      exit(EXIT_FAILURE);
    }
  }
  SS0_feSave = fe;
  SS0_TSave = TKelvin;
  return fe;
} 
double VCS_SPECIES_THERMO::G0_R_calc(size_t kglob, double TKelvin)
{
    double fe, H, S;
    if (SS0_Model == VCS_SS0_CONSTANT) {
        return SS0_feSave;
    }
    if (TKelvin == SS0_TSave) {
        return SS0_feSave;
    }
    if (UseCanteraCalls) {
        if (m_VCS_UnitsFormat != VCS_UNITS_MKS) {
            throw CanteraError("VCS_SPECIES_THERMO::G0_R_calc",
                               "Possible inconsistency");
        }
        size_t kspec = IndexSpeciesPhase;
        OwningPhase->setState_T(TKelvin);
        fe = OwningPhase->G0_calc_one(kspec);
        double R = vcsUtil_gasConstant(m_VCS_UnitsFormat);
        fe /= R;
    } else {
        switch (SS0_Model) {
        case VCS_SS0_CONSTANT:
            fe = SS0_feSave;
            break;
        case VCS_SS0_CONSTANT_CP:
            H  = SS0_H0 + (TKelvin - SS0_T0) * SS0_Cp0;
            S  = SS0_Cp0 + SS0_Cp0 * log((TKelvin / SS0_T0));
            fe = H - TKelvin * S;
            break;
        default:
            throw CanteraError("VCS_SPECIES_THERMO::G0_R_calc",
                               "unknown model");
        }
    }
    SS0_feSave = fe;
    SS0_TSave = TKelvin;
    return fe;
}