Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions src/c_plot_card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,37 @@ c_plot_card::c_plot_card()
p2 = 0;
p3 = 0;
p4 = 0;

plot_fp = NULL;
}

c_plot_card::c_plot_card(const c_plot_card& p)
{
p1 = p.p1;
p2 = p.p2;
p3 = p.p3;
p4 = p.p4;

plot_fp = p.plot_fp;
}

c_plot_card::c_plot_card(int itmp1, int itmp2, int itmp3, int itmp4, string& filename)
{
p1 = itmp1;
p2 = itmp2;
p3 = itmp3;
p4 = itmp4;

plot_fp = NULL;


/* Open plot file */
if ( (plot_fp = fopen(filename.c_str(), "w")) == NULL )
FILE* file = fopen(filename.c_str(), "w");
if (file == NULL)
{
throw 100;
}
plot_fp = std::shared_ptr<FILE>(file, fclose);
}

c_plot_card::~c_plot_card()
{
if ( plot_fp != NULL )
fclose( plot_fp );
}
c_plot_card::~c_plot_card() = default;

bool c_plot_card::is_valid() const { return (NULL != plot_fp); }
bool c_plot_card::is_valid() const { return (nullptr != plot_fp); }

bool c_plot_card::storing() const { return (p1 != 0); }
bool c_plot_card::currents() const { return (p1 == 1); }
Expand All @@ -85,23 +79,23 @@ void c_plot_card::set_plot_real_imag_currents()

void c_plot_card::plot_endl() const
{
if (NULL == plot_fp)
if (nullptr == plot_fp)
throw 100;

fprintf( plot_fp, "\n");
fprintf( plot_fp.get(), "\n");
}

void c_plot_card::plot_double(nec_float x) const
{
if (NULL == plot_fp)
if (nullptr == plot_fp)
throw 100;

fprintf( plot_fp, "%12.4E ", x );
fprintf( plot_fp.get(), "%12.4E ", x );
}

void c_plot_card::plot_complex(nec_complex x) const
{
if (NULL == plot_fp)
if (nullptr == plot_fp)
throw 100;

switch( p2 )
Expand Down Expand Up @@ -156,7 +150,7 @@ void c_plot_card::plot_segments(int i,
if (false == near_field())
return;

fprintf( plot_fp, "%12.4E %12.4E %12.4E "
fprintf( plot_fp.get(), "%12.4E %12.4E %12.4E "
"%12.4E %12.4E %12.4E %12.4E %5d %5d %5d\n",
x[i],y[i],z[i],si[i],xw2,yw2,bi[i],icon1[i],i+1,icon2[i] );
}
Expand Down
3 changes: 2 additions & 1 deletion src/c_plot_card.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


#include "math_util.h"
#include <memory>
#include <string>
#include <stdio.h>

Expand Down Expand Up @@ -87,5 +88,5 @@ class c_plot_card
nec_float g_vert, nec_float g_horiz, nec_float g_tot);
private:
int p1, p2, p3, p4;
FILE* plot_fp;
std::shared_ptr<FILE> plot_fp;
};
8 changes: 6 additions & 2 deletions src/nec_radiation_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "c_geometry.h"
#include "nec_exception.h"

namespace {
constexpr int RP_POWER_AVERAGE_ONLY = 2;
}

int nec_radiation_pattern::get_index(int theta_index, int phi_index) const {
if (theta_index >= n_theta)
throw nec_exception("nec_radiation_pattern: Theta index too large");
Expand Down Expand Up @@ -131,7 +135,7 @@ void nec_radiation_pattern::write_to_file_aux(ostream& os)

nec_float phi = m_phi_start- delta_phi;

for (int kph = 0; kph < n_phi; kph++ ) {
for (int kph = 0; (kph < n_phi) && (m_rp_power_average != RP_POWER_AVERAGE_ONLY); kph++ ) {
phi += delta_phi;
nec_float thet= m_theta_start- delta_theta;

Expand Down Expand Up @@ -383,7 +387,7 @@ void nec_radiation_pattern::analyze(nec_context* m_context)
da *=.5;
pint += tstor1 * da;

if ( m_rp_power_average == 2) // do not print the power gain values (just compute the average)
if ( m_rp_power_average == RP_POWER_AVERAGE_ONLY) // do not print the power gain values (just compute the average)
continue;
}

Expand Down
Loading