spectrum: Keep results file open and do not append to previous content

This commit is contained in:
Eduardo Almeida
2024-06-20 18:32:01 +01:00
parent 7c4b0dac96
commit 709c9b767f

View File

@@ -58,7 +58,8 @@ using namespace ns3;
static Ptr<ThreeGppPropagationLossModel>
m_propagationLossModel; //!< the PropagationLossModel object
static Ptr<ThreeGppSpectrumPropagationLossModel>
m_spectrumLossModel; //!< the SpectrumPropagationLossModel object
m_spectrumLossModel; //!< the SpectrumPropagationLossModel object
static std::ofstream resultsFile; //!< The results file
/**
* @brief Create the PSD for the TX
@@ -298,12 +299,10 @@ ComputeSnr(ComputeSnrParams& params)
// compute the SNR
NS_LOG_DEBUG("Average SNR " << 10 * log10(Sum(*rxSsp->psd) / Sum(*noisePsd)) << " dB");
// print the SNR and pathloss values in the ntn-snr-trace.txt file
std::ofstream f;
f.open("ntn-snr-trace.txt", std::ios::out | std::ios::app);
f << Simulator::Now().GetSeconds() << " " << 10 * log10(Sum(*rxSsp->psd) / Sum(*noisePsd))
<< " " << propagationGainDb << std::endl;
f.close();
// print the SNR and pathloss values in the output file
resultsFile << Simulator::Now().GetSeconds() << " "
<< 10 * log10(Sum(*rxSsp->psd) / Sum(*noisePsd)) << " " << propagationGainDb
<< std::endl;
}
int
@@ -482,6 +481,10 @@ main(int argc, char* argv[])
DoBeamforming(rxDev, rxAntenna, txDev);
DoBeamforming(txDev, txAntenna, rxDev);
// Open the output results file
resultsFile.open("ntn-snr-trace.txt", std::ios::out);
NS_ASSERT_MSG(resultsFile.is_open(), "Results file could not be created");
for (int i = 0; i < floor(simTimeMs / timeResMs); i++)
{
Simulator::Schedule(MilliSeconds(timeResMs * i),
@@ -499,5 +502,8 @@ main(int argc, char* argv[])
Simulator::Run();
Simulator::Destroy();
resultsFile.close();
return 0;
}