Ejemplo n.º 1
0
void generate_bloc(unsigned xmin, unsigned ymin, unsigned zmin, 
		   unsigned xmax, unsigned ymax, unsigned zmax,
		   float yspeed)
{
  for(int z = zmin*2; z <= zmax*2; z += 2) {
    for(int y = ymin*2; y <= ymax*2; y += 2) { // Change to < for thin borders
      for(int x = xmin*2; x <= xmax*2; x += 2) {

	// Place 4 atoms per lattice
	// 0, 0, 0
	add_atom(x, y, z,
		 0.0, yspeed, 0.0,
		 2*xmin, 2*ymin, 2*zmin,
		 2*xmax, 2*ymax, 2*zmax);
	// 0, 1/2, 1/2
	add_atom(x, y + 1, z + 1,
		 0.0, yspeed, 0.0,
		 2*xmin, 2*ymin, 2*zmin,
		 2*xmax, 2*ymax, 2*zmax);
	// 1/2, 0, 1/2
	add_atom(x + 1, y, z + 1,
		 0.0, yspeed, 0.0,
		 2*xmin, 2*ymin, 2*zmin,
		 2*xmax, 2*ymax, 2*zmax);
	// 1/2, 1/2, 0 
	add_atom(x + 1, y + 1, z,
		 0.0, yspeed, 0.0,
		 2*xmin, 2*ymin, 2*zmin,
		 2*xmax, 2*ymax, 2*zmax);
      }
    }
  }
}
Ejemplo n.º 2
0
void compute_torus_center (double probe_radius, struct sphere *sphere1,struct sphere *sphere2, double torus_center[3])
{
	int k;
	double radius1, radius2, asymmetry, distance12_squared;
	char message[MAXLINE];
    struct cept *ex;

	distance12_squared =
		distance_squared (sphere1 -> center, sphere2 -> center);
	if (distance12_squared <= 0.0) {
		ex = new_cept (GEOMETRY_ERROR,  DEGENERACY,  FATAL_SEVERITY);
		add_function (ex, "compute_torus_center");
		add_source (ex, "mstorus.c");
		add_message (ex, "coincident atoms");
		add_atom (ex, sphere1);
		add_atom (ex, sphere2);
		return;
	}
	radius1 = sphere1 -> radius;
	radius2 = sphere2 -> radius;
	asymmetry = (radius1 + probe_radius) * (radius1 + probe_radius) -
		(radius2 + probe_radius) * (radius2 + probe_radius);
	for (k = 0; k < 3; k++)
		torus_center[k] = 0.5 * (sphere1 -> center[k] + sphere2 -> center[k])
			+ 0.5 * ( asymmetry / distance12_squared) *
			(sphere2 -> center[k] - sphere1 -> center[k]);
}
Ejemplo n.º 3
0
static void handle_text(char *s)
{
  char *opstart = s;
  operand *op;
  dblock *db = NULL;

  if (db = parse_string(&opstart,*s,8)) {
    add_atom(0,new_data_atom(db,1));
    s = opstart;
  }
  if (!db) {
    op = new_operand();
    s = skip_operand(s);
    if (parse_operand(opstart,s-opstart,op,DATA_OPERAND(8))) {
      atom *a;

      a = new_datadef_atom(8,op);
      a->align = 1;
      add_atom(0,a);
    }
    else
      syntax_error(8);  /* invalid data operand */
  }
  eol(s);
}
Ejemplo n.º 4
0
Archivo: syntax.c Proyecto: kusma/vasm
static void handle_datadef(char *s,int sz)
{
  for (;;) {
    char *opstart = s;
    operand *op;
    dblock *db = NULL;

    if (OPSZ_BITS(sz)==8 && (*s=='\"' || *s=='\'')) {
      if (db = parse_string(&opstart,*s,8)) {
        add_atom(0,new_data_atom(db,1));
        s = opstart;
      }
    }
    if (!db) {
      op = new_operand();
      s = skip_operand(s);
      if (parse_operand(opstart,s-opstart,op,DATA_OPERAND(sz)))
        add_atom(0,new_datadef_atom(OPSZ_BITS(sz),op));
      else
        syntax_error(8);  /* invalid data operand */
    }

    s = skip(s);
    if (*s == ',')
      s = skip(s+1);
    else
      break;
  }
}
Ejemplo n.º 5
0
static void handle_data_offset(char *s,int size,int offset)
{
  for (;;) {
    char *opstart = s;
    operand *op;
    dblock *db = NULL;

    if (size==8 && (*s=='\"' || *s=='\'')) {
      if (db = parse_string(&opstart,*s,8)) {
        if (offset != 0) {
          int i;

          for (i=0; i<db->size; i++)
            db->data[i] = db->data[i] + offset;
        }
        add_atom(0,new_data_atom(db,1));
        s = opstart;
      }
    }
    if (!db) {
      op = new_operand();
      s = skip_operand(s);
      if (parse_operand(opstart,s-opstart,op,DATA_OPERAND(size))) {
        atom *a;

        if (offset != 0)
          op->value = make_expr(ADD,number_expr(offset),op->value);
        a = new_datadef_atom(abs(size),op);
        a->align = 1;
        add_atom(0,a);
      }
      else
        syntax_error(8);  /* invalid data operand */
    }

    s = skip(s);
    if (*s == ',') {
      s = skip(s+1);
    }
    else if (*s == commentchar) {
      break;
    }
    else if (*s) {
      syntax_error(9);  /* , expected */
      return;
    }
    else
      break;
  }

  eol(s);
}
Ejemplo n.º 6
0
static void do_alignment(taddr align,expr *offset)
{
  atom *a = new_space_atom(offset,1,0);

  a->align = align;
  add_atom(0,a);
}
Ejemplo n.º 7
0
Archivo: syntax.c Proyecto: kusma/vasm
static void do_alignment(taddr align,expr *offset,size_t pad,expr *fill)
{
  atom *a = new_space_atom(offset,pad,fill);

  a->align = align;
  add_atom(0,a);
}
Ejemplo n.º 8
0
/**
    Read a line specifying an atom, store it in the config. Use
    supplied types to add assign radius and class. Returns
    FREESASA_WARN for duplicates. Returns FREESASA_FAIL for syntax
    errors or memory allocation errors. FREESASA_SUCCESS else.
 */
