Detailed Description
This is an example of how to directly carry outdoor propagation. The full example is distributed with the installation.
#include <stdio.h>
#include <string>
#include <iostream>
#include "outdoor_propagation.h"
#ifndef API_DATA_FOLDER
#define API_DATA_FOLDER "../../api/winprop/data/"
#endif // !API_DATA_FOLDER
int main(int argc, char** argv)
{
int Error = 0;
WinProp_ParaMain GeneralParameters;
WinProp_Antenna Antenna;
WinProp_Callback Callback;
WinProp_Result Resultmatrix;
WinProp_RayMatrix RayMatrix;
WinProp_Propagation_Results OutputResults;
const char* my_opb_database = API_DATA_FOLDER "outdoor/City";
WinProp_Structure_Init_ParameterMain(&GeneralParameters);
WinProp_Structure_Init_Antenna(&Antenna);
WinProp_Structure_Init_Callback(&Callback);
WinProp_Structure_Init_Result(&Resultmatrix);
WinProp_Structure_Init_RayMatrix(&RayMatrix);
WinProp_Structure_Init_Propagation_Results(&OutputResults);
GeneralParameters.ScenarioMode = SCENARIOMODE_URBAN;
GeneralParameters.PredictionModelUrban = PREDMODEL_UDP;
GeneralParameters.UrbanLowerLeftX = 100.0;
GeneralParameters.UrbanLowerLeftY = 100.0;
GeneralParameters.UrbanUpperRightX = 2200.0;
GeneralParameters.UrbanUpperRightY = 3200.0;
GeneralParameters.RuralLowerLeftX = GeneralParameters.UrbanLowerLeftX;
GeneralParameters.RuralLowerLeftY = GeneralParameters.UrbanLowerLeftY;
GeneralParameters.RuralUpperRightX = GeneralParameters.UrbanUpperRightX;
GeneralParameters.RuralUpperRightY = GeneralParameters.UrbanUpperRightY;
double PredictionHeight = 1.5;
GeneralParameters.Resolution = 10.0;
GeneralParameters.NrLayers = 1;
GeneralParameters.PredictionHeights = &PredictionHeight;
GeneralParameters.BuildingsMode = BUILDINGSMODE_UDP;
sprintf(GeneralParameters.BuildingsName, "%s", my_opb_database);
Antenna.Id = 1;
Antenna.SiteId = 1;
Antenna.Longitude_X = 1100.0;
Antenna.Latitude_Y = 2100.0;
Antenna.Height = 20.0;
Antenna.Power = 43.0;
Antenna.Frequency = 1800.0;
sprintf(Antenna.Name, "%s", "Antenna 1");
GeneralParameters.OutputResults = &OutputResults;
sprintf(OutputResults.ResultPath, "%s", API_DATA_FOLDER "output/outdoor_propagation");
OutputResults.FieldStrength = 1;
OutputResults.PathLoss = 1;
OutputResults.StatusLOS = 1;
OutputResults.RayFilePropPaths = 1;
OutputResults.StrFilePropPaths = 1;
Callback.Percentage = CallbackProgress;
Callback.Message = CallbackMessage;
Callback.Error = CallbackError;
Error = OutdoorPlugIn_ComputePrediction(
&Antenna, &GeneralParameters, NULL, 0, NULL, NULL, NULL, NULL, &Callback, &Resultmatrix, &RayMatrix, NULL, NULL);
if (Error == 0) {
const char* Filename = API_DATA_FOLDER "output/outdoor_propagation/PowerResults.txt";
write_ascii(&Resultmatrix, Filename);
}
else {
CallbackError(GeneralParameters.ErrorMessageMain, Error);
}
WinProp_FreeResult(&Resultmatrix);
WinProp_FreeRayMatrix(&RayMatrix);
return 0;
}
int _STD_CALL CallbackMessage(const char * Text)
{
if (Text == nullptr)
return 0;
std::cout << "\n" << Text;
return(0);
}
int _STD_CALL CallbackError(const char * Text, int Error)
{
if (Text == nullptr)
return 0;
std::cout << "\n";
#ifdef __LINUX
std::cout << "\033[31m" << "Error (" << Error << "): ";
#else
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED);
std::cout << "Error (" << Error << "): ";
#endif // __LINUX
std::cout << Text;
#ifdef __LINUX
std::cout << "\033[0m";
#else
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
#endif // __LINUX
return 0;
}
int _STD_CALL CallbackProgress(int value, const char* text)
{
char Line[200];
sprintf(Line, "\n%d%% %s", value, text);
std::cout << Line;
return(0);
}
void write_ascii(const WinProp_Result* Resultmatrix, const char* Filename) {
FILE* OutputFile = fopen(Filename,"w");
if (OutputFile)
{
for (int x = 0; x < Resultmatrix->Columns; x++)
{
for (int y = 0; y < Resultmatrix->Lines; y++)
{
double Coordinate_X = Resultmatrix->LowerLeftX + ((double)x + 0.5) * Resultmatrix->Resolution;
double Coordinate_Y = Resultmatrix->LowerLeftY + ((double)y + 0.5) * Resultmatrix->Resolution;
if (Resultmatrix->Matrix[0][x][y] > -1000)
fprintf(OutputFile, "%.2f\t%.2f\t%.2f\n", Coordinate_X, Coordinate_Y, Resultmatrix->Matrix[0][x][y]);
}
}
fclose(OutputFile);
}
else
printf("\nCould not open the File: %s for writing.\n",Filename);
}