示例#1
0
文件: rndtest.c 项目: rforge/muste
static int poker_results()
        {
        int r;
        double chi2,a,b,e;
        double f2,e2;
        int df;
        char s1[LLENGTH],s2[LLENGTH];
                                 /* d=n_pok k=poklen */
        stirling(poklen,s_pok);
        chi2=0.0;
        b=(double)n/(double)poklen/pow((double)n_pok,(double)poklen);
        print_line(" ");
        sprintf(sbuf,"Poker test: Different values r in sequences of %d.",poklen);
        print_line(sbuf);
        print_line("     r    Frequency   Expected");
        f2=e2=0.0; df=-1;
        for (r=1; r<=n_pok; ++r)
            {
            b*=(double)(n_pok-r+1);
            e=b*s_pok[r-1];
            fconv(e,"",s1);
            sprintf(sbuf,"%6d   %8u        %s",r,f_pok[r-1],s1);
            print_line(sbuf);
            e2+=e; f2+=f_pok[r-1];
            if (e2<5.0 && r<n_pok) continue;
            a=f2-e2;
            chi2+=a*a/e2; ++df;
            e2=f2=0.0;
            }
        fnconv2(chi2,accuracy,s1);
        fnconv2(1.0-muste_cdf_chi2(chi2,(double)df,1e-15),accuracy,s2);
        sprintf(sbuf,"Chi2=%s df=%d P[poker]=%s",s1,df,s2);
        print_line(sbuf);
        return(1);
        }
示例#2
0
int main()
{ /* solve set of linear equations */
    int i,j,n;
    miracl *mip=mirsys(20,MAXBASE);
    do
    {
        printf("Order of Hilbert matrix H= ");
        scanf("%d",&n);
        getchar();
    } while (n<2 || n>49);
    for (i=0;i<n;i++)
    {
        AA[i][n]=mirvar(0);
        bb[i]=mirvar(1);
        for (j=0;j<n;j++)
        {
            AA[i][j]=mirvar(0);
            fconv(1,i+j+1,AA[i][j]);
        }
    }
    
    if (gauss(AA,bb,n))
    {
        printf("\nSolution is\n");
        for (i=0;i<n;i++)
        {
            printf("x[%d] = ",i+1);
            cotnum(bb[i],stdout);
        }
        if (mip->EXACT) printf("Result is exact!\n");
    }
    else printf("H is singular!\n");
    return 0;
}
示例#3
0
/*
  Unpack file into a new file
  Return value: size of the new file, or -1 if an error occured
*/
int hts_zunpack(char* filename,char* newfile) {
    char catbuff[CATBUFF_SIZE];
    if (gz_is_available && filename && newfile) {
        if (filename[0] && newfile[0]) {
            gzFile gz = gzopen (filename, "rb");
            if (gz) {
                FILE* fpout=fopen(fconv(catbuff, newfile),"wb");
                int size=0;
                if (fpout) {
                    int nr;
                    do {
                        char BIGSTK buff[1024];
                        nr=gzread (gz, buff, 1024);
                        if (nr>0) {
                            size+=nr;
                            if (fwrite(buff,1,nr,fpout) != nr)
                                nr=size=-1;
                        }
                    } while(nr>0);
                    fclose(fpout);
                } else
                    size=-1;
                gzclose(gz);
                return (int) size;
            }
        }
    }
    return -1;
}
示例#4
0
文件: rndtest.c 项目: rforge/muste
static int coup_results()
        {
        int i,r;
        double chi2,a,b,e;
        double f2,e2;
        int df;
        unsigned int nc;
        char s1[LLENGTH],s2[LLENGTH];

                          /* d=couplen t=coupmax */
        b=1.0;
        for (r=2; r<couplen; ++r) b*=(double)r/(double)couplen;
        nc=0L; for (i=couplen-1; i<coup_max; ++i) nc+=f_coup[i];

        print_line(" ");
        sprintf(sbuf,"Coupon collector's test: Waiting time r for a complete series of %d alternatives.",couplen);
        print_line(sbuf);
        print_line("     r    Frequency   Expected");
        f2=e2=0.0; df=-1; chi2=0.0;
        for (r=couplen; r<coup_max; ++r)
            {
            b/=(double)couplen;
            stirling(r-1,s_coup);
            e=(double)nc*b*s_coup[couplen-2];
            fconv(e,"",s1);
            sprintf(sbuf,"%6d   %8u     %s",r,f_coup[r-1],s1);
            print_line(sbuf);
            e2+=e; f2+=f_coup[r-1];
            if (e2<5.0) continue;
            a=f2-e2; chi2+=a*a/e2; ++df;
            e2=f2=0.0;
            }

        stirling(coup_max-1,s_coup);
        e=(double)nc*(1.0-b*s_coup[couplen-1]);
        fconv(e,"",s1);
        sprintf(sbuf,"%6d-  %8u   %s",coup_max,f_coup[coup_max-1],s1);
        print_line(sbuf);
        e2+=e; f2+=f_coup[coup_max-1];
        a=f2-e2; chi2+=a*a/e2; ++df;
        fnconv2(chi2,accuracy,s1);
        fnconv2(1.0-muste_cdf_chi2(chi2,(double)df,1e-15),accuracy,s2);
        sprintf(sbuf,"Chi2=%s df=%d P[coupon]=%s",s1,df,s2);
        print_line(sbuf);
        return(1);
        }
