Esempio n. 1
0
void Gas::printVec_m(){
  cout<<"_____ Begin printVec_m() "<<endl;
  for (int i=0; i< this->N; i++){
  	cout<< this->vec_m[indx(i,0)]<< ", " << this->vec_m[indx(i,1)] <<endl;
  }
  cout<<"_____ End printVec_m() "<<endl;
}
Esempio n. 2
0
 bool basis_req_parcel::operator<(const basis_req_parcel& rs) const {
     if (devnum() != rs.devnum()) return (devnum() < rs.devnum());
     if (kind() != rs.kind()) return (kind() < rs.kind());
     if (chanel() != rs.chanel()) return (chanel() < rs.chanel());
     if (addr() != rs.addr()) return (addr() < rs.addr());
     if (indx() != rs.indx()) return (indx() < rs.indx());
     if (size() != rs.size()) return (size() < rs.size());
     return false;
 }
Esempio n. 3
0
File: sm2geo.c Progetto: pa345/lib
void sm2geo_green(double fday,int deg_want,                     /* chosen */
                  int deg_ext,int deg_day,double coeff[], /* given */
                  tsm2geo_green green_day_r,tsm2geo_green green_day_i)

{
  int ncoeff_want = deg_want*(deg_want+2);
  int ncoeff_ext = deg_ext*(deg_ext+2);
  int ncoeff_day = deg_day*2+1;
  int ncoeff = ncoeff_ext * ncoeff_ext * ncoeff_day;
  int igeo,ism,iday,md,ic;
  int n,mgeo,msm,i1,i2;
  double harm_d_r,harm_d_i;

  for (ism = 0; ism < ncoeff_ext; ism++) 
    for (igeo = 0; igeo < ncoeff_ext; igeo++)
      { 
        for (iday = 0;iday <= deg_day;iday++) green_day_r[ism][igeo][iday] = 0.0;
        for (iday = 0;iday <= deg_day;iday++) green_day_i[ism][igeo][iday] = 0.0;
      }
    
  ic = 0;
  for (n = 1;n<=deg_want;n++)
    for (i1 = 0; i1<=2*n; i1++)
      {
        msm = i2m(i1);
        ism = indx(n,msm);
        for (i2 = 0; i2<=2*n; i2++)
          {
            mgeo = i2m(i2);
            igeo = indx(n,mgeo);
            for (md = -deg_day; md <= deg_day; md++) 
              {
                if (md == 0)
                  {
                    harm_d_r = 1.0;
                    harm_d_i = 0.0;
                  }
                if (md > 0) 
                  {
                    harm_d_r = cos(md * WD * fday);
                    harm_d_i = sin(md * WD * fday);
                  }
                if (md < 0)
                  {
                    harm_d_r = sin(md * WD * fday);
                    harm_d_i = cos(md * WD * fday);
                  }
                ic++;
                if  (md < 0) iday = -md; else iday = md; 
                green_day_r[ism][igeo][iday] += harm_d_r * coeff[ic-1];
                green_day_i[ism][igeo][iday] += harm_d_i * coeff[ic-1];
                        /*                        printf("%d %d %d %d %d %12.5f\n",ism,igeo,md,ic,coeff[ic-1]); */
              }  /*for md*/
          } /* for mgeo */
      } /* for msm */
  return;
} /* sm2geo_green */
Esempio n. 4
0
File: sm2geo.c Progetto: pa345/lib
int sm2geo_init(char fname[],int *deg_ext,int *deg_day,int maxcoeff,double coeff[])
{
   int i,ism,igeo,iday,ncoeff;
   int n,mgeo,msm,i1,i2;
   int ncoeff_ext,ncoeff_day,ie0,ie1,id,in0,im0,im1;

   cfile = fopen(fname, "r");
   if (cfile == NULL) {printf("%s%s%s\n","file ",fname," could not be opened"); exit(EXIT_FAILURE);}
   fscanf(cfile,"%*[^\n]");
   getc(cfile);
   fscanf(cfile,"%d%d%*[^\n]",deg_ext,deg_day);
   ncoeff_ext = *deg_ext*(*deg_ext+2);
   ncoeff_day = *deg_day*2+1;
   ncoeff = ncoeff_ext * ncoeff_ext * ncoeff_day;
   if (ncoeff > maxcoeff) {printf("array size for coefficients is too small"); exit(EXIT_FAILURE);}
   getc(cfile);
   fscanf(cfile,"%*[^\n]");
   getc(cfile);
   fscanf(cfile,"%*[^\n]");
   getc(cfile);

   i = 0;
   for (n = 1;n<=*deg_ext;n++)
     for (i1 = 0; i1<=2*n; i1++)
       {
         msm = i2m(i1);
         ism = indx(n,msm);
         for (i2 = 0; i2<=2*n; i2++)
           {
             mgeo = i2m(i2);
             igeo = indx(n,mgeo);
             for (iday = 0;iday<ncoeff_day;iday++)
               {
                 fscanf(cfile,"%d%d%d%d",&in0,&im0,&im1,&id);
/*                   printf("sm2geo read: n %d m %d m %d iday %d\n",in0,im0,im1,id); */
                 ie0 = indx(in0,im0);
                 ie1 = indx(in0,im1);
                 if (ie0 != ism || ie1 != igeo || id != iday-*deg_day) 
                   {
                     printf("loop: n %d m %d m %d iday %d\n",n,msm,mgeo,id);
                     printf("read: n %d m %d m %d iday %d\n",in0,im0,im1,id);
                     printf("sm2geo: something is wrong with input file! %d <> %d or %d <> %d or %d <> %d\n",
                            ie0,ism,ie1,igeo,id,iday-*deg_day);
                     exit(EXIT_FAILURE);
                   }
                 fscanf(cfile,"%lg",&coeff[i]);
                 /*                 printf("%12.5f\n",coeff[i]); */
                 i++;
                 fscanf(cfile,"%*[^\n]");
                 getc(cfile);
               } /* for iday */
           } /* for mgeo */
       } /* for msm */
   fclose(cfile);
   return ncoeff;
}
Esempio n. 5
0
void Gas::calculateEpotFNB(double eps){
  // alpha=\infty
	Ep=0.0;
  for (int i=0; i<N-1; i++){
    // 1-cos(theta_{i+1} - theta_{i})
    Ep += 1.0 -(  vec_m[indx(i+1,0)]*vec_m[indx(i,0)] 
                + vec_m[indx(i+1,1)]*vec_m[indx(i,1)]);
  }
  Ep = 0.5*eps*Ep;
}
Esempio n. 6
0
/* read bc,de,hl|ix|iy,sp. hl|ix|iy only if it is already indexed the same. */
static int rd_rrxx (const char **p) {
	const char *listx[] = { "bc", "de", "ix", "sp", NULL };
	const char *listy[] = { "bc", "de", "iy", "sp", NULL };
	const char *list[] = { "bc", "de", "hl", "sp", NULL };
	if (indexed == 0xdd)
		return indx (p, listx, 1, NULL);
	if (indexed == 0xfd)
		return indx (p, listy, 1, NULL);
	return indx (p, list, 1, NULL);
}
Esempio n. 7
0
void Gas::calculateVec_flux2(double eps, int i){
  vec_flux[i] = 0.0;
  double sinthetaij = 0.0;
  double f_ij =0.0;
  for (int j=0; j<i; j++){
      sinthetaij = vec_m[indx(i,1)]*vec_m[indx(j,0)] - vec_m[indx(i,0)]*vec_m[indx(j,1)];
      f_ij = -0.5*eps*(invNtildeI[i]+ invNtildeI[j])*sinthetaij*inv_ijalpha[abs(i-j)];
      vec_flux[i] += 0.5*f_ij*(omega[i] + omega[j]);
//      vec_flux[i] = 0.5*(omega[i]+omega[j])*f_ij;
  }
}
Esempio n. 8
0
void Gas::calculateEpotAlpha(double eps){
  Ep = 0.0;
  double costhetaij =0.0;
  for (int i=0; i<N; i++){
    for (int j=0; j<i; j++){
      costhetaij = vec_m[indx(i,0)]*vec_m[indx(j,0)] + vec_m[indx(i,1)]*vec_m[indx(j,1)] ;
//      Ep += (1.0 -(vec_m[indx(i,0)]*vec_m[indx(j,0)] + vec_m[indx(i,1)]*vec_m[indx(j,1)]))*inv_ijalpha[abs(i-j)];
      Ep += (1.0 - costhetaij)*inv_ijalpha[abs(i-j)];
    }
  }
  Ep = eps*Ep/Ntilde;
}
Esempio n. 9
0
void Gas::calculateVec_M(){
  this->vec_M[0]=0;
  this->vec_M[1]=0;
  for (int i=0; i<this->N; i++){
    this->vec_M[0] += this->vec_m[indx(i,0)];
    this->vec_M[1] += this->vec_m[indx(i,1)];
  }

  this->vec_M[0] = this->vec_M[0]/this->N;
  this->vec_M[1] = this->vec_M[1]/this->N;
//  cout<<this->vec_M[0]<<" "<<this->vec_M[1]<<endl;
}
Esempio n. 10
0
void Gas::calculateVec_fluxFNB(double eps, int i){
  vec_flux[i] = 0.0;
  double sinthetaij = 0.0;
  double f_ij =0.0;
  int j=i-1;
  if (i<=1) cout<< "Houston we have a problem!" <<endl;
//  for (int j=0; j<i; j++){
      sinthetaij = vec_m[indx(i,1)]*vec_m[indx(j,0)] - vec_m[indx(i,0)]*vec_m[indx(j,1)];
      f_ij = -0.5*eps*sinthetaij;
      vec_flux[i] += 0.5*f_ij*(omega[i] + omega[j]);
//      vec_flux[i] = 0.5*(omega[i]+omega[j])*f_ij;
//  }
}
Esempio n. 11
0
void Gas::calculateEpotAlpha2(double eps){
  double auxEp = 0.0;
  double costhetaij = 0.0;
  Ep = 0.0;
  for (int i=0; i<N; i++){
    auxEp = 0.0;
    for (int j=0; j<i; j++){
      costhetaij = vec_m[indx(i,0)]*vec_m[indx(j,0)] + vec_m[indx(i,1)]*vec_m[indx(j,1)] ;
      auxEp += (1.0 - costhetaij)*inv_ijalpha[abs(i-j)];
    }
    Ep += invNtildeI[i]*auxEp;
  }
  Ep = eps*Ep;
}
Esempio n. 12
0
/* read b,c,d,e,h,l,(hl),a,(ix+nn),(iy+nn),nn 
 * but now with extra hl or i[xy](15) for add-instruction
 * and set variables accordingly */
