Forums › General Discussions › TG44A Sweep to Path Loss conversion utility › Reply To: TG44A Sweep to Path Loss conversion utility
Phil
Hmmm. .cpp files blocked. Ugly text follows:
// SHPathLossGen.cpp : Defines the entry point for the console application.
//
// This is more complex than initially thought. Due to limitations in SignalHound 2.18B
// the .CSV data points must be compressed down to 100 data points or less for the Path Loss file
// otherwise bad things happen WRT to signal levels in the SignalHound application.
// As such, the strategy is to divide the number of data points in the CSV file into less than 100 bins (the max allowable
// number of Path Loss Data points) and average the loss/gain of those CSV data points in each bin to come up with a
// single Path Loss datapoint per bin.
// *** Note this 100 point limitation means that Pass loss files will not be exact replicas of Track Gen loss sweeps,
// particularly if there are sharp changes in loss/gain over the span ***
#include “stdafx.h”
#include “stdlib.h”
#include “winerror.h”
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
struct CSVRecord {
double frequency;
double minAmp;
double maxAmp;
};
vector<CSVRecord> CSVList;
string line;
unsigned int pos1, pos2;
CSVRecord tempCSV;
ifstream fSHExport;
ofstream fSHPathLoss;
if((argv[1] == NULL) || (argv[2] == NULL))
{
printf(“\r\nConversion utility from SignalHound .csv output to SH Path Loss file format\r\n”);
printf(“Missing Arguments!\r\n”);
printf(“Usage:\r\n\r\n”);
printf(“%s <Input file> <Output file>\r\n\r\n”, argv[0]);
printf(“Where:\r\n”);
printf(“\r\n Input File – .csv file exported from SignalHound application\r\n”);
printf(“\r\n Output file – file to be written with PathLoss data for import into SignalHound application\r\n”);
printf(“\r\n Note the utility takes the MINIMUM amplitude from the .csv file for the Path Loss.\r\n”);
return ERROR_BAD_ARGUMENTS;
}
fSHExport.open(argv[1]);
fSHPathLoss.open(argv[2]);
//Load the CSV file records into CSVList vector
if(fSHExport.is_open() && fSHPathLoss.is_open())
{
//Toss the first line
getline(fSHExport, line);
while (fSHExport.good())
{
getline(fSHExport, line);
if(fSHExport.eofbit)
{
pos1 = line.find(“,”);
if(pos1 != -1)
{
pos2 = line.find(“,”, pos1+1);
tempCSV.frequency = atof((line.substr(0, pos1).c_str()));
tempCSV.minAmp = atof((line.substr(pos1+1, pos1-pos2).c_str()));
tempCSV.maxAmp = atof((line.substr(pos2+1).c_str()));
CSVList.push_back(tempCSV);
}
}
}
//Calculate the number of CSV records/bin we will need from the number of records in the CSVList vector
// Experimental – divide by 100, round up to nearest whole number – this should give us somewhere
// between 50 and 100 bins
double j = (double) CSVList.size()/100;
int bin_size = ceil(j);
//Iterate through the records, adding them up in bins and averaging the frequency and amplitude for each bin
vector<CSVRecord>::iterator it = CSVList.begin();
while(it != CSVList.end())
{
CSVRecord totCSVRecord;
totCSVRecord.frequency = 0;
totCSVRecord.minAmp = 0;
totCSVRecord.maxAmp = 0;
for(int i = 0; i < bin_size; ++i)
{
if(it == CSVList.end())
{
//if we are here we should be in the last bin – set the bin size to the amount of remaining records
//to allow the averaging for the last bin to be correct.
bin_size = i;
break;
}
//cout << “bin: ” << i << ” “;
tempCSV = *it;
//invert amplitude for Path loss instead of gain
tempCSV.minAmp = -tempCSV.minAmp;
tempCSV.maxAmp = -tempCSV.maxAmp;
totCSVRecord.frequency += tempCSV.frequency;
totCSVRecord.minAmp += tempCSV.minAmp;
totCSVRecord.maxAmp += tempCSV.maxAmp;
//cout << tempCSV.frequency << “:” << tempCSV.minAmp << “:” << tempCSV.maxAmp << endl;
++it;
}
cout << (totCSVRecord.frequency/bin_size) << “,” << ((totCSVRecord.minAmp/bin_size) + (totCSVRecord.maxAmp/bin_size))/2 << endl;
fSHPathLoss << (totCSVRecord.frequency/bin_size) << “,” << ((totCSVRecord.minAmp/bin_size) + (totCSVRecord.maxAmp/bin_size))/2 << endl;
}
fSHExport.close();
fSHPathLoss.close();
}
else
{
cout << “Unable to open either input or output file!” << endl;
return ERROR_FILE_NOT_FOUND;
}
printf(“Finished!”);
return ERROR_SUCCESS;
}