示例#5
0
	void * thread_each_part( void *p )
	{
		MODEL *model = ThreadRules.model;
		const FEATURE_PYRAMID *pyra = ThreadRules.pyra;

		ThreadParam *pData = (ThreadParam*)p;
		int comp = pData->comp;
		MODEL::RULE_DATA &RuleData = model->RuleData[comp];
		int f = pData->filterIndex; 
		//printf("\n>>thread(%d) begins",f);

		int partFilterIndex = RuleData.filter_index[f];
		int partSymbol = RuleData.sym_terminal[f];
		int partNonTerminal = RuleData.sym_nonTerminal[f];
		int num_levels = pyra->num_levels, interval = model->interval;

		// filter response of each part ( including root part )
		const vector<Mat> &filters = model->x_filters;
		vector<Mat> &SymScore = model->symbols[partSymbol].score;
		SymScore.resize( num_levels );
		if( f==0 )
			fconv( pyra->feat, filters[partFilterIndex], SymScore, interval, num_levels, ThreadRules.ScoreSz );
		else
			fconv( pyra->feat, filters[partFilterIndex], SymScore, 0, num_levels-interval, ThreadRules.ScoreSz );

		if( f==0 ){
			//printf("\n>>thread(%d) ends",f);
			return NULL;
		}

		// apply deformation rule
		vector<Mat> &SymNtScore = model->symbols[partNonTerminal].score;
		vector<Mat> &Ix = model->rules[partNonTerminal][0].Ix;
		vector<Mat> &Iy = model->rules[partNonTerminal][0].Iy;
		SymNtScore.resize( num_levels );
		Ix.resize( num_levels );
		Iy.resize( num_levels );
		for( int lv=0; lv<num_levels-interval; lv++ )
			/* method 1. */
			//bounded_dt( SymScore[lv], RuleData.defcoeff[f-1], SymNtScore[lv], Ix[lv], Iy[lv] );
			/* method 2. */
			bounded_dt2( SymScore[lv], RuleData.DXDEF[f-1], RuleData.DYDEF[f-1], SymNtScore[lv], Ix[lv], Iy[lv] ); 

		//printf("\n>>thread(%d) ends",f);
		return NULL;
	}