static int
read_atoms_line(struct classifier_config *config,
                const struct classifier_types *types,
                const char* line)
{
    size_t blen=100;
    char buf1[blen], buf2[blen], buf3[blen];
    int res, type, atom;
    if (sscanf(line,"%s %s %s",buf1,buf2,buf3) == 3) {
        type = find_string(types->name, buf3, types->n_types);
        if (type < 0) 
            return freesasa_fail("Unknown atom type '%s' in line '%s'",buf3,line);
        res = add_residue(config,buf1);
        if (res == FREESASA_FAIL) return fail_msg("");
        atom = add_atom(config->residue[res],
                        buf2,
                        types->type_radius[type],
                        types->type_class[type]);

        if (atom == FREESASA_FAIL) return fail_msg("");
        if (atom == FREESASA_WARN) return FREESASA_WARN;
        
    } else {
        return freesasa_fail("in %s(): Could not parse line '%s', expecting triplet of type "
                             "'RESIDUE ATOM CLASS', for example 'ALA CB C_ALI'.",
                             __func__, line);
    }
    return FREESASA_SUCCESS;
}
Ejemplo n.º 9
0
Archivo: syntax.c Proyecto: ezrec/vasm
static void stab_entry(char *name,int type,int othr,int desc,char *s)
{
  section *stabs;

  if (!(stabs = find_section(stabname,stabattr))) {
    section *str;
    dblock *db;

    stabs = new_section(stabname,stabattr,4);
    if (!(str = find_section(stabstrname,stabstrattr))) {
      str = new_section(stabstrname,stabstrattr,1);
    }
    else {
      if (str->pc != 0)
        ierror(0);
    }
    /* first byte of .stabstr is 0 */
    add_atom(str,new_space_atom(number_expr(1),1,0)); 
    /* compilation unit header has to be patched by output module */
    new_stabstr(getfilename());
    db = new_dblock();
    db->size = 12;
    db->data = mymalloc(12);
    add_atom(stabs,new_data_atom(db,1));
  }

  add_const_datadef(stabs,name?new_stabstr(name):0,32,1);
  add_const_datadef(stabs,type,8,1);
  add_const_datadef(stabs,othr,8,1);
  add_const_datadef(stabs,desc,16,1);
  if (s) {
    operand *op = new_operand();
    int len = oplen(skip_operand(s),s);

    if (parse_operand(s,len,op,DATA_OPERAND(32))) {
      atom *a = new_datadef_atom(32,op);

      a->align = 1;
      add_atom(stabs,a);
    }
    else
      syntax_error(8);
  }
  else
    add_atom(stabs,new_space_atom(number_expr(4),1,0));  /* no value */
}
Ejemplo n.º 10
0
Archivo: syntax.c Proyecto: ezrec/vasm
static void do_align(taddr align,expr *fill,taddr max)
/* @@@ 'max' alignment is not really supported at the moment */
{
  atom *a = new_space_atom(number_expr(0),1,fill);

  a->align = align;
  add_atom(0,a);
}
Ejemplo n.º 11
0
Archivo: syntax.c Proyecto: kusma/vasm
static void do_space(int size,expr *cnt,expr *fill)
{
  atom *a;

  a = new_space_atom(cnt,size>>3,fill);
  a->align = DATA_ALIGN(size);
  add_atom(0,a);
}
Ejemplo n.º 12
0
Archivo: syntax.c Proyecto: ezrec/vasm
static void handle_align(char *s)
{
  taddr align=parse_constexpr(&s);
  atom *a=new_space_atom(number_expr(0),1,0);
  a->align=1<<align;
  add_atom(0,a);
  eol(s);
}
Ejemplo n.º 13
0
Archivo: syntax.c Proyecto: ezrec/vasm
static void handle_data(char *s,int size,int noalign)
{
  for (;;) {
    char *opstart = s;
    operand *op;
    dblock *db = NULL;

    if ((size==8 || size==16) && *s=='\"') {
      if (db = parse_string(&opstart,*s,size)) {
        add_atom(0,new_data_atom(db,1));
        s = opstart;
      }
    }
    if (!db) {
      op = new_operand();
      s = skip_operand(s);
      if (parse_operand(opstart,s-opstart,op,DATA_OPERAND(size))) {
        atom *a;

        a = new_datadef_atom(size,op);
        if (noalign)
          a->align=1;
        add_atom(0,a);
      }
      else
        syntax_error(8);  /* invalid data operand */
    }

    s = skip(s);
    if (*s == ',') {
      s = skip(s+1);
    }
    else if (*s==commentchar)
      break;
    else if (*s) {
      syntax_error(9);  /* , expected */
      return;
    }
    else
      break;
  }

  eol(s);
}
Ejemplo n.º 14
0
Archivo: syntax.c Proyecto: ezrec/vasm
static void new_bss(char *s,int global)
{
  char *name;
  symbol *sym;
  atom *a;
  taddr size;
  section *bss;

  if(!(name=parse_identifier(&s))){
    syntax_error(10);  /* identifier expected */
    return;
  }
  size=comma_constexpr(&s);
  if(size<=sdlimit){
    if(!(bss=find_section(sbssname,sbssattr)))
      bss=new_section(sbssname,sbssattr,1);
  }
  else{
    if(!(bss=find_section(bssname,bssattr)))
      bss=new_section(bssname,bssattr,1);
  }
  sym=new_labsym(bss,name);
  sym->flags|=TYPE_OBJECT;
  if(global) sym->flags|=EXPORT;
  sym->size=number_expr(size);
  myfree(name);
  s=skip(s);
  if(*s==','){
    s=skip(s+1);
    sym->align=parse_constexpr(&s);
  }
  else
    sym->align=(size>=8)?8:4;
  a=new_label_atom(sym);
  if(sym->align)
    a->align=sym->align;
  add_atom(bss,a);
  a=new_space_atom(number_expr(size),1,0);
  if(sym->align)
    a->align=sym->align;
  add_atom(bss,a);
  eol(s);
}
Ejemplo n.º 15
0
Archivo: syntax.c Proyecto: ezrec/vasm
static void handle_space(char *s)
{
  expr *space,*fill=0;
  space=parse_expr_tmplab(&s);
  s=skip(s);
  if(*s==','){
    s=skip(s+1);
    fill=parse_expr_tmplab(&s);
  }
  add_atom(0,new_space_atom(space,1,fill));
  eol(s);  
}
Ejemplo n.º 16
0
void generate_pointe(unsigned xmin, unsigned ymin, unsigned zmin, 
		     unsigned xmax, unsigned ymax, unsigned zmax,
		     float yspeed)
{
  for(int z = zmin*2; z <= zmax*2; z += 2) {
    unsigned skipped = xmax - xmin - 2;

    for(int y = ymin*2; y <= ymax*2; y += 2) {
      for(int x = xmin*2; x <= xmax*2; x += 2) {

	// Place 4 atoms per lattice
	// 0, 0, 0
	add_atom(x, y, z,
		 0.0, yspeed, 0.0,
		 2*xmin + skipped, 2*ymin, 2*zmin + skipped,
		 2*xmax - skipped, 2*ymax, 2*zmax - skipped);

	// 1/2, 0, 1/2
	add_atom(x + 1, y, z + 1,
		 0.0, yspeed, 0.0,
		 2*xmin + skipped, 2*ymin, 2*zmin + skipped,
		 2*xmax - skipped, 2*ymax, 2*zmax - skipped);

	// 0, 1/2, 1/2
	add_atom(x, y + 1, z + 1,
		 0.0, yspeed, 0.0,
		 2*xmin + skipped, 2*ymin, 2*zmin + skipped,
		 2*xmax - skipped, 2*ymax, 2*zmax - skipped);

	// 1/2, 1/2, 0 
	add_atom(x + 1, y + 1, z,
		 0.0, yspeed, 0.0,
		 2*xmin + skipped, 2*ymin, 2*zmin + skipped,
		 2*xmax - skipped, 2*ymax, 2*zmax - skipped);
      }
    if(skipped)
      skipped --;
    }
  }
}
Ejemplo n.º 17
0
Archivo: syntax.c Proyecto: ezrec/vasm
static void handle_data(char *s,int size,int noalign,int zeroterm)
{
  expr *tree;
  dblock *db;
  do{
    char *opstart=s;
    operand *op;
    if(size==8&&*s=='\"'){
      s=string(s,&db);
      add_atom(0,new_data_atom(db,1));
    }else{
      op=new_operand();
      s=skip_operand(s);
      if(!parse_operand(opstart,s-opstart,op,DATA_OPERAND(size))){
        syntax_error(8);
      }else{
        atom *a=new_datadef_atom(size,op);
        if(noalign)
          a->align=1;
        add_atom(0,a);
      }
    }
    s=skip(s);
    if(*s==','){
      s=skip(s+1);
    }else if(*s)
      syntax_error(9);
  }while(*s);
  if(zeroterm){
    if(size!=8)
      ierror(0);
    db=new_dblock();
    db->size=1;
    db->data=mymalloc(1);
    *db->data=0;
    add_atom(0,new_data_atom(db,1));
  }    
  eol(s);
}
Ejemplo n.º 18
0
Archivo: syntax.c Proyecto: ezrec/vasm
static taddr new_stabstr(char *name)
{
  section *str;
  taddr index;
  dblock *db;

  if (!(str = find_section(stabstrname,stabstrattr)))
    ierror(0);
  index = str->pc;
  db = new_dblock();
  db->size = strlen(name) + 1;
  db->data = name;
  add_atom(str,new_data_atom(db,1));
  return index;
}
Ejemplo n.º 19
0
Archivo: syntax.c Proyecto: ezrec/vasm
static void handle_org(char *s)
{
  if (*s == current_pc_char) {    /*  "* = * + <expr>" reserves bytes */
    s = skip(s+1);
    if (*s == '+') {
      add_atom(0,new_space_atom(parse_expr_tmplab(&s),1,0));
    }
    else {
      syntax_error(18);  /* syntax error */
      return;
    }
  }
  else {
    new_org(parse_constexpr(&s));
  }
  eol(s);
}
Ejemplo n.º 20
0
END_TEST

