Indoor Propagation

Detailed Description

This is an example of how to use the WinProp API for indoor propagation. The full example is distributed with the installation.
#include <stdio.h>
#include <string>
#include <iostream>

#include "indoor_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, ProjectHandle = 0;
	WinProp_Scenario    WinPropScenario;
	WinProp_Callback    WinPropCallback;
	WinProp_Area        WinPropArea;
	WinProp_Antenna     WinPropAntenna;
	WinProp_Result      *PowerResult = NULL, *DelayResult = NULL, *LosResult = NULL;
	WinProp_RayMatrix   *RayMatrix = NULL;
	WinProp_Pattern     WinPropPattern;
	WinProp_Additional  WinPropMore;
	WinProp_Propagation_Results OutputResults;
	double              PredictionHeight = 1.5;
	

	/* ------------------------ Initialization of structures --------------------- */
	WinProp_Structure_Init_Scenario(&WinPropScenario);
	WinProp_Structure_Init_Area(&WinPropArea);
	WinProp_Structure_Init_Antenna(&WinPropAntenna);
	WinProp_Structure_Init_Pattern(&WinPropPattern);
	WinProp_Structure_Init_Additional(&WinPropMore);
	WinProp_Structure_Init_Propagation_Results(&OutputResults);

	/* ---------- Load indoor vector database and initialise scenario ------------ */
	/* Assign database name. */
	WinPropScenario.Scenario = WINPROP_SCENARIO_INDOOR;
	WinPropScenario.VectorDatabase = API_DATA_FOLDER "../data/indoor/IndoorVectordatabase.idb";
	/* Define callback functions. */
	WinPropCallback.Percentage = CallbackProgress;
	WinPropCallback.Message = CallbackMessage;
	WinPropCallback.Error = CallbackError;


	/* Call the WinProp API to open a project and load the vector database. */
	Error = WinProp_Open(&ProjectHandle, &WinPropScenario, &WinPropCallback);
	/* ----------------------- Set up prediction --------------------------------- */
	if (Error == 0) {
		/* Definition of prediction area and resolution. */
		WinPropArea.LowerLeftX = -4.5;
		WinPropArea.LowerLeftY = -44.5;
		WinPropArea.UpperRightX = 101.5;
		WinPropArea.UpperRightY = 43.0;
		WinPropArea.Resolution = 1.0; // Resolution 1.0 meter
		WinPropArea.NrHeights = 1; // Number of prediction heights
		WinPropArea.Heights = &PredictionHeight; // Prediction height 1.5 meter

		/* Definition of antenna pattern. */
		WinPropPattern.Mode = PATTERN_MODE_FILE; // Load pattern from file
		WinPropPattern.Filename = API_DATA_FOLDER "antennas/Antenna.apb"; // Pattern file (including extension)

		/* Defintion of antenna properties. */
		WinPropAntenna.Enabled = 1;
		WinPropAntenna.Id = 1;
		WinPropAntenna.Longitude_X = 60.25;
		WinPropAntenna.Latitude_Y = 6.25;
		WinPropAntenna.Height = 2.0; // Antenna height 2.0 meter
		WinPropAntenna.Model = WINPROP_MODEL_DPM; // Use the DPM
		WinPropAntenna.DataType = PROP_RESULT_POWER; // Compute received power
		WinPropAntenna.Power = 10.0; // Power in dBm
		WinPropAntenna.Frequency = 1800.0; // Frequency 1800 MHz
		WinPropAntenna.Pattern = &WinPropPattern; // Use pattern defined above
		WinPropAntenna.Azimuth = 270.0; // Antenna points in western direction
		WinPropAntenna.Downtilt = 1.0; // Downtilt of 1 degree
		WinPropAntenna.Name = "my_antenna_name"; // name of the antenna

		/* Definition of outputs to be computed and written in WinProp format. */
		WinPropMore.OutputResults = &OutputResults;
		OutputResults.ResultPath = API_DATA_FOLDER "output/Indoor_Output"; // Output data directory 
		OutputResults.FieldStrength = 1;
		OutputResults.PathLoss = 1;

		/* Further parameters: With filtering. */
		WinPropMore.ResultFiltering = 1;

		/* ----------------------- Start prediction ------------------------------ */
		Error = WinProp_Predict(ProjectHandle, &WinPropAntenna, &WinPropArea, nullptr, &WinPropMore, &PowerResult, &DelayResult, &LosResult, &RayMatrix, nullptr);
	}
	WinProp_Close(ProjectHandle);
	
	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 << "): "; // highlight error in red color
#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"; // highlight error in red color
#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(WinProp_Result Resultmatrix, char* Filename) {
	FILE* OutputFile = fopen(Filename,"w");
	if (OutputFile)
	{
		/* Loop through WinPropall pixels. */
		for (int x = 0; x < Resultmatrix.Columns; x++)
		{
			for (int y = 0; y < Resultmatrix.Lines; y++)
			{
				/* Compute real coordinates. */
				double Coordinate_X = Resultmatrix.LowerLeftX + ((double)x + 0.5) * Resultmatrix.Resolution;
				double Coordinate_Y = Resultmatrix.LowerLeftY + ((double)y + 0.5) * Resultmatrix.Resolution;

				/* Check if pixel was computed or not */
				if (Resultmatrix.Matrix[0][x][y] > -1000)
					fprintf(OutputFile, "%.2f\t%.2f\t%.2f\n", Coordinate_X, Coordinate_Y, Resultmatrix.Matrix[0][x][y]);
			}
		}

		/* Close file. */
		fclose(OutputFile);
	}
	else
		printf("\nCould not open the File: %s for writing.\n",Filename);
}