示例#6
0
文件: rndtest.c 项目: rforge/muste
static int gap_results()
        {
        int i,max,k,stop;
        double dp,a;
        unsigned int n2;
        char s1[LLENGTH],s2[LLENGTH],s3[LLENGTH];
        double e,chi2,schi2;
        int df;


        for (i=maxgap-1; i>=0; --i) if (gap[i]>0L) break;
        max=i;
        n2=0L; for (i=0; i<=max; ++i) n2+=gap[i];
        dp=(double)(n-n2)/(double)n;
        fconv(a_gap,"",s1); fconv(b_gap,"",s2);
        fnconv2(1.0-dp,accuracy,s3);
        print_line(" ");
        sprintf(sbuf,"Gap test: P(%s,%s)=%s",s1,s2,s3); print_line(sbuf);
        print_line("Length    Frequency    Expected     Chi2");
        e=(1.0-dp)*(double)n2; schi2=0.0; df=-2;  /* 26.6.93 */
        stop=0;
        for (i=0; i<=max; ++i)
            {
            if (e<5.0 || i==max)
                {
                e/=(double)(1.0-dp);
                for (k=i+1; k<=max; ++k) gap[i]+=gap[k];
                stop=1;
                }
            a=gap[i]-e; chi2=a*a/e;
            schi2+=chi2; ++df;
            fnconv(e,accuracy,s1); fnconv(chi2,accuracy,s2);
            sprintf(sbuf,"%6d  %8u      %s      %s",
                          i, gap[i], s1, s2);
            if (stop) sbuf[7]='-';
            print_line(sbuf);
            if (stop) break;
            e*=dp;
            }
        fnconv2(schi2,accuracy,s1);
        fnconv2(1.0-muste_cdf_chi2(schi2,(double)df,1e-15),accuracy,s2);
        sprintf(sbuf,"Chi2=%s df=%d P[gap]=%s    Max.gap=%u",s1,df,s2,gapmax);
        print_line(sbuf);
        return(1);
        }
示例#7
0
/* Note: utf-8 */
int hts_zunpack(char *filename, char *newfile) {
  int ret = -1;

  if (filename != NULL && newfile != NULL) {
    if (filename[0] && newfile[0]) {
      char catbuff[CATBUFF_SIZE];
      FILE *const in = FOPEN(fconv(catbuff, sizeof(catbuff), filename), "rb");
      const int fd = in != NULL ? fileno(in) : -1;
      const int dup_fd = fd != -1 ? dup(fd) : -1;
      // Note: we must dup to be able to flose cleanly.
      const gzFile gz = dup_fd != -1 ? gzdopen(dup_fd, "rb") : NULL;

      if (gz) {
        FILE *const fpout = FOPEN(fconv(catbuff, sizeof(catbuff), newfile), "wb");
        int size = 0;

        if (fpout) {
          int nr;

          do {
            char BIGSTK buff[1024];

            nr = gzread(gz, buff, sizeof(buff));
            if (nr > 0) {
              size += nr;
              if (fwrite(buff, 1, nr, fpout) != nr)
                nr = size = -1;
            }
          } while(nr > 0);
          fclose(fpout);
        } else
          size = -1;
        gzclose(gz);
        ret = (int) size;
      }
      if (in != NULL) {
        fclose(in);
      }
    }
  }
  return ret;
}
示例#8
0
int
main(int argc, const char *argv[])
{
    int i;
    int *mem = malloc(1100000);

    capture_stdio();
    for (i = 0;; ++i) {
	int32_t t0[2], t1[2];
	char *msg;
	int n;

	gp_get_usertime(t0);
	switch (i) {
	    case 0:
		iadd(0, n = 10000000, &msg);
		break;
	    case 1:
		imul(1, n = 1000000, &msg);
		break;
	    case 2:
		idiv(1, n = 1000000, &msg);
		break;
	    case 3:
		fadd(3.14, n = 10000000, &msg);
		break;
	    case 4:
		fmul(1.0000001, n = 10000000, &msg);
		break;
	    case 5:
		fdiv(1.0000001, n = 1000000, &msg);
		break;
	    case 6:
		fconv(12345, n = 10000000, &msg);
		break;
	    case 7:
		mfast(mem, n = 10000000, &msg);
		break;
	    case 8:
		mslow(mem, n = 1000000, &msg);
		break;
	    default:
		free(mem);
		exit(0);
	}
	gp_get_usertime(t1);
	fprintf(stdout, "Time for %9d %s = %g ms\n", n, msg,
		(t1[0] - t0[0]) * 1000.0 + (t1[1] - t0[1]) / 1000000.0);
	fflush(stdout);
    }
}
示例#9
0
文件: fits.c 项目: eddyem/fits_filter
/**
 * build IMAGE image from data array indata
 */
