Esempio n. 1
0
Exec_stat MCVariableValue::fetch(MCExecPoint& ep, bool p_copy)
{
	switch(get_type())
	{
	case VF_UNDEFINED:
		ep . setboth("", 0.0);
	break;

	case VF_STRING:
		assert(is_string());
		ep . setsvalue(get_string());
		if (p_copy)
			ep . grabsvalue();
	break;

	case VF_NUMBER:
		ep . setnvalue(get_real());
	break;

	case VF_BOTH:
		ep . setboth(get_string(), get_real());
		if (p_copy)
			ep . grabsvalue();
	break;

	case VF_ARRAY:
		if (!p_copy)
			ep . setarray(this, False);
		else
			ep . setarray(new MCVariableValue(*this), True);
	break;
	}

	return ES_NORMAL;
}
Esempio n. 2
0
void test_align() {
    {
        const std::size_t size = 1;
        const std::size_t alignment = 1;
        const std::size_t real_size = need_alloc(size, alignment);
        void *real = malloc(real_size);
        assert(real != nullptr);
        void *result = align(real, alignment);
        assert(reinterpret_cast<std::size_t>(result) % alignment == 0);
        assert(get_real(result) == real);
        assert(reinterpret_cast<char *>(real) + real_size >= reinterpret_cast<char *>(result) + size);
        free(real);
    }
    {
        const std::size_t size = sizeof(void *);
        const std::size_t alignment = 1;
        const std::size_t real_size = need_alloc(size, alignment);
        void *real = malloc(real_size);
        assert(real != nullptr);
        void *result = align(real, alignment);
        assert(reinterpret_cast<std::size_t>(result) % alignment == 0);
        assert(get_real(result) == real);
        assert(reinterpret_cast<char *>(real) + real_size >= reinterpret_cast<char *>(result) + size);
        free(real);
    }
    {
        const std::size_t size = sizeof(void *);
        const std::size_t alignment = sizeof(void *);
        const std::size_t real_size = need_alloc(size, alignment);
        void *real = malloc(real_size);
        assert(real != nullptr);
        void *result = align(real, alignment);
        assert(reinterpret_cast<std::size_t>(result) % alignment == 0);
        assert(get_real(result) == real);
        assert(reinterpret_cast<char *>(real) + real_size >= reinterpret_cast<char *>(result) + size);
        free(real);
    }
    {
        const std::size_t size = sizeof(void *);
        const std::size_t alignment = sizeof(void *) + 1;
        const std::size_t real_size = need_alloc(size, alignment);
        void *real = malloc(real_size);
        assert(real != nullptr);
        void *result = align(real, alignment);
        assert(reinterpret_cast<std::size_t>(result) % alignment == 0);
        assert(get_real(result) == real);
        assert(reinterpret_cast<char *>(real) + real_size >= reinterpret_cast<char *>(result) + size);
        free(real);
    }
}
Esempio n. 3
0
int Jenarix::colorsphere( jx_ob ob )
{

    GLdouble xyz[3], r, rgb[3];
    unsigned int ixyz = 0;
    unsigned int irgb = 1;
    unsigned int irad = 2;
    assert (jx_list_check(ob));
    int nval = jx_list_size(ob);
    //printf ("%d sphere\n", nval);

    for ( int index = 0; index < nval; ++index ) {
      jx_ob xyz_rgb_rad = jx_list_shift(ob);
      glPushMatrix();
      //printf ("%d\n", value[index].size());
      get_point(jx_list_get(xyz_rgb_rad, ixyz), xyz);
      glTranslated(xyz[0], xyz[1], xyz[2]);
      get_point(jx_list_get(xyz_rgb_rad, irgb), rgb);
      color(rgb[0], rgb[1], rgb[2], 0.0);
      GLUquadricObj* quadric = gluNewQuadric();
      gluQuadricDrawStyle(quadric, GLU_FILL);
      gluQuadricOrientation(quadric, GLU_OUTSIDE);
      gluQuadricNormals(quadric, GLU_SMOOTH);
      //printf ("%f %f %f\n", xyz[0], xyz[1], xyz[2]);
      r = get_real(jx_list_get(xyz_rgb_rad, irad));
      gluSphere(quadric, r, 20, 20);
      //printf ("%f\n", r);
      gluDeleteQuadric(quadric);
      glPopMatrix();
    }

   return nval;
}
Esempio n. 4
0
void print_object(pointer P, symbol_table* table)
{
    FILE* out = stdout;
    if(P == NIL)
    {
        fputs("NIL", out);
        return;
    }

    switch(get_type_id(P))
    {
    case DT_Pair:
        if(is_type(pair_car(P), DT_Pair))
        {
            putc('(', out);
            print_object(pair_car(P), table);
            putc(')', out);
        }
        else
            print_object(pair_car(P), table);

        putc(' ', out);
        if(pair_cdr(P) != NIL)
        {
            if(!is_type(pair_cdr(P), DT_Pair))
                fputs(". ", out);

            print_object(pair_cdr(P), table);
        }
        break;
    case DT_Symbol:
        fputs(string_from_symbol(table, *get_symbol(P)), out);
        break;
    case DT_Int:
        fprintf(out, "%d", get_int(P));
        break;
    case DT_Real:
        fprintf(out, "%f", get_real(P));
        break;
    case DT_String:
        fputs(get_string(P), out);
        break;
    case DT_Char:
        putc(get_char(P), out);
        break;
    case DT_TypeInfo:
        print_typeinfo(P, table, out);
        break;
    case DT_Invalid:
        fputs("#INVALID#", out);
        break;
    case DT_Any:
        fputs("#ANY#", out);
        break;
    }
}
Esempio n. 5
0
int get_point( jx_ob ob, GLdouble xyz[3] ) {

    assert (jx_list_check(ob));
    assert (jx_list_size(ob) == 3);
    for (unsigned int index=0; index < 3; ++index) {
      xyz[index] = get_real(jx_list_shift(ob));
    }

  return 3;
}
Esempio n. 6
0
void zerophase(int window_size, void* args, Spectra source,
               Spectra result) {
    gsl_rng* r = gsl_rng_alloc(gsl_rng_default);

    int i;
    for (i = 0; i < window_size / 2 + 1; i++) {
        set_by_polar(result, i, get_magnitude(source, i),
                     gsl_rng_uniform (r) * 2 * M_PI);
        fprintf(stderr, "%f\n", get_phase(result, i));
        if (i > 0 && i < window_size / 2) {
            set_value(result, window_size - i, get_real(result, i),
                      get_imag(result, i));
        }
    }
}
Esempio n. 7
0
int Jenarix::cylinder( jx_ob ob) 
{
    GLdouble bxyz[3], txyz[3], r;
    GLdouble dx, dy, dz, h;

    unsigned int ibxyz = 0;
    unsigned int itxyz = 1;
    unsigned int irad = 2;
    assert (jx_list_check(ob));
    int nval = jx_list_size(ob);
    //printf ("%d cylinder\n", nval);
    for ( int index = 0; index < nval; ++index ) {
      jx_ob base_tip_rad = jx_list_shift(ob);
      //printf ("%d\n", value[index].size());
      get_point(jx_list_get(base_tip_rad,ibxyz), bxyz);
      //printf ("%f %f %f\n", bxyz[0], bxyz[1], bxyz[2]);
      get_point(jx_list_get(base_tip_rad,itxyz), txyz);
      //printf ("%f %f %f\n", txyz[0], txyz[1], txyz[2]);
      dx = txyz[0] - bxyz[0];
      dy = txyz[1] - bxyz[1];
      dz = txyz[2] - bxyz[2];
      h = sqrt(dx*dx + dy*dy + dz*dz);
      glPushMatrix();
      align_from_z(bxyz, txyz);
      GLUquadricObj* quadric = gluNewQuadric();
      gluQuadricDrawStyle(quadric, GLU_FILL);
      gluQuadricOrientation(quadric, GLU_OUTSIDE);
      gluQuadricNormals(quadric, GLU_SMOOTH);
      r = get_real(jx_list_get(base_tip_rad, irad));
      //printf ("%f\n", r);
      gluCylinder(quadric, r, r, h, 20, 20);
      gluDeleteQuadric(quadric);
      glPopMatrix();
    }

    return nval;
}
Esempio n. 8
0
int print_histograms (IO_BUFFER *iobuf)
{
   int mhisto, ihisto, rc, ncounts;
   char title[256];
   char type, cdummy;
   long ident;
   unsigned long entries=0, tentries=0;
   int nbins=0, nbins_2d=0, ibin;
   double content=0., content_inside=0.;
   int ls;
   IO_ITEM_HEADER item_header;
   
   if ( iobuf == (IO_BUFFER *) NULL )
      return -1;

   item_header.type = 100;
   if ( (rc = get_item_begin(iobuf,&item_header)) != 0 )
      return rc;
   printf("Histogram block, version %d, size %ld:\n", 
      item_header.version, iobuf->item_length[iobuf->item_level-1]);

   if ( item_header.version < 1 || item_header.version > 2 )
   {
      Warning("Wrong version no. of histogram data to be read");
      return -1;
   }

   mhisto = get_short(iobuf);

   for (ihisto=0; ihisto<mhisto; ihisto++)
   {
      type = (char) get_byte(iobuf);
      if ( (ls = get_string(title,sizeof(title)-1,iobuf)) % 2 == 0 )
         cdummy = get_byte(iobuf); // Compiler may warn about it but this is OK.
      if ( ls < 0 )
         ls = 0;
      else if ( (size_t) ls >= sizeof(title) )
         ls = sizeof(title)-1;
      title[ls] = '\0'; /* Make sure title is properly truncated */
      ident = get_long(iobuf);
      nbins = (int) get_short(iobuf);
      nbins_2d = (int) get_short(iobuf);
      entries = (uint32_t) get_long(iobuf); /* 32 bit number */
      tentries = (uint32_t) get_long(iobuf);
      (void) get_long(iobuf);
      (void) get_long(iobuf);

      // printf("   Histogram %ld of type %c with %dx%d bins and %lu/%lu entries: %s\n",
      //   ident, type,  nbins, nbins_2d, tentries, entries, title);

      if ( type == 'R' || type == 'r' || type == 'F' || type == 'D' )
      {
         (void) get_real(iobuf);
         (void) get_real(iobuf);
         (void) get_real(iobuf);
         (void) get_real(iobuf);
      }
      else if ( type == 'I' || type == 'i' )
      {
         (void) get_long(iobuf);
         (void) get_long(iobuf);
         (void) get_long(iobuf);
         (void) get_long(iobuf);
      }
      else
      {
         printf("   Histogram %ld of type %c with %dx%d bins and %ld/%ld entries: %s\n",
            ident, type,  nbins, nbins_2d, tentries, entries, title);
         Warning("Invalid histogram type");
         return -1;
      }
      if ( nbins_2d > 0 )
      {
         (void) get_long(iobuf);
         (void) get_long(iobuf);
         if ( type == 'R' || type == 'r' || type == 'F' || type == 'D' )
         {
            (void) get_real(iobuf);
            (void) get_real(iobuf);
            (void) get_real(iobuf);
            (void) get_real(iobuf);
         }
         else
         {
            (void) get_long(iobuf);
            (void) get_long(iobuf);
            (void) get_long(iobuf);
            (void) get_long(iobuf);
         }
         ncounts = nbins * nbins_2d;
      }
      else
         ncounts = nbins;

      /* Don't attempt to allocate histograms without data. */
      if ( ncounts <= 0 )
      {
         printf("   Histogram %ld of type %c with %dx%d bins and %lu/%lu entries: %s\n      HAS NO CONTENTS!\n",
            ident, type,  nbins, nbins_2d, tentries, entries, title);
         continue;
      }

      if ( type == 'F' || type == 'D' )
      {
         content = get_real(iobuf);
         content_inside = get_real(iobuf);
         for (ibin=0; ibin<8; ibin++ )
            (void) get_real(iobuf); /* content_outside... in histogram extension */
      }
      if ( tentries > 0 )
         for (ibin=0; ibin<ncounts; ibin++)
            (void) get_long(iobuf); /* long and real is the same length */

      if ( type == 'F' || type == 'D' )
         printf("   Histogram %ld of type %c with %dx%d bins and %lu/%lu entries (contents: %g/%g): %s\n",
            ident, type,  nbins, nbins_2d, tentries, entries, content_inside, content, title);
      else
         printf("   Histogram %ld of type %c with %dx%d bins and %lu/%lu entries: %s\n",
            ident, type,  nbins, nbins_2d, tentries, entries, title);
   }

   if ( (rc = get_item_end(iobuf,&item_header)) != 0 )
      return rc;

   return(mhisto);
}
Esempio n. 9
0
int read_histograms_x (HISTOGRAM **phisto, int nhisto, const long *xcld_ids, int nxcld, IO_BUFFER *iobuf)
{
   int mhisto, ihisto, rc, ncounts;
   char title[256];
   char type, cdummy;
   long ident;
   double rlower[2] = {0., 0.}, rupper[2] = {0., 0.}, 
          rsum[2] = {0., 0.}, rtsum[2] = {0., 0.};
   long ilower[2] = {0,0}, iupper[2] = {0,0}, isum[2] = {0,0}, itsum[2] = {0,0};
   long entries=0, tentries=0, underflow[2] = {0,0}, overflow[2] = {0,0};
   int nbins=0, nbins_2d=0, ibin, mbins[2] = {0,0};
   HISTOGRAM *thisto=NULL, *ohisto=NULL;
   IO_ITEM_HEADER item_header;
   int adding = 0;
   
   if  ( nhisto < 0 )
   {
      adding = 1;
      nhisto = -nhisto;
   }

   if ( iobuf == (IO_BUFFER *) NULL )
      return -1;

   item_header.type = 100;
   if ( (rc = get_item_begin(iobuf,&item_header)) != 0 )
      return rc;

   if ( item_header.version < 1 || item_header.version > 2 )
   {
      Warning("Wrong version no. of histogram data to be read");
      return -1;
   }
// fprintf(stderr,"Read histograms called, with %d histograms excluded\n",nxcld);
   mhisto = get_short(iobuf);

   for (ihisto=0; ihisto<mhisto; ihisto++)
   {
      int add_this = 0, exclude_this = 0;
      type = (char) get_byte(iobuf);
      if ( get_string(title,sizeof(title)-1,iobuf) % 2 == 0 )
         cdummy = get_byte(iobuf); // Compiler may warn about it but this is OK.
      ident = get_long(iobuf);
      nbins = (int) get_short(iobuf);
      nbins_2d = (int) get_short(iobuf);
      entries = (uint32_t) get_long(iobuf);
      tentries = (uint32_t) get_long(iobuf);
      underflow[0] = (uint32_t) get_long(iobuf);
      overflow[0] = (uint32_t) get_long(iobuf);
      if ( type == 'R' || type == 'r' || type == 'F' || type == 'D' )
      {
         rlower[0] = get_real(iobuf);
         rupper[0] = get_real(iobuf);
         rsum[0] = get_real(iobuf);
         rtsum[0] = get_real(iobuf);
      }
      else
      {
         ilower[0] = get_long(iobuf);
         iupper[0] = get_long(iobuf);
         isum[0] = get_long(iobuf);
         itsum[0] = get_long(iobuf);
      }
      if ( nbins_2d > 0 )
      {
         underflow[1] = (uint32_t) get_long(iobuf);
         overflow[1] = (uint32_t) get_long(iobuf);
         if ( type == 'R' || type == 'r' || type == 'F' || type == 'D' )
         {
            rlower[1] = get_real(iobuf);
            rupper[1] = get_real(iobuf);
            rsum[1] = get_real(iobuf);
            rtsum[1] = get_real(iobuf);
         }
         else
         {
            ilower[1] = get_long(iobuf);
            iupper[1] = get_long(iobuf);
            isum[1] = get_long(iobuf);
            itsum[1] = get_long(iobuf);
         }
         ncounts = nbins * nbins_2d;
      }
      else
         ncounts = nbins;

      /* Don't attempt to allocate histograms without data. */
      if ( ncounts <= 0 )
         continue;

      if ( xcld_ids != (const long *) NULL && nxcld > 0 )
      {
         int ixcld;
         for ( ixcld=0; ixcld<nxcld && xcld_ids[ixcld] > 0; ixcld++ )
         {
            if ( xcld_ids[ixcld] == ident )
            {
               exclude_this = 1;
               break;
            }
         }
      }

      /* If the histogram has a numerical identifier delete a */
      /* previously existing histogram with the same identifier. */
      ohisto = NULL;
      if ( ident != 0 )
      {
         if ( (ohisto=get_histogram_by_ident(ident)) !=
               (HISTOGRAM *)NULL )
         {
            if ( adding && ! exclude_this )
               add_this = 1;
            else
               free_histogram(ohisto);
         }
      }

      /* (Re-) Allocate the new histogram according to its type. */
      thisto = NULL;
      // if ( ! exclude_this ) /* Would really exclude all histograms of this ID but we just don't want to add it up */
      {
         if ( nbins_2d > 0 )
         {
            if ( type == 'R' || type == 'r' )
               thisto = alloc_2d_real_histogram(rlower[0],rupper[0],nbins,
                   rlower[1],rupper[1],nbins_2d);
            else if ( type == 'F' || type == 'D' )
            {
               mbins[0] = nbins;
               mbins[1] = nbins_2d;
               thisto = allocate_histogram(&type,2,rlower,rupper,mbins);
            }
            else
               thisto = alloc_2d_int_histogram(ilower[0],iupper[0],nbins,
                   ilower[1],iupper[1],nbins_2d);
         }
         else
         {
            if ( type == 'R' || type == 'r' )
               thisto = alloc_real_histogram(rlower[0],rupper[0],nbins);
            else if ( type == 'F' || type == 'D' )
               thisto = allocate_histogram(&type,1,rlower,rupper,&nbins);
            else
               thisto = alloc_int_histogram(ilower[0],iupper[0],nbins);
         }
      }
      
      /* If the allocation failed or the histogram should be excluded, skip the histogram contents. */
      /* This should guarantee that reading the input doesn't get */
      /* confused when there is not enough memory available to allocate */
      /* a histogram. The drawback is that, so far, there is no failure */
      /* indicator for the caller. */
      if ( thisto == (HISTOGRAM *) NULL )
      {
         if ( type == 'F' || type == 'D' )
            for (ibin=0; ibin<10; ibin++ )
               (void) get_real(iobuf); /* contents... in histogram extension */
         if ( tentries > 0 )
            for (ibin=0; ibin<ncounts; ibin++)
               (void) get_long(iobuf); /* long and real is the same length */
         continue;
      }
      else
         thisto->type = type;

      /* Give the histogram its title and identifier. */
      if ( *title )
         describe_histogram(thisto,title,add_this?0:ident);

#ifdef _REENTRANT
      histogram_lock(thisto);
#endif

      /* Set the values for histogram statistics. */
      thisto->entries = entries;
      thisto->tentries = tentries;
      thisto->underflow = underflow[0];
      thisto->overflow = overflow[0];
      if ( type == 'R' || type == 'r' || type == 'F' || type == 'D' )
      {
         thisto->specific.real.sum = rsum[0];
         thisto->specific.real.tsum = rtsum[0];
      }
      else
      {
         thisto->specific.integer.sum = isum[0];
         thisto->specific.integer.tsum = itsum[0];
      }
      if ( nbins_2d > 0 )
      {
         thisto->underflow_2d = underflow[1];
         thisto->overflow_2d = overflow[1];
         if ( type == 'R' || type == 'r' || type == 'F' || type == 'D' )
         {
            thisto->specific_2d.real.sum = rsum[1];
            thisto->specific_2d.real.tsum = rtsum[1];
         }
         else
         {
            thisto->specific_2d.integer.sum = isum[1];
            thisto->specific_2d.integer.tsum = itsum[1];
         }
      }

      /* If wanted and possible, return the pointer to caller. */
      if ( phisto != (HISTOGRAM **) NULL && ihisto < nhisto )
         phisto[ihisto] = (add_this ? ohisto : thisto);

      /* Finally, read the histogram contents. */
      if ( type == 'F' || type == 'D' )
      {
         struct Histogram_Extension *he = thisto->extension;
         he->content_all = get_real(iobuf);
         he->content_inside = get_real(iobuf);
         get_vector_of_real(he->content_outside,8,iobuf);
         if ( type == 'F' )
         {
            if ( thisto->tentries > 0 )
               for ( ibin=0; ibin<ncounts; ibin++ )
                  he->fdata[ibin] = (float) get_real(iobuf);
            else
               for ( ibin=0; ibin<ncounts; ibin++ )
                  he->fdata[ibin] = (float) 0.;
         }
         else
         {
            if ( thisto->tentries > 0 )
               get_vector_of_real(he->ddata,ncounts,iobuf);
            else
               for ( ibin=0; ibin<ncounts; ibin++ )
                  he->ddata[ibin] = 0.;
         }
      }
      else
      {
         if ( thisto->tentries > 0 )
            get_vector_of_long((long *)thisto->counts,ncounts,iobuf);
         else
            for ( ibin=0; ibin<nbins; ibin++ )
               thisto->counts[ibin] = 0;
      }
#ifdef _REENTRANT
      histogram_unlock(thisto);
#endif

      if ( add_this )
      {
// fprintf(stderr,"Adding histogram ID %ld\n", ident);
         add_histogram(ohisto,thisto);
         free_histogram(thisto);
      }

   }

   if ( (rc = get_item_end(iobuf,&item_header)) != 0 )
      return rc;

   return(mhisto);
}
Esempio n. 10
0
/************************************************************************
**	can_expand:		tries to expand the macro passed to it - returns
**		true if it succeeded in expanding it.  It will only return FALSE
**		if a macro name was found, a paren was expected, and a paren was
**		not the next non white character.
************************************************************************/
int can_expand(pdefn_t pdef)
{
    UCHAR		c;
    int			n_formals;
    int			return_value = FALSE;

    Tiny_lexer_nesting = 0;
    Save_Exp_ptr = Exp_ptr;		/* not necessarily EXP_BUFFER */
    Macro_line = Linenumber;
expand_name:

    P_actuals = Act_ptr;
    N_actuals = 0;

    n_formals = DEFN_NFORMALS(pdef);
    if( PRE_DEFINED(pdef) ) {
	push_macro(pdef);
	DEFN_EXPANDING(CURRENT_MACRO)++;
	if(rescan_expansion()) {
	    return(TRUE);			/* could expand macro */
	}
    }
    else if( n_formals == 0 ) {
	return_value = TRUE;
	if(DEFN_TEXT(pdef)) {
	    push_macro(pdef);
	    expand_definition();
	}
	else {
	    /*
		**	Macro expands to nothing (no definition).  Since it
		**	didn't have any actuals, Act_ptr is already correct.
		**	Exp_ptr must be changed however to delete the
		**	identifier from the expanded text.
		*/
	    Exp_ptr = Save_Exp_ptr;
	}
    }
    else {
	if( n_formals == -1 ) {
	    n_formals = 0;
	}
name_comment_paren:
	if( can_get_non_white()) {
	    if(CHARMAP(CHECKCH()) == LX_SLASH) {
		SKIPCH();
		if(skip_comment()) {
		    goto name_comment_paren;
		}
		else {
		    UNGETCH();
		}
	    }
	    if(CHARMAP(CHECKCH())==LX_OPAREN) {
		SKIPCH();
		return_value = TRUE;
		get_actuals(pdef, n_formals);
	    }
	    else {
		/*
				**	#define xx(a) a
				**  xx bar();
				**  don't lose white space between "xx" and "bar"
				*/
		ptext_t	p = Exp_ptr;

		push_macro(pdef);
		DEFN_EXPANDING(CURRENT_MACRO)++;
		Exp_ptr = p;
		if( rescan_expansion() ) {
		    return(FALSE);
		}
	    }
	}
	else {
	}
    }
    /*
	**	makes sure a macro is being worked on. At this point, there will
	**	be a macro to expand, unless the macro expand_the_named_macro was
	**	passed had no definition text.  If it had no defintion text,
	**	Tiny_lexer_nesting was not incremented.
	*/
    while(Tiny_lexer_nesting != 0) {
	if(Exp_ptr >= ELIMIT) {
	    fatal_in_macro(10056);
	}
	switch(CHARMAP(c = GETCH())) {
	case LX_ID:
	case LX_MACFORMAL:
	    Save_Exp_ptr = Exp_ptr;
	    if(tl_getid(c) && ((pdef = get_defined())!= 0)) {
		if(DEFN_EXPANDING(pdef)) {
		    /*
						**	the macro is already being expanded, so just
						**	write the do not expand marker and the
						**	identifier to the expand area.  The do not
						**	expand marker is necessary so this macro
						**	doesn't get expanded on the rescan
						*/
		    int		len = Reuse_1_length - 1;

		    *Exp_ptr++ = LX_NOEXPANDMARK;
		    *Exp_ptr++ = ((UCHAR)len);
		}
		else {
		    /*
						** a legal identifier was read, it is defined, and
						** it is not currently being expanded.  This means
						** there is reason to believe it can be expanded.
						*/
		    goto expand_name;
		}
	    }
	    if(InIf &&(memcmp(Reuse_1, "defined", 8) ==0)) {
		do_defined(Reuse_1);
	    }
	    continue;
	    break;
	case LX_NUMBER:
	    /* getnum with Prep on to keep leading 0x on number */
	    {
		int	Save_prep = Prep;
		Prep = TRUE;
		getnum(c);
		Prep = Save_prep;
	    }
	    continue;
	    break;
	case LX_DOT:
	    *Exp_ptr++ = '.';
dot_switch:
	    switch(CHARMAP(c = GETCH())) {
	    case LX_EOS:
		if(handle_eos() != BACKSLASH_EOS) {
		    if(Tiny_lexer_nesting > 0) {
			goto dot_switch;
		    }
		    continue;
		}
		break;
	    case LX_DOT:
		*Exp_ptr++ = '.';
		if( ! checkop('.')) {
		    break;	/* error will be caught on rescan */
		}
		*Exp_ptr++ = '.';
		continue;
		break;
	    case LX_NUMBER:
		*Exp_ptr++ = c;
		get_real(Exp_ptr);
		continue;
	    }
	    UNGETCH();
	    continue;
	case LX_CHARFORMAL:
	    move_to_exp_esc('\'', do_strformal());
	    continue;
	    break;
	case LX_STRFORMAL:
	    move_to_exp_esc('"', do_strformal());
	    continue;
	    break;
	case LX_DQUOTE:
	case LX_SQUOTE:
	    /*
	    ** 	gather_chars is called even though the error reported
	    **	on overflow may need to be changed.
	    */
	    Exp_ptr = gather_chars(Exp_ptr, c);
	    continue;
	    break;
	case LX_WHITE:
	    while(LXC_IS_WHITE(GETCH())) {
		;
	    }
	    UNGETCH();
	    c = ' ';
	    break;
	case LX_EOS:
	    if(handle_eos() == BACKSLASH_EOS) {
		*Exp_ptr++ = c;
		c = GETCH();
		break;
	    }
	    continue;
	    break;
	}
	*Exp_ptr++ = c;
    }
    return(return_value);
}
Esempio n. 11
0
static int oct_parser_lex (){
  int c;
  char *symbuf = 0;
  int length = 0;
  
  /* Ignore whitespace, get first nonwhite character.  */
  while ((c = par_string[par_pos++]) == ' ' || c == '\t');
	
  if (c == '\0')
    return '\n';
	
  /* Char starts a number => parse the number.         */
  if (c == '.' || isdigit (c)){
    par_pos--;
    par_pos += get_real(&par_string[par_pos], &GSL_REAL(yylval.val));
    return NUM;
  }

  /* get the logical operators */
  if (c == '<' && par_string[par_pos] == '='){
    par_pos++;
    return LE;
  }

  if (c == '>' && par_string[par_pos] == '='){
    par_pos++;
    return GE;
  }

  if (c == '=' && par_string[par_pos] == '='){
    par_pos++;
    return EQUAL;
  }

  /*
  if (c == ':' && par_string[par_pos] == '='){
    par_pos++;
    return SET;
  }
  */

  if (c == '&' && par_string[par_pos] == '&'){
    par_pos++;
    return LAND;
  }

  if (c == '|' && par_string[par_pos] == '|'){
    par_pos++;
    return LOR;
  }
     
  /* Char starts an identifier => read the name.       */
  if (isalpha (c) || c == '\'' || c == '\"'){
    symrec *s;
    char startc = c;
    int i;
		
    /* Initially make the buffer long enough
       for a 40-character symbol name.  */
    if (length == 0)
      length = 40, symbuf = (char *)malloc (length + 1);
    
    if(startc == '\'' || startc == '\"')
      c = par_string[par_pos++];
    else
      startc = 0; /* false */
    
    i = 0;
    do{
      /* If buffer is full, make it larger.        */
      if (i == length){
	length *= 2;
	symbuf = (char *)realloc (symbuf, length + 1);
      }
      /* Add this character to the buffer.         */
      symbuf[i++] = c;
      /* Get another character.                    */
      c = par_string[par_pos++];
    }while (c != '\0' && 
	    ((startc && c!=startc) || (!startc && (isalnum(c) || c == '_' ))));
    
    if(!startc) par_pos--;
    symbuf[i] = '\0';
    
    if(!startc){
      s = getsym (symbuf);
      if (s == 0){
	int jj;
	for (jj = 0; reserved_symbols[jj] != 0; jj++){
	  if(strcmp(symbuf, reserved_symbols[jj]) == 0){
	    fprintf(stderr, "Error: trying to redefine reserved symbol '%s'", symbuf);
	    exit(1);
	  }
	}
	
	s = putsym (symbuf, S_CMPLX);
      }
      yylval.tptr = s;

      free(symbuf);
      if(s->type == S_CMPLX)
	return VAR;
      else
	return FNCT;
    }else{
      yylval.str = strdup(symbuf);

      free(symbuf);
      return STR;
    }
  }
	
  /* Any other character is a token by itself.        */
  return c;
}
Esempio n. 12
0
/************************************************************************
 * GETNUM - Get a number from the input stream.
 *
 * ARGUMENTS
 *      radix - the radix of the number to be accumulated.  Can only be 8, 10,
 *                      or 16
 *      pval - a pointer to a VALUE union to be filled in with the value
 *
 * RETURNS - type of the token (L_CINTEGER or L_CFLOAT)
 *
 * SIDE EFFECTS -
 *      does push back on the input stream.
 *      writes into pval by reference
 *  uses buffer Reuse_W
 *
 * DESCRIPTION -
 *      Accumulate the number according to the rules for each radix.
 *      Set up the format string according to the radix (or distinguish
 *      integer from float if radix is 10) and convert to binary.
 *
 * AUTHOR - Ralph Ryan, Sept. 8, 1982
 *
 * MODIFICATIONS - none
 *
 ************************************************************************/
