예제 #1
0
파일: scratch.c 프로젝트: screen-editor/se
LINEDESC *se_gettxt (int line)
{
	LINEDESC *k;

	k = getind (line);
	gtxt (k);

	return (k);
}
예제 #2
0
static int genpoints (int attr) {
    poly_t *pp;
    int zip, npanxxloc, ctbna;
    short county, blk;
    char state, blks;
    char *s;
    item_t *itemmem, *itemp;
    int itemi;
    int *indp;
    edge_t *e1p, *e2p;
    int edgepi;
    vertex_t *v1p, *v2p, *v3p;
    int xyi;

    for (
        pp = (poly_t *) dtflatten (polydict); pp;
        pp = (poly_t *) dtlink (polydict, pp)
    ) {
        if (pp->edgepl == 0)
            continue;
        e1p = pp->edgeps[0];
        if (e1p->p0p == pp) {
            blks = e1p->blksl;
            blk = e1p->blkl;
            ctbna = e1p->ctbnal;
            county = e1p->countyl;
            state = e1p->statel;
            zip = e1p->zipl;
            npanxxloc = e1p->npanxxlocl;
        } else {
            blks = e1p->blksr;
            blk = e1p->blkr;
            ctbna = e1p->ctbnar;
            county = e1p->countyr;
            state = e1p->stater;
            zip = e1p->zipr;
            npanxxloc = e1p->npanxxlocr;
        }
        s = NULL;
        switch (attr) {
        case T_EATTR_BLKS:
            if ((state > 0) && (county > 0) && (ctbna > 0) && (blk > 0))
                s = sfprints (
                    "%02d%03d%06d%03d%c", state, county, ctbna, blk, blks
                );
            break;
        case T_EATTR_BLK:
            if ((state > 0) && (county > 0) && (ctbna > 0) && (blk > 0))
                s = sfprints ("%02d%03d%06d%03d", state, county, ctbna, blk);
            break;
        case T_EATTR_BLKG:
            if ((state > 0) && (county > 0) && (ctbna > 0) && (blk > 0))
                s = sfprints (
                    "%02d%03d%06d%d", state, county, ctbna, blk / 100
                );
            break;
        case T_EATTR_CTBNA:
            if ((state > 0) && (county > 0) && (ctbna > 0))
                s = sfprints ("%02d%03d%06d", state, county, ctbna);
            break;
        case T_EATTR_COUNTY:
            if ((state > 0) && (county > 0))
                s = sfprints ("%02d%03d", state, county);
            break;
        case T_EATTR_STATE:
            if ((state > 0))
                s = sfprints ("%02d", state);
            break;
        case T_EATTR_ZIP:
            if ((zip > 0))
                s = sfprints ("%05d", zip);
            break;
        case T_EATTR_NPANXXLOC:
            if ((npanxxloc > -1))
                s = sfprints ("%d", npanxxloc);
            break;
        case T_EATTR_COUNTRY:
            s = "USA";
            break;
        }
        if (!s)
            continue;
        if (!(itemmem = malloc (sizeof (item_t)))) {
            SUwarning (1, "genpoints", "malloc failed for itemmem");
            return -1;
        }
        itemmem->name = strdup (s);
        if (!(itemp = dtinsert (itemdict, itemmem))) {
            SUwarning (1, "genpoints", "dtinsert failed for itemp");
            return -1;
        }
        if (itemp == itemmem) {
            itemp->pointn = 0, itemp->pointm = POINTINCR;
            if (!(itemp->points = malloc (sizeof (point_t) * itemp->pointm))) {
                SUwarning (1, "genpoints", "malloc failed for points");
                return -1;
            }
            itemp->indn = 0, itemp->indm = INDINCR;
            if (!(itemp->inds = malloc (sizeof (int) * itemp->indm))) {
                SUwarning (1, "genpoints", "malloc failed for inds");
                return -1;
            }
            itemp->trin = 0, itemp->trim = TRIINCR;
            if (!(itemp->tris = malloc (sizeof (tri_t) * itemp->trim))) {
                SUwarning (1, "genpoints", "malloc failed for tris");
                return -1;
            }
        }
        orderedges (pp);
        for (v1p = NULL, edgepi = 0; edgepi < pp->edgepl; edgepi++) {
            e1p = pp->edgeps[edgepi];
            if (!v1p) {
                if (!(indp = getind (itemp, 0))) {
                    SUwarning (1, "genpoints", "getind failed");
                    return -1;
                }
                if (e1p->p0p == pp)
                    v1p = e1p->v0p, v2p = e1p->v1p;
                else
                    v1p = e1p->v1p, v2p = e1p->v0p;
                v3p = v1p;
            }
            (*indp)++;
            if (!getpoint (itemp, v1p->xy)) {
                SUwarning (1, "genpoints", "getpoint failed (1)");
                return -1;
            }
            if (v1p == e1p->v0p) {
                for (xyi = 0; xyi < e1p->xyn; xyi++) {
                    (*indp)++;
                    if (!getpoint (itemp, e1p->xys[xyi])) {
                        SUwarning (1, "genpoints", "getpoint failed (2)");
                        return -1;
                    }
                }
            } else {
                for (xyi = e1p->xyn - 1; xyi >= 0; xyi--) {
                    (*indp)++;
                    if (!getpoint (itemp, e1p->xys[xyi])) {
                        SUwarning (1, "genpoints", "getpoint failed (3)");
                        return -1;
                    }
                }
            }
            v1p = NULL;
            if (edgepi + 1 < pp->edgepl) {
                e2p = pp->edgeps[edgepi + 1];
                if (e2p->v0p == v2p)
                    v1p = e2p->v0p, v2p = e2p->v1p;
                else if (e2p->v1p == v2p)
                    v1p = e2p->v1p, v2p = e2p->v0p;
            }
            if (!v1p) {
                (*indp)++;
                if (!getpoint (itemp, v2p->xy)) {
                    SUwarning (1, "genpoints", "getpoint failed (4)");
                    return -1;
                }
                if (savemask & 8) {
                    if (v2p->xy.x != v3p->xy.x || v2p->xy.y != v3p->xy.y) {
                        (*indp)++;
                        if (!getpoint (itemp, v3p->xy)) {
                            SUwarning (1, "genpoints", "getpoint failed (5)");
                            return -1;
                        }
                    }
                }
            }
        }
    }
    itempn = dtsize (itemdict);
    if (!(itemps = malloc (sizeof (item_t *) * itempn))) {
        SUwarning (1, "genpoints", "malloc failed for itemps");
        return -1;
    }
    for (
        itemi = 0, itemp = (item_t *) dtflatten (itemdict); itemp;
        itemp = (item_t *) dtlink (itemdict, itemp)
    )
        itemps[itemi++] = itemp;
    return 0;
}
예제 #3
0
  int SysSPA2d::doSPAwindowed(int window, int niter, double sLambda, int useCSparse)
  {
    // number of nodes
    int nnodes = nodes.size();
    if (nnodes < 2) return 0;

    int nlow = nnodes - window;
    if (nlow < 1) nlow = 1;     // always have one fixed node

    if (verbose)
      cout << "[SPA Window] From " << nlow << " to " << nnodes << endl;

    // number of constraints
    int ncons = p2cons.size();

    // set up SPA
    SysSPA2d spa;
    spa.verbose = verbose;

    // node, constraint vectors and index mapping
    std::vector<Node2d,Eigen::aligned_allocator<Node2d> > &wnodes = spa.nodes;
    std::vector<Con2dP2,Eigen::aligned_allocator<Con2dP2> > &wp2cons = spa.p2cons;
    std::map<int,int> inds;
    std::vector<int> rinds;     // reverse indices

    // loop through all constraints and set up fixed nodes and constraints
    for (int i=0; i<ncons; i++)
      {
        Con2dP2 &con = p2cons[i];
        if (con.ndr >= nlow || con.nd1 >= nlow)
            wp2cons.push_back(con);

        if (con.ndr >= nlow && con.nd1 < nlow) // have a winner
          {
            int j = getind(inds,con.nd1); // corresponding index
            if (j < 0)      // not present, add it in
              {
                inds.insert(std::pair<int,int>(con.nd1,wnodes.size()));
                wnodes.push_back(nodes[con.nd1]);
              }
            rinds.push_back(con.nd1);
          }
        else if (con.nd1 >= nlow && con.ndr < nlow)
          {
            int j = getind(inds,con.ndr); // corresponding index
            if (j < 0)      // not present, add it in
              {
                inds.insert(std::pair<int,int>(con.ndr,wnodes.size()));
                wnodes.push_back(nodes[con.ndr]);
              }
            rinds.push_back(con.ndr);
          }
      }

    spa.nFixed = wnodes.size();
    if (verbose)
      cout << "[SPA Window] Fixed node count: " << spa.nFixed << endl;

    // add in variable nodes
    for (int i=0; i<(int)wp2cons.size(); i++)
      {
        Con2dP2 &con = wp2cons[i];
        if (con.nd1 >= nlow && con.ndr >= nlow) // have a winner
          {
            int n0 = getind(inds,con.ndr);
            if (n0 < 0)
              {
                inds.insert(std::pair<int,int>(con.ndr,wnodes.size()));
                wnodes.push_back(nodes[con.ndr]);
                rinds.push_back(con.ndr);
              }
            int n1 = getind(inds,con.nd1);
            if (n1 < 0)
              {
                inds.insert(std::pair<int,int>(con.nd1,wnodes.size()));
                wnodes.push_back(nodes[con.nd1]);
                rinds.push_back(con.nd1);
              }
          }
      }

    if (verbose)
      {
        cout << "[SPA Window] Variable node count: " << spa.nodes.size() - spa.nFixed << endl;
        cout << "[SPA Window] Constraint count: " << spa.p2cons.size() << endl;
      }

    // new constraint indices
    for (int i=0; i<(int)wp2cons.size(); i++)
      {
        Con2dP2 &con = wp2cons[i];
        con.ndr = getind(inds,con.ndr);
        con.nd1 = getind(inds,con.nd1);
      }

    // run spa
    niter = spa.doSPA(niter,sLambda,useCSparse);
    
    // reset constraint indices
    for (int i=0; i<(int)wp2cons.size(); i++)
      {
        Con2dP2 &con = wp2cons[i];
        con.ndr = rinds[con.ndr];
        con.nd1 = rinds[con.nd1];
      }
    return niter;
  }
