int main(void)
{
	int var;
	scanf("%d", &var);
	printf("!%d: %d\n", var, bang(var));
	return 0;
}
Esempio n. 2
0
void hLabel::mousePressed(int xx, int yy, int btn)
{
	if(data->selectable) {
		data->selected = !data->selected;
		bang();
	}
}
Esempio n. 3
0
void hSlider::mouseDragged(int xx, int yy, int btn)
{
    if(data->disabled == true) return;
	position = xx - x;

	if(position < 0) position = 0;
	else if(position > (w-2)) position = w-2;

    double pRange = w - 2;
    double val = 0;

    if(table == NULL) {
        double vRange = max - min;
        val = min + ((position * vRange) / pRange);
        // cout << "vRange = " << vRange << ", ";
        // cout << "val = " << val << endl;
    }
    else {
        double tMin = table->getMinValue();
        double tMax = table->getMaxValue();
        double vRange = tMax - tMin;
        double submitedValue = tMin + ((position * vRange) / pRange);
        val = table->getNearestValue(submitedValue);
        // cout << "vRange = " << vRange << ", ";
        // cout << "submitedValue = " << submitedValue << ", ";
        // cout << "val = " << val << endl;
    }

	data->value = val;
    //setLinkedValues();

	bang();
}
Esempio n. 4
0
void GemWindow::render(void){
  if(!makeCurrent()) {
    error("unable to switch to current window (do you have one?), cannot render!");
    return;
  }
  if(!pushContext()) {
    error("unable to switch to current context, cannot render!");
    return;
  }
  bang();
  if(m_buffer==2)
    swapBuffers();

  popContext();
}
Esempio n. 5
0
int main() {
  printf("Test with main.\n");
  printf("bitAnd Result: %d\n", bitAnd(15,3));
  printf("getByte Result: %d \n",getByte(0x12345678,22));
  printf("bitcount Result: %d \n", bitCount(1));
  printf("bang result is: %d \n", bang(3));
  printf("minimum two's complement integer is: %d \n",tmin());
  printf("fitbits result is: %d \n",fitsBits(-4,3));
  printf("divpwr2 result  is: %d \n",divpwr2(-33,4));
  printf("negate result is: %d \n",negate(4));
  printf("isPositive result is: %d \n",isPositive(-4));
  printf("isLessOrEqual result is: %d \n",isLessOrEqual(5,5));
  printf("float_neg result is: %d \n",float_neg(13));
  printf("float_i2f result is: %d \n",float_i2f(15));
  printf("float_twice result is: %d \n",float_twice(9.84));

}
Esempio n. 6
0
void gemglutwindow :: doRender()
{
  // FIXME: ?????
  bang();
}
Esempio n. 7
0
void magblocks4(void)
{
   static char command[COMMANDLEN + 2];
   static double undoFit[NA], undoFitUnc[NA];
   int npnts, j;
   double qmax, qmin;

   /* Process command */
      while (queryString("magblocks4% ", command, COMMANDLEN + 2) == NULL);
      caps(command);

      /* Spawn a command */
      if (strcmp(command, "!") == 0 || strcmp(command, "!!") == 0) {
        bang(command);

      /* Print current directory */
      } else if (strcmp(command, "PWD") == 0) {
         puts(currentDir);

      /* Change current directory */
      } else if (strcmp(command, "CD") == 0) {
         cd(command);
         
      /* Help */
      } else if (
         strcmp(command, "?") == 0 ||
         strcmp(command, "HE") == 0
      ) {
         help(command + (*command == '?' ? 1 : 2));

      /* Value of vacuum QCSQ */
      } else if (
         strcmp(command, "QCV") == 0 ||
         strcmp(command, "VQC") == 0
      ) {
         setVQCSQ(qcsq);

      /* Vacuum QCMSQ */
      } else if (
         strcmp(command, "QMV") == 0 ||
         strcmp(command, "VQM") == 0
      ) {
         setVMQCSQ(qcmsq);

      /* Value of vacuum linear absorption coefficient */
      } else if (
         strcmp(command, "MUV") == 0 ||
         strcmp(command, "VMU") == 0
      ) {
         setVMU(mu);

      /* Enter critical Q squared */
      } else if (strncmp(command, "QC", 2) == 0) {
         setQCSQ(command + 2, qcsq, Dqcsq);

      /* Top magnetic critical Q squared */
      } else if (strncmp(command, "QM", 2) == 0) {
         setMQCSQ(command + 2, qcmsq, Dqcmsq);

      /* Top length absorption coefficient */
      } else if (strncmp(command, "MU", 2) == 0) {
         setMU(command + 2, mu, Dmu);

      /* Thicknesses of magnetic layers */
      } else if (strncmp(command, "DM", 2) == 0) {
         setDM(command + 2, dm, Ddm);

      /* Delta lambda */
      } else if (strcmp(command, "DL") == 0) {
         setLamdel(&lamdel);

      /* Delta theta */
      } else if (strcmp(command, "DT") == 0) {
         setThedel(&thedel);

      /* Enter chemical thickness */
      } else if (command[0] == 'D') {
         setD(command + 1, d, Dd);

      /* Chemical roughnesses */
      } else if (strncmp(command, "RO", 2) == 0) {
         setRO(command + 2, rough, Drough);

      /* Magnetic roughnesses of layers */
      } else if (strncmp(command, "RM", 2) == 0) {
         setMRO(command + 2, mrough, Dmrough);

      /* Theta angle of average moment in layer */
      } else if (strncmp(command, "TH", 2) == 0) {
         setTHE(command + 2, the, Dthe);

      /* Wavelength */
      } else if (strcmp(command, "WL") == 0) {
         setWavelength(&lambda);

      /* Guide angle */
      } else if (strcmp(command, "EPS") == 0) {
         setGuideangle(&aguide);

      /* Number of layers */
      } else if (strcmp(command, "NL") == 0) {
         if (!setNlayer(&nlayer))
         /* Bug found Wed Jun  7 10:38:45 EDT 2000 by KOD */
         /* since it starts at 0, correction for vacuum forces zero */
         for (j = 1; j <= nlayer; j++)
            /* Set all absorptions to non-zero values */
            if (mu[j] < *mu) mu[j] = *mu + 1.e-20;

      /* Add or remove layers */
      } else if (strcmp(command, "AL") == 0 || strcmp(command, "RL") == 0) {
         modifyLayers(command);

      /* Copy layer */
      } else if (strcmp(command, "CL") == 0) {
         copyLayer(command);

      /* Make superlattice */
      } else if (strcmp(command, "SL") == 0) {
         superLayer(command);

      /* Maximum number of layers used to simulate rough interface */
      } else if (strcmp(command, "NR") == 0) {
         if (!setNrough(&nrough)) {
            /* Generate interface profile */
            if (nrough < 3) nrough = 11;
            if (proftyp[0] == 'H')
               gentanh(nrough, zint, rufint);
            else
               generf(nrough, zint, rufint);
         }

      /* Specify error function or hyperbolic tangent profile */
      } else if (strcmp(command, "PR") == 0) {
         setProfile(proftyp, PROFTYPLEN + 2);

      /* Range of Q to be scanned */
      } else if (strcmp(command, "QL") == 0) {
         if (!setQrange(&qmin, &qmax)) {
            qmina = qmin;
            qmaxa = qmax;
            qminb = qmin;
            qmaxb = qmax;
            qminc = qmin;
            qmaxc = qmax;
            qmind = qmin;
            qmaxd = qmax;
         }

      /* Number of points scanned */
      } else if (strcmp(command, "NP") == 0) {
         if (!setNpnts(&npnts)) {
            npntsa = npnts;
            npntsb = npnts;
            npntsc = npnts;
            npntsd = npnts;
         }

      /* File for input data */
      } else if (strcmp(command, "IF") == 0) {
         setFilename(infile, INFILELEN + 2);

      /* File for output data */
      } else if (strcmp(command, "OF") == 0) {
         setFilename(outfile, OUTFILELEN + 2);

      /* File for parameters */
      } else if (strcmp(command, "PF") == 0) {
         setFilename(parfile, PARFILELEN + 2);

      /* Polarization state */
      } else if (strcmp(command, "PS") == 0) {
         setPolstat(polstat, POLSTATLEN + 2);

      /* Beam intensity */
      } else if (strcmp(command, "BI") == 0) {
         setBeamIntens(&bmintns, &Dbmintns);

      /* Background intensity */
      } else if (strcmp(command, "BK") == 0) {
         setBackground(&bki, &Dbki);

      /* Verify parameters by printing out */
      } else if (strncmp(command, "VE", 2) == 0) {
         printLayers(command);

      /* Get data from file */
      } else if (strcmp(command, "GD") == 0) {
         loadData(infile, xspin);

      /* Edit constraints */
      } else if (strcmp(command, "EC") == 0) {
         constrainFunc newmodule;

         newmodule = newConstraints(constrainScript, constrainModule);
         if (newmodule != NULL) Constrain = newmodule;

      /* Reload constrain module */
      } else if (strcmp(command, "LC") == 0) {
         Constrain = loadConstrain(constrainModule);

      /* Unload constrain module */
      } else if (strcmp(command, "ULC") == 0) {
         Constrain = loadConstrain(NULL);

      /* Load parameters from parameter file */
      } else if (strncmp(command, "LP", 2) == 0) {
         loadParms(command, parfile, constrainScript, constrainModule);

      /* Save parameters to parameter file */
      } else if (strcmp(command, "SP") == 0) {
         parms(qcsq, qcmsq, d, dm, rough, mrough, mu, the,
               MAXLAY, &lambda, &lamdel, &thedel, &aguide,
              &nlayer, &qmina, &qmaxa, &npntsa,
              &qminb, &qmaxb, &npntsb, &qminc, &qmaxc, &npntsc,
              &qmind, &qmaxd, &npntsd,
               infile, outfile,
              &bmintns, &bki, listA, &mfit, NA, &nrough, proftyp,
               polstat, DA, constrainScript, parfile, TRUE);

      /* List data and fit */
      } else if (strcmp(command, "LID") == 0) {
         listData();

      /* Generate logarithm of bare (unconvoluted) reflectivity */
      /* or generate reflected amplitude */
      } else if (strcmp(command,"GR") == 0 || strcmp(command, "GA") == 0) {
         genReflect(command);

      /* Generate and display layer profile */
      } else if (
         strcmp(command, "GLP") == 0 ||
         strncmp(command, "SLP", 3) == 0
      ) {
         genProfile(command);

      /* Save values in Q4X and YFIT to OUTFILE */
      } else if (strcmp(command, "SV") == 0) {
         saveTemps(outfile, xspin, y4x, n4x, FALSE);

      /* Save values in Q4X and YFITA to OUTFILE */
      } else if (strcmp(command, "SVA") == 0) {
         saveTemps(outfile, xspin, yfita, n4x, TRUE);

      /* Calculate derivative of reflectivity or spin asymmetry with respect */
      /* to a fit parameter or save a fit to disk file */
      } else if (
         strcmp(command, "RD") == 0 ||
         strcmp(command, "SRF") == 0
      ) {
         printDerivs(command, npnts);

      /* Turn off all varied parameters */
      } else if (strcmp(command, "VANONE") == 0) {
         clearLista(listA);

      /* Specify which parameters are to be varied in the reflectivity fit */
      } else if (strncmp(command, "VA", 2) == 0) {
         varyParm(command);

      /* Calculate chi-squared */
      } else if (
         strcmp(command, "CSR") == 0 ||
         strcmp(command, "CS") == 0
      ) {
         calcChiSq(command);

      /* Fit reflectivity */
      } else if (strncmp(command, "FR", 2) == 0) {
         for (j = 0; j < NA; j++) {
            undoFit[j] = A[j];
            undoFitUnc[j] = DA[j];
         }
         fitReflec(command);

      /* Undo last fit */
      } else if (strcmp(command, "UF") == 0) {
         for (j = 0; j < NA; j++) {
            A[j] = undoFit[j];
            DA[j] = undoFitUnc[j];
         }

      /* Exit */
      } else if (
         strcmp(command, "EX") == 0 ||
         strcmp(command, "EXS") == 0
      ) {
         parms(qcsq, qcmsq, d, dm, rough, mrough, mu, the,
               MAXLAY, &lambda, &lamdel, &thedel, &aguide,
              &nlayer, &qmina, &qmaxa, &npntsa,
              &qminb, &qmaxb, &npntsb, &qminc, &qmaxc, &npntsc,
              &qmind, &qmaxd, &npntsd,
               infile, outfile,
              &bmintns, &bki, listA, &mfit, NA, &nrough, proftyp,
               polstat, DA, constrainScript, parfile, TRUE);
         /* Print elapsed CPU time */
         if (strcmp(command, "EXS") == 0) system("ps");
         exit(0);

      /* Exit without saving changes */
      } else if (strcmp(command, "QU") == 0 || strcmp(command, "QUIT") == 0) {
         exit(0);

      /* Plot reflectivity on screen */
      } else if (strncmp(command, "PRF", 3) == 0) {
         plotfit(command, xspin);

      /* Plot profile on screen */
      } else if (strncmp(command, "PLP", 3) == 0) {
         plotprofile(command, xspin);

      /* Plot movie of reflectivity change from fit */
      } else if (strncmp(command, "MVF", 3) == 0) {
         fitMovie(command, xspin, undoFit);

      /* Plot general movie from data file on screen */
      } else if (strncmp(command, "MVX", 3) == 0) {
         arbitraryMovie(command, xspin);

      /* Plot movie of parameter on screen */
      } else if (strncmp(command, "MV", 2) == 0) {
         oneParmMovie(command, xspin);

      /* Update constraints */
      } else if (strcmp(command, "UC") == 0) {
         genshift(a, TRUE);
         /* constrain(a); */
         (*Constrain)(FALSE, a, nlayer);
         genshift(a, FALSE);

      /* Determine number of points required for resolution extension */
      } else if (strcmp(command, "RE") == 0) {
         calcExtend(xspin);

#if 0 /* Dead code --- shadowed by "CD" command earlier */
      /* Convolute input raw data set with instrumental resolution */
      } else if (strcmp(command, "CD") == 0) {
         calcConvolve(polstat);
#endif

      /* Send data to other processes. */
      } else if (strcmp(command, "SEND") == 0) {
	ipc_send(command);

      /* Receive data to other processes. */
      } else if (strcmp(command, "RECV") == 0) {
	ipc_recv(command);

      /* Faulty input */
      } else
         ERROR("/** Unrecognized command **/");
}
Esempio n. 8
0
void hCheckBox::mousePressed(int xx, int yy, int btn)
{
    toggleSelection();
	bang();
}
Esempio n. 9
0
void pix_noise :: GREYMess(void)
{
    m_mode = GL_LUMINANCE;
    bang();
}
Esempio n. 10
0
void pix_noise :: RGBMess(void)
{
    m_mode = GL_RGB;
    bang();
}
Esempio n. 11
0
void pix_noise :: seed(int seedval)
{
    initRandom(seedval);
    bang();
}
Esempio n. 12
0
void mlayer(void)
{
   static char command[COMMANDLEN+2];
   static double undoFit[NA], undoFitUnc[NA];

   /* Process command */
      while (queryString("mlayer% ", command, COMMANDLEN + 2) == NULL);
      caps(command);

      /* Spawn a command */
      if (strcmp(command, "!") == 0 || strcmp(command, "!!") == 0) {
         bang(command);

      /* Print current directory */
      } else if (strcmp(command, "PWD") == 0) {
         puts(currentDir);

      /* Change current directory */
      } else if (strcmp(command, "CD") == 0) {
         cd(command);

      /* Help */
      } else if (strcmp(command, "?") == 0
		 || strcmp(command, "HE") == 0
		 || strcmp(command, "HELP") == 0) {
         help(command + (*command == '?' ? 1 : 2));

      /* Value of vacuum QCSQ */
      } else if (strcmp(command, "QCV") == 0 || strcmp(command, "VQC") == 0) {
         setVQCSQ(tqcsq);

      /* Value of vacuum linear absorption coefficient */
      } else if (strcmp(command, "MUV") == 0 || strcmp(command, "VMU") == 0) {
         setVMU(tmu);

      /* Wavelength */
      } else if (strcmp(command, "WL") == 0) {
	 double v = lambda;
         if (setWavelength(&lambda)==0 && lambda != v) {
	   /* May need to recalculate Q for the new wavelength */
	   if (theta_offset != 0. && loaded) loadData(infile); 
	 }

      /* Theta offset */
      } else if (strcmp(command, "TO") == 0) {
	 double v = theta_offset;
	 if (setThetaoffset(&theta_offset)==0 && theta_offset != v) {
	   /* May need to recalculate Q for the new theta offset */
	   if (loaded) loadData(infile); 
	 }

      /* Number of layers */
      } else if (
         strcmp(command, "NTL") == 0 ||
         strcmp(command, "NML") == 0 ||
         strcmp(command, "NBL") == 0
      ) switch (command[1]) {
         case 'T':
            setNLayer(&ntlayer);
            break;
         case 'M':
            setNLayer(&nmlayer);
            break;
         case 'B':
            setNLayer(&nblayer);
            break;

      /* Add or remove layers */
      } else if (
         strcmp(command, "ATL") == 0 ||
         strcmp(command, "AML") == 0 ||
         strcmp(command, "ABL") == 0 ||
         strcmp(command, "RTL") == 0 ||
         strcmp(command, "RML") == 0 ||
         strcmp(command, "RBL") == 0
      ) {
         modifyLayers(command);

      /* Copy layer */
      } else if (strcmp(command, "CL") == 0) {
         copyLayer(command);

      /* Maximum number of layers used to simulate rough interface */
      } else if (
         strcmp(command, "NR") == 0 &&
         !setNRough(&nrough)
      ) {
         /* Generate interface profile */
         if (nrough < 3) nrough = 11;
         if (*proftyp == 'H')
            gentanh(nrough, zint, rufint);
         else
            generf(nrough, zint, rufint);

      /* Specify error function or hyperbolic tangent profile */
      } else if (strcmp(command, "PR") == 0) {
         setProfile(proftyp, PROFTYPLEN + 2);

      /* Number of layers in multilayer */
      } else if (strcmp(command, "NMR") == 0) {
         setNrepeat(&nrepeat);

      /* Range of Q to be scanned */
      } else if (strcmp(command, "QL") == 0) {
         setQrange(&qmin, &qmax);

      /* Number of points scanned */
      } else if (strcmp(command, "NP") == 0) {
         setNpnts();

      /* File for input data */
      } else if (strcmp(command, "IF") == 0) {
         setFilename(infile, INFILELEN + 2);

      /* File for output data */
      } else if (strcmp(command, "OF") == 0) {
         setFilename(outfile, OUTFILELEN + 2);

      /* File for parameters */
      } else if (strcmp(command, "PF") == 0) {
         setFilename(parfile, PARFILELEN + 2);

      /* Delta lambda */
      } else if (strcmp(command, "DL") == 0) {
         setLamdel(&lamdel);

      /* Delta theta */
      } else if (strcmp(command, "DT") == 0) {
         setThedel(&thedel);

      /* Beam intensity */
      } else if (strcmp(command, "BI") == 0) {
         setBeamIntens(&bmintns, &Dbmintns);

      /* Background intensity */
      } else if (strcmp(command, "BK") == 0) {
         setBackground(&bki, &Dbki);

      /* Verify parameters by printing out */
      } else if (
         strncmp(command, "TVE", 3) == 0 ||
         strncmp(command, "MVE", 3) == 0 ||
         strncmp(command, "BVE", 3) == 0 ||
         strncmp(command, "VE", 2) == 0
      ) {
         printLayers(command);

      /* Get data from file */
      } else if (strcmp(command, "GD") == 0) {
         loadData(infile);

      /* Edit constraints */
      } else if (strcmp(command, "EC") == 0) {
         constrainFunc newmodule;

         newmodule = newConstraints(constrainScript, constrainModule);
         if (newmodule != NULL) Constrain = newmodule;

      /* Reload constrain module */
      } else if (strcmp(command, "LC") == 0) {
         Constrain = loadConstrain(constrainModule);

      /* Unload constrain module */
      } else if (strcmp(command, "ULC") == 0) {
         Constrain = loadConstrain(NULL);

      /* Load parameters from parameter file */
      } else if (strncmp(command, "LP", 2) == 0) {
         loadParms(command, &npnts, parfile, constrainScript, constrainModule);

      /* Save parameters to parameter file */
      } else if (strcmp(command, "SP") == 0) {
         parms(tqcsq, mqcsq, bqcsq, tqcmsq, mqcmsq, bqcmsq, td, md, bd,
               trough, mrough, brough, tmu, mmu, bmu,
               MAXLAY, &lambda, &lamdel, &thedel, &theta_offset,
               &ntlayer, &nmlayer, &nblayer, &nrepeat, &qmin, &qmax, &npnts,
               infile, outfile,
               &bmintns, &bki, listA, &mfit, NA, &nrough, proftyp,
               DA, constrainScript, parfile, TRUE);

      /* List data and fit */
      } else if (strcmp(command, "LID") == 0) {
         listData();

      /* Generate logarithm of bare (unconvoluted) reflectivity */
      } else if (strcmp(command, "GR") == 0 || strcmp(command, "SA") == 0) {
         genReflect(command);

      /* Generate and display layer profile used for roughness */
      } else if (strcmp(command, "GLP") == 0) {
         genProfile();

      /* Save layer profile to OUTFILE */
      } else if (
         strcmp(command, "SLP") == 0 ||
         strcmp(command, "SSP") == 0
      ) {
         saveProfile(command);

      /* Save values in XTEMP and YTEMP to OUTFILE */
      } else if (strcmp(command, "SV") == 0) {
         saveTemps(outfile);

      /* Calculate derivative of reflectivity or spin asymmetry with respect
         to a fit parameter or save a fit to disk file */
      } else if (
         strcmp(command, "RD") == 0 ||
         strcmp(command, "RSD") == 0 ||
         strcmp(command, "SRF") == 0 ||
         strcmp(command, "SRSF") == 0
      ) {
         printDerivs(command);

      /* Turn off all varied parameters */
      } else if (strcmp(command, "VANONE") == 0) {
         clearLista(listA);

      /* Specify which parameters are to be varied in the reflectivity fit */
      } else if (strncmp(command, "VA", 2) == 0) {
         varyParm(command);

      /* Calculate chi-squared */
      } else if (strcmp(command, "CSR") == 0 || strcmp(command, "CSRS") == 0) {
         printChiSq(command);

      /* Fit five-layer reflectivity */
      } else if (strncmp(command, "FR", 2) == 0) {
         register int n;

         for (n = 0; n < NA; n++) {
            undoFit[n] = A[n];
            undoFitUnc[n] = DA[n];
         }
         fitReflec(command);

      /* Undo last fit */
      } else if (strcmp(command, "UF") == 0) {
         register int n;

         for (n = 0; n < NA; n++) {
            A[n] = undoFit[n];
            DA[n] = undoFitUnc[n];
         }

      /* Exit */
      } else if (strcmp(command, "EX") == 0) {
         parms(tqcsq, mqcsq, bqcsq, tqcmsq, mqcmsq, bqcmsq, td, md, bd,
               trough, mrough, brough, tmu, mmu, bmu,
               MAXLAY, &lambda, &lamdel, &thedel, &theta_offset,
               &ntlayer, &nmlayer, &nblayer, &nrepeat, &qmin, &qmax, &npnts,
               infile, outfile,
               &bmintns, &bki, listA, &mfit, NA, &nrough, proftyp,
               DA, constrainScript, parfile, TRUE);
         exit(0);

      /* Exit without saving changes */
      } else if (strcmp(command, "QU") == 0 || strcmp(command, "QUIT") == 0) {
         exit(0);

      /***** Start new ************** */

      /* Plot reflectivity on screen */
      } else if (strncmp(command, "PRF", 3) == 0) {
         plotfit(command);

      /* Plot profile on screen */
      } else if (strcmp(command, "PLP") == 0) {
      /* Generate profile */
         plotprofile(command);

      /* Send data to other processes. */
      } else if (strcmp(command, "SEND") == 0) {
	ipc_send(command);

      /* Receive data to other processes. */
      } else if (strcmp(command, "RECV") == 0) {
	ipc_recv(command);

      /* Plot movie of reflectivity change from fit */
      } else if (strncmp(command, "MVF", 3) == 0) {
         fitMovie(command, undoFit);

      /* Plot general movie from data file on screen */
      } else if (strncmp(command, "MVX", 3) == 0) {
         arbitraryMovie(command);

      /* Plot movie of parameter on screen */
      } else if (strncmp(command, "MV", 2) == 0) {
         oneParmMovie(command);

      /* Update constraints */
      } else if (strcmp(command, "UC") == 0) {
         genshift(a, TRUE);
         /* constrain(a); */
         (*Constrain)(FALSE, a, ntlayer, nmlayer, nrepeat, nblayer);
         genshift(a, FALSE);

      /* Enter critical Q squared */
      /* or */
      /* Top length absorption coefficient */
      /* or */
      /* Thicknesses of top layers */
      /* or */
      /* Roughnesses of top layers */

      } else {
         static char *paramcom[] = {"QC", "MU", "D", "RO"};
         static double  *top[] = { tqcsq,  tmu,  td,  trough};
         static double  *mid[] = { mqcsq,  mmu,  md,  mrough};
         static double  *bot[] = { bqcsq,  bmu,  bd,  brough};
         static double *Dtop[] = {Dtqcsq, Dtmu, Dtd, Dtrough};
         static double *Dmid[] = {Dmqcsq, Dmmu, Dmd, Dmrough};
         static double *Dbot[] = {Dbqcsq, Dbmu, Dbd, Dbrough};
         static int (*store[])(int, double *, double *) = {
            setQCSQ, setMU, setD, setRO
         };
         int param, code = -1;

         for (param = 0; param < sizeof(paramcom) / sizeof(paramcom[0]); param++) {
            code = fetchLayParam(command, paramcom[param], top[param],
               mid[param], bot[param], Dtop[param], Dmid[param], Dbot[param],
               store[param]);
            if (code > -1) break;
         }
         if (code == -1)
            ERROR("/** Unrecognized command: %s **/\n", command);
      }
}
Esempio n. 13
0
void gemsdlwindow :: doRender()
{
  // FIXME: ?????
  bang();
}
Esempio n. 14
0
static void runs (void)
{   /*{{{*/
    unsigned int     a       = 0;
    int              n1      = 0, n2 = 0, meanruns = 0;
    int              lastdir = 0;
    double           mua, sigmaa2, Zzeroa, Zzerob, mub, sigmab2;
    double           sum    = 0.0, mean, chisquare;
    unsigned int     *runlengths, maxrun = 0;
    int             rl;
    double         **oi;
    size_t           i;
    double *restrict A = malloc(sizeof(double) * ITER);

    iprintf("\nRuns Test:\n");
    for (i = 0; i < ITER; ++i) {
        A[i] = qtimer_fastrand();
        sum += A[i];
        if (i > 0) {
            if (A[i] > A[i - 1]) {
                if (lastdir == -1) {
                    ++a;
                }
                lastdir = 1;
            } else {
                if (lastdir == 1) {
                    ++a;
                }
                lastdir = -1;
            }
        }
    }
    mean = sum / (double)ITER;
    for (i = 0; i < ITER; ++i) {
        if (A[i] > mean) {
            n1++;
        } else {
            n2++;
        }
    }
    lastdir = (A[0] > mean) ? 1 : -1;
    for (i = 1; i < ITER; ++i) {
        if (A[i] > mean) {
            if (lastdir == -1) {
                meanruns++;
            }
            lastdir = 1;
        } else {
            if (lastdir == 1) {
                meanruns++;
            }
            lastdir = -1;
        }
    }
    mua     = ((2.0 * ITER) - 1.0) / 3.0;
    sigmaa2 = ((16.0 * ITER) - 29.0) / 90.0;
    Zzeroa  = (a - mua) / sigmaa2;
    mub     = ((2.0 * n1 * n2) / (double)ITER) + 0.5;
    sigmab2 = (2.0 * n1 * n2 * ((2.0 * n1 * n2) - ITER)) / (double)(ITER * ITER * (ITER - 1));
    Zzerob  = (meanruns - mub) / sqrt(sigmab2);

    runlengths     = (unsigned int *)calloc(sizeof(unsigned int), ITER);
    rl             = 0;
    runlengths[rl] = 1;
    lastdir        = 1;
    maxrun         = 0;
    for (i = 1; i < ITER; ++i) {
        if (A[i] > A[i - 1]) {
            if (lastdir == -1) {
                if (maxrun < runlengths[rl]) {
                    maxrun = runlengths[rl];
                }
                rl++;
            }
            lastdir = 1;
            runlengths[rl]++;
        } else {
            if (lastdir == 1) {
                if (maxrun < runlengths[rl]) {
                    maxrun = runlengths[rl];
                }
                ++rl;
            }
            lastdir = -1;
            runlengths[rl]++;
        }
    }
    oi = malloc(sizeof(double *) * 3);
    assert(oi);
    oi[0] = calloc(sizeof(double), maxrun);
    oi[1] = calloc(sizeof(double), maxrun);
    oi[2] = calloc(sizeof(double), maxrun);
    /* count the observed runs */
    for (i = 0; i < a; ++i) {
        oi[0][runlengths[i] - 1]++;
    }
    /* expected run calculation */
    for (i = 0; i < maxrun; ++i) {
        if (i <= ITER - 2) {
            oi[1][i] = (2.0 / bang(i + 3.0)) * (ITER * (i * i + 3 * i + 1) - (i * i * i + 3 * i * i - i - 4));
        } else {
            oi[1][i] = 2.0 / bang(ITER);
        }
    }
    /* insert expectation value combining here, start from high-end */
    if (maxrun > 2) {
        for (i = maxrun - 1; i > 0; --i) {
            if (oi[1][i] < 5) {
                size_t j;
                oi[1][i - 1] += oi[1][i];
                // oi[2][i-1] += oi[2][i];
                for (j = i; j + 1 < maxrun; ++j) {
                    oi[1][j] = oi[1][j + 1];
                    // oi[2][j] = oi[1][j+1];
                }
                maxrun--;
            }
        }
    }
    /* calc chisquare parts */
    for (i = 0; i < maxrun; ++i) {
        oi[2][i] = ((oi[0][i] - oi[1][i]) * (oi[0][i] - oi[1][i])) / oi[1][i];
    }
    /* count up chisquare sum */
    chisquare = 0.0;
    for (i = 0; i < maxrun; ++i) {
        chisquare += oi[2][i];
    }

    iprintf("       runs with alpha 0.05: %s\n", (Zzeroa >= -1.96 && Zzeroa <= 1.96) ? "Passed" : "Failed");
    iprintf("  mean runs with alpha 0.05: %s\n", (Zzerob >= -1.96 && Zzerob <= 1.96) ? "Passed" : "Failed");
    iprintf("run lengths with alpha 0.05: %s\n", (chisquare < chisquare_alphafive(maxrun - 1)) ? "Passed" : "Failed");
    free(oi[2]);
    free(oi[1]);
    free(oi[0]);
    free(oi);
    free(runlengths);
    free(A);
} /*}}}*/
Esempio n. 15
0
// Returns the next token in the character stream.
// If no next token can be identified, an error
// is emitted and we return the error token.
Token
Lexer::scan()
{
  // Keep consuming characters until we find
  // a token.
  while (true) {
    space();

    // Update the position of the current source location.
    // This denotes the beginning of the current token.
    loc_ = in_.location();

    switch (peek()) {
      case 0: return eof();

      case '{': return lbrace();
      case '}': return rbrace();
      case '(': return lparen();
      case ')': return rparen();
      case '[': return lbrack();
      case ']': return rbrack();
      case ',': return comma();
      case ':': return colon();
      case ';': return semicolon();
      case '.': return dot();
      case '+': return plus();
      case '-': return minus();
      case '*': return star();

      case '/':
        get();
        if (peek() == '/') {
          comment();
          continue;
        } else {
          return slash();
        }

      case '%': return percent();
      case '=': return equal();
      case '!': return bang();
      case '<': return langle();
      case '>': return rangle();
      case '&': return ampersand();
      case '|': return bar();
      case '^': return hat();

      case '0':
        // if the next character is a 'b' then this
        // is a binary literal
        if (peek(1) == 'b')
          return binary_integer();
        // if the next character is an 'x' then this
        // is a hexadecimal integer
        if (peek(1) == 'x')
          return hexadecimal_integer();
        // otherwise proceed to regular integer lexing
      case '1': case '2': case '3': case '4':
      case '5': case '6': case '7': case '8': case '9':
        return integer();

      case 'a': case 'b': case 'c': case 'd': case 'e':
      case 'f': case 'g': case 'h': case 'i': case 'j':
      case 'k': case 'l': case 'm': case 'n': case 'o':
      case 'p': case 'q': case 'r': case 's': case 't':
      case 'u': case 'v': case 'w': case 'x': case 'y':
      case 'z':
      case 'A': case 'B': case 'C': case 'D': case 'E':
      case 'F': case 'G': case 'H': case 'I': case 'J':
      case 'K': case 'L': case 'M': case 'N': case 'O':
      case 'P': case 'Q': case 'R': case 'S': case 'T':
      case 'U': case 'V': case 'W': case 'X': case 'Y':
      case 'Z':
      case '_':
        return word();

      case '\'': return character();
      case '"': return string();

      default:
        return error();
    }
  }
}
Esempio n. 16
0
int main(void) {
    gpgme_check_version (NULL);

    gpgme_error_t err;
    gpgme_data_t plain, cipher;
    gpgme_ctx_t ctx;
    gpgme_key_t recp[2] = { NULL, NULL };
    gpgme_encrypt_flags_t flags = GPGME_ENCRYPT_ALWAYS_TRUST;

    char *plaintext = "foo bar\0";
    char *fp = "845B80B9AD12DB400CE534F6837EED10F97A36A1";
    char *result_file = "./result.gpg";
    char *verify_file = "./result";
    size_t max_buflen = 2048, buflen;
    char *buf = malloc(max_buflen * sizeof(char));
    FILE *fh = NULL;

    err = gpgme_new (&ctx);
    if(err) return bang (err);

    gpgme_set_armor (ctx, 1);

    err = gpgme_get_key (ctx, fp, &recp[0], 0);
    if(err) return bang (err);

    err = gpgme_data_new_from_mem (&plain, plaintext, strlen(plaintext), 0);
    if(err) return bang (err);

    err = gpgme_data_new (&cipher);
    if(err) return bang (err);

    err = gpgme_op_encrypt (ctx, recp, flags, plain, cipher);
    if(err) return bang (err);

    gpgme_data_seek(cipher, 0, SEEK_SET);
    buflen = gpgme_data_read(cipher, buf, max_buflen);
    if (1 > buflen || buflen == max_buflen)
        return bang_ ("Failed to read ciphertext");

    fh = fopen(result_file, "w");
    if(!fh) bang_ ("failed to open result_file");

    fwrite(buf, sizeof(char), buflen, fh);
    fclose(fh);
    fh = NULL;

    memset(buf, 0, max_buflen);
    snprintf(buf, max_buflen-1, "gpg --output %s -d %s", verify_file, result_file);
    system(buf);

    memset(buf, 0, max_buflen);
    fh = fopen(verify_file, "rb");
    if(!fh) return bang_ ("failed to open verify_file");

    buflen = fread(buf, sizeof(char), max_buflen, fh);
    fclose(fh);

    if(buflen < 1 || buflen == max_buflen)
        return bang_ ("Failed to read result file");

    #ifdef INSERT_FAILURE
    buf[buflen-1] = '\0';
    #endif

    if (strncmp(buf, plaintext, strlen(plaintext)) != 0)
        return bang_ ("Decrypted text is different from original plaintext");

    return 0;
}