Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Enumerations | Functions
general.h File Reference

Utility functions needed across the whole project. More...

#include <QFile>
#include <QFileInfo>
#include <QString>
#include <QList>
#include <QPointF>
#include <QRegularExpression>
#include <cmath>
#include <complex>
Include dependency graph for general.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  Units {
  Capacitance , Inductance , Length , Resistance ,
  Degrees , NoUnits
}
 Unit types for engineering values.
 

Functions

QString RoundVariablePrecision (double)
 Rounds double to minimum decimal places needed.
 
QString num2str (std::complex< double > Z, Units CompType)
 Converts complex number to string with units.
 
QString num2str (double, Units)
 Converts double to string with engineering notation and units.
 
QString num2str (double)
 Converts double to string with engineering notation.
 
std::complex< double > Str2Complex (QString)
 Parses string to complex number.
 
QString ConvertLengthFromM (QString, double)
 Converts length in meters to appropriate unit with auto-scaling.
 
void convert_MA_RI_to_dB (double &S_1, double &S_2, double &S_3, double &S_4, QString format)
 Converts S-parameter from MA/RI/DB format to dB, angle, real, and imaginary.
 
double getFreqScale (QString frequency_unit)
 Gets frequency scale factor from unit string.
 
double getScaleFactor (QString scale)
 Gets scale factor from SI prefix.
 
int findClosestIndex (const QList< double > &list, double value)
 Finds index of closest value in list.
 
double getFreqFromText (QString freq)
 Parses frequency string to Hz.
 
QPointF findClosestPoint (const QList< double > &xValues, const QList< double > &yValues, double targetX)
 Finds closest point in x-y data series.
 
QMap< QString, QList< double > > readTouchstoneFile (const QString &filePath)
 Reads Touchstone file and extracts S-parameter data.
 
void showHTMLDocs (QString path)
 Show HTML documentation in the web browser.
 

Detailed Description

Utility functions needed across the whole project.

Author
Andrés Martínez Mera - andre.nosp@m.smme.nosp@m.ra@pr.nosp@m.oton.nosp@m.mail..nosp@m.com
Date
Jan 4, 2026

Function Documentation

◆ convert_MA_RI_to_dB()

void convert_MA_RI_to_dB ( double &  S_1,
double &  S_2,
double &  S_3,
double &  S_4,
QString  format 
)

Converts S-parameter from MA/RI/DB format to dB, angle, real, and imaginary.

Parameters
[in,out]S_1Magnitude (MA), Real (RI), or dB (DB) → dB output
[in,out]S_2Angle (MA/DB) or Imaginary (RI) → angle output
[out]S_3Real part output
[out]S_4Imaginary part output
formatInput format: "MA", "RI", or "DB" (case insensitive)

◆ ConvertLengthFromM()

QString ConvertLengthFromM ( QString  units,
double  len 
)

Converts length in meters to appropriate unit with auto-scaling.

Parameters
unitsCurrent unit (mm, mil, um, nm, inch, ft, m)
lenLength in meters
Returns
Formatted string with auto-scaled unit

◆ findClosestIndex()

int findClosestIndex ( const QList< double > &  list,
double  value 
)

Finds index of closest value in list.

Parameters
listList to search
valueTarget value
Returns
Index of closest element

◆ findClosestPoint()

QPointF findClosestPoint ( const QList< double > &  xValues,
const QList< double > &  yValues,
double  targetX 
)

Finds closest point in x-y data series.

Parameters
xValuesX-axis values
yValuesY-axis values
targetXTarget x value
Returns
Closest point as QPointF

◆ getFreqFromText()

double getFreqFromText ( QString  freq)

Parses frequency string to Hz.

Parameters
freqFrequency string (e.g., "2.4 GHz", "100MHz")
Returns
Frequency in Hz, or -1 if invalid

◆ getFreqScale()

double getFreqScale ( QString  frequency_unit)

Gets frequency scale factor from unit string.

Parameters
frequency_unitUnit string (Hz, kHz, MHz, GHz)
Returns
Scale factor relative to Hz

◆ getScaleFactor()

double getScaleFactor ( QString  scale)

Gets scale factor from SI prefix.

Parameters
scalePrefix string (Y, Z, E, P, T, G, M, k, m, u, n, p, f, a, z, y)
Returns
Scale factor

◆ num2str() [1/3]

QString num2str ( double  Num)

Converts double to string with engineering notation.

Parameters
NumValue to convert
Returns
Formatted string

◆ num2str() [2/3]

QString num2str ( double  Num,
Units  CompType 
)

Converts double to string with engineering notation and units.

Parameters
NumValue to convert
CompTypeUnit type
Returns
Formatted string

◆ num2str() [3/3]

QString num2str ( std::complex< double >  Z,
Units  CompType 
)

Converts complex number to string with units.

Parameters
ZComplex value
CompTypeUnit type
Returns
Formatted string

◆ readTouchstoneFile()

QMap< QString, QList< double > > readTouchstoneFile ( const QString &  filePath)

Reads Touchstone file and extracts S-parameter data.

Parameters
filePathPath to the Touchstone file (.sNp)
Returns
Map of variable names to data arrays

◆ RoundVariablePrecision()

QString RoundVariablePrecision ( double  val)

Rounds double to minimum decimal places needed.

Parameters
valValue to round
Returns
Formatted string

◆ showHTMLDocs()

void showHTMLDocs ( QString  path)

Show HTML documentation in the web browser.

Parameters
pathPath to the HTML file

◆ Str2Complex()

std::complex< double > Str2Complex ( QString  num)

Parses string to complex number.

Parameters
numString representation (e.g., "50+j25", "j50", "50")
Returns
Complex number