예제 #1
0
main()
{
  double alpha[3],beta[3],gamma[3];
  double x0,x1,x2;

  int n_in[3], n_out[4];
  double *in=NULL;
  double *out=NULL; 

  int i0,i1,i2,i2b;

  FILE *fin, *fout;

  n_in[0]= n0;
  n_in[1]= n1;
  n_in[2]= n2;
  n_out[0]=nout0;
  n_out[1]=nout1;
  n_out[2]=nout2;
  n_out[3]=nout2-3;

  in=(double*)malloc(sizeof(double)*n_in[0]*n_in[1]*n_in[2]);
  out=(double*)malloc(sizeof(double)*n_out[0]*n_out[1]*n_out[2]);
   

  alpha[0]=0.5;
  alpha[1]=0.5;
  alpha[2]=0.5*0.8;
  beta[0]=1.0;
  beta[1]=1.0;
  beta[2]=1.0*0.8;
  gamma[0]=0.5;
  gamma[1]=0.5;
  gamma[2]=0.5;

  for (i0=0;i0<n_in[0];i0++) {
    x0= gamma[0]+i0-n_in[0]/2;
    for (i1=0;i1<n_in[1];i1++) {
      x1 =gamma[1]+i1-n_in[1]/2;
      for (i2=0;i2<n_in[2];i2++) {
        x2= gamma[2]+i2-n_in[2]/2;
	in_ref(i0,i1,i2)= x0*x0+x1*x1+x2*x2;
      }
    }
  }

  fin= fopen("in","w");
  for (i0=0;i0<n_in[0];i0++) {
    x0=(gamma[0]+i0)/n_in[0]; 
    for (i1=0;i1<n_in[1];i1++) {
      x1=(gamma[1]+i1)/n_in[1];
#if 0
      for (i2=0;i2<n_in[2];i2++) {
	x2= (gamma[2]+i2)/n_in[2];
#else
	for (i2b=0;i2b<=n_in[2];i2b++) {
	  x2= (gamma[2]+i2b)/n_in[2];
	  i2 = i2b % n_in[2];
#endif
	  /*  printf("%lf %lf ",in[i0][i1][i2].r, in[i0][i1][i2].i); */
	  fprintf(fin,"%lf %lf %lf %lf\n",x0,x1,x2,in_ref(i0,i1,i2));
	}
	fprintf(fin,"\n");
      }
    }
    fprintf(fin,"\n");
    fclose(fin);


    TRAN_FFT_Dinterpolation3D( n_in, in, n_out, out, alpha,beta,gamma);


    fout= fopen("out","w");
    for (i0=0;i0<n_out[0];i0++) {
      x0=(alpha[0]+beta[0]*i0)/n_out[0];
      for (i1=0;i1<n_out[1];i1++) {
	x1=(alpha[1]+beta[1]*i1)/n_out[1];
	for (i2=0;i2<n_out[2];i2++) {
	  x2=(alpha[2]+beta[2]*i2)/n_out[2];
	  /*printf("%lf %lf ",out[i0][i1][i2].r, out[i0][i1][i2].i);*/
	  fprintf(fout,"%lf %lf %lf %lf\n",x0,x1,x2,out_ref(i0,i1,i2));

	}
	fprintf(fout,"\n");
      }
    }
    fclose(fout);

    free(out);
    free(in);

  }
예제 #2
0
파일: genhtml.c 프로젝트: jpieper/RTKLIB
/* generate stream page ------------------------------------------------------*/
static int gen_page2(gtime_t time, const char *temp, const char *page)
{
    FILE *ifp,*ofp;
    gtime_t ts,te;
    double ep[6],hour[24],late[MAXSTA][24]= {{0}},avai[MAXSTA][24]= {{0}};
    double val1[MAXSTA],val2[MAXSTA];
    char buff[1024],file[1024],*sta[MAXSTA],str[MAXSTA][32];
    int i,j,n,nsta=0,sec=0;

    ts=timeadd(time,-90000.0);
    te=timeadd(time, -3600.0);

    for (i=0; i<MAXSTA; i++) sta[i]=str[i];

    for (i=0; i<24; i++) {
        time2epoch(timeadd(ts,i*3600.0),ep);
        sprintf(file,REP_FILE,ep[0],ep[1],ep[2],ep[3]);

        if (!(n=read_rep(file,sta,val1,val2))) continue;

        for (j=0; j<n; j++) {
            late[j][i]=val1[j];
            avai[j][i]=val2[j];
        }
        hour[i]=ep[3];
        nsta=n;
    }
    if (!(ifp=fopen(temp,"r"))) {
        fprintf(stderr,"file open error: %s\n",temp);
        return 0;
    }
    if (!(ofp=fopen(page,"w"))) {
        fprintf(stderr,"file open error: %s\n",page);
        fclose(ifp);
        return 0;
    }
    while (fgets(buff,sizeof(buff),ifp)) {

        if      (strstr(buff,"@DATE START"  )) sec=1;
        else if (strstr(buff,"@TABLE0 START")) sec=2;
        else if (strstr(buff,"@TABLE1 START")) sec=3;
        else if (strstr(buff,"@TABLE2 START")) sec=4;
        else if (strstr(buff,"@DATE END"    )) sec=0;
        else if (strstr(buff,"@TABLE0 END"  )) sec=0;
        else if (strstr(buff,"@TABLE1 END"  )) sec=0;
        else if (strstr(buff,"@TABLE2 END"  )) sec=0;

        switch (sec) {
        case 0:
            fputs(buff,ofp);
            break;
        case 1:
            out_date(ofp,ts,te);
            break;
        case 2:
            out_ref(ofp,ts);
            break;
        case 3:
            out_table1(ofp,sta,nsta,hour,avai,1);
            break;
        case 4:
            out_table1(ofp,sta,nsta,hour,late,1);
            break;
        }
    }
    fclose(ifp);
    fclose(ofp);
    return 1;
}