Пример #1
0
   void interpret(Context *context)
   {
      if (context->Input.length() == 0)
      {
         return;
      }

      if (context->InputStrStartsWith(Nine()))
      {
         context->Output  += (9 * Multiplier());
         context->Input  = context->Input.substr(2);
      }
      else if (context->InputStrStartsWith(Four()))
      {
         context->Output += (4 * Multiplier());
         context->Input = context->Input.substr(2);
      }
      else if (context->InputStrStartsWith(Five()))
      {
         context->Output += (5 * Multiplier());
         context->Input = context->Input.substr(1);
      }

      while (context->InputStrStartsWith(One()))
      {
          context->Output += (1 * Multiplier());
          context->Input   = context->Input.substr(1);
      }
   }
Пример #2
0
bool Sub(void)
{	bool ok = true;
	ok &= One();
	ok &= Two(); 
	ok &= Three(); 
	ok &= Four();
	return ok;
}
// ------------------------------------------------------------------------
int main( void ) {
	cout <<"                                 ID  Name\n";
	Ball One;			cerr <<"a. " << One <<endl;     // Default constructor 
	Ball Two( 75 );		cerr <<"b. " << Two <<endl;     // Normal constructor		
	Ball Three("Ali");	cerr <<"c. " << Three <<endl;	// Normal constructor		
	Ball Four( One );	cerr <<"d. " << Four <<endl; 	// Copy constructor
	Ball Five = Three;	cerr <<"e. " << Five <<endl;	// Copy Constructor
    cout << "\nReady to construct an array:" <<"\n";
	Ball Six[2];		cerr <<"\t" <<"f. "<< Six[0] <<"\t   " <<Six[1] <<"\n";
	// Ball Bad = Ball(77);						// Bad: Ball(77) not a Ball&
	cerr <<"\nNow " << One.getcount() <<" Ball objects have been created.\n"; 
	Four = Two; 		cerr << "g............................\n" // Assignment
                             <<"\t" << Four <<"\n\t"  << Two <<endl;   
	bye();
	return 0;
}
Пример #4
0
void vspectra(void)
{

    int i, j, k, kk, num, numm, i4, maxi, r;
    int m, mm, blsiz, blsiz2, nsam, n_read;
    double avsig, av, max, min, noise, wid;
    uint8_t *bufferRead = malloc((NSAM) * sizeof(uint8_t));
    static double vspec[NSPEC];
    static int wtt[NSPEC];
    static double re[NSPEC * 2], am[NSPEC * 2];
    double smax;
    fftwf_plan p0;
    float *reamin0, *reamout0;


    blsiz = NSPEC * 2;
    blsiz2 = blsiz / 2;
    d1.bw = 2.4;                // fixed 2.4 for TV dongle 10 MHz for ADC card
    if (d1.fbw == 0.0)
        d1.fbw = 2.0;           //  use bandwidth default if not set in srt.cat
    d1.f1 = 0.5 - (d1.fbw / d1.bw) * 0.5;
    d1.f2 = 0.5 + (d1.fbw / d1.bw) * 0.5;
    d1.fc = (d1.f1 + d1.f2) * 0.5;
    d1.lofreq = 0;              // not used but needs to be set to zero to flag the use of the dongle 
    d1.efflofreq = d1.freq - d1.bw * 0.5;

    if (!d1.fftsim) {
        fft_init(blsiz2, &p0, &reamin0, &reamout0);
    }

    num = d1.nblk;              //was 20   // was 100
    nsam = NSAM;
    d1.nsam = NSAM * num;
    avsig = 0;
    numm = 0;
    smax = 0;
    max = -1e99;
    min = 1e99;
    for (i = 0; i < blsiz2; i++)
        vspec[i] = 0.0;
    for (k = 0; k < num; k++) {
        if (!d1.radiosim)
// Read the raw data from the RTL Dongle
            r = rtlsdr_read_sync(dev, bufferRead, nsam, &n_read);
        else {
            av = 5.0;
            if (d1.elnow < 5.0)
                av = av * (d1.tsys + d1.tcal) / d1.tsys;
            if (strstr(soutrack, "Sun")) {
                av = sqrt(d1.eloff * d1.eloff +
                          d1.azoff * d1.azoff * cos(d1.elnow * PI / 180.0) * cos(d1.elnow * PI / 180.0) +
                          1e-6);
                if (av > d1.beamw)
                    av = d1.beamw;
                av = 5.0 + 25.0 * cos(av * PI * 0.5 / d1.beamw) * cos(av * PI * 0.5 / d1.beamw);
            }
            for (i = 0; i < nsam; i++)
                bufferRead[i] = (uint8_t) (sqrt(av) * gauss() + 127.397 + 0.5 + 0 * sin(2.0 * PI * 0.5 * (i / 2) / d1.bw)); // simulate data
        }

//   for(i=0;i<nsam;i+=0x10000)  printf("%d %f\n",i,(double)(bufferRead[i]-127.397));
        for (kk = 0; kk < nsam / blsiz; kk++) {
            if (d1.fftsim)
                for (i = 0; i < blsiz2; i++) {
                    re[i] = (double) (bufferRead[2 * i + kk * blsiz] - 127.397);
                    am[i] = (double) (bufferRead[2 * i + 1 + kk * blsiz] - 127.397);
                    if (re[i] > smax)
                        smax = re[i];
            } else
                for (i = 0; i < blsiz2; i++) {
                    reamin0[2 * i] = (float) (bufferRead[2 * i + kk * blsiz] - 127.397);
                    reamin0[2 * i + 1] = (float) (bufferRead[2 * i + 1 + kk * blsiz] - 127.397);
                    if (reamin0[2 * i] > smax)
                        smax = reamin0[2 * i];
                }

            if (d1.fftsim)
                Four(re, am, blsiz2);
            else {
                cfft(&p0);
                for (i = 0; i < blsiz2; i++) {
                    re[i] = reamout0[2 * i];
                    am[i] = reamout0[2 * i + 1];
                }
            }
// for(i = 0; i < blsiz2; i++) if(re[i] > max) max=re[i];
// for(i = 0; i < blsiz2; i++) if(re[i] < min) min=re[i];
            for (i = 0; i < blsiz2; i++) {
                if (i < blsiz2 / 2)
                    j = i + blsiz2 / 2;
                else
                    j = i - blsiz2 / 2;
                vspec[j] += re[i] * re[i] + am[i] * am[i];
                numm++;
            }
        }
    }
//   printf("max %f min %f\n",max,min);
    max = av = 0;
    maxi = 0;
    for (i = 0; i < blsiz2; i++)
        wtt[i] = 1;
    if (numm > 0) {
        if (d1.nfreq == blsiz2) {
            for (i = 0; i < blsiz2; i++) {
                if (i > 10)
                    spec[i] = vspec[i] / (double) numm;
                else
                    spec[i] = 0;
            }
        } else {
            m = blsiz2 / d1.nfreq;
            for (i = 0; i < d1.nrfi; i++) {
                i4 = (d1.rfi[i] - d1.freq + d1.bw * 0.5) * blsiz2 / d1.bw + 0.5; // index of rfi MHz 
                wid = 0.5 * d1.rfiwid[i] / (d1.bw / NSPEC);
                for (j = -wid; j <= wid; j++)
                    if ((i4 + j) >= 0 && (i4 + j) < blsiz2)
                        wtt[i4 + j] = 0;
            }
            for (j = 0; j < d1.nfreq; j++) {
                av = mm = 0;
                for (i = j * m - m / 2; i <= j * m + m / 2; i++) {
                    if (i > 10 && i < blsiz2 && wtt[i]) { // wtt=0 removal of spurs
                        av += vspec[i] / (double) numm;
                        if (vspec[i] > max) {
                            max = vspec[i];
                            maxi = i;
                        }
                        mm++;
                    }
                }
                if (mm > 0)
                    spec[j] = av / mm;
                else {
                    spec[j] = 0;
                    if (j > 10)
                        printf("check RFI settings in srt.cat data deleted at %8.3f\n",
                               j * d1.bw / d1.nfreq + d1.freq - d1.bw * 0.5);
                }
            }
            max = max / (double) numm;
            noise = spec[maxi / m] * sqrt(2.0 * blsiz2 / (double) d1.nsam);
            if (max > spec[maxi / m] + d1.rfisigma * noise && d1.printout) // rfisigma sigma
                printf("check for RFI at %8.4f MHz max %5.0e av %5.0e smax %5.0f %3.0f sigma\n",
                       maxi * d1.bw / blsiz2 + d1.freq - d1.bw * 0.5, max, spec[maxi / m], smax,
                       (max - spec[maxi / m]) / noise);
        }
    }
    d1.smax = smax;
    if (!d1.fftsim)
        fft_free(&p0, &reamin0, &reamout0);
    free(bufferRead);
}
Пример #5
0
void vspectra(void)
{

    int i, j, size, sizep, kk, kkk, num, numm, i4;
    int k, m, mm, blsiz, blsiz2, nsam, info, maxi;
    double avsig, av, wid, noise, max;
    static double vspec[NSPEC];
    static int wtt[NSPEC];
    static float ream[NSPEC * 4];
    static double re[NSPEC * 2], am[NSPEC * 2];
    double smax, aam, rre, aam2, rre2;
    double *comm;

    d1.bw = 10.0;               // 10 MHz
    d1.lofreq = 1416.0;         // Luff 1416 MHz
    d1.efflofreq = d1.lofreq;
    d1.f1 = (d1.freq - d1.lofreq) / d1.bw - (d1.fbw / d1.bw) * 0.5;
    d1.f2 = (d1.freq - d1.lofreq) / d1.bw + (d1.fbw / d1.bw) * 0.5;
    d1.fc = (d1.f1 + d1.f2) * 0.5;

    blsiz = NSPEC * 2;

    info = 0;
    comm = 0;
    if (!d1.fftsim) {
        comm = (double *) malloc((5 * blsiz + 100) * sizeof(double));
        fft_init(blsiz, ream, comm, &info);
    }
//    printf("comm %x\n",comm);

    nsam = 0x100000;
    blsiz2 = blsiz / 2;
    num = 20;                   // was 100
    d1.nsam = nsam * num;
    avsig = 0;
    size = 0;
    numm = 0;
    smax = 0;
    av = 0;
    for (i = 0; i < blsiz2; i++)
        vspec[i] = 0.0;
    size = -1;
    if (!d1.radiosim)
        while (size != nsam)
            size = get_pci(buffer1, nsam); // wait for transfer to complete
    else {
        av = 5.0;
        if (d1.elnow < 5.0)
            av = av * (d1.tsys + d1.tcal) / d1.tsys;
        if (strstr(soutrack, "Sun")) {
            av = sqrt(d1.eloff * d1.eloff +
                      d1.azoff * d1.azoff * cos(d1.elnow * PI / 180.0) * cos(d1.elnow * PI / 180.0) + 1e-6);
            if (av > d1.beamw)
                av = d1.beamw;
            av = 5.0 + 25.0 * cos(av * PI * 0.5 / d1.beamw) * cos(av * PI * 0.5 / d1.beamw);
        }

        for (i = 0; i < nsam; i++)
            buffer1[i] = 2048 + sqrt(av) * gauss();
        size = nsam;
    }                           // simulate transfer
    sizep = size;
    for (k = 0; k < num; k++) {
        if (k < num - 1) {
            if (!d1.radiosim)
                size = get_pci(buffer1, nsam); // start new transfer
            else {
                for (i = 0; i < nsam; i++)
                    buffer1[i] = 2048 + sqrt(av) * gauss();
                size = nsam;
            }                   // simulate transfer
        }
        if (sizep == nsam) {    // work on previous buffer
            for (kk = 0; kk < sizep / blsiz; kk++) {
                avsig = 2048;   // should be 2048   
//                avsig = 2300;
                kkk = kk * blsiz;
                for (j = 0; j < blsiz; j++) {
//                      if(j==0 && kkk==0) printf("sam %f\n",(buffer1[j + kkk] & 0xfff) - avsig);
                    if (kk % 2 == 0)
                        ream[2 * j] = ((double) (buffer1[j + kkk] & 0xfff) - avsig);
                    else
                        ream[2 * j + 1] = ((double) (buffer1[j + kkk] & 0xfff) - avsig);
                    if (j && ream[2 * j] > smax)
                        smax = ream[2 * j];
                }
                if (kk % 2 == 1) {
                    if (d1.fftsim) {
                        for (i = 0; i < blsiz2; i++) {
                            re[i] = ream[2 * i];
                            am[i] = ream[2 * i + 1];
                        }
                        Four(re, am, blsiz2);
                    } else
                        cfft(blsiz, ream, comm, &info);

                    for (i = 0; i < blsiz2; i++) {
                        if (i >= 1) {
                            rre = ream[2 * i] + ream[2 * (blsiz - i)];
                            aam = ream[2 * i + 1] - ream[2 * (blsiz - i) + 1];
                            aam2 = -ream[2 * i] + ream[2 * (blsiz - i)];
                            rre2 = ream[2 * i + 1] + ream[2 * (blsiz - i) + 1];
                        } else {
                            rre = ream[2 * i] + ream[0];
                            aam = ream[2 * i + 1] - ream[1];
                            aam2 = -ream[2 * i] + ream[0];
                            rre2 = ream[2 * i + 1] + ream[1];
                        }
                        vspec[i] += rre * rre + aam * aam + rre2 * rre2 + aam2 * aam2;
                    }
                }
            }
            numm++;
        }
        while (size != nsam)
            if (!d1.radiosim)
                size = get_pci(buffer1, nsam); // wait for transfer to complete
            else {
                for (i = 0; i < nsam; i++)
                    buffer1[i] = 2048 + 10.0 * gauss();
                size = nsam;
            }                   // simulate transfer
        sizep = size;
    }
    av = max = 0;
    maxi = 0;
    for (i = 0; i < blsiz2; i++)
        wtt[i] = 1;
    if (numm > 0) {
        if (d1.nfreq == blsiz2) {
            for (i = 0; i < blsiz2; i++) {
                if (i > 10)
                    spec[i] = vspec[i] / (double) numm;
                else
                    spec[i] = 0;
            }
        } else {
            m = blsiz2 / d1.nfreq;
            for (i = 0; i < d1.nrfi; i++) {
                i4 = (d1.rfi[i] - d1.lofreq) * blsiz2 / d1.bw + 0.5; // index of rfi MHz 
                wid = 0.5 * d1.rfiwid[i] / (d1.bw / NSPEC);
                for (j = -wid; j <= wid; j++)
                    if ((i4 + j) >= 0 && (i4 + j) < blsiz2)
                        wtt[i4 + j] = 0;
            }
            for (j = 0; j < d1.nfreq; j++) {
                av = mm = 0;
                for (i = j * m - m / 2; i <= j * m + m / 2; i++) {
                    if (i > 10 && i < blsiz2 && wtt[i]) { // wtt=0 removal of spurs
                        av += vspec[i] / (double) numm;
                        if (vspec[i] > max) {
                            max = vspec[i];
                            maxi = i;
                        }
                        mm++;
                    }
                }
                if (mm > 0)
                    spec[j] = av / mm;
                else {
                    spec[j] = 0;
                    if (j > 10)
                        printf("check RFI settings in srt.cat data deleted at %8.3f\n",
                               j * d1.bw / d1.nfreq + d1.lofreq);
                }
            }
            max = max / (double) numm;
            noise = spec[maxi / m] * sqrt(2.0 * blsiz2 / (double) d1.nsam);
            if (max > spec[maxi / m] + d1.rfisigma * noise && d1.printout) // rfisigma sigma
                printf("check for RFI at %8.4f MHz max %5.0e av %5.0e smax %5.0f %3.0f sigma\n",
                       maxi * d1.bw / blsiz2 + d1.lofreq, max, spec[maxi / m], smax,
                       (max - spec[maxi / m]) / noise);
        }
    }
    d1.smax = smax;
    if (!d1.fftsim)
        free(comm);

}