static int rd_r_add (const char **p) {
#define addHL 	15
	int i;
	const char *list[] = {
		"ixl", "ixh", "iyl", "iyh", "b", "c", "d", "e", "h", "l",
		"( hl )", "a", "( ix +)", "( iy +)", "hl", "ix", "iy", "*", NULL
	};
	const char *nn;
	i = indx (p, list, 0, &nn);
	if (i == 18) { /* expression */
		readbyte = nn;
		writebyte = 1;
		return 7;
	}
	if (i > 14) { /* hl, ix, iy */
		if (i > 15)
			indexed = 0xDD + 0x20 * (i - 16);
		return addHL;
	}
	if (i <= 4) {/* i[xy][hl]  */
		indexed = 0xdd + 0x20 * (i > 2);
		return 6 - (i & 1);
	}
	i -= 4;
	if (i < 9)
		return i;
	indexed = 0xDD + 0x20 * (i - 9);	/* (i[xy] +) */
	indexjmp = nn;
	return 7;
}
Esempio n. 13
0
inline
array_nd<T> cat(size_t dim, const array_nd<T, S1>& a1,
				const array_nd<T, S2>& a2, const array_nd<T, S3>& a3)
{
	CHECK(dim < a1.ndims(), edims());
	CHECK(dim >= 0, edims());
	CHECK (a1.ndims() == a2.ndims(), eshape());
	CHECK (a2.ndims() == a3.ndims(), eshape());
	for (size_t j = 0; j < a1.ndims(); j++)
		if (j != dim) {
			CHECK(a1.size_nd()[j] == a2.size_nd()[j], eshape());
			CHECK(a2.size_nd()[j] == a3.size_nd()[j], eshape());
		}

	size_array sz(a1.size());
	sz[dim] = a1.size_nd(dim);
	sz[dim] += a2.size_nd(dim);
	sz[dim] += a3.size_nd(dim);
	array_nd<T> c(sz);

	array<index_array> indx(a1.ndims(), index_all());
	indx[dim] = size_range(0, a1.size_nd(dim) - 1);
	c(indx) = a1;
	indx[dim] = size_range(indx[dim].last + 1,
							indx[dim].last + a2.size_nd(dim));
	c(indx) = a2;
	indx[dim] = size_range(indx[dim].last + 1,
							indx[dim].last + a3.size_nd(dim));
	c(indx) = a3;
	return c;
}
Esempio n. 14
0
inline
typename array_nd<T, S>::create_new cat(
	size_t dim, const array<array_nd<T, S> >& a)
{
	for (size_t i = 0; i < a.length() - 1; i++) {
		CHECK (a[i].ndims() == a[i + 1].ndims(), eshape());
		for (size_t j = 0; j < a[i].ndims(); j++)
			if (j != dim) {
				CHECK(a[i].size_nd()[j] == a[i + 1].size_nd()[j], eshape());
			}
	}
	CHECK(dim < a[0].ndims(), edims());
	CHECK(dim >= 0, edims());
	size_array sz(a[0].ndims());

	for (size_t i = 0; i < a[0].ndims(); i++)
		sz[i] = a[0].size_nd()[i];
	sz[dim] = 0;
	for (size_t j = 0; j < a.length(); j++)
		sz[dim] += a[j].size_nd()[dim];
	typename array_nd<T, S>::create_new c(sz);

	size_t offs = 0;
	for (size_t j = 0; j < a.length(); j++) {
		array<index_array> indx(a[j].ndims());

		for (size_t i = 0; i < a[j].ndims(); i++)
			indx[i] = size_range((i == dim) ? offs : 0,
					a[j].size_nd()[i] - 1 + ((i == dim) ? offs : 0));

		offs += a[j].size_nd()[dim];
		c(indx) = a[j];
	}
	return c;
}
Esempio n. 15
0
array<typename array_nd<T, S>::create_new> split(
	const array_nd<T, S>& a, const array<size_t, D>& spoint , size_t dim)
{
	CHECK (dim < a.ndims(), edims());
	CHECK (dim >= 0, edims());

	array<typename array_nd<T, S>::create_new> result(spoint.length() + 1);

	for (size_t j = 0; j < spoint.length(); j++)
		CHECK(spoint[j] <= a.size_nd()[dim], erange());

	for (size_t j = 0; j < spoint.length() + 1; j++) {
		array<index_array, tiny> indx(a.ndims());
		for (size_t i = 0; i < a.ndims(); i++) {
			if(i != dim)
				indx[i] = size_array(
					size_range(0, a.size_nd()[i] - 1));
			else
				indx[i] = size_array(size_range((j == 0 ? 0 : spoint[j - 1]),
					(j == (spoint.length()) ?
						a.size_nd()[i] - 1 : spoint[j] - 1) ));
		}
		result[j] = a(indx);
	}
	return result;
}
// Return det|a| and leave matrix a constant(complex version)
dcomplex Determinant(const Array2 <dcomplex> & a, const int n)
{
  Array2 <dcomplex> temp(n,n);
  temp.Resize(n,n);
  Array1 <int>& indx(itmp1);
  indx.Resize(n);
  dcomplex d;

  // a(i,j) first index i is row index (convention)
  // elements of column vectors are stored contiguous in memory in C style arrays
  // a(i) refers to a column vector

  // calculate the inverse of the transposed matrix because this
  // allows to pass a column vector to lubksb() instead of a row

  // put the transposed matrix in temp
  for(int i=0;i<n;++i)
  {
    for(int j=0;j<n;++j)
    {
      temp(i,j)=a(i,j);
    }
  }

  doublevar det_sign;
  ludcmp(temp,n,indx,det_sign);

  d=det_sign;
  for(int j=0;j<n;++j)
  {
    d *= temp(j,j);
  }
  return d;
}
// Return det|a| and leave matrix a constant
doublevar Determinant(const Array2 <doublevar> & a, const int n)
{
  Array2 <doublevar>& temp(tmp2);
  temp.Resize(n,n);
  Array1 <int>& indx(itmp1);
  indx.Resize(n);
  doublevar d;

  // a(i,j) first index i is row index (convention)
  // elements of column vectors are stored contiguous in memory in C style arrays
  // a(i) refers to a column vector

  // calculate the inverse of the transposed matrix because this
  // allows to pass a column vector to lubksb() instead of a row

  // put the transposed matrix in temp
//#ifdef USE_LAPACK
/*  if(n==0) return 1;
  for(int i=0; i < n;++i) {
    for(int j=0; j< n; ++j) { 
      temp(i,j)=a(i,j);
    }
  }
  dgetrf(n, n, temp.v, n, indx.v);
  double det=1;
  for(int i=0; i< n; i++) { 
    if(indx(i) != i+1)
      det*= -temp(i,i);
    else det*=temp(i,i);
  }
  return det;
  */
/*
  for(int i=0; i< n; i++) { 
    if(indx(i)!=i+1) logdet.sign*=-1;
    logdet.logval+=log(fabs(temp(i,i)));
    if(temp(i,i) <0) logdet.sign*=-1;
  }

  //cout << " det " << det << " logval " << logdet.val() << endl;
  //return det;
  return logdet;
  */
//#endif  
//#else 
 
  for(int i=0;i<n;++i) {
    for(int j=0;j<n;++j) {
      temp(i,j)=a(i,j);
    }
  }

  ludcmp(temp,n,indx,d);

  for(int j=0;j<n;++j) {
    d *= temp(j,j);
  }
  return d;
//#endif
}
Esempio n. 18
0
/* read argument of ld b|c|d|e|h|l */
static int rd_ldbcdehla (const char **p) {
	int i;
	const char *list[] = {
		"b", "c", "d", "e", "h", "l", "( hl )", "a", "( ix +)", "( iy +)", "ixh",
		"ixl", "iyh", "iyl", "*", NULL
	};
	const char *nn;
	i = indx (p, list, 0, &nn);
	if (i == 15) {
		readbyte = nn;
		writebyte = 1;
		return 7;
	}
	if (i > 10) {
		int x;
		x = 0xdd + 0x20 * (i > 12);
		if (indexed && indexed != x) {
			eprintf ("illegal use of index registers\n");
			return 0;
		}
		indexed = x;
		return 6 - (i & 1);
	}
	if (i > 8) {
		if (indexed) {
			eprintf ("illegal use of index registers\n");
			return 0;
		}
		indexed = 0xDD + 0x20 * (i == 10);
		indexjmp = nn;
		return 7;
	}
	return i;
}
Esempio n. 19
0
/* read argument of ld a, */
static int rd_lda (const char **p) {
#define A_I 9
#define A_R 10
#define A_NN 11
	int i;
	const char *list[] = {
		"( sp )", "( iy +)", "( de )", "( bc )", "( ix +)", "b", "c", "d", "e", "h",
		"l", "( hl )", "a", "i", "r", "(*)", "*", NULL
	};
	const char *nn;
	i = indx (p, list, 0, &nn);
	if (i == 2 || i == 5) {
		indexed = (i == 2) ? 0xFD : 0xDD;
		indexjmp = nn;
		return 7;
	}
	if (i == 17) {
		readbyte = nn;
		writebyte = 1;
		return 7;
	}
	if (i == 16)
		readword = nn;
	return i - 5;
}
//---------------------------------------------------------------------------
Matrix invert(const Matrix& A)
{
  Matrix y(A.numRows(), A.numRows(), false);

  // Make sure A is square!
  if (A.numRows() != A.numCols())
  {
    std::cerr << "ERROR!  A must be square matrix!\n";
    return y;
  }

  const int N = A.numRows();

  // Make a copy of A since it gets modified
  Matrix Acopy(A);

 // y.setSize(N,N);
  Matrix col(N,1);
  Matrix indx(N,1);
  double d;
  int i,j;

  ludcmp(Acopy,indx,d);
  for (j = 0; j < N; j++)
  {
    for (i = 0; i < N; i++) col(i,0) = 0.0;
    col(j,0) = 1.0;
    lubksb(Acopy,indx,col);
    for (i = 0; i < N; i++) y(i,j) = col(i,0);
  }

  std::cout.flush();
  // Return result
  return y;
}
Esempio n. 21
0
PRIVATE     VOID
map(int blocks)
{
    int         i, k;
    uint8       r, g, b;

    for (i = 0; i < (2 * blocks); i++)
      {
          k = indx(color_pt[i].c[RED], color_pt[i].c[GREEN], color_pt[i].c[BLUE]);

          if (trans[k] == -1)
            {
                r = (uint8) (color_pt[i].c[RED] << 3);
                g = (uint8) (color_pt[i].c[GREEN] << 3);
                b = (uint8) (color_pt[i].c[BLUE] << 3);
                trans[k] = nearest_color(r, g, b);
                /*
                   printf("map: %d %d %d mapped to %d %d %d\n", r, g, b, new_pal[tran
                   s[k]*3
                   ],
                   new_pal[trans[k]*3+1], new_pal[trans[k]*3+2]);
                 */
            }
      }
}   /* end of map */
//---------------------------------------------------------------------------
Matrix solveLinearSystem(const Matrix& A, const Matrix& b)
{
  Matrix x;

  // Make sure A is square!
  if (A.numRows() != A.numCols())
  {
    std::cerr << "ERROR!  A must be square matrix!\n";
    return x;
  }

  // Make sure b is a column vector with the same dimensions
  // as A
  if (b.numRows() != A.numRows())
  {
    std::cerr << "ERROR!  b must be a column vector with the same dimensions as square matrix A!\n";
    return x;
  }

  // Make a copy of A since it gets modified
  Matrix Acopy(A);

  const int N = Acopy.numRows();
  Matrix indx(N,1);
  double d;
  ludcmp(Acopy,indx,d);
  x = b;  // x will contain solution
  lubksb(Acopy,indx,x);

  // Return solution column vector
  return x;
}
int ns1__luinv(struct soap *soap, matrix *a, matrix *b)
{ vector col(soap);
  ivector indx(soap);
  double d;
  int i, j, k, n;
  if (ludcmp(soap, *a, indx, d))
    return soap_sender_fault(soap, "Singular matrix in routine ludcmp", NULL);
  n = a->size();
  col.resize(n);
  b->resize(n, n);
  for (j = 1; j <= n; j++)
  { for (i = 1; i <= n; i++)
      col[i] = 0.0;
    col[j] = 1.0;
    lubksb(*a, indx, col);
    for (i = 1; i <= n; i++)
      (*b)[i][j] = col[i];
  }
  for (i = 1; i <= n; i++)
  { for (j = 1; j <= n; j++)
      if (fabs((*b)[i][j]) > 1.0e-15)
        break;
    for (k = n; k > j; k--)
      if (fabs((*b)[i][k]) > 1.0e-15)
        break;
    (*b)[i].resize(j, k);
  }
  return SOAP_OK;
}
Esempio n. 24
0
void NR::voltra(const DP t0, const DP h, Vec_O_DP &t, Mat_O_DP &f,
	DP g(const int, const DP),
	DP ak(const int, const int, const DP, const DP))
{
	int i,j,k,l;
	DP d,sum;

	int m=f.nrows();
	int n=f.ncols();
	Vec_INT indx(m);
	Vec_DP b(m);
	Mat_DP a(m,m);
	t[0]=t0;
	for (k=0;k<m;k++) f[k][0]=g(k,t[0]);
	for (i=1;i<n;i++) {
		t[i]=t[i-1]+h;
		for (k=0;k<m;k++) {
			sum=g(k,t[i]);
			for (l=0;l<m;l++) {
				sum += 0.5*h*ak(k,l,t[i],t[0])*f[l][0];
				for (j=1;j<i;j++)
					sum += h*ak(k,l,t[i],t[j])*f[l][j];
				if (k == l)
					a[k][l]=1.0-0.5*h*ak(k,l,t[i],t[i]);
				else
					a[k][l] = -0.5*h*ak(k,l,t[i],t[i]);
			}
			b[k]=sum;
		}
		ludcmp(a,indx,d);
		lubksb(a,indx,b);
		for (k=0;k<m;k++) f[k][i]=b[k];
	}
}
 /**
  * @param n a positive integer
  * @param primes the given prime list
  * @return the nth super ugly number
  */
 int nthSuperUglyNumber(int n, vector<int>& primes) {
     // Write your code here
     if(n <= 1)
         return n;
     if(!primes.size())
         return 0;
     int k = primes.size();
     vector<int> indx(k, 0);
     vector<int> ans(n);
     map<long long, int> heap;
     ans[0] = 1;
     for(int i = 0; i < k; ++ i){
         heap[primes[i]] = i;
     }
     int id = 1;
     while(id < n){
         auto cur = *(heap.begin());
         heap.erase(heap.begin());
         if(cur.first != ans[id - 1])
             ans[id ++] = cur.first;
         indx[cur.second] ++;
         while(heap.count( primes[cur.second]*ans[indx[cur.second]] )){
             indx[cur.second] ++;
         }
         heap[primes[cur.second]*ans[indx[cur.second]]] = cur.second;
     }
     
     return ans[n - 1];
 }
