Code:
#include <gnls.h>
#include <iostream>
#include <time.h>
#define GHz 0.001
int main(int argc,char *argv []){
if(argc!=12){
cout<<"Usage :\n";
cout<<"mdwdm <Peak_Power> <Pulse_Width> <Chirp> <Innital Freq> <Space> <DeTune> <Filter FileName> <Fgain> <Channels> <# Map> <QF File Name>\n";
exit(1);
}
double peak_power = atof(argv [1]);
double pulse_width = atof(argv [2]);
double chirp = atof(argv [3]);
//fixed parameters for fibre
double D=8.0;
char* filterName=argv[7];
double S=0.057;
double loss=0.205;
double length=50;
double RD=-16;
double RS=-0.116;
double Rloss=0.28;
double Rlength=25;
//fixed parameters for signal
double seperation=25; //for 40Gbit/s
double num_of_bits=128;
int field_win=(seperation*num_of_bits)/2;
double phase=0;
//Frequency
double freq=0.0;
double init_freq=atof(argv [4]);
double space=atof(argv [5]);
double f_detune= atof(argv [6]);
double fgain= atof(argv [8]);
int channels=atoi(argv [9]);
int num_map=atoi(argv [10]);
//Aplifier
double ampgain=length*loss+Rlength*Rloss;
double noise=1.5;
//Qfactor
ofstream qf_data_stream[(channels)],sample_stream[(channels)],eye_stream[(channels)];
double cutoff=1000/(seperation*1000);
int fp=0;
char num[10];
char ind[20];
string qf_file,qf_buff=(argv[11]); //Change
string eye_file,eye_buff="eye";
string sample_file,sample_buff="sample";
//bool minuse_detune=true;
fgain=0;
//********
long int seed=0;
seed=time(0);
srand48(seed);
//****************
Loop::break_on_interrupt();
Fibre::verbosity=true;
Fibre::unit_system=Fibre::ps_per_nm_per_km;
Field field((field_win*2),field_win);
Field *cp_ptr[channels];
Fibre Teralight(0,D,S,0,1.55,loss,65);
Fibre RTeralight(0,RD,RS,0,1.55,Rloss,25);
OutputUnit wdmtera("multiwdm_filt",field);
//*******Opening files for eye diagram and q_factor
for(fp=0;fp<(channels);fp++){
//convert int to string and put into num
sprintf(num,"%d",fp);
sprintf(ind, "-%d_%.1f_%.1f",(int)pulse_width,(space*1000),f_detune*1000);
qf_file=qf_buff+ind+"_C"+num+".dat";
eye_file=eye_buff+ind+"_C"+num+".dat";
sample_file=sample_buff+ind+"_C"+num+".dat";
qf_data_stream[fp].open(qf_file.c_str());
cout<<"Opened File: "<<qf_file<<"\n";
qf_file.erase(1);
eye_file.erase(1);
sample_file.erase(1);
}
//*************GT Gaussian transmitter*****************
if(channels%2==0)freq=init_freq-(space*0.5+(channels/2-1)*space);
else freq=init_freq-(channels-1)/2*space;
Add G_Pulse;
for(int i=0;i<channels;i++){
cout<<"Frequncy channel A: "<<freq<<"\n";
double posn=-drand48()*num_of_bits*seperation*0.5;
cout<<"Signal position + "<<-posn<<endl;
G_Pulse.add_system(
Gaussian(pulse_width,peak_power,posn,0,0,chirp)
+GeneratePattern(PRBS(field,7,seperation,0,freq,phase))
+OutputField(wdmtera)
+ReadFilter(filterName,(freq-f_detune))
);
freq=freq+space;
}
//************Transmitter=GT+GF*************************
System Tx;
Tx= G_Pulse +OutputField(wdmtera)
;
//*************TeraLight + RTL Fibre********************
Add TLFibre;
TLFibre.add_system(
FibreSegment(Teralight,length)+
FibreSegment(RTeralight,Rlength)+
Amplifier(ampgain,noise,1.55)+
OutputField(wdmtera)
);
Add RTLFibre;
RTLFibre.add_system(
FibreSegment(RTeralight,Rlength)+
FibreSegment(Teralight,length)+
Amplifier(ampgain,noise,1.55)+
OutputField(wdmtera)
);
//*************System GF+GF+TLfibre*********************
Tx.propagate(field);
System mwdmsys;
for(int k=1;k<=num_map;k++){
mwdmsys=TLFibre+RTLFibre;
FixEnergy Att(mwdmsys);
Att.propagate(field);
}
//*************DeMutiplex Field and applie Qfac********
System C_wdm[(channels)];
for (int i=0;i<(channels);i++){
cp_ptr[i] = new Field((field_win*2),field_win);
*cp_ptr[i] = field;
}
//Open Qfactor Files
if(channels%2==0)freq=init_freq-(space*0.5+(channels/2-1)*space);
else freq=init_freq-(channels-1)/2*space;
fp=0;
for(fp=0;fp<(channels);fp++){
C_wdm[fp]=
ReadFilter(filterName,(freq-f_detune))+
QFactor(RZ,qf_data_stream[fp],(freq),10,cutoff*1.0,seperation,64)
+OutputField(wdmtera)
;
freq=freq+space;
C_wdm[fp].propagate(*cp_ptr[fp]);
}
//*************Closing all QFac Files*******************
//Close all QFACTOR files and cleanup
cout<<"Closing all Qfactor files: \n";
for(fp=0;fp<(channels);fp++){
qf_data_stream[fp].close();
cout<<"Closing File Number: "<<fp<<"\n";
}
for (int i=0;i<(channels);i++){
delete cp_ptr[i];
}
return 0;
}