START_TEST (test_classifier) 
{
    freesasa_set_verbosity(FREESASA_V_SILENT);

    set_fail_freq(1);
    ck_assert_ptr_eq(classifier_types_new(),NULL);
    ck_assert_ptr_eq(classifier_residue_new("A"),NULL);
    ck_assert_ptr_eq(classifier_config_new(),NULL);

    for (int i = 1; i < 5; ++i) {
        set_fail_freq(10000);
        struct classifier_types *types = classifier_types_new();
        struct classifier_residue *res = classifier_residue_new("ALA");
        struct classifier_config *cfg = classifier_config_new();

        if (i < 3) {
            set_fail_freq(i);
            ck_assert_int_eq(add_class(types,"A"),FREESASA_FAIL);        
            set_fail_freq(i);
            ck_assert_int_eq(add_type(types,"a","A",1.0),FREESASA_FAIL);
        } 
        set_fail_freq(i);
        ck_assert_int_eq(add_atom(res,"A",1.0,0),FREESASA_FAIL);
        set_fail_freq(i);
        ck_assert_int_eq(add_residue(cfg,"A"),FREESASA_FAIL);
        classifier_types_free(types);
        classifier_residue_free(res);
        classifier_config_free(cfg);
    }
    // don't test all levels, but make sure errors in low level
    // allocation propagates to the interface
    FILE *config = fopen(SHAREDIR "naccess.config","r");
    ck_assert_ptr_ne(config, NULL);
    for (int i = 1; i < 50; ++i) {
        set_fail_freq(i);
        ck_assert_ptr_eq(freesasa_classifier_from_file(config),NULL);
        rewind(config);
    }
    fclose(config);
    freesasa_set_verbosity(FREESASA_V_NORMAL);
}
Ejemplo n.º 21
0
Archivo: syntax.c Proyecto: kusma/vasm
static void handle_assert(char *s)
{
  char *expstr = s;
  expr *aexp = NULL;

  do {
    s = skip(s);
    if (aexp)  /* concat. expressions with log. AND */
      aexp = make_expr(LAND,aexp,parse_expr(&s));
    else
      aexp = parse_expr(&s);
    simplify_expr(aexp);
    s = skip(s);
  }
  while (*s++ == ',');  /* another assertion, separated by comma? */

  s--;
  add_atom(0,new_assert_atom(aexp,cnvstr(expstr,s-expstr),NULL));
  eol(s);
}
Ejemplo n.º 22
0
Archivo: syntax.c Proyecto: ezrec/vasm
static void add_const_datadef(section *s,taddr val,int size,int align)
{
  char buf[32];
  int len;
  operand *op;

  if (size <= 32) {
    len = sprintf(buf,"%ld",(long)val);
    op = new_operand();
    if (parse_operand(buf,len,op,DATA_OPERAND(size))) {
      atom *a = new_datadef_atom(size,op);

      a->align = align;
      add_atom(s,a);
    }
    else
      syntax_error(8);
  }
  else
    ierror(0);
}
Ejemplo n.º 23
0
System read_conf_from_grofile(const std::string& path, const real sigma)
{
    std::ifstream ifs { path, std::ifstream::in };

    constexpr size_t buflen = 256;
    std::string buffer (buflen, ' ');

    getline(ifs, buffer);
    const std::string title = buffer;

    getline(ifs, buffer);
    const auto num_atoms = static_cast<uint64_t>(stoi(buffer));

    auto list = CellList(num_atoms, RVec {0.0, 0.0, 0.0}, RVec {0.0, 0.0, 0.0});

    for (unsigned i = 0; i < num_atoms; ++i)
    {
        getline(ifs, buffer);

        const auto x = std::stod(buffer.substr(20, 8)) / sigma;
        const auto y = std::stod(buffer.substr(28, 8)) / sigma;
        const auto z = std::stod(buffer.substr(36, 8)) / sigma;

        list.add_atom(x, y, z);
    }

    getline(ifs, buffer);
    const auto dx = std::stod(buffer.substr(0, 10)) / sigma;
    const auto dy = std::stod(buffer.substr(10, 10)) / sigma;
    const auto dz = std::stod(buffer.substr(20, 10)) / sigma;

    const RVec box_size {dx, dy, dz};
    list.size = box_size;

    auto system = System(title, box_size);
    system.cell_lists.push_back(std::move(list));

    return system;
}
Ejemplo n.º 24
0
/* create tori */
void create_tori (struct surface *this_srf)
{
	int k;
	long n_pair;
	double root1, root2, distance12, squared_distance12;
	double radius1, radius2, torus_radius;
	double axis[3];
	double *sphere1_center, *sphere2_center;
	char message[MAXLINE];
	struct sphere *sphere1, *sphere2;
	struct neighbor *first_neighbor, *last_neighbor, *neighbor;
	struct neighbor *first_neighbor2, *last_neighbor2, *neighbor2;
	struct pair *pair_ptr;
    struct cept *ex;

	if (this_srf -> n_pair <= 0) return;

	/* initialize to tmp tor array beginning */
	pair_ptr = this_srf -> pair_array;
	n_pair = 0;

	/* loop through sphere list */
	for (sphere1 = (struct sphere *) (this_srf -> head_atom); sphere1 != NULL;
		sphere1 = sphere1 -> next) {
		if ((first_neighbor = sphere1 -> first_neighbor) == NULL) continue;
		last_neighbor = sphere1 -> last_neighbor;
		/* transfer info to local variables */
		sphere1_center = sphere1 -> center;
		radius1 = sphere1 -> radius;
		/* loop through neighbors of this sphere */
		for (neighbor = first_neighbor; neighbor <= last_neighbor;
			neighbor++) {
			sphere2 = neighbor -> sphptr;
			if (sphere1 >= sphere2) continue; /* no duplication */
			/* transfer info to local variables */
			sphere2_center = sphere2 -> center;
			radius2 = sphere2 -> radius;
			/* geometric computations for torus */
			for (k = 0; k < 3; k++)
				axis[k] = *(sphere2_center + k) - *(sphere1_center + k);
			distance12 = norm (axis);
			if (distance12 <= 0.0) {
				ex = new_cept (GEOMETRY_ERROR,  DEGENERACY,  FATAL_SEVERITY);
				add_function (ex, "create_tori");
				add_source (ex, "mstorus.c");
				add_message (ex, "coincident atoms");
				add_atom (ex, sphere1);
				add_atom (ex, sphere2);
				return;
			}
			squared_distance12 = distance12 * distance12;
			if (squared_distance12 <= 0.0) {
				ex = new_cept (GEOMETRY_ERROR,  DEGENERACY,  FATAL_SEVERITY);
				add_function (ex, "create_tori");
				add_source (ex, "mstorus.c");
				add_message (ex, "coincident atoms");
				add_atom (ex, sphere1);
				add_atom (ex, sphere2);
				return;
			}
			root1 = (radius1 + radius2 + 2 * this_srf -> probe_radius) *
				(radius1 + radius2 + 2 * this_srf -> probe_radius) -
				squared_distance12;
			if (root1 < 0.0) continue; /* sphere too far away */
			root1 = sqrt (root1);
			root2 = squared_distance12 - (radius1 - radius2) * (radius1 - radius2);
			if (root2 < 0.0) continue; /* one sphere inside other */
			root2 = sqrt (root2);
			torus_radius = 0.5 * root1 * root2 / distance12;
			if (torus_radius <= 0.0) continue;
			/* store pointer for torus in first spheres list */
			neighbor -> torptr = pair_ptr;
			/* store pointer for torus in second spheres list */
			first_neighbor2 = sphere2 -> first_neighbor;
			last_neighbor2 = sphere2 -> last_neighbor;
			for (neighbor2 = first_neighbor2;
				neighbor2 <= last_neighbor2; neighbor2++)
				if (neighbor2 -> sphptr == sphere1) {
					neighbor2 -> torptr = pair_ptr;
					break;
				}
			pair_ptr -> free = TRUE;
			pair_ptr -> buried = TRUE;
			pair_ptr -> sph[0] = sphere1;
			pair_ptr -> sph[1] = sphere2;
			pair_ptr++;
			n_pair = pair_ptr - this_srf -> pair_array;
			if (n_pair > this_srf -> n_pair) {
				ex = new_cept (LOGIC_ERROR,  INCONSISTENCY,  FATAL_SEVERITY);
				add_function (ex, "create_tori");
				add_source (ex, "mstorus.c");
				add_long (ex, "before", this_srf -> n_pair);
				add_long (ex, "after", n_pair);
				add_message (ex, "inconsistent number of neighbors");
				return;
			}
		}
	}

	this_srf -> n_pair = n_pair;
	sprintf (message, "%8ld neighbor pairs", n_pair);
	inform (message);
	return;
}
Ejemplo n.º 25
0
void setup_torus_fields (double probe_radius, struct pair *pair_ptr, double torus_center[3], double *return_radius, double torus_axis[3])
{
	int k;
	double root1, root2, asymmetry;
	double distance12, distance12_squared;
	double radius1, radius2, torus_radius;
	double *sphere1_center, *sphere2_center;
	char message[MAXLINE];
	struct sphere *sphere1, *sphere2;
    struct cept *ex;

	sphere1 = pair_ptr -> sph[0];
	sphere2 = pair_ptr -> sph[1];
	if (sphere1 >= sphere2) {
		ex = new_cept (LOGIC_ERROR,  INCONSISTENCY,  FATAL_SEVERITY);
		add_function (ex, "setup_torus_fields");
		add_source (ex, "mstorus.c");
		add_atom (ex, sphere1);
		add_atom (ex, sphere2);
		return;
	}
	/* transfer info to local variables */
	sphere1_center = sphere1 -> center;
	radius1 = sphere1 -> radius;
	sphere2_center = sphere2 -> center;
	radius2 = sphere2 -> radius;
	/* geometric computations for torus */
	for (k = 0; k < 3; k++)
		torus_axis[k] = *(sphere2_center + k) - *(sphere1_center + k);
	distance12 = norm (torus_axis);
	if (distance12 <= 0.0) {
		ex = new_cept (GEOMETRY_ERROR,  DEGENERACY,  FATAL_SEVERITY);
		add_function (ex, "setup_torus_fields");
		add_source (ex, "mstorus.c");
		add_message (ex, "coincident atoms");
		add_atom (ex, sphere1);
		add_atom (ex, sphere2);
		return;
	}
	distance12_squared = distance12 * distance12;
	if (distance12_squared <= 0.0) {
		ex = new_cept (GEOMETRY_ERROR,  DEGENERACY,  FATAL_SEVERITY);
		add_function (ex, "setup_torus_fields");
		add_source (ex, "mstorus.c");
		add_message (ex, "coincident atoms");
		add_atom (ex, sphere1);
		add_atom (ex, sphere2);
		return;
	}
	for (k = 0; k < 3; k++) torus_axis[k] /= distance12;
	root1 = (radius1 + radius2 + 2 * probe_radius) *
		(radius1 + radius2 + 2 * probe_radius) - distance12_squared;
	if (root1 < 0.0) {
		ex = new_cept (LOGIC_ERROR,  INCONSISTENCY,  FATAL_SEVERITY);
		add_function (ex, "setup_torus_fields");
		add_source (ex, "mstorus.c");
		add_message (ex, "inconsistent existence of torus");
		add_atom (ex, sphere1);
		add_atom (ex, sphere2);
		add_double (ex, "root1", root1);
		return;
	}
	root1 = sqrt (root1);
	root2 = distance12_squared - (radius1 - radius2) *
		(radius1 - radius2);
	if (root2 < 0.0) {
		ex = new_cept (LOGIC_ERROR,  INCONSISTENCY,  FATAL_SEVERITY);
		add_function (ex, "setup_torus_fields");
		add_source (ex, "mstorus.c");
		add_message (ex, "inconsistent existence of torus");
		add_atom (ex, sphere1);
		add_atom (ex, sphere2);
		add_double (ex, "root2", root2);
		return;
	}
	root2 = sqrt (root2);
	torus_radius = 0.5 * root1 * root2 / distance12;
	if (torus_radius <= 0) {
		ex = new_cept (LOGIC_ERROR,  INCONSISTENCY,  FATAL_SEVERITY);
		add_function (ex, "setup_torus_fields");
		add_source (ex, "mstorus.c");
		add_message (ex, "inconsistent existence of torus");
		add_atom (ex, sphere1);
		add_atom (ex, sphere2);
		add_double (ex, "torus_radius", torus_radius);
		return;
	}
	asymmetry = (radius1 + probe_radius) * (radius1 + probe_radius) -
		(radius2 + probe_radius) * (radius2 + probe_radius);
	for (k = 0; k < 3; k++)
		torus_center[k] = 0.5 * (*(sphere1_center + k) +
			*(sphere2_center + k))
		+ 0.5 * torus_axis[k] * asymmetry / distance12;

	*return_radius = torus_radius;
	return;
}
Ejemplo n.º 26
0
/* regular saddle surfaces for this torus */
void regular_saddle (struct surface *this_srf, struct torus *torus_ptr)
{
	int k, n_torus_arcs, arc_index;
	int index0, index1;
	struct arc *arc1, *arc2;
	struct circle *circle1, *circle2;
	double circle_points[MAX_SORT][3];
	double point_vector1[3];
	double point_vector2[3];
	short arc_orn[MAX_SORT];
	short indices[MAX_SORT];
	struct arc **arc_list, **arc_hdl;
	double wrap_angle;
    struct cept *ex;

	/* set up circles */

	circle1 = new_contact_circle (this_srf, torus_ptr, 0); if (error()) return;
	circle2 = new_contact_circle (this_srf, torus_ptr, 1); if (error()) return;

	/* count arcs belonging to torus */
	n_torus_arcs = 0;
	for (arc1 = torus_ptr -> first_arc; arc1 != NULL;
		arc1 = arc1 -> next) n_torus_arcs++;
	if (n_torus_arcs <= 0) return;

	/* must be even */
	if (0 != n_torus_arcs % 2) {
        ex = new_cept (GEOMETRY_ERROR, INCONSISTENCY, FATAL_SEVERITY);
        add_function (ex, "regular_saddle");
        add_source (ex, "msface.c");
        add_long (ex, "n_torus_arcs", n_torus_arcs);
        add_atom (ex, torus_ptr -> atm[0]);
        add_atom (ex, torus_ptr -> atm[1]);
		add_message (ex, "odd number of torus arcs");
		return;
	}
	if (n_torus_arcs > MAX_SORT) {
        ex = new_cept (GEOMETRY_ERROR, MSOVERFLOW, FATAL_SEVERITY);
        add_function (ex, "regular_saddle");
        add_source (ex, "msface.c");
        add_long (ex, "n_torus_arcs", n_torus_arcs);
        add_long (ex, "MAX_SORT", MAX_SORT);
        add_atom (ex, torus_ptr -> atm[0]);
        add_atom (ex, torus_ptr -> atm[1]);
		return;
	}

	/* allocate memory */
	arc_list = (struct arc **)
		allocate_pointers (ARC, n_torus_arcs);
	if (arc_list == NULL) {
        ex = new_cept (MEMORY_ERROR, ALLOCATION, FATAL_SEVERITY);
        add_function (ex, "regular_saddle");
        add_source (ex, "msface.c");
        add_atom (ex, torus_ptr -> atm[0]);
        add_atom (ex, torus_ptr -> atm[1]);
		return;
	}

	/* set up torus arc pointer list */
	for (arc1 = torus_ptr -> first_arc, arc_index = 0;
		arc_index < n_torus_arcs;
		arc1 = arc1 -> next, arc_index++) {
		arc_hdl = arc_list + arc_index;
		*arc_hdl = arc1;			/* pointer to arc */
	}

	setup_torus_arcs (torus_ptr -> axis, n_torus_arcs, arc_list,
		circle_points, arc_orn);
	if (error()) return;

	sort_points (torus_ptr -> center, torus_ptr -> radius,
		torus_ptr -> axis, n_torus_arcs, circle_points,
		arc_orn, indices);
	if (error()) return;

	for (arc_index = 0; arc_index < n_torus_arcs; arc_index += 2) {
		index0 = indices[arc_index];
		arc_hdl = arc_list + index0;
		arc1 = *arc_hdl;
		index1 = indices[arc_index+1];
		arc_hdl = arc_list + index1;
		arc2 = *arc_hdl;

		/* compute saddle wrap angle */
		for (k = 0; k < 3; k++) {
			point_vector1[k] =
				(circle_points[index0][k] - torus_ptr -> center[k]) /
					torus_ptr -> radius;
			point_vector2[k] =
				(circle_points[index1][k] - torus_ptr -> center[k]) /
					torus_ptr -> radius;
		}
		wrap_angle = positive_angle (point_vector1, point_vector2,
			torus_ptr -> axis);
		/* create saddle face */
		newsad (this_srf, arc1, arc2, circle1, circle2, torus_ptr, wrap_angle);
		if (error()) return;
	}

	/* free temporary memory */
	free_pointers (ARC, arc_list);
}
Ejemplo n.º 27
0
void
logon ()
{
  int len;
  char *sn = PARAM_SCREEN_NAME;
  char *pass;
  char login[11];
  stream_t stream;
  u_int16_t streamid = htons(0x16);

  log (LOG_NOTICE, _("Loging into provider as '%s'\n"), sn);
  get_password (sn, &pass);
  len = strlen (sn);
  if (len < 10)
    {
      strncpy (login, sn, len);
      memset (&login[len], ' ', 10 - len);
      sn = login;
      sn[10]=0;
    }

  stream_init(&stream);
  stream_put(&stream, sizeof(streamid), &streamid);
  add_atom(&stream, UNI_PID, UNI_START_STREAM, 0);
  add_atom(&stream, MAN_PID, MAN_SET_CONTEXT_RELATIVE, 1);
  add_atom(&stream, MAN_PID, MAN_SET_CONTEXT_INDEX, 5);
  add_atom(&stream, DE_PID , DE_DATA, sn);
  add_atom(&stream, MAN_PID, MAN_END_CONTEXT, 0);
  add_atom(&stream, MAN_PID, MAN_END_CONTEXT, 0);
  add_atom(&stream, MAN_PID, MAN_SET_CONTEXT_RELATIVE, 2);
  add_atom(&stream, DE_PID , DE_DATA, pass);
  add_atom(&stream, MAN_PID, MAN_END_CONTEXT, 0);
  add_atom(&stream, MAN_PID, MAN_SET_CONTEXT_RELATIVE, 16);
  add_atom(&stream, MAN_PID, MAN_SET_CONTEXT_INDEX, 1);
  add_atom(&stream, MAN_PID, MAN_END_CONTEXT, 0);
  add_atom(&stream, MAN_PID, MAN_END_CONTEXT, 0);
  add_atom(&stream, UNI_PID, UNI_END_STREAM, 0);
  fdo_send (TOKEN ("Dd"), stream.data, stream.used);
  stream_destroy(&stream);

  fdo_unregister (TOKEN ("SD"));
  fdo_register (TOKEN ("At"), login_confirm);
  fdo_register (TOKEN ("AT"), atom_handler);
  fdo_register (TOKEN ("at"), atom_handler);
}
Ejemplo n.º 28
0
Archivo: syntax.c Proyecto: ezrec/vasm
void parse(void)
{
  char *s,*line,*ext[MAX_QUALIFIERS?MAX_QUALIFIERS:1],*op[MAX_OPERANDS];
  char *labname,*start;
  int inst_len,ext_len[MAX_QUALIFIERS?MAX_QUALIFIERS:1],op_len[MAX_OPERANDS];
  int ext_cnt,op_cnt;
  instruction *ip;

  while (line=read_next_line()){
    if (clev >= MAXCONDLEV)
      syntax_error(16,clev);  /* nesting depth exceeded */

    if (!cond[clev]) {
      /* skip source until ELSE or ENDIF */
      int idx;

      s = line;
      idx = check_directive(&s);
      if (idx >= 0) {
        if (!strncmp(directives[idx].name,"if",2)) {
          ifnesting++;
        }
        else if (ifnesting==0 && !strncmp(directives[idx].name,"else",4)) {
          cond[clev] = 1;
        }
        else if (directives[idx].func == handle_endif) {
          if (ifnesting == 0) {
            if (clev > 0)
              clev--;
            else
              syntax_error(14);  /* endif without if */
          }
          else
            ifnesting--;
        }
      }
      continue;
    }

    s=skip(line);

    if(handle_directive(s))
      continue;

    /* skip spaces */
    s=skip(s);
    if(!*s||*s==commentchar)
      continue;

    /* check for label */
    start=s;
    if(labname=get_local_label(&s)){   /* local label? */
      if(*s!=':'){
        s=start;
        myfree(labname);
        labname=NULL;
      }
    }
    else if(ISIDSTART(*s)){            /* or global label? */
      s++;
      while(ISIDCHAR(*s)) s++;
      if(*s!=':')
        s=start;
      else
        labname=cnvstr(start,s-start);
    }
    if(labname){
      /* we have found a valid global or local label */
      add_atom(0,new_label_atom(new_labsym(0,labname)));
      s=skip(s+1);
      myfree(labname);
    }

    if(!*s||*s==commentchar)
      continue;

    s=skip(parse_cpu_special(s));
    if(*s==0||*s==commentchar)
      continue;

    if(handle_directive(s))
      continue;

    /* read mnemonic name */
    start=s;
    ext_cnt=0;
    if(!ISIDSTART(*s)){
      syntax_error(10);
      continue;
    }
#if MAX_QUALIFIERS==0
    while(*s&&!isspace((unsigned char)*s))
      s++;
    inst_len=s-start;
#else
    s=parse_instruction(s,&inst_len,ext,ext_len,&ext_cnt);
#endif
    s=skip(s);

    if(execute_macro(start,inst_len,ext,ext_len,ext_cnt,s,clev))
      continue;

    /* read operands, terminated by comma (unless in parentheses)  */
    op_cnt=0;
    while(*s&&*s!=commentchar&&op_cnt<MAX_OPERANDS){
      op[op_cnt]=s;
      s=skip_operand(s);
      op_len[op_cnt]=oplen(s,op[op_cnt]);
#if !ALLOW_EMPTY_OPS
      if(op_len[op_cnt]<=0)
        syntax_error(5);
      else
#endif
        op_cnt++;
      s=skip(s);
      if(*s!=','){
        break;
      }else{
        s=skip(s+1);
      }
    }      
    s=skip(s);
    if(*s!=0&&*s!=commentchar) syntax_error(6);
    ip=new_inst(start,inst_len,op_cnt,op,op_len);
#if MAX_QUALIFIERS>0
    if(ip){
      int i;
      for(i=0;i<ext_cnt;i++)
        ip->qualifiers[i]=cnvstr(ext[i],ext_len[i]);
      for(;i<MAX_QUALIFIERS;i++)
        ip->qualifiers[i]=0;
    }
#endif
    if(ip){
      add_atom(0,new_inst_atom(ip));
    }else
      ;
  }

  if (clev > 0)
    syntax_error(15);  /* if without endif */
}
Ejemplo n.º 29
0
/* This procedure is part of the MUMPS compiler. Under certain circumstances, procedure patstr will decide that a
 * pattern is a candidate for optimized processing using a DFA method. In such cases, procedure dfa_calc is called
 * to compile the instructions for do_pattern to execute the DFA evaluation. When, later, either dfa_calc or patstr
 * decides that the rest of the pattern invalidates the DFA strategy, this procedure is called to undo the compilation
 * for the DFA engine and build the data that would "normally" have been compiled for the pattern segment in question.
 */