IMAGE *buildFITSfromdat(size_t h, size_t w, int dtype, uint8_t *indata){
	size_t stride = 0;
	double (*fconv)(uint8_t *data) = NULL;
	double ubyteconv(uint8_t *data){return (double)*data;}
	double ushortconv(uint8_t *data){return (double)*(int16_t*)data;}
	double ulongconv(uint8_t *data){return (double)*(uint32_t*)data;}
	double ulonglongconv(uint8_t *data){return (double)*(uint64_t*)data;}
	double floatconv(uint8_t *data){return (double)*(float*)data;}
	IMAGE *out = newFITS(h, w, dtype);
	switch (dtype){
		case BYTE_IMG:
			stride = 1;
			fconv = ubyteconv;
		break;
		case SHORT_IMG:
			stride = 2;
			fconv = ushortconv;
		break;
		case LONG_IMG:
			stride = 4;
			fconv = ulongconv;
		break;
		case FLOAT_IMG:
			stride = 4;
			fconv = floatconv;
		break;
		case LONGLONG_IMG:
			fconv = ulonglongconv;
			stride = 8;
		break;
		case DOUBLE_IMG:
			memcpy(out->data, indata, sizeof(double)*w*h);
			return out;
		break;
		default:
		/// Неправильный тип данных
			ERRX(_("Wrong data type"));
	}
	size_t y, W = w*stride;
	Item *data = out->data;
	OMP_FOR(shared(data))
	for(y = 0; y < h; ++y){
		Item *dout = &data[y*w];
		uint8_t *din = &indata[y*W];
		size_t x;
		for(x = 0; x < w; ++x, din += stride)
			*dout++ = fconv(din);
	}
	return out;
}
示例#10
0
int ll_findfirst (const char *path, int attr, struct ll_findbuffer *buffer)
{
  USHORT rc;
  ULONG count;
  HDIR hdir;
  FILEFINDBUF ffbuf;

  hdir = HDIR_CREATE;
  count = 1;
  rc = DosFindFirst ((PSZ)path, &hdir, attr, &ffbuf, sizeof (ffbuf),
		     &count, 0L);
  if (rc != 0 || count != 1)
    return 0;
  FHDIR (buffer) = hdir;
  fconv (buffer, &ffbuf);
  return 1;
}
示例#11
0
int ll_findnext (struct ll_findbuffer *buffer)
{
  USHORT rc;
  ULONG count;
  HDIR hdir;
  FILEFINDBUF ffbuf;

  hdir = FHDIR (buffer);
  count = 1;
  rc = DosFindNext (hdir, &ffbuf, sizeof (ffbuf), &count);
  if (rc != 0 || count != 1)
    {
      DosFindClose (hdir);
      return 0;
    }
  fconv (buffer, &ffbuf);
  return 1;
}
示例#12
0
文件: mrflsh4.c 项目: FlexCOS/code
void fatanh(_MIPD_ flash x,flash y)
{ /* calculate y=atanh(x) */
    int op[5];
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    copy(x,y);
    if (mr_mip->ERNUM || size(y)==0) return;

    MR_IN(64)
    fconv(_MIPP_ 1,1,mr_mip->w11);
    op[0]=0x66;
    op[1]=op[2]=op[3]=1;
    op[4]=(-1);
    flop(_MIPP_ mr_mip->w11,y,op,y);
    flog(_MIPP_ y,y);
    fpmul(_MIPP_ y,1,2,y);
    MR_OUT
}
示例#13
0
int main()
{ /* Brents example program */
    flash x,pi;
    miracl *mip=mirsys(-35,0);
    x=mirvar(0);
    pi=mirvar(0);
    mip->RPOINT=ON;
    printf("Calculating pi..\n");
    fpi(pi);
    cotnum(pi,stdout); /* output pi */
    printf("Calculating exp(pi*(163/9)^0.5)\n");
    fconv(163,9,x);
    froot(x,2,x);
    fmul(x,pi,x);
    fexp(x,x);
    cotnum(x,stdout);
    printf("Calculating exp(pi*(163)^0.5)\n");
    fpower(x,3,x);
    cotnum(x,stdout);
    return 0;
}
示例#14
0
// écrire cookies.txt
// !=0 : erreur
int cookie_save(t_cookie * cookie, char *name) {
  char catbuff[CATBUFF_SIZE];

  if (strnotempty(cookie->data)) {
    char BIGSTK line[8192];
    FILE *fp = fopen(fconv(catbuff, name), "wb");

    if (fp) {
      char *a = cookie->data;

      fprintf(fp,
              "# HTTrack Website Copier Cookie File" LF
              "# This file format is compatible with Netscape cookies" LF);
      do {
        a += binput(a, line, 8000);
        fprintf(fp, "%s" LF, line);
      } while(strnotempty(line));
      fclose(fp);
      return 0;
    }
  } else
    return 0;
  return -1;
}
示例#15
0
/* Note: utf-8 */
int hts_zunpack(char *filename, char *newfile) {
  int ret = -1;
  char catbuff[CATBUFF_SIZE];

  if (filename && newfile) {
    if (filename[0] && newfile[0]) {
      // not: NOT an UTF-8 filename
      gzFile gz = gzopen(filename, "rb");

      if (gz) {
        FILE *const fpout = FOPEN(fconv(catbuff, newfile), "wb");
        int size = 0;

        if (fpout) {
          int nr;

          do {
            char BIGSTK buff[1024];

            nr = gzread(gz, buff, 1024);
            if (nr > 0) {
              size += nr;
              if (fwrite(buff, 1, nr, fpout) != nr)
                nr = size = -1;
            }
          } while(nr > 0);
          fclose(fpout);
        } else
          size = -1;
        gzclose(gz);
        ret = (int) size;
      }
    }
  }
  return ret;
}
示例#16
0
void my_rev_fath(vector<double>& fath_vec, vector<double>& moth_vec, vector<double>& h_vec,  vector<double>& fath_up_vec)
{
  unsigned int len=fath_vec.size();  
  unsigned int lenup=fath_up_vec.size();  
  vector<double> dyfath_vec(2*len-1,0.0);
  vector<double> dymoth_vec(2*len-1,0.0);
  
  dydadup(fath_vec,dyfath_vec);
  dydadup(moth_vec,dymoth_vec);
  
  vector<double> fconv(h_vec.size()+2*len-2,0.0);
  vector<double> mconv(h_vec.size()+2*len-2,0.0);  
 
  db_vit fconv_vit=fconv.begin(); 
  db_vit mconv_vit=mconv.begin();
  
  vector<double> sconv(h_vec.size()+2*len-1,0.0);
  conv_dec(h_vec.begin(), h_vec.end(), 3, dyfath_vec.begin(), dyfath_vec.end(), 0, fconv_vit);
  conv_dec(h_vec.begin(), h_vec.end(), 0, dymoth_vec.begin(), dymoth_vec.end(), 0, mconv_vit);
  VVdif(&fconv,&mconv, &sconv);
  
  for(unsigned int it=0;it<lenup;it++)
    fath_up_vec[it]=*(sconv.begin()+h_vec.size()-2+it);  
}
示例#17
0
/*
 * Name										: PPCFFRELS_init
 * Description						: 在使用辨识之前需要先用该函数初始化,并指定3个必要的变量,注意这里辨识的初值没有让用户指定
 * Entry                  : PPCFFRELS_T的结构体指针,nf1(不包括积分项)的阶数,ng的阶数,控制延迟d
 * Return                 : void
 * Author									: lynx [email protected].
 *
 * History
 * ----------------------
 * Rev										: 0.00
 * Date										: 06/14/2013
 *
 * create.
 * ----------------------
 */
