Skip to content

Commit

Permalink
Modifying sim_real to support XCFs and 16-pulse sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
egthomas committed Oct 7, 2024
1 parent 375b183 commit 4f7bd8c
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
</option>
<option><on>-tauscan</on><od>use Ray Greenwald's 13-pulse sequence.</od>
</option>
<option><on>-spaletascan</on><od>use Mrinal Balaji / Jef Spaleta's 16-pulse sequence.</od>
</option>
<option><on>-oldscan</on><od>use the old 7-pulse sequence.</od>
</option>
<option><on>-constant</on><od>use a constant irregularity lifetime distribution (default is exponential).</od>
Expand Down
245 changes: 154 additions & 91 deletions codebase/superdarn/src.bin/tk/tool/sim_real.1.0/sim_real.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ void makeRadarParm2(struct RadarParm *prm2, char *argv[], int argc, int cpid,
prm2->rxrise = in_prm->rxrise;
prm2->intt.sc = (int16)(smsep*n_samples*nave);
prm2->intt.us = (int)(((smsep*n_samples*nave)-(int)(smsep*n_samples*nave))*1e6);
prm2->txpl = 300;
prm2->txpl = in_prm->txpl;
prm2->mpinc = (int16)(dt*1e6);
prm2->mppul = (int16)n_pul;
prm2->mplgs = (int16)n_lags;
prm2->mplgexs = (int16)n_lags;
prm2->nrang = in_prm->nrang;
prm2->frang = in_prm->frang;
prm2->rsep = in_prm->rsep;
prm2->xcf = 0;
prm2->xcf = in_prm->xcf;
prm2->tfreq = in_prm->tfreq;
prm2->offset = in_prm->offset;
prm2->mxpwr = in_prm->mxpwr;
Expand All @@ -169,6 +169,21 @@ void makeRadarParm2(struct RadarParm *prm2, char *argv[], int argc, int cpid,
int16 temp_lag[100] = {0,0,15,16,27,29,29,32,23,27,27,32,23,29,16,23,15,23,
23,32,16,27,15,27,16,29,15,29,32,47,16,32,15,32};
RadarParmSetLag(prm2,n_lags,temp_lag);
} else if (cpid == 9100) {
int16 temp_lag[244] = {1495,1495,0,4,4,19,0,19,19,42,42,78,4,42,0,42,78,127,19,78,
127,191,4,78,0,78,191,270,42,127,270,364,19,127,364,474,78,191,4,127,
474,600,0,127,127,270,600,745,42,191,745,905,191,364,19,191,905,1083,4,191,
0,191,78,270,1083,1280,270,474,1280,1495,42,270,127,364,364,600,19,270,4,270,
0,270,474,745,191,474,78,364,600,905,42,364,270,600,745,1083,19,364,127,474,
4,364,0,364,905,1280,364,745,78,474,191,600,1083,1495,474,905,42,474,19,474,
4,474,127,600,0,474,270,745,600,1083,78,600,745,1280,364,905,191,745,42,600,
19,600,905,1495,4,600,0,600,474,1083,127,745,270,905,78,745,600,1280,42,745,
191,905,364,1083,19,745,4,745,0,745,745,1495,127,905,474,1280,270,1083,78,905,
42,905,19,905,191,1083,600,1495,4,905,0,905,364,1280,127,1083,78,1083,270,1280,
474,1495,42,1083,19,1083,4,1083,0,1083,191,1280,364,1495,127,1280,78,1280,270,1495,
42,1280,19,1280,4,1280,0,1280,191,1495,127,1495,78,1495,42,1495,19,1495,4,1495,
0,1495,1495,1495};
RadarParmSetLag(prm2,n_lags,temp_lag);
} else {
int16 temp_lag[100] = {0,0,42,43,22,24,24,27,27,31,22,27,24,31,14,22,22,
31,14,24,31,42,31,43,14,27,0,14,27,42,27,43,14,31,
Expand All @@ -194,22 +209,25 @@ int main(int argc,char *argv[])

FILE *fp=NULL;

int xcf = 0;

int katscan = 0;
int oldscan = 0;
int tauscan = 0;
int spaletascan = 0;

/********************************************************
** definitions of variables needed for data generation **
********************************************************/
double t_d = .04; /*Irregualrity decay time s*/
double w = -9999.; /*spectral width*/
double v_dop = 450.; /*Background velocity (m/s)*/
//double w = -9999.; /*spectral width*/
//double v_dop = 450.; /*Background velocity (m/s)*/
double freq = 12.e6; /*transmit frequency*/
double amp0 = 1.; /*amplitude scaling factor*/
int noise_flg = 1; /*flag to indicate whether white noise is included*/
double noise_lev = 0.; /*white noise level (ratio)*/
int nave = 50; /*number of pulse sequences in an integration period*/
int nrang = 100; /*number of range gates*/
int nrang = 300; /*number of range gates*/
int lagfr = 4; /*lag to first range*/
int life_dist = 0; /*lifetime distribution*/
double smsep = 300.e-6; /*sample spearation*/
Expand All @@ -235,6 +253,7 @@ int main(int argc,char *argv[])
OptionAdd(&opt,"katscan",'x',&katscan); /* control program */
OptionAdd(&opt,"oldscan",'x',&oldscan);
OptionAdd(&opt,"tauscan",'x',&tauscan);
OptionAdd(&opt,"spaletascan",'x',&spaletascan);

OptionAdd(&opt,"constant",'x',&life_dist); /* irregularity distribution */
OptionAdd(&opt,"nocri",'x',&cri_flg); /* remove cross-range interference */
Expand Down Expand Up @@ -311,9 +330,124 @@ int main(int argc,char *argv[])
for (i=0;i<nrang;i++)
qflg[i] = 0;

double *psi_obs = malloc(nrang*sizeof(double));
for (i=0;i<nrang;i++)
psi_obs[i] = 0.;

/*Creating the output array for ACFs*/
complex double **acfs = malloc(nrang*sizeof(complex double *));

/*oldscan*/
if (oldscan) {
cpid = 1;
n_pul = 7; /*number of pulses*/
n_lags = 18; /*number of lags in the ACFs*/

/*fill the pulse table*/
pulse_t = malloc(n_pul*sizeof(int));
pulse_t[0] = 0;
pulse_t[1] = 9;
pulse_t[2] = 12;
pulse_t[3] = 20;
pulse_t[4] = 22;
pulse_t[5] = 26;
pulse_t[6] = 27;

/*Creating lag array*/
tau = malloc(n_lags*sizeof(int));
for (i=0;i<n_lags;i++)
tau[i] = i;
/*no lag 16*/
tau[16] += 1;
tau[17] += 1;
}
/*tauscan*/
else if (tauscan) {
cpid = 503;
n_pul = 13; /*number of pulses*/
n_lags = 17; /*number of lags in the ACFs*/

/*fill the pulse table*/
pulse_t = malloc(n_pul*sizeof(int));
pulse_t[0] = 0;
pulse_t[1] = 15;
pulse_t[2] = 16;
pulse_t[3] = 23;
pulse_t[4] = 27;
pulse_t[5] = 29;
pulse_t[6] = 32;
pulse_t[7] = 47;
pulse_t[8] = 50;
pulse_t[9] = 52;
pulse_t[10] = 56;
pulse_t[11] = 63;
pulse_t[12] = 64;

/*Creating lag array*/
tau = malloc(n_lags*sizeof(int));
for (i=0;i<10;i++)
tau[i] = i;
/*no lag 10*/
for (i=10;i<n_lags;i++)
tau[i] = (i+1);
}
/*spaletascan*/
else if (spaletascan) {
cpid = 9100;
n_pul = 16; /*number of pulses*/
n_lags = 121; /*number of lags in the ACFs*/

/*fill the pulse table*/
pulse_t = malloc(n_pul*sizeof(int));
pulse_t[0] = 0;
pulse_t[1] = 4;
pulse_t[2] = 19;
pulse_t[3] = 42;
pulse_t[4] = 78;
pulse_t[5] = 127;
pulse_t[6] = 191;
pulse_t[7] = 270;
pulse_t[8] = 364;
pulse_t[9] = 474;
pulse_t[10] = 600;
pulse_t[11] = 745;
pulse_t[12] = 905;
pulse_t[13] = 1083;
pulse_t[14] = 1280;
pulse_t[15] = 1495;

/*Creating lag array*/
tau = malloc(n_lags*sizeof(int));
for (i=0;i<n_lags;i++)
tau[i] = i;
}
/*katscan (default)*/
else {
cpid = 150;
n_pul = 8; /*number of pulses*/
n_lags = 23; /*number of lags in the ACFs*/

/*fill the pulse table*/
pulse_t = malloc(n_pul*sizeof(int));
pulse_t[0] = 0;
pulse_t[1] = 14;
pulse_t[2] = 22;
pulse_t[3] = 24;
pulse_t[4] = 27;
pulse_t[5] = 31;
pulse_t[6] = 42;
pulse_t[7] = 43;
/*Creating lag array*/
tau = malloc(n_lags*sizeof(int));
for (i=0;i<6;i++)
tau[i] = i;
/*no lag 6*/
for (i=6;i<22;i++)
tau[i] = (i+1);
/*no lag 23*/
tau[22] = 24;
}


while (FitFread(fp,prm,fit) !=-1) {

Expand All @@ -331,88 +465,12 @@ int main(int argc,char *argv[])

lambda = C/freq;

/*oldscan*/
if (oldscan) {
cpid = 1;
n_pul = 7; /*number of pulses*/
n_lags = 18; /*number of lags in the ACFs*/

/*fill the pulse table*/
pulse_t = malloc(n_pul*sizeof(int));
pulse_t[0] = 0;
pulse_t[1] = 9;
pulse_t[2] = 12;
pulse_t[3] = 20;
pulse_t[4] = 22;
pulse_t[5] = 26;
pulse_t[6] = 27;

/*Creating lag array*/
tau = malloc(n_lags*sizeof(int));
for (i=0;i<n_lags;i++)
tau[i] = i;
/*no lag 16*/
tau[16] += 1;
tau[17] += 1;
}
/*tauscan*/
else if (tauscan) {
cpid = 503;
n_pul = 13; /*number of pulses*/
n_lags = 17; /*number of lags in the ACFs*/

/*fill the pulse table*/
pulse_t = malloc(n_pul*sizeof(int));
pulse_t[0] = 0;
pulse_t[1] = 15;
pulse_t[2] = 16;
pulse_t[3] = 23;
pulse_t[4] = 27;
pulse_t[5] = 29;
pulse_t[6] = 32;
pulse_t[7] = 47;
pulse_t[8] = 50;
pulse_t[9] = 52;
pulse_t[10] = 56;
pulse_t[11] = 63;
pulse_t[12] = 64;

/*Creating lag array*/
tau = malloc(n_lags*sizeof(int));
for (i=0;i<10;i++)
tau[i] = i;
/*no lag 10*/
for (i=10;i<n_lags;i++)
tau[i] = (i+1);
}
/*katscan (default)*/
else {
cpid = 150;
n_pul = 8; /*number of pulses*/
n_lags = 23; /*number of lags in the ACFs*/

/*fill the pulse table*/
pulse_t = malloc(n_pul*sizeof(int));
pulse_t[0] = 0;
pulse_t[1] = 14;
pulse_t[2] = 22;
pulse_t[3] = 24;
pulse_t[4] = 27;
pulse_t[5] = 31;
pulse_t[6] = 42;
pulse_t[7] = 43;
/*Creating lag array*/
tau = malloc(n_lags*sizeof(int));
for (i=0;i<6;i++)
tau[i] = i;
/*no lag 6*/
for (i=6;i<22;i++)
tau[i] = (i+1);
/*no lag 23*/
tau[22] = 24;
if (prm->xcf) {
xcf = 1;
} else {
xcf = 0;
}


/*control program dependent variables*/
taus = dt/smsep; /*lag time in samples*/
n_samples = (pulse_t[n_pul-1]*taus+nrang+lagfr); /*number of samples in 1 pulse sequence*/
Expand All @@ -438,6 +496,10 @@ int main(int argc,char *argv[])
amp0 = noise_lev*pow(10.,(fit->rng[i].p_0/10.));
amp0_arr[i] = amp0;

if (xcf) {
if (fit->xrng != NULL) psi_obs[i] = fit->xrng[i].phi0;
}

acfs[i] = malloc(n_lags*sizeof(complex double));
for (j=0;j<n_lags;j++)
acfs[i][j] = 0.+I*0.;
Expand Down Expand Up @@ -466,8 +528,8 @@ int main(int argc,char *argv[])
for (j=0;j<n_lags;j++) {
acfd[i*n_lags*2+j*2] = creal(acfs[i][j]);
acfd[i*n_lags*2+j*2+1] = cimag(acfs[i][j]);
xcfd[i*n_lags*2+j*2] = 0.;
xcfd[i*n_lags*2+j*2+1] = 0.;
xcfd[i*n_lags*2+j*2] = xcf*creal(acfs[i][j]*(cos(psi_obs[i])+I*sin(psi_obs[i])));
xcfd[i*n_lags*2+j*2+1] = xcf*cimag(acfs[i][j]*(cos(psi_obs[i])+I*sin(psi_obs[i])));
}
}

Expand Down Expand Up @@ -512,8 +574,8 @@ int main(int argc,char *argv[])
}
/*interferometer array samples*/
for (j=0;j<n_samples;j++) {
samples[i*n_samples*2*2+j*2+n_samples] = 0;
samples[i*n_samples*2*2+j*2+1+n_samples] = 0;
samples[i*n_samples*2*2+j*2+n_samples] = (int16)(xcf*creal(raw_samples[i*n_samples+j]*(cos(psi_obs[i])+I*sin(psi_obs[i]))));
samples[i*n_samples*2*2+j*2+1+n_samples] = (int16)(xcf*cimag(raw_samples[i*n_samples+j]*(cos(psi_obs[i])+I*sin(psi_obs[i]))));
}
}

Expand All @@ -530,22 +592,23 @@ int main(int argc,char *argv[])
free(badtr);
}

free(pulse_t);
free(tau);
free(raw_samples);
for (i=0;i<nrang;i++)
free(acfs[i]);
}

/*free dynamically allocated memory*/
free(acfs);
free(pulse_t);
free(tau);
free(qflg);
free(t_d_arr);
free(t_g_arr);
free(t_c_arr);
free(v_dop_arr);
free(velo_arr);
free(amp0_arr);
free(psi_obs);
fclose(fp);

return 0;
Expand Down

0 comments on commit 4f7bd8c

Please sign in to comment.