int ns1__ludet(struct soap *soap, matrix *a, double &d)
{ ivector indx(soap);
  if (ludcmp(soap, *a, indx, d))
    return soap_sender_fault(soap, "Singular matrix in routine ludcmp", NULL);
  for (int i = 1; i <= a->__size; i++)
    d *= (*a)[i][i];
  return SOAP_OK;
}
Esempio n. 27
0
/* read argument of ld (hl), */
static int rd_ld_hl (const char **p) {
	int i;
	const char *list[] = { "b", "c", "d", "e", "h", "l", "", "a", "*", NULL };
	i = indx (p, list, 0, &readbyte);
	if (i < 9)
		return i;
	writebyte = 1;
	return 7;
}
int ns1__lusol(struct soap *soap, matrix *a, vector *b, vector *x)
{ ivector indx(soap);
  double d;
  if (ludcmp(soap, *a, indx, d))
    return soap_sender_fault(soap, "Singular matrix in routine ludcmp", NULL);
  lubksb(*a, indx, *b);
  *x = *b;
  return SOAP_OK;
}
Esempio n. 29
0
/* read bc,de,hl,af */
static int rd_stack (const char **p) {
	int i;
	const char *list[] = { "bc", "de", "hl", "af", "ix", "iy", NULL };
	i = indx (p, list, 1, NULL);
	if (i < 5)
		return i;
	indexed = 0xDD + 0x20 * (i - 5);
	return 3;
}
Esempio n. 30
0
/* read hl, ix, or iy */
static int rd_hlx (const char **p) {
	int i;
	const char *list[] = { "hl", "ix", "iy", NULL };
	i = indx (p, list, 1, NULL);
	if (i < 2)
		return i;
	indexed = 0xDD + 0x20 * (i - 2);
	return 1;
}