void PPCFFRELS_init(PPCFFRELS_T* relsIn, int na, int nb, int d, float am1, float am2, float am3)
{
	int RELS_i = 0;  //循环用的变量
	float RELS_tmp_M1[PPCFFRELS_ML_A][PPCFFRELS_ML_A];  //用于矩阵运算的临时变量 矩阵
	float RELS_tmp_VT1[1][PPCFFRELS_ML_A];  //用于矩阵运算的临时变量 转置向量
	float RELS_tmp_VT2[1][PPCFFRELS_ML_A];  //用于矩阵运算的临时变量 转置向量
	
	if(na<=0 && nb<=0 && d<=0 && am1<=0 && am2<=0 && am3<=0){
		relsIn->NA = 2;  //如果未定义三个关键参数则使用默认参数
		relsIn->NB = 1;
		relsIn->D = 3;
		matrix_init0((float*)relsIn->AM, 1, PPCFFRELS_ML_A);  //初始化为0
		relsIn->AM[0][0] = 1.0;
		relsIn->AM[0][1] = -1.3;
		relsIn->AM[0][2] = 0.48;
		relsIn->NAM = 2;
	}else{
		relsIn->NA = na;  //给结构体赋值
		relsIn->NB = nb;
		relsIn->D = d;
		matrix_init0((float*)relsIn->AM, 1, PPCFFRELS_ML_A);  //初始化为0
		relsIn->AM[0][0] = am1;
		relsIn->AM[0][1] = am2;
		relsIn->AM[0][2] = am3;
		relsIn->NAM = 2;
	}
	
	//计算一大堆长度参数
	relsIn->NF = relsIn->NB+relsIn->D-1;
	relsIn->NG = relsIn->NA-1;
	relsIn->NA0=2*relsIn->NA-relsIn->NAM-relsIn->NB-1;  //na0=2*na-nam-nb-1; %观测器最低阶次
	
	//计算ML
	relsIn->ML = relsIn->NF+1+relsIn->NG+1;
	
	//计算A0
	matrix_init0((float*)relsIn->A0, 1, PPCFFRELS_ML_A);  //初始化为0
	matrix_init0((float*)RELS_tmp_VT1, 1, PPCFFRELS_ML_A);  //初始化为0
	matrix_init0((float*)RELS_tmp_VT2, 1, PPCFFRELS_ML_A);  //初始化为0
	relsIn->A0[0][0] = 1;   //给A0赋初值
	RELS_tmp_VT1[0][0] = 1;   //[1 0.3-i*0.1]
	RELS_tmp_VT1[0][1] = 0.3; 
	for(RELS_i=0;RELS_i<relsIn->NA0;RELS_i++){
		RELS_tmp_VT1[0][1] -= 0.1;   //A0=conv(A0,[1 0.3-i*0.1]);%生成观测器
		fconv((float*)relsIn->A0, 1+RELS_i, (float*)RELS_tmp_VT1, 2, (float*)RELS_tmp_VT2);
		matrix_copy((float*)RELS_tmp_VT2, 1, PPCFFRELS_ML_A, (float*)relsIn->A0);
		matrix_init0((float*)RELS_tmp_VT2, 1, PPCFFRELS_ML_A);  //初始化为0
	}
	matrix_init0((float*)relsIn->AA, 1, PPCFFRELS_ML_A);  //初始化为0
	fconv((float*)relsIn->A0, relsIn->NA0+1, (float*)relsIn->AM, relsIn->NAM+1, (float*)relsIn->AA);   //AA=conv(A0,Am); naa=na0+nam; %A0*Am
	relsIn->NAA = relsIn->NA0+relsIn->NAM;
	
	relsIn->NR = relsIn->NA0;
	
	
	//RELS初始化
	//thetae_1=0.001*ones(na+nb+1+nc,1);%非常小的正数(此处不能为0)
	for(RELS_i=0;RELS_i<relsIn->ML;RELS_i++){   
		relsIn->thetae_1[RELS_i][0] = 0.001;  //0.001*1
	}
	//因为把thetae的更新提前了,这里就对一个初始化防止thetae变0
	matrix_copy((float*)relsIn->thetae_1, relsIn->ML, 1, (float*)relsIn->thetae);
	//P=10^6*eye(na+nb+1+nc);  初始化P
	matrix_eye((float*)RELS_tmp_M1, relsIn->ML);
	matrix_multiply_k((float*)RELS_tmp_M1, 1000000.0, relsIn->ML, relsIn->ML, (float*)relsIn->P); 
}
示例#18
0
static int hts_parse_java(t_hts_callbackarg * carg, httrackp * opt,
                          htsmoduleStruct * str) {
  /* The wrapper_name memebr has changed: not for us anymore */
  if (str->wrapper_name == NULL || strcmp(str->wrapper_name, libName) != 0) {
    /* Call parent functions if multiple callbacks are chained. */
    if (CALLBACKARG_PREV_FUN(carg, parse) != NULL) {
      return CALLBACKARG_PREV_FUN(carg, parse) (CALLBACKARG_PREV_CARG(carg),
                                                opt, str);
    }
    strcpy(str->err_msg,
           "unexpected error: bad wrapper_name and no previous wrapper");
    return 0;                   /* Unexpected error */
  } else {
    if (detect_mime(str)) {

      /* (Legacy code) */
      char catbuff[CATBUFF_SIZE];
      FILE *fpout;
      JAVA_HEADER header;
      RESP_STRUCT *tab;
      const char *file = str->filename;

      str->relativeToHtmlLink = 1;

#if JAVADEBUG
      printf("fopen\n");
#endif
      if ((fpout = FOPEN(fconv(catbuff, sizeof(catbuff), file), "r+b")) == NULL) {
        //fprintf(stderr, "Cannot open input file.\n");
        sprintf(str->err_msg, "Unable to open file %s", file);
        return 0;               // une erreur..
      }
#if JAVADEBUG
      printf("fread\n");
#endif
      //if (fread(&header,1,sizeof(JAVA_HEADER),fpout) != sizeof(JAVA_HEADER)) {   // pas complet..
      if (fread(&header, 1, 10, fpout) != 10) { // pas complet..
        fclose(fpout);
        sprintf(str->err_msg, "File header too small (file len = " LLintP ")",
                (LLint) fsize(file));
        return 0;
      }
#if JAVADEBUG
      printf("header\n");
#endif
      // tester en tête
      if (reverse_endian()) {
        header.magic = hts_swap32(header.magic);
        header.count = hts_swap16(header.count);
      }
      if (header.magic != 0xCAFEBABE) {
        sprintf(str->err_msg, "non java file");
        if (fpout) {
          fclose(fpout);
          fpout = NULL;
        }
        return 0;
      }

      tab = (RESP_STRUCT *) calloc(header.count, sizeof(RESP_STRUCT));
      if (!tab) {
        sprintf(str->err_msg, "Unable to alloc %d bytes",
                (int) sizeof(RESP_STRUCT));
        if (fpout) {
          fclose(fpout);
          fpout = NULL;
        }
        return 0;               // erreur..
      }
#if JAVADEBUG
      printf("calchead\n");
#endif
      {
        int i;

        for(i = 1; i < header.count; i++) {
          int err = 0;          // ++    

          tab[i] = readtable(str, fpout, tab[i], &err);
          if (!err) {
            if ((tab[i].type == HTS_LONG) || (tab[i].type == HTS_DOUBLE))
              i++;              //2 element si double ou float
          } else {              // ++ une erreur est survenue!
            if (strnotempty(str->err_msg) == 0)
              strcpy(str->err_msg, "Internal readtable error");
            free(tab);
            if (fpout) {
              fclose(fpout);
              fpout = NULL;
            }
            return 0;
          }
        }

      }

#if JAVADEBUG
      printf("addfiles\n");
#endif
      {
        //unsigned int acess;
        unsigned int Class;
        unsigned int SClass;
        int i;

        //acess = readshort(fpout);
        Class = readshort(fpout);
        SClass = readshort(fpout);

        for(i = 1; i < header.count; i++) {

          if (tab[i].type == HTS_CLASS) {

            if ((tab[i].index1 < header.count) && (tab[i].index1 >= 0)) {

              if ((tab[i].index1 != SClass) && (tab[i].index1 != Class)
                  && (tab[tab[i].index1].name[0] != '[')) {

                if (!strstr(tab[tab[i].index1].name, "java/")) {
                  char BIGSTK tempo[1024];

                  tempo[0] = '\0';

                  sprintf(tempo, "%s.class", tab[tab[i].index1].name);
#if JAVADEBUG
                  printf("add %s\n", tempo);
#endif
                  if (tab[tab[i].index1].file_position >= 0)
                    str->addLink(str, tempo);   /* tab[tab[i].index1].file_position */
                }

              }
            } else {
              i = header.count; // exit 
            }
          }

        }
      }

#if JAVADEBUG
      printf("end\n");
#endif
      free(tab);
      if (fpout) {
        fclose(fpout);
        fpout = NULL;
      }
      return 1;

    } else {
      strcpy(str->err_msg, "bad MIME type");
    }
  }
  return 0;                     /* Error */
}