예제 #4
0
std::vector<double> calcYlm_coeff(int l, int mval) {
  // Form list of cartesian coefficients

  // Size of returned array
  const int N=(l+1)*(l+2)/2;

  // Returned array
  std::vector<double> ret;
  ret.reserve(N);
  ret.resize(N);

  int m=abs(mval);

  // Compute prefactor
  double prefac=sqrt((2*l+1)/(4.0*M_PI))*pow(2.0,-l);
  if(m!=0)
    prefac*=sqrt(fact(l-m)*2.0/fact(l+m));

  // Calculate bar Pi contribution
  for(int k=0;k<=(l-m)/2;k++) {
    // Compute factor in front
    double ffac=pow(-1.0,k)*choose(l,k)*choose(2*(l-k),l);
    if(m!=0)
      ffac*=fact(l-2*k)/fact(l-2*k-m);
    ffac*=prefac;

    // Distribute exponents
    for(int a=0;a<=k;a++) {
      double afac=choose(k,a)*ffac;

      for(int b=0;b<=a;b++) {
	double fac=choose(a,b)*afac;

	// Current exponents
	int zexp=2*b-2*k+l-m;
	int yexp=2*(a-b);
	int xexp=2*(k-a);

	// Now, add in the contribution of A or B.
	if(mval>0) {
	  // Contribution from A_m
	  for(int p=0;p<=m;p++) {

	    // Check if term contributes
	    int cosfac;
	    switch((m-p)%4) {
	    case(0):
	      // cos(0) = 1
	      cosfac=1;
	      break;
	    case(1):
	      // cos(pi/2) = 0
	      cosfac=0;
	      break;
	    case(2):
	      // cos(pi) = -1
	      cosfac=-1;
	      break;
	    case(3):
	      // cos(3*pi/2) = 0
	      cosfac=0;
	      break;
	    default:
	      ERROR_INFO();
	      throw std::domain_error("An error occurred in Am(x,y).\n");
	    }

	    if(cosfac!=0) {
	      // OK, term contributes, store result.
	      //	      printf("Contribution to %i %i %i\n",xexp+p,yexp+absm-p,zexp);
	      ret[getind(xexp+p,yexp+m-p,zexp)]+=cosfac*choose(m,p)*fac;
	    }
	  }
	} else if(m==0) {
	  // No A_m or B_m term.
	  ret[getind(xexp,yexp,zexp)]+=fac;

	} else {
	  // B_m contributes
	  for(int p=0;p<=m;p++) {

	    // Check contribution of current term
	    int sinfac;
	    switch((m-p)%4) {
	    case(0):
	      // sin(0) = 0
	      sinfac=0;
	      break;
	    case(1):
	      // sin(pi/2) = 1
	      sinfac=1;
	      break;
	    case(2):
	      // sin(pi) = 0
	      sinfac=0;
	      break;
	    case(3):
	      // sin(3*pi/2) = -1
	      sinfac=-1;
	      break;
	    default:
	      ERROR_INFO();
	      throw std::domain_error("An error occurred in Bm(x,y).\n");
	    }

	    if(sinfac!=0) {
	      // OK, contribution is made
	      //	      printf("Contribution to %i %i %i\n",xexp+p,yexp+absm-p,zexp);
	      ret[getind(xexp+p,yexp+m-p,zexp)]+=sinfac*choose(m,p)*fac;
	    }
	  } // End loop over p
	} // End B_m clause
      } // End loop over b
    } // End loop over a
  } // End loop over k

#ifdef DEBUG
  printf("Y %i %i\n",l,mval);
  for(int ii=0; ii<=l; ii++) {
    int nx=l - ii;
    for(int jj=0; jj<=ii; jj++) {
      int ny=ii - jj;
      int nz=jj;

      if(ret[getind(nx,ny,nz)]!=0)
	printf("%e\t%i\t%i\t%i\n",ret[getind(nx,ny,nz)],nx,ny,nz);
    }
  }
  printf("\n");
#endif

  return ret;
}