// Vaddina Prakash Rao
// Chair of Telecommunications
// TU Dresden

// Program to set node positions along a circle drawn with a radius equal to the personal operating space of each node. 


#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;

#define RADIANS 6.285714286

double add(int, double);

int main(int argc, char *argv[])
{
    ofstream out("wpan.scn", ios::trunc);
    int q1=0, NUM_OF_NODES, X, Y, POS;
    double x_pos, y_pos, sector_ang, dPOS;
    
    if (!out)
	{
	    cout << "Error Opening file, wpan.scn. The program will now terminate" << endl;
	    exit(EXIT_FAILURE);
	}
	
    if (argc<5 || argc>5)
	{
	    cout << "Error !!! Insufficient or excess parameters." << endl;
	    cout << "Usage:" << endl;
	    cout << "./scen_gen <number-of-nodes> <X-Position-of-Coord> <Y-Position-of-Coord> <Personal-Operating-Space>" << endl;
	    cout << "\tnumber-of-nodes: Number of nodes to be arranged around the coordinator. Currently the program only works when the number of nodes to be arranged around the coordinator is divisible by 4." << endl;
	    cout << "\tX-Position-of-Coord: The x-ordinate of the coordinator" << endl;
	    cout << "\tY-Position-of-Coord: The y-ordinate of the coordinator" << endl;
	    cout << "\tPersonal-Operating-Space: The POS of a node." << endl;
	    cout << "Example: ./scen_gen 11 25 25 10" << endl;
	    exit(EXIT_FAILURE);
	}
    else
	{
	    NUM_OF_NODES = atoi(*(argv+1));
	    X = atoi(*(argv+2));
	    Y = atoi(*(argv+3));
	    POS = atoi(*(argv+4));
	    dPOS = POS;
	    sector_ang = RADIANS/NUM_OF_NODES;
	    
	    // Entering the position for node-0. 
	    out << "$node_(0) set X_ " << X << endl; 
	    out << "$node_(0) set Y_ " << Y << endl; 
	    out << "$node_(0) set Z_ 0" << endl << endl; 
	}
    
    //cout << cos(45.00) << sin(45.00) << endl;
    
    for (int i=0; i<NUM_OF_NODES; i++)
	{
		x_pos = dPOS * cos(sector_ang*i);
		y_pos = dPOS * sin(sector_ang*i);
		
		out << "$node_(" << i+1 << ") set X_ " << add(X, x_pos) << endl; 
		out << "$node_(" << i+1 << ") set Y_ " << add(Y, y_pos) << endl; 
		out << "$node_(" << i+1 << ") set Z_ 0" << endl << endl; 
	}
    out.close();    
    return 0;
}

// Function to add an integer and a double and return the double value.
double add(int a1, double b1)
{
    return a1+b1;
}