boolean_t pat_unwind(
	int		*count,
	struct leaf	*leaves,
	int		leaf_num,
	int		*total_min,
	int		*total_max,
	int		min[],
	int		max[],
	int		size[],
	int		altmin,
	int		altmax,
	boolean_t	*last_infinite_ptr,
	uint4		**fstchar_ptr,
	uint4		**outchar_ptr,
	uint4		**lastpatptr_ptr)
{
	pat_strlit	strlit;
	uint4		pattern_mask;
	int		minim, maxim, leaf_cnt, charpos, offset, atom_map;
	boolean_t	infinite;

	assert(MAX_SYM > leaf_num);
	for (atom_map = *count, leaf_cnt = 0; leaf_cnt < leaf_num; atom_map++)
	{
		infinite = leaves->nullable[leaf_cnt];
		if (!(leaves->letter[leaf_cnt][0] & DFABIT))
		{
			pattern_mask = PATM_STRLIT;
			for (offset = 0; offset < size[atom_map]; offset += charpos)
			{
				for (charpos = 0; leaves->letter[leaf_cnt][charpos] >= 0; charpos++)
				{
					assert((SIZEOF(strlit.buff) / SIZEOF(strlit.buff[0])) > (offset + charpos));
					strlit.buff[offset + charpos] = leaves->letter[leaf_cnt][charpos];
				}
				leaf_cnt++;
			}
		} else
		{
			pattern_mask = 0;
			for (charpos = 0; leaves->letter[leaf_cnt][charpos] >= 0; charpos++)
			{
				assert(MAX_DFA_STRLEN > charpos);
				pattern_mask |= leaves->letter[leaf_cnt][charpos];
			}
			leaf_cnt++;
		}
		minim = min[atom_map];
		maxim = max[atom_map];
		leaf_cnt += MAX(minim - 1, 0) * size[atom_map];
		strlit.bytelen = offset;
 		/* Since multi-byte characters currently dont go through DFA logic, the bytelen is guaranteed to be charlen */
 		strlit.charlen = offset;
		/* Since non-ascii characters in strings currently dont go through DFA logic, it is guaranteed to be an ascii
		 * string with no badchars */
		strlit.flags = 0;
		if ((MAX_PATTERN_ATOMS <= *count)
				|| !add_atom(count, pattern_mask, &strlit, infinite,
					&min[*count], &max[*count], &size[*count], total_min, total_max,
					minim, maxim, altmin, altmax, last_infinite_ptr, fstchar_ptr, outchar_ptr, lastpatptr_ptr))
			return FALSE;
	}
	return TRUE;
}
Ejemplo n.º 30
0
Archivo: syntax.c Proyecto: ezrec/vasm
/* Very simple, very incomplete. */
void parse(void)
{
  char *s,*line,*inst,*ext[MAX_QUALIFIERS?MAX_QUALIFIERS:1],*op[MAX_OPERANDS];
  int inst_len,ext_len[MAX_QUALIFIERS?MAX_QUALIFIERS:1],op_len[MAX_OPERANDS];
  int i,ext_cnt,op_cnt,par_cnt;
  instruction *ip;
  while(line=read_next_line()){
    s=line;

    if(isalnum((unsigned char)*s)){
      /* Handle labels at beginning of line */
      char *labname,*equ;
      symbol *label;
      while(*s&&!isspace((unsigned char)*s)&&*s!=':')
        s++;
      labname=cnvstr(line,s-line);
      s=skip(s+1);
      if(!strncmp(s,"equ",3)&&isspace((unsigned char)s[3])){
        s=skip(s+3);
        label=new_abs(labname,parse_expr(&s));
      }else{
        label=new_labsym(0,labname);
        add_atom(0,new_label_atom(label));
      }
      free(labname);
    }

    s=parse_cpu_special(s);

    if(handle_directive(s))
      continue;

    /* skip spaces */
    s=skip(s);
    if(!*s)
      continue;

    /* read mnemonic name */
    inst=s;
    if(!ISIDSTART(*s)){
      syntax_error(10);
      continue;
    }
#if MAX_QUALIFIERS==0
    while(*s&&!isspace((unsigned char)*s))
      s++;
#else
    while(*s&&*s!='.'&&!isspace((unsigned char)*s))
      s++;
#endif
    inst_len=s-inst;

    /* read qualifiers */
    ext_cnt=0;
    while(*s=='.'&&ext_cnt<MAX_QUALIFIERS){
      s++;
      ext[ext_cnt]=s;
      while(*s&&*s!='.'&&!isspace((unsigned char)*s))
        s++;
      ext_len[ext_cnt]=s-ext[ext_cnt];
      if(ext_len[ext_cnt]<=0)
        syntax_error(1);
      else
        ext_cnt++;
    }

    if(!isspace((unsigned char)*s)) syntax_error(2);
    
    /* read operands, terminated by comma (unless in parentheses)  */
    s=skip(s);
    op_cnt=0;
    while(*s&&op_cnt<MAX_OPERANDS){
      op[op_cnt]=s;
      s=skip_operand(s);
      op_len[op_cnt]=s-op[op_cnt];
      if(op_len[op_cnt]<=0)
        syntax_error(5);
      else
        op_cnt++;
      s=skip(s);
      if(*s!=','){
        break;
      }else{
        s=skip(s+1);
      }
    }      
    s=skip(s);
    if(*s!=0) syntax_error(6);
    ip=new_inst(inst,inst_len,op_cnt,op,op_len);
#if MAX_QUALIFIERS>0
    if(ip){
      for(i=0;i<ext_cnt;i++)
        ip->qualifiers[i]=cnvstr(ext[i],ext_len[i]);
      for(;i<MAX_QUALIFIERS;i++)
        ip->qualifiers[i]=0;
    }
#endif
    if(ip){
      add_atom(0,new_inst_atom(ip));
    }else
      ;
  }
}