token_t getnum(REG      WCHAR           c)
{
    REG WCHAR   *p;
    WCHAR       *start;
    int         radix;
    token_t     tok;
    value_t     value;

    tok = L_CINTEGER;
    start = (Tiny_lexer_nesting ? Exp_ptr : Reuse_W);
    p = start;
    if( c == L'0' ) {
        c = get_non_eof();
        if( IS_X(c) ) {
            radix = 16;
            if( Prep ) {
                *p++ = L'0';
                *p++ = L'x';
            }
            for(c = get_non_eof(); LXC_IS_XDIGIT(c); c = get_non_eof()) {
                /* no check for overflow? */
                *p++ = c;
            }
            if((p == Reuse_W) && (Tiny_lexer_nesting == 0)) {
                strcpy (Msg_Text, GET_MSG (2153));
                error(2153);
            }
            goto check_suffix;
        }
        else {
            radix = 8;
            *p++ = L'0'; /* for preprocessing or 0.xxx case */
        }
    }
    else {
        radix = 10;
    }

    while( LXC_IS_DIGIT((WCHAR)c) ) {
        *p++ = c;
        c = get_non_eof();
    }

    if( IS_DOT(c) || IS_E(c) ) {
        UNGETCH();
        return(get_real(p));
    }

check_suffix:
    if( IS_EL(c) ) {
        if( Prep ) {
            *p++ = c;
        }
        c = get_non_eof();
        if( IS_U(c) ) {
            if(Prep) {
                *p++ = c;
            }
            tok = L_LONGUNSIGNED;
        }
        else {
            tok = L_LONGINT;
            UNGETCH();
        }
    }
    else if( IS_U(c) ) {
        if( Prep ) {
            *p++ = c;
        }
        c = get_non_eof();
        if( IS_EL(c) ) {
            if( Prep ) {
                *p++ = c;
            }
            tok = L_LONGUNSIGNED;
        }
        else {
            tok = L_CUNSIGNED;
            UNGETCH();
        }
    }
    else {
        UNGETCH();
    }
    *p = L'\0';
    if( start == Exp_ptr ) {
        Exp_ptr = p;
        return(L_NOTOKEN);
    }
    else if( Prep ) {
        myfwrite( Reuse_W, (size_t)(p - Reuse_W) * sizeof(WCHAR), 1, OUTPUTFILE);
        return(L_NOTOKEN);
    }
    value.v_long = matol(Reuse_W,radix);
    switch(tok) {
    case L_CINTEGER:
        tok = (radix == 10)
            ? c_size(value.v_long)
            : uc_size(value.v_long)
            ;
        break;
    case L_LONGINT:
        tok = l_size(value.v_long);
        break;
    case L_CUNSIGNED:
        tok = ul_size(value.v_long);
        break;
    }
    yylval.yy_tree = build_const(tok, &value);
    return(tok);
}
Esempio n. 13
0
int exec_menu(MENU menu)
{
 int i=0, cidx=0, fine;
 int off, ecnt=1;
 char tmp[MAXLEN];
 char output[MAXLEN];
 MENU tmenu = menu;
 int ret;
 int cpid;

 fine=1;
 while(cidx < tmenu.ncmd && fine)
 {
  off=1;
  switch(tmenu.cmd[cidx][0])
  {
   case '-':
   	if(*(tmenu.cmd[cidx] + off)=='!') off++;
   	parsecmd(tmenu.cmd[cidx] +off, tmp);
	cpid = fork();
	if(cpid)
	{
	 waitpid(cpid,&ret,0);
	 if(ret!=-1 && WIFEXITED(ret)) 
	  ret = WEXITSTATUS(ret);
	}
	else
	{
	 close(comport);
	 ret=system(tmp);
	 if(ret!=-1 && WIFEXITED(ret)) 
	  ret = WEXITSTATUS(ret);
	 exit(ret);
	}
	if(off==1) ret=1;
	break;
   case '+':
   	if(*(tmenu.cmd[cidx] + off)=='!') off++;
   	parsecmd(tmenu.cmd[cidx] +off, tmp);
	ret=execute(tmp, output, MAXLEN);
	sprintf(tmp, "$%d", ecnt++);
	setvar(tmp, output);
	if(off==1) ret=1;
	break;
   case '<':
	argcnt = split(tmenu.cmd[cidx]+1, args[0], MAXARGS, MAXARGLEN);
	substvar(args[0], MAXARGS, MAXARGLEN);
  	/*for(i=0; i<argcnt; i++)
   	 printf("%d: --%s--\n",i,args[i]);*/
	if(strcmp(args[0],"YesNo")==0 && argcnt==2)
	{
	 ret=get_yesno(args[1]);
	 sprintf(output,"%d",ret-1);
	 setvar("$YesNo",output);
	}
	if(strcmp(args[0],"OnOff")==0 && argcnt==3)
	{
	 ret=get_onoff(args[1], atoi(args[2]));
	 sprintf(output,"%d",ret-1);
	 setvar("$OnOff",output);
	}
	if(strcmp(args[0],"Percent")==0 && argcnt==4)
	{
	 ret=get_percent(args[1], atoi(args[2]), atoi(args[3]));
	 sprintf(output,"%d",ret-1);
	 setvar("$Percent",output);
	}
	if(strcmp(args[0],"Choice")==0 && argcnt>=4)
	{
	 init_choice();
	 for(i=3; i<argcnt; i++)
	  addchoice(args[i]);
	 ret=get_choice(args[1], atoi(args[2]));
	 sprintf(output,"%d",ret);
	 setvar("$Choice",output);
	}
	if(strcmp(args[0],"Real")==0 && (argcnt==4 || argcnt==5))
	{
	 if(argcnt==4) strcpy(args[4],"");
	 ret=get_real(output, args[1], args[2], args[3], args[4]);
	 setvar("$Real",output);
	}
	if(strcmp(args[0],"Int")==0 && (argcnt==5 || argcnt==6))
	{
	 if(argcnt==5) strcpy(args[5],"0");
	 ret=get_integer(output, args[1], args[2], atoi(args[3]), atoi(args[4]), atoi(args[5]));
	 setvar("$Int",output);
	}
	if(strcmp(args[0],"Phone")==0 && (argcnt==3 || argcnt==4))
	{
	 if(argcnt==3) strcpy(args[3],"");
	 ret=get_phone(output, args[1], args[2], args[3]);
	 setvar("$Phone",output);
	}
	if(strcmp(args[0],"Date")==0 && argcnt==2)
	{
	 ret=get_date(output, args[1]);
	 setvar("$Date",output);
	}
	if(strcmp(args[0],"Text")==0 && (argcnt==4 || argcnt==5))
	{
	 if(argcnt==4) strcpy(args[4],"");
	 ret=get_text(output, args[1], args[2], atoi(args[3]), args[4]);
	 setvar("$Text",output);
	}
	if(strcmp(args[0],"Secret")==0 && argcnt==4)
	{
	 ret=get_secret(output, args[1], args[2], atoi(args[3]));
	 setvar("$Secret",output);
	}
	break;
   case '>':
	argcnt = split(tmenu.cmd[cidx]+1, args[0], MAXARGS, MAXARGLEN);
	substvar(args[0], MAXARGS, MAXARGLEN);
  	/*for(i=0; i<argcnt; i++)
   	 printf("%d: --%s--\n",i,args[i]);*/
	if(strcmp(args[0],"MsgBox")==0 && (argcnt==2 || argcnt==3))
	{
	 if(argcnt==2) strcpy(args[2],"");
	 ret=msgbox(args[1], atoi(args[2]));
	}
	if(strcmp(args[0],"Info")==0 && argcnt>=3)
	 ret=info(args[1], args[2]);
	if(strcmp(args[0],"Status")==0 && argcnt>=2)
	 ret=status(args[1]);
	break;
   case ':':
   	for(i=0; i<fncnt; i++)
	 if(strcmp(tmenu.cmd[cidx]+1,flist[i].name)==0)
	  ret = flist[i].fn();
	break;
  }
  if(ret<=0) fine=0;
  cidx++;
 }
 return 0;
}
Esempio n. 14
0
void sum_menu()
{
  short board, value;	
  short address;	
  float tvalue = 0;
  float DesiredTiming = 0;//should be global?
  char *verb;
  char *tablepath;
  int4 iverb,eDelay,rate, patchnumber, ecount ;
  
  CPLD_disconect();
  
  while(True)
    {
      verb = action_menu( "SUM_BOARD_MENU", &iverb);
      
      if(strcmp(verb,"ENABLE_THR")==0)
	{
	  STInfo.threshold_control_flag=true;
	  printf("Threshold control ON \n");
	}
      
      if(strcmp(verb,"DISABLE_THR")==0)
	{
	  STInfo.threshold_control_flag=false;
	  printf("Threshold control OFF\n");
	}
      
      if(strcmp(verb,"LOAD_THRE_TABLE")==0)
	{
	  printf("LOADING..\n");
	}
      
      if(strcmp(verb,"SAVE_THRESHOLDS")==0)
	{   
	  FILE *Tfile;
	  int i;
	  Tfile= fopen ((char *)ASData.thr_outputname, "a" );     
	  fprintf(Tfile,"#Macrocell     #Threshold [V]\n");
	  for(i=0;i<55;i++)
	    {
	      fprintf(Tfile,"%i          %f\n",i+1,ASData.threshold[i]);
	    }
	  fclose ( Tfile );
	}
      
      if(strcmp(verb,"PRINT_THRESHOLDS")==0)
        {
          printf("#Macrocell       #Threshold [V]\n");
          int i;
          for(i=0;i<55;i++)
            {
              printf("%i          %f\n", i+1, ASData.threshold[i]);
            }
        }

      if(strcmp(verb,"PRINT_Rates")==0)
	{   
	  printf("#Macrocell:  Rates: \n");
	  int i;
	  for(i=0;i<55;i++)
            {
	      printf("%i          %f\n", i+1, (float)ASData.rate[i]);
            }
	  printf("Total rate: %f", (float)ASData.globalrate);
        }
      
      if(strcmp(verb,"CHANGE_ONE_THRE_DB")==0)
	{   
            int board=0;
            int addres=0;
            int macro=0;
            int data=0;
            float tvalue=0;
            float db=0;
            get_short("Macrocell",(int2*) &macro,1,55);
		    get_real("Set attenuation",&db, 0,0); 
            tvalue=ASData.threshold[macro-1]*pow(10.0,db/20.0);
            data=(tvalue +2.0)*thre_conv;
            board=(int)macro/3.;
            address=(int)macro%3;
            printf("board %i, address %i\n",(int)board,address);
            if (tvalue >-2 && tvalue < 2)
            {
                printf("Threshold %f, on Macrocell %i\n",tvalue,macro);
                printf(" DBG Threshold %i, on Macrocell %i\n",(unsigned short)data,macro);
                transfer(FUNC_SUM_THR ,board,address,(unsigned short)data);
                ASData.threshold[macro-1]=tvalue;
            }
            else printf("Threshold value outside limits\n");
        }
		
	if(strcmp(verb,"CHANGE_ALL_THRE_DB")==0)
	{   
            int board=0;
            int addres=0;
            int data=0;
            int i=0;
            float tvalue=0;
            float db=0;
		    get_real("Set attenuation",&db, 0,0); 
            for(i=0;i<55;i++)
            {
                tvalue=ASData.threshold[i]*pow(10.0,db/20.0);
                if (tvalue>2) tvalue=2;
                if (tvalue<0) tvalue=0;
                data=(tvalue +2.0)*thre_conv;
                board=(int)i/3.;
                address=(int)i%3;
                printf("Threshold %f, on Macrocell %i\n",tvalue,i+1);
                printf(" DBG Threshold %i, on Macrocell %i\n",(unsigned short)data,i+1);
                printf(" DBG Board %i,  Addres %i\n",board, address);
                transfer(FUNC_SUM_THR ,board,address,(unsigned short)data);
                ASData.threshold[i]=tvalue;
            }
        }
		
	if(strcmp(verb,"PRINT_AVERAGE_THR")==0)
	{   
	    int i;
            float average=0;
	    for(i=0;i<55;i++)
            {
                average+=ASData.threshold[i];
            }
                printf(" Average Threshold %f [V] \n", average/55.);
        }
		
        if(strcmp(verb,"OUTPUTNAME_THR")==0)
	{
			
            get_text("Enter Sum-Board Table name",(char *)ASData.thr_outputname);
	}
    
	if(strcmp(verb,"PATHSUMTABLES")==0)
	{
		get_text("Enter Sum-Board Table(s) path",(char *)tablepath);
	}
    
	if(strcmp(verb,"SET_ONE_MAX")==0)
	{
            get_short("Macrocell",(int2*) &board,1,55);
            get_short("Maximum rate",(int2*) &value,1,10000);
            
            ASData.rate_max[board-1]=value;
	}
    
	if(strcmp(verb,"SET_ONE_MIN")==0)
	{
            get_short("Macrocell",(int2*) &board,1,55);
            get_short("Minimum rate",(int2*) &value,1,10000);
            ASData.rate_min[board-1]=value;
	}
    
	if(strcmp(verb,"SET_ALL_MAX")==0)
	{
            get_short("Maximum rate", &value,1,10000);
            int i;
            for(i=0;i<55;i++)
            {    
                ASData.rate_max[i]=value;
            }
	}
    
	if(strcmp(verb,"SET_ALL_MIN")==0)
	{
            get_short("Minimum rate", &value,1,10000);
            int i;
            for(i=0;i<55;i++)
            {    
                ASData.rate_min[i]=value;
            }
	}


	if(strcmp(verb,"SET_ONE_T")==0)
	{
            float data;
            get_short("Board",(int2*) &board,1,19);
            get_short("Address",(int2*) &address,1,3);
	    get_real("Threshold Value (-2,2)",&tvalue, 0,0); 
            data=(tvalue +2.0)*thre_conv;
            transfer(FUNC_SUM_THR ,board-1,address-1,(unsigned short)data);
            printf("Set %f Threshold on address %i on board %i\n", tvalue, address,board);
            ASData.threshold[address-1+board*3]=tvalue;
	}
		
	if(strcmp(verb,"SET_BOARD_T")==0)
	{
            float data;
            get_short("Board",(int2*) &board,1,19);
		    get_real("Threshold Value (-2,2)",&tvalue, 0,0); 
            data=(tvalue +2.0)*thre_conv;
            int i;
            for (i=0;i<3;i++)
            {
                transfer(FUNC_SUM_THR ,board-1,i,(unsigned short)data);
                ASData.threshold[i+board*3]=tvalue;
            }
            printf("%f Threshold on all the address on board %i\n", tvalue,board);

	}
		
	if(strcmp(verb,"SET_CRATE_T")==0)
	{
            float data;
		    get_real("Threshold Value (-2,2)",&tvalue, 0,0); 
            data=(tvalue +2.0)*thre_conv;
            int i,j;
            for (j=0;j<19;j++)
            {
                for (i=0;i<3;i++)
                {
                    transfer(FUNC_SUM_THR ,j,i,(unsigned short)data);
                    ASData.threshold[i+j*3]=tvalue;
                }
            }
              
            printf("*********************************\n");
            printf("%f Threshold on all the crate\n", tvalue);
            printf("*********************************\n");
		
        }
    
		if(strcmp(verb,"RETURN")==0)
			return;
	}
}
Esempio n. 15
0
void astro_menu(void)
{
	
	float DesiredPatch ;
	float DesiredDelay = 0;
	float DesiredDelay1 = 0;
	float DesiredDelay2 = 0;
	float DesiredDelay3 = 0;
	float DesiredRateCounts = 0;
	float DesiredRateTime = 0;
	float DesiredRate = 0;
	float DesiredTiming = 0;
	short data = 0;
	float datat = 0;
	int Macrocell = 0;
	short Refchannel = 0;
	char *verb;
	char *tablepath;
    int status;
    int4 iverb,eDelay,Delay,rate, patchnumber, ecount;
     int data1;
     int data2;
     int data3;
     data1=1;
     data2=2;

    CPLD_disconect();
    while(True)
	{
		verb = action_menu( "ASTRO_BOARD_MENU", &iverb);
		if(strcmp(verb,"TMWAIT")==0) 
		{                
			  printf("Maximum time,%i ",ASData.Tmax*1000);
			  usleep(ASData.Tmax*1000);
		}   	

		if(strcmp(verb,"RESET_START")==0)
		{
		    status = transfer(FUNC_ASTRO_RES,0,0,0);   
			printf("Reset every MCPs and start counting\n");
	        	
		}
    
		if(strcmp(verb,"TMAX")==0)
		{
			printf("Default 20 ms\n");
			get_real("Set desired maximum time [ms]",&DesiredRateTime,1,65000);
            status = transfer(FUNC_ASTRO_TOUT,0,0,DesiredRateTime);   
            ASData.Tmax=DesiredRateTime;
		}
    
		if(strcmp(verb,"CMAX")==0)
		{
		    printf("Default 65000 counts\n");
		    get_real("set desired maximum number of counts",&DesiredRateCounts,10.,65000);
		    status = transfer(FUNC_ASTRO_MCNT,0,0,DesiredRateCounts);   
		    ASData.Cmax=DesiredRateCounts;
		}
    
  		if(strcmp(verb,"GLOBALREAD")==0)
                {
                    int Macrocell;
                    status = transfer_c(0xA7,&data1,&data2,&Macrocell);
		    ASData.globalrate=Macrocell;
		    printf("counts %i, elapsed time %i [ms],rate %i[Hz]\n ",data1,data2,Macrocell);
        	}

		if(strcmp(verb,"TIM_ONEREAD")==0)
		  {
		    int j=0;
		    get_short("Macrocell",(int2*) &Macrocell,1,55);
		    j=Macrocell;
		    status = transfer_c(FUNC_ASTRO_TIM,&data1,&data2,&Macrocell);   
		    ASData.tim[j-1]=Macrocell;
		    printf("counts %i, elapsed time %i [ms], "
                   "rate %i[Hz]\n ",data1,data2,Macrocell);
		}
    
		if(strcmp(verb,"TIM_ALLREAD")==0)
		{
			int i;

			printf("Reading all Astro-Board Macrocells\n");
			for ( i=0;i<55;i++)
			  { 
			    data3=i;
			    status = transfer_c(FUNC_ASTRO_TIM,&data1,&data2,&data3);   
			    printf("counts %i, elapsed time %i [ms], "
				   "rate %i[Hz] \n",data1,data2,data3);
			    ASData.tim[i]=data3;
			  }
		}
		
		if(strcmp(verb,"AMP_ONEREAD")==0)
		  {
		    int j=0;
		    get_short("Macrocell",(int2*) &Macrocell,1,55);
		    j=Macrocell;
		    status = transfer_c(FUNC_ASTRO_AMP,&data1,&data2,&Macrocell);   
		    ASData.amp[j-1]=Macrocell;
		    printf("counts %i, elapsed time %i [ms],rate %i[Hz]\n ",data1,data2,Macrocell);
		}
		
		if(strcmp(verb,"ALLREAD")==0)
		  {
		    int i;
		    printf(" DBG Reading all Astro-Board Macrocells\n");
		    for ( i=0;i<55;i++)
		      { 
			data3=i;
			status = transfer_c(FUNC_ASTRO_AMP,&data1,&data2,&data3);   
			ASData.rate[i]=data3;
			printf("macrocell %d  counts %d   elapsed time %d [ms], "
			       "rate %i[Hz] \n",i+1, data1,data2,data3);
		      }


		    status = transfer_c(0xA7,&data1,&data2,&data3);
		    ASData.globalrate=data3;
		    printf("Total rate:  counts %d   elapsed time %d [ms], "
			   "total rate %i[Hz] \n", data1,data2,data3);



		  }
		
		if(strcmp(verb,"ONEREAD")==0)
		  {
		    int j=0;
		    get_short("Macrocell",(int2*) &Macrocell,1,55);
		    j=Macrocell;
		    status = transfer_c(FUNC_ASTRO_RATES,&data1,&data2,&Macrocell);   
		    
		    ASData.rate[j-1]=Macrocell;
		    printf("counts %i, elapsed time %i [ms],rate %i[Hz]\n ",data1,data2,Macrocell);
		  }
    
/*	
	if(strcmp(verb,"ALLREAD")==0)
		{
			int i;
            printf("Reading all Astro-Board Macrocells\n");
            for ( i=0;i<55;i++)
            { 
                data3=i;
                status = transfer_c(FUNC_ASTRO_RATES,&data1,&data2,&data3);   
                ASData.rate[i]=data3;
                printf("counts %i, elapsed time %i [ms],rate %i[Hz]\n ",data1,data2,data3);
           }
        }
  */  

		if(strcmp(verb,"SAVE_RATES")==0)
		{   
		  FILE *Tfile;
		  int i;
		  printf("Saving all Astro-Board Macrocells\n");
		  Tfile= fopen ((char *)ASData.rates_outputname, "a" );     
		  fprintf(Tfile,"#Macrocell     #Rates [Hz]\n");
		  for(i=0;i<55;i++)
		    {
		      fprintf(Tfile,"%i          %f\n",i+1,ASData.rate[i]);
		    }
		  
		  fprintf(Tfile,"Total rate:          %d\n" , (int)ASData.globalrate);
		  fclose ( Tfile );
		}
    
        if(strcmp(verb,"OUTPUTNAME_RATES")==0)
		{
			
            get_text("Enter Sum-Board Table name",(char *)ASData.rates_outputname);
		}
		if(strcmp(verb,"COMPARATOR")==0)
		{
            int channel=0;
            float datat=0;
            get_short("Channel",(int2*) &channel,1,2);
            get_real("Threshold value [0,2.5]", &datat,0,2.5);
            
			printf("Comparator threshold on channel %i is %f\n",channel,datat);
            ASData.cthreshold[channel-1]=datat;
		}
    
		if(strcmp(verb,"ALLDDEL")==0)
		{
		    int i;
		    get_real("Set desired delay (ns)",&DesiredDelay,0.0,5.6);
         	    
		   for (i=0;i<55;i++)
		   {
		        ASData.ddelay[Macrocell-1]=DesiredDelay;
			    status = transfer(FUNC_ASTRO_DEL,i,0,(unsigned short)(DesiredDelay*ddel_conv));
		   	    printf("%d ns delay on Macrocell %d\n", (int)(DesiredDelay*ddel_conv),i);
		   }
		}
    
		if(strcmp(verb,"ONEDDEL")==0)
		{
		    get_short("Macrocell",(int2*) &Macrocell,1,55);
		    get_real("Set desired delay (ns)",&DesiredDelay,0.0,5.6);
          
		    status = transfer(FUNC_ASTRO_DEL,Macrocell-1,0,(int)(DesiredDelay*ddel_conv));
		    ASData.ddelay[Macrocell-1]=DesiredDelay;
		    printf("%i ns delay on Macrocell %i\n", DesiredDelay,Macrocell);
		}
    
		if(strcmp(verb,"ONEDREF")==0)
		{
            get_short("Macrocell",(int2*) &Refchannel,0,1);
            get_real("set desired delay (ns)",&DesiredDelay,0.0,5.6);
		    status = transfer(FUNC_ASTRO_ADEL, Refchannel,0,(int)(DesiredDelay*ddel_conv));
            ASData.dref[Refchannel]=DesiredDelay;
            printf("%f ns delay on analog signal on anlaog input %i\n", DesiredDelay,Refchannel);
        
		}
    
		if(strcmp(verb,"LDDEL")==0)
		{
			printf("Loading Delay tables...\n");
			//load_tables(astro_Delay);
		}
    
		if(strcmp(verb,"SDDEL")==0)
		{
	
			//load_tables(astro_Delay);
		}
    
    
		if(strcmp(verb,"ATABLEPATH")==0)
		{
			//get_text("Enter AStro-Board Table(s) path:",(char *)tablepath);
		//	printf("The astrotables path is: ");
		}
    
		if(strcmp(verb,"WAIT")==0)
		{
			int4 secs=5;
			get_integer("How many secs?",&secs,0,0);
			usleep(secs);
		}
		if(strcmp(verb,"EDEL")==0)
		{
            int line=0;
            float edel_conv=0;
            get_short("Select delay line",(int2*) &line,1,6);
            if (line < 4)
            {
			    get_real("Set desired delay (ns)",&DesiredDelay1,0.,510.);
                edel_conv=edel_conv1;
            }
            if (line > 3 && line < 7)
            {
                get_real("Set desired delay (ns)",&DesiredDelay1,0.,64);
                edel_conv=edel_conv2;
            }
		    
            status = transfer(FUNC_ASTRO_ED,line,0,(int)(DesiredDelay1*edel_conv));
            ASData.edel[line-1] = DesiredDelay1; 
        }
    
		if(strcmp(verb,"ALLEDEL")==0)
		{
            int i;
            get_real("Set desired delay (ns)",&DesiredDelay1,0.,64.);
        
		    status = transfer(FUNC_ASTRO_ED,0x00,7,DesiredDelay1);
            for (i=0;i<7;i++)
            ASData.edel[i] = DesiredDelay1; 
        }
    
		if(strcmp(verb,"ATEMP")==0)
		{
            short data=0;
            status = transfer_t(FUNC_ASTRO_TEM,0 ,0,&data);
			printf("AStro-Board Temperature %i\n",data);
            ASData.TAst=data;
		}
    
		if(strcmp(verb,"STATUS")==0)
		{
            short data=0;
            transfer_t(FUNC_ASTRO_ERR,0 ,0,&data);
            ASData.Astatus= data;
			switch (data)
            {
                case 0:
                    printf("AStro-Board status OK\n");
                    break;  
                case 1:
                    printf(" Error on temperature device\n");
                    break;  
                case 2:
                    printf(" Error on set-read threshold\n");
                    break;  
                case 3:
                    printf(" Error on temperature device & on set-read threshold\n");
                    break;  
           //     case 4:
           //         printf(" STATUS not checked\n");
           //         break;  
            }
		}
    
		if(strcmp(verb,"VERSION")==0)
		{
            status = transfer(FUNC_ASTRO_VER,0,0,0);   
			printf("Reading AStro-Version\n");
		}
    
		if(strcmp(verb,"ENGATE")==0)
		{
            status = transfer(FUNC_ASTRO_GEN,0,0,0);   
            ASData.Gate=1;
			printf("Gate Enable\n");
		}
    
		if(strcmp(verb,"DISGATE")==0)
		{
            status = transfer(FUNC_ASTRO_GDIS,0,0,0);   
            ASData.Gate=0;
			printf("Gate disable\n");
		}
    
		if(strcmp(verb,"PRINT")==0)
		{
		    int i;
            printf("******************************************* \n");
            printf(" One shot delays \n");
			printf(" Macrocell   Delay [ns]\n");
		    for (i=0;i<55;i++)
            {    
                printf("   %i          %f   \n",i+1,ASData.ddelay[i]);
            }
            printf("\n");
            printf("******************************************* \n");
		
            printf(" One shot  anlogue delays \n");
			printf("Analogue   Delay [ns]\n");
		    for (i=0;i<2;i++)
            {    
                printf("   %i          %f   \n",i,ASData.dref[i]);
            }
            printf("\n");
            printf("******************************************* \n");
            
            printf(" Last rates value \n");
			printf(" Macrocell   Rate [counts/ms]\n");
		    for (i=0;i<55;i++)
            {    
                printf("   %i          %f   \n",i+1,ASData.rate[i]);
            }
            printf("\n");
            printf("******************************************* \n");
            
            printf(" Thresholds \n");
			printf(" Macrocell   Threshold [V]\n");
		    for (i=0;i<55;i++)
            {    
                printf("   %i          %f   \n",i+1,ASData.threshold[i]);
            }
            printf("\n");
            printf("******************************************* \n");
            printf(" One shot anlogue delays \n");
            
			printf("Analogue   Delay [ns]\n");
		    for (i=0;i<2;i++)
            {    
                printf("   %i          %f   \n",i,ASData.dref[i]);
            }
            printf("\n");
            printf("******************************************* \n");
            
		
            printf(" One shot anlogue delays \n");
			printf("Analogue   Threshold [V]\n");
		    for (i=0;i<2;i++)
            {    
                printf("   %i          %f   \n",i,ASData.cthreshold[i]);
            }
            printf("\n");
            printf("******************************************* \n");
		
            printf(" External delays \n");
			printf("Analogue   Delay [ns]\n");
		    for (i=0;i<6;i++)
            {    
                printf("   %i          %f   \n",i,ASData.edel[i]);
            }
            printf("\n");
            printf("******************************************* \n");
		
            printf(" STATUS \n");
            data= ASData.Astatus;
			switch (data)
            {
                case 0:
                    printf("AStro-Board status OK\n");
                    break;  
                case 1:
                    printf(" Error on temperature device\n");
                    break;  
                case 2:
                    printf(" Error on set-read threshold\n");
                    break;  
                case 3:
                    printf(" Error on temperature device & on set-read threshold\n");
                    break;  
            }
            printf("\n");
            printf("******************************************* \n");
        }
    
		if(strcmp(verb,"RETURN")==0)
			return;
	}
}
Esempio n. 16
0
int read_test1(TEST_DATA *data, IO_BUFFER *iobuf)
{
   IO_ITEM_HEADER item_header;
   int i;
   
   item_header.type = 99;             /* test data */
   if ( get_item_begin(iobuf,&item_header) < 0 )
   {
      Warning("Missing or invalid test data block.");
      return -4;
   }

   data->lvar[0]  = get_long(iobuf);
   data->lvar[1]  = get_long(iobuf);
   data->ilvar[0] = get_long(iobuf);
   data->ilvar[1] = get_long(iobuf);
   data->isvar[0] = get_short(iobuf);
   data->isvar[1] = get_short(iobuf);
   data->svar[0]  = get_short(iobuf);
   data->svar[1]  = get_short(iobuf);
   data->svar[2]  = get_short(iobuf);
   data->fvar[0]  = get_real(iobuf);
   data->fvar[1]  = get_real(iobuf);
   data->dvar[0]  = get_double(iobuf);
   data->dvar[1]  = get_double(iobuf);
   data->hvar[0]  = get_sfloat(iobuf);
   data->hvar[1]  = get_sfloat(iobuf);
   data->i8var[0] = get_byte(iobuf);
   data->i8var[1] = get_byte(iobuf);
   data->u8var[0] = get_byte(iobuf);
   data->u8var[1] = get_byte(iobuf);
   data->i16var[0] = get_short(iobuf);
   data->i16var[1] = get_short(iobuf);
   data->u16var[0] = get_short(iobuf);
   data->u16var[1] = get_short(iobuf);
   data->i32var[0] = get_int32(iobuf);
   data->i32var[1] = get_int32(iobuf);
   data->u32var[0] = get_uint32(iobuf);
   data->u32var[1] = get_uint32(iobuf);
#ifdef HAVE_64BIT_INT
   get_vector_of_int64(&data->i64var[0],1,iobuf);
   get_vector_of_int64(&data->i64var[1],1,iobuf);
   get_vector_of_uint64(&data->u64var[0],1,iobuf);
   get_vector_of_uint64(&data->u64var[1],1,iobuf);
#endif   
   data->nbvar = get_count(iobuf);
   data->bvar[0] = get_byte(iobuf);
   data->bvar[1] = get_byte(iobuf);
   for (i=0; i<4; i++)
      data->cnt16var[i] = get_count16(iobuf);
   for (i=0; i<6; i++)
      data->cnt32var[i] = get_count32(iobuf);
   for (i=0; i<6; i++)
      data->cntzvar[i] = get_count(iobuf);
   for (i=0; i<8; i++)
      data->cntvar[i] = get_count(iobuf);
   for (i=0; i<10; i++)
      data->scnt16var[i] = get_scount16(iobuf);
   for (i=0; i<12; i++)
      data->scnt32var[i] = get_scount32(iobuf);
   for (i=0; i<12; i++)
      data->scntzvar[i] = get_scount(iobuf);
   for (i=0; i<14; i++)
      data->scntvar[i] = get_scount(iobuf);
   get_string(data->str16var,sizeof(data->str16var),iobuf);
   get_long_string(data->str32var,sizeof(data->str32var),iobuf);
   get_var_string(data->strvvar,sizeof(data->strvvar),iobuf);

   return(get_item_end(iobuf,&item_header));
}
Esempio n. 17
0
void aligned_free(void* chunk) {
    return free(chunk == nullptr ? chunk : get_real(chunk));
}
Esempio n. 18
0
static void verify (int d1, int d2, int d3, int nt,
		    boolean *verified, char *cclass) {

/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/

    int ierr, size, i;
    double err, epsilon;

/*--------------------------------------------------------------------
c   Sample size reference checksums
c-------------------------------------------------------------------*/
    
/*--------------------------------------------------------------------
c   Class S size reference checksums
c-------------------------------------------------------------------*/
    double vdata_real_s[6+1] = { 0.0,
				 5.546087004964e+02,
				 5.546385409189e+02,
				 5.546148406171e+02,
				 5.545423607415e+02,
				 5.544255039624e+02,
				 5.542683411902e+02 };
    double vdata_imag_s[6+1] = { 0.0,
				 4.845363331978e+02,
				 4.865304269511e+02,
				 4.883910722336e+02,
				 4.901273169046e+02,
				 4.917475857993e+02,
				 4.932597244941e+02 };
/*--------------------------------------------------------------------
c   Class W size reference checksums
c-------------------------------------------------------------------*/
    double vdata_real_w[6+1] = { 0.0,
				 5.673612178944e+02,
				 5.631436885271e+02,
				 5.594024089970e+02,
				 5.560698047020e+02,
				 5.530898991250e+02,
				 5.504159734538e+02 };
    double vdata_imag_w[6+1] = { 0.0,
				 5.293246849175e+02,
				 5.282149986629e+02,
				 5.270996558037e+02, 
				 5.260027904925e+02, 
				 5.249400845633e+02,
				 5.239212247086e+02 };
/*--------------------------------------------------------------------
c   Class A size reference checksums
c-------------------------------------------------------------------*/
    double vdata_real_a[6+1] = { 0.0,
				 5.046735008193e+02,
				 5.059412319734e+02,
				 5.069376896287e+02,
				 5.077892868474e+02,
				 5.085233095391e+02,
				 5.091487099959e+02 };
    double vdata_imag_a[6+1] = { 0.0,
				 5.114047905510e+02,
				 5.098809666433e+02,
				 5.098144042213e+02,
				 5.101336130759e+02,
				 5.104914655194e+02,
				 5.107917842803e+02 };
/*--------------------------------------------------------------------
c   Class B size reference checksums
c-------------------------------------------------------------------*/
    double vdata_real_b[20+1] = { 0.0,
				  5.177643571579e+02,
				  5.154521291263e+02,
				  5.146409228649e+02,
				  5.142378756213e+02,
				  5.139626667737e+02,
				  5.137423460082e+02,
				  5.135547056878e+02,
				  5.133910925466e+02,
				  5.132470705390e+02,
				  5.131197729984e+02,
				  5.130070319283e+02,
				  5.129070537032e+02,
				  5.128182883502e+02,
				  5.127393733383e+02,
				  5.126691062020e+02,
				  5.126064276004e+02,
				  5.125504076570e+02,
				  5.125002331720e+02,
				  5.124551951846e+02,
				  5.124146770029e+02 };
    double vdata_imag_b[20+1] = { 0.0,
				  5.077803458597e+02,
				  5.088249431599e+02,                  
				  5.096208912659e+02,
				  5.101023387619e+02,                  
				  5.103976610617e+02,                  
				  5.105948019802e+02,                  
				  5.107404165783e+02,                  
				  5.108576573661e+02,                  
				  5.109577278523e+02,
				  5.110460304483e+02,                  
				  5.111252433800e+02,                  
				  5.111968077718e+02,                  
				  5.112616233064e+02,                  
				  5.113203605551e+02,                  
				  5.113735928093e+02,                  
				  5.114218460548e+02,
				  5.114656139760e+02,
				  5.115053595966e+02,
				  5.115415130407e+02,
				  5.115744692211e+02 };
/*--------------------------------------------------------------------
c   Class C size reference checksums
c-------------------------------------------------------------------*/
    double vdata_real_c[20+1] = { 0.0,
				  5.195078707457e+02,
				  5.155422171134e+02,
				  5.144678022222e+02,
				  5.140150594328e+02,
				  5.137550426810e+02,
				  5.135811056728e+02,
				  5.134569343165e+02,
				  5.133651975661e+02,
				  5.132955192805e+02,
				  5.132410471738e+02,
				  5.131971141679e+02,
				  5.131605205716e+02,
				  5.131290734194e+02,
				  5.131012720314e+02,
				  5.130760908195e+02,
				  5.130528295923e+02,
				  5.130310107773e+02,
				  5.130103090133e+02,
				  5.129905029333e+02,
				  5.129714421109e+02 };
    double vdata_imag_c[20+1] = { 0.0,
				  5.149019699238e+02,
				  5.127578201997e+02,
				  5.122251847514e+02,
				  5.121090289018e+02,
				  5.121143685824e+02,
				  5.121496764568e+02,
				  5.121870921893e+02,
				  5.122193250322e+02,
				  5.122454735794e+02,
				  5.122663649603e+02,
				  5.122830879827e+02,
				  5.122965869718e+02,
				  5.123075927445e+02,
				  5.123166486553e+02,
				  5.123241541685e+02,
				  5.123304037599e+02,
				  5.123356167976e+02,
				  5.123399592211e+02,
				  5.123435588985e+02,
				  5.123465164008e+02 };

    epsilon = 1.0e-12;
    *verified = TRUE;
    *cclass = 'U';

    if (d1 == 64 &&
	d2 == 64 &&
	d3 == 64 &&
	nt == 6) {
	*cclass = 'S';
	for (i = 1; i <= nt; i++) {
            err = (get_real(sums[i]) - vdata_real_s[i]) / vdata_real_s[i];
            if (fabs(err) > epsilon) {
	      *verified = FALSE;
	      break;
	    }
            err = (get_imag(sums[i]) - vdata_imag_s[i]) / vdata_imag_s[i];
            if (fabs(err) > epsilon) {
	      *verified = FALSE;
	      break;
	    }
	}
    } else if (d1 == 128 &&
	       d2 == 128 &&
	       d3 == 32 &&
	       nt == 6) {
	*cclass = 'W';
	for (i = 1; i <= nt; i++) {
            err = (get_real(sums[i]) - vdata_real_w[i]) / vdata_real_w[i];
            if (fabs(err) > epsilon) {
	      *verified = FALSE;
	      break;
	    }
            err = (get_imag(sums[i]) - vdata_imag_w[i]) / vdata_imag_w[i];
            if (fabs(err) > epsilon) {
	      *verified = FALSE;
	      break;
	    }
	}
    } else if (d1 == 256 &&
	       d2 == 256 &&
	       d3 == 128 &&
	       nt == 6) {
	*cclass = 'A';
	for (i = 1; i <= nt; i++) {
            err = (get_real(sums[i]) - vdata_real_a[i]) / vdata_real_a[i];
            if (fabs(err) > epsilon) {
	      *verified = FALSE;
	      break;
	    }
            err = (get_imag(sums[i]) - vdata_imag_a[i]) / vdata_imag_a[i];
            if (fabs(err) > epsilon) {
	      *verified = FALSE;
	      break;
	    }
	}
    } else if (d1 == 512 &&
	       d2 == 256 &&
	       d3 == 256 &&
	       nt == 20) {
	*cclass = 'B';
	for (i = 1; i <= nt; i++) {
            err = (get_real(sums[i]) - vdata_real_b[i]) / vdata_real_b[i];
            if (fabs(err) > epsilon) {
	      *verified = FALSE;
	      break;
	    }
            err = (get_imag(sums[i]) - vdata_imag_b[i]) / vdata_imag_b[i];
            if (fabs(err) > epsilon) {
	      *verified = FALSE;
	      break;
	    }
	}
    } else if (d1 == 512 &&
	       d2 == 512 &&
	       d3 == 512 &&
	       nt == 20) {
	*cclass = 'C';
	for (i = 1; i <= nt; i++) {
            err = (get_real(sums[i]) - vdata_real_c[i]) / vdata_real_c[i];
            if (fabs(err) > epsilon) {
	      *verified = FALSE;
	      break;
	    }
            err = (get_imag(sums[i]) - vdata_imag_c[i]) / vdata_imag_c[i];
            if (fabs(err) > epsilon) {
	      *verified = FALSE;
	      break;
	    }
	}
    }
    
    if (*cclass != 'U') {
	printf("Result verification successful\n");
    } else {
	printf("Result verification failed\n");
    }
    printf("cclass = %1c\n", *cclass);
}