Ejemplo n.º 1
0
int main(void) {
  REAL8TimeSeries *conv, *data, *response, *exactConv;
  const UINT4 N = 101;
  const LIGOTimeGPS zero = {0, 0};
  UINT4 i;

  conv = XLALCreateREAL8TimeSeries("FFT Convolution", &zero, 0.0, 0.01, &lalDimensionlessUnit, N);
  data = XLALCreateREAL8TimeSeries("data", &zero, 0.0, 0.01, &lalDimensionlessUnit, N);
  response = XLALCreateREAL8TimeSeries("response function", &zero, 0.0, 0.01, &lalDimensionlessUnit, N);
  exactConv = XLALCreateREAL8TimeSeries("exact convolution", &zero, 0.0, 0.01, &lalDimensionlessUnit, N);

  data->data->data[0] = 1.0;
  for (i = 1; i < N; i++) {
    /* Data is 1/i */
    data->data->data[i] = 1.0 / i;
  }

  response->data->data[0] = 1.0;
  for (i = 1; i <= (N-1)/2; i++) {
    response->data->data[i] = exp(-(i/10.0)); /* Decaying exponential with time constant 10. */
    response->data->data[N-i] = exp(-(i/10.0)); /* Same in the negative, wrapped dimension. */
  }
  if (N % 2 == 0) {
    response->data->data[N/2] = exp(-(N/20.0));
  }

  /* Exact, O(N^2) convolution */
  for (i = 0; i < N; i++) {
    REAL8 sum = 0.0;
    UINT4 j;

    for (j = MAX_INT(0, ((int)i)-((int) N/2)); j <= MIN_INT(i+N/2, N-1); j++) {
      UINT4 rIndex = (j > i ? i + (N - j) : i - j);

      sum += data->data->data[j]*response->data->data[rIndex];
    }

    exactConv->data->data[i] = sum;
  }

  convolveTimeSeries(conv, data, response);

  for (i = 0; i < N; i++) {
    if (fabs(exactConv->data->data[i] - conv->data->data[i]) > 1e-8) {
      fprintf(stderr, "Index %d differs (exact = %g, FFT = %g)\n", 
              i, exactConv->data->data[i], conv->data->data[i]);
    }
  }

  XLALDestroyREAL8TimeSeries(conv);
  XLALDestroyREAL8TimeSeries(data);
  XLALDestroyREAL8TimeSeries(response);
  XLALDestroyREAL8TimeSeries(exactConv);

  return 0;
}
Ejemplo n.º 2
0
/**
* Стартовые статы при любых условиях должны соответствовать границам ролла.
* В случае старого ролла тут это всплывет из-за нулевых статов.
*/
bool bad_start_stats(CHAR_DATA *ch)
{
	if (ch->get_start_stat(G_STR) > MAX_STR(ch)
			|| ch->get_start_stat(G_STR) < MIN_STR(ch)
			|| ch->get_start_stat(G_DEX) > MAX_DEX(ch)
			|| ch->get_start_stat(G_DEX) < MIN_DEX(ch)
			|| ch->get_start_stat(G_INT) > MAX_INT(ch)
			|| ch->get_start_stat(G_INT) < MIN_INT(ch)
			|| ch->get_start_stat(G_WIS) > MAX_WIS(ch)
			|| ch->get_start_stat(G_WIS) < MIN_WIS(ch)
			|| ch->get_start_stat(G_CON) > MAX_CON(ch)
			|| ch->get_start_stat(G_CON) < MIN_CON(ch)
			|| ch->get_start_stat(G_CHA) > MAX_CHA(ch)
			|| ch->get_start_stat(G_CHA) < MIN_CHA(ch)
			|| start_stats_count(ch) != SUM_ALL_STATS)
	{
		return 1;
	}
	return 0;
}
Ejemplo n.º 3
0
int backgroundBlit(void)
{
	SDL_Rect *camera = sdlStore(NULL,GET_CAMERA);
	if(camera == 0)
	{
		puts("DEBUG: backgroundBlit() 1");
		return -1;
	}
	SDL_Surface *screen = sdlStore(NULL,GET_SCREEN);
	if(screen == 0)
	{
		puts("DEBUG: backgroundBlit() 2");
		return -1;
	}
	struct bgData *initData = sdlStore(NULL,GET_BACKGROUND);
	if(initData == 0)
	{
		puts("DEBUG: backgroundBlit() 3");
		return -1;
	}
	int *bgSizes = (int *)sdlStore(NULL,GET_BG_SIZE);
	if(bgSizes == 0)
	{
		puts("DEBUG: backgroundBlit() 4");
		return -1;
	}
	int bgOffset[BG_AMOUNT][COORDS];
	int i;
	for(i = 0;i < BG_AMOUNT;i++)
	{
		bgOffset[i][0] = ((camera->x * BG_MULT) / bgSizes[i]) % camera->w;
		bgOffset[i][1] = ((camera->y * BG_MULT) / bgSizes[i]) % camera->h;
	}
	//DEBUG
	//printf("bg0: x %d y %d cam: x %d y %d\n",bgOffset[0][0],bgOffset[0][1],camera->x,camera->y);
	
	//Iterate over background layers
	for(i = 0;i < BG_AMOUNT;i++)
	{
		//For tiling
		int mw;
		for(mw = 0;mw < (camera->w * 2);mw += BG_INIT_W_SIZE)
		{
			int mh;
			for(mh = 0;mh < (camera->h * 2);mh += BG_INIT_H_SIZE)
			{
				int k;
				for(k = 0;k < (MIN_INT(BG_INIT_W_SIZE,camera->w) * MIN_INT(BG_INIT_H_SIZE,camera->h)) / 
				(BG_INIT_MAX_SPACING * BG_INIT_MAX_SPACING);k++)
				{
					int index = k * (i + 1);
					SDL_Rect tmpRect;
					tmpRect.x = initData[index].pos.x + mw - bgOffset[i][0];
					tmpRect.y = initData[index].pos.y + mh - bgOffset[i][1];
					//DEBUG
					//printf("x %5d y %5d w %5d h %5d\n",tmpRect.x,tmpRect.y,tmpRect.w,tmpRect.h);
					
					blitCircle(bgSizes[i],screen,tmpRect,(SDL_Color){255,255,255});
				}
			}
		}
	}
	return 0;
}
Ejemplo n.º 4
0
/**
* Проверка стартовых и итоговых статов.
* Если невалидные стартовые статы - чар отправляется на реролл.
* Если невалидные только итоговые статы - идет перезапись со стартовых с учетом мортов и славы.
*/
bool check_stats(CHAR_DATA *ch)
{
	// иммов травмировать не стоит
	if (IS_IMMORTAL(ch))
	{
		return 1;
	}

	int have_stats = ch->get_inborn_str() + ch->get_inborn_dex() + ch->get_inborn_int() + ch->get_inborn_wis() 
		+ ch->get_inborn_con() + ch->get_inborn_cha();

	// чар со старым роллом статов или после попыток поправить статы в файле
	if (bad_start_stats(ch))
	{
		snprintf(buf, MAX_STRING_LENGTH, "\r\n%sВаши параметры за вычетом перевоплощений:\r\n"
			"Сила: %d, Ловкость: %d, Ум: %d, Мудрость: %d, Телосложение: %d, Обаяние: %d\r\n"
			"Если вы долго отсутствовали в игре, то изменения, касающиеся стартовых параметров были следующие:%s\r\n"
			"\r\n"
			"\tДобавлено ограничение на максимальный класс защиты:\r\n"
			"\tВоры, наемники и дружинники - -250\r\n"
			"\tКупцы, богатыри, витязи, охотники, кузнецы - -200\r\n"
			"\tЛекари, волхвы - -150\r\n"
			"\tКудесники, чернокнижники, колдуны, волшебники - -100\r\n"
			"\r\n"
			"\tТелосложение: изменились коэффициенты профессий и максимальное родное тело (50) в расчетах при\r\n"
			"\tполучении уровня, поэтому изменены границы стартового телосложения у некоторых профессий,\r\n"
			"\tв целом это увеличивает кол-во жизней персонажа тем сильнее, чем больше у него было ремортов.\r\n"
			"\r\n",
			CCIGRN(ch, C_SPR),
			ch->get_inborn_str() - GET_REMORT(ch),
			ch->get_inborn_dex() - GET_REMORT(ch),
			ch->get_inborn_int() - GET_REMORT(ch),
			ch->get_inborn_wis() - GET_REMORT(ch),
			ch->get_inborn_con() - GET_REMORT(ch),
			ch->get_inborn_cha() - GET_REMORT(ch),
			CCNRM(ch, C_SPR));
		SEND_TO_Q(buf, ch->desc);

		// данную фигню мы делаем для того, чтобы из ролла нельзя было случайно так просто выйти
		// сразу, не раскидав статы, а то много любителей тригов и просто нажатий не глядя
		ch->set_str(MIN_STR(ch));
		ch->set_dex(MIN_DEX(ch));
		ch->set_int(MIN_INT(ch));
		ch->set_wis(MIN_WIS(ch));
		ch->set_con(MIN_CON(ch));
		ch->set_cha(MIN_CHA(ch));

		snprintf(buf, MAX_STRING_LENGTH, "%sПросим вас заново распределить основные параметры персонажа.%s\r\n",
			CCIGRN(ch, C_SPR), CCNRM(ch, C_SPR));
		SEND_TO_Q(buf, ch->desc);
		SEND_TO_Q("\r\n* В связи с проблемами перевода фразы ANYKEY нажмите ENTER *", ch->desc);
		STATE(ch->desc) = CON_RESET_STATS;
		return 0;
	}
	// стартовые статы в поряде, но слава не сходится (снялась по времени или иммом)
	if (bad_real_stats(ch, have_stats))
	{
		recalculate_stats(ch);
	}
	return 1;
}
Ejemplo n.º 5
0
Archivo: uwerr.c Proyecto: etmc/cvc
int uwerr (char* append) {

  const double epsilon = 2.0e-16;

  int i, n, label;
  int ndata, Wmax, W, Wopt, k;
  double **a_b, *a_bb, *a_proj, a_bb_proj;
  double *F_b, *F_bb, *F_bw;
  double *Gamma_F, C_F, C_Fopt, v_Fbb, dv_Fbb, tau, *tau_int;
  double *f_alpha, *h_alpha, *m_alpha, *data_ptr, func_res;
  double value, dvalue, ddvalue, tau_intbb, dtau_intbb;
  double chisqr, Qval, *p_r, p_r_mean, p_r_var, delta, lobd, *bins;
  char filename[80], format[80];
  FILE *ofs;

  printf("[uwerr] The following arguments have been read:\n");
  printf("[uwerr] nalpha   = %d\n", nalpha);
  printf("[uwerr] nreplica = %d\n", nreplica);
  for(i=0; i<nreplica; i++) {
    printf("[uwerr] n_r(%2d)  = %d\n", i, n_r[i]);
  }
  printf("[uwerr] npara    = %d\n", npara);
  for(i=0; i<npara; i++) {
    printf("[uwerr] para(%2d) = %e\n", i, para[i]);
  }
  printf("[uwerr] ipo      = %d\n", ipo);
  printf("[uwerr] s_tau    = %e\n", s_tau);
  printf("[uwerr] obsname  = %s\n", obsname);
  printf("[uwerr] append   = %s\n", append);

  fprintf(stdout, "[uwerr]: Starting ...\n");

  /*************************************************************
   * check if combination of values in ipo an func are allowed *
   *************************************************************/
  label = ipo;
  if(ipo>0 && func!=NULL) {
    ipo = 0;
  }
  else if ( ipo==0 && func==NULL) {
    fprintf(stdout, "[uwerr] illegal values of func and ipo, return");
    return(1);
  }

  fprintf(stdout, "[uwerr]: checked ipo and func\n");

  /* ndata - total number of rows in data */
  for( i=1, ndata = *n_r; i<nreplica; ndata += *(n_r + i++) );
  /* Wmax - longest possible summation index + 1 */
  MIN_INT(n_r, nreplica, &Wmax);

  fprintf(stdout, "[uwerr]: have ndata and Wmax ready\n");

  /*******************
   * allocate memory *
   *******************/
  F_b     = (double *)calloc(nreplica, sizeof(double));
  F_bb    = (double *)calloc(1, sizeof(double));
  F_bw    = (double *)calloc(1, sizeof(double));
  Gamma_F = (double *)calloc(Wmax, sizeof(double));  
  tau_int = (double *)calloc(Wmax, sizeof(double));
  if (ipo==0 && func!=NULL) /* only necessary in case of derived quantity */ {
    a_b  = (double**)calloc(nreplica, sizeof(double*));
    a_bb = (double *)calloc(nalpha,   sizeof(double));
    for(n=0; n<nreplica; n++) { *(a_b+n)=(double*)calloc(nalpha, sizeof(double)); }
  }

  fprintf(stdout, "[uwerr]: allocated memory\n");

  /*********************************************************************
   * calculate estimators for primary observable/derived quantity      *
   *********************************************************************/
  if(ipo>0 && func==NULL)     /* here estimators for one of the prim. observables */ {
    data_ptr = *(data+ipo-1); /* points to column of ipo in data */
    for(n=0; n<nreplica; n++) {
      ARITHMEAN(data_ptr, *(n_r+n), F_b+n); /* arithmetic mean for replia */
      data_ptr = data_ptr + *(n_r+n);       /* pointer set to beginning of next replia */
      /* test */
      fprintf(stdout, "[uwerr] F_b(%d) = %18.16e\n", n, *(F_b+n));
    }
    ARITHMEAN(*(data+ipo-1), ndata, F_bb);  /* mean including all data for ipo */
    /* test */
    fprintf(stdout, "[uwerr] F_bn = %18.16e\n", *F_bb);
  }
  else if (ipo==0 && func!=NULL) {          /* estimators for derived quantity */
    /* calculate means per replica and total mean */
    for(i=0; i<nalpha; i++) {
      data_ptr = *(data+i);
      for(n=0; n<nreplica; n++) {
	ARITHMEAN(data_ptr, *(n_r+n), *(a_b+n)+i);
	data_ptr += *(n_r+n);
      }
      ARITHMEAN(*(data+i), ndata, a_bb+i);
    }
    /* calculate estimators per replica for derived quatity */
    for(n=0; n<nreplica; n++) {
      func(nalpha, *(a_b+n), npara, para, F_b+n);         /* est. for means per replicum */
    }
    func(nalpha, a_bb, npara, para, F_bb);                /* est. for total mean */
  }
  /* in case of more than one replica 
     calculate weighed mean of F_b's with weights n_r */
  if(nreplica > 1) {
    WEIGHEDMEAN(F_b, nreplica, F_bw, n_r);
    /* test */
    fprintf(stdout, "[uwerr] F_bw = %18.16e\n", *F_bw);
  }

  fprintf(stdout, "[uwerr]: have estimators ready\n");

  /***********************************************
   * calculate projection of data and mean value *
   ***********************************************/
  if(ipo>0 && func==NULL) {
    a_proj = *(data + ipo - 1); /* data is projectet to itself in case of prim.
				   observable */
    a_bb_proj = *F_bb;          /* projected mean is total mean */
  }
  else if (ipo==0 && func!=NULL) {
    f_alpha = (double *)calloc(nalpha, sizeof(double));
    h_alpha = (double *)calloc(nalpha, sizeof(double));
    m_alpha = (double *)calloc(ndata, sizeof(double));
    a_proj  = (double *)calloc(ndata, sizeof(double));
    
    /* calculate derivatives of func with respect to A_alpha */
    for(i=0; i<nalpha; i++) { /* loop over all prim. observables */
      SET_TO(h_alpha, nalpha, 0.0); 
      STDDEV(*(data+i), ndata, h_alpha+i);
      /* test */
      fprintf(stdout, "[uwerr] halpha = %18.16e\n", *(h_alpha+i));
      if(*(h_alpha+i)==0.0) {
	fprintf(stdout, "[uwerr] Warning: no fluctuation in primary observable %d\n", i);
	*(f_alpha + i) = 0.0;
      }
      else {
	ADD_ASSIGN(m_alpha, a_bb, h_alpha, nalpha);
	func(nalpha, m_alpha, npara, para, &func_res);
	*(f_alpha+i) = func_res;
	SUB_ASSIGN(m_alpha, a_bb, h_alpha, nalpha);
	func(nalpha, m_alpha, npara, para, &func_res);
	*(f_alpha+i) -= func_res;
	*(f_alpha+i) = *(f_alpha+i) / (2.0 * *(h_alpha+i));
      }
    }
    SET_TO(a_proj, ndata, 0.0);
    a_bb_proj = 0.0;
    for(i=0; i<nalpha; i++) {
      for(n=0; n<ndata; n++) { 
	*(a_proj + n) = *(a_proj + n) + ( *(*(data+i)+n) ) * ( *(f_alpha+i) );
      }
      a_bb_proj = a_bb_proj + *(a_bb+i) * (*(f_alpha+i));
    }
    free(m_alpha);
    free(f_alpha);
    free(h_alpha);
    for(n=0; n<nreplica; n++) { free(*(a_b+n)); }
    free(a_b);
    free(a_bb);
  }

  fprintf(stdout, "[uwerr]: have projected data ready\n");

  /**********************************************************************
   * calculate error, error of the error; automatic windowing condition *
   **********************************************************************/

  /* (1) Gamma_F(t), t=0,...,Wmax */
  SET_TO(Gamma_F, Wmax, 0.0);  
  SET_TO(tau_int, Wmax, 0.0);
  for(i=0,v_Fbb=0.0; i<ndata; i++) {
    v_Fbb = v_Fbb + SQR( (*(a_proj+i) - a_bb_proj) );
  }
  v_Fbb /= (double)ndata;
  C_F      = v_Fbb;
  *Gamma_F = v_Fbb;
  /* test */
  fprintf(stdout, "[uwerr] a_bb_proj  = %18.16e\n", a_bb_proj);
  fprintf(stdout, "[uwerr] Gamma_F(%1d) = %18.16e\n", 0, *Gamma_F);
  if (*Gamma_F==0.0) {
    fprintf(stderr, "[uwerr] ERROR, no fluctuations; return\n");
    strcpy(filename, obsname);
    strcat(filename,"_uwerr");
    ofs = fopen(filename, append);
    if ((void*)ofs==NULL) {
      fprintf(stderr, "[uwerr] Could not open file %s\n", filename);
      return(1);
    }
    fprintf(ofs, "%d\t%18.16e\t%18.16e\t%18.16e\t%18.16e\t%18.16e\t%18.16e\t"\
	    "%18.16e\t%18.16e\n", label, *F_bb, 0.0, 0.0, 0.0, \
	    0.0, -1.0, 0.0, 0.0);
    if (fclose(ofs)!=0) {
      fprintf(stderr, "[uwerr] Could not close file %s\n", filename);
      return(1);
    }
    return(-5);
  }
  *tau_int = 0.5; 
  for(W=1; W<Wmax-1; W++) {
    /* calculate Gamma_F(W) */
    data_ptr = a_proj;
    for(n=0; n<nreplica; n++) {
      for(i=0; i<(*(n_r+n)-W); i++) {
	*(Gamma_F+W) += (*(data_ptr+i) - a_bb_proj) * (*(data_ptr+i+W) - a_bb_proj);
      }
      data_ptr = data_ptr + *(n_r+n);
    }
    *(Gamma_F+W) = *(Gamma_F+W) / (double)(ndata-nreplica*W);
    /* test */
    fprintf(stdout, "[uwerr] Gamma_F(%d) = %18.16e\n", W, *(Gamma_F+W));
    C_F = C_F + 2.0 * *(Gamma_F+W);
    *tau_int = C_F / (2.0*v_Fbb);
    if(*tau_int < 0.5) {
      fprintf(stdout, "[uwerr] Warning: tau_int < 0.5; tau set to %f\n", TINY);
      tau = TINY;
    }
    else {
      tau = s_tau / log( (*tau_int+0.5) / (*tau_int-0.5) );
    }
    /* test */
    fprintf(stdout, "[uwerr] tau(%d) = %18.16e\n", W, tau);
    if( exp(-(double)W / tau) - tau / sqrt((double)(W*ndata)) < 0.0 ) {
      Wopt = W;
      /* test */
      fprintf(stdout, "[uwerr] Wopt = %d\n", Wopt);
      break;
     }
  }

  if(W==Wmax-1) {
    fprintf(stdout, "[uwerr] windowing condition failed after W = %d\n", W);
    return(1);
  }
  else {
    SUM(Gamma_F+1, Wopt, &C_Fopt);
    C_Fopt = 2.0 * C_Fopt + *Gamma_F;
    /* test */
    fprintf(stdout, "[uwerr] before: C_Fopt = %18.16e\n", C_Fopt);
    for(W=0; W<=Wopt; W++) {
      *(Gamma_F+W) = *(Gamma_F+W) + C_Fopt/((double)ndata);
    }
    SUM(Gamma_F+1, Wopt, &C_Fopt);
    C_Fopt = 2.0 * C_Fopt + *Gamma_F;
    /* test */
    fprintf(stdout, "[uwerr] after: C_Fopt = %18.16e\n", C_Fopt);
    v_Fbb = *Gamma_F;
    *tau_int = 0.5*v_Fbb;
    for(W=1; W<=Wopt; W++) *(tau_int+W) = *(tau_int+W-1) + *(Gamma_F+W);
    for(W=0; W<=Wopt; W++) *(tau_int+W) /= v_Fbb;
  }

  fprintf(stdout, "[uwerr]: perfomed automatic windowing\n");

  /***********************************
   * bias cancellation of mean value *
   ***********************************/
  if(nreplica > 1 ) {
    *F_bb = ( (double)nreplica * *F_bb - *F_bw ) / ((double)(nreplica-1));
  }

  fprintf(stdout, "[uwerr]: leading bias cancelled\n");


  /**************************
   * calculation of results *
   **************************/
  value = *F_bb;
  dvalue = sqrt(C_Fopt/((double)ndata));
  ddvalue = dvalue * sqrt((Wopt + 0.5)/ndata);
  tau_intbb = C_Fopt / (2.0 * v_Fbb);
  dtau_intbb = sqrt( 2.0 * ( 2.0*Wopt-3.0*tau_intbb + 1 + \
			     1/(4.0*tau_intbb))/((double)ndata) ) * tau_intbb;
  dv_Fbb = sqrt(2.0*(tau_intbb + 1/(4.0*tau_intbb)) / (double)ndata) * v_Fbb;

  /*******************************************
   * consistency checks in case nreplica > 0 *
   *******************************************/
  if(nreplica>1) {
  /* (1) calculate Q-value <---> determine goodness of the fit 
     F_b(n) = F_bw = const. */
    chisqr = 0.0;
    for(n=0; n<nreplica; n++) {
      chisqr = chisqr + SQR( *(F_b+n) - *F_bw ) / (C_Fopt/(double)(*(n_r+n)));
    }
    /* test */
    fprintf(stdout, "[uwerr]: chisqr = %18.16e\n", chisqr);
    fprintf(stdout, "[uwerr]: n      = %d     \n", (nreplica-1)/2);

    Qval = 1.0 - incomp_gamma(chisqr/2.0, (nreplica-1)/2);
  
  /* (2) inspection of p_r's defined below in a histogramm */
    p_r = (double *)calloc(nreplica, sizeof(double));
    for(n=0; n<nreplica; n++) {
      *(p_r+n) = (*(F_b+n) - *F_bw) / \
	(dvalue*sqrt(((double)ndata/(double)(*(n_r+n)))-1.0));
    }
    ARITHMEAN(p_r, nreplica, &p_r_mean);
    VAR(p_r, nreplica, &p_r_var);
    k = 1 + (int)rint(log((double)nreplica)/log(2.0));
    strcpy(filename, obsname);
    strcat(filename, "_uwerr_hist");
    ofs = fopen(filename, append);
    fprintf(ofs, "# mean of p_r's:\tp_r_mean = %8.6e\n" \
	    "# variance of p_r's:\tp_r_var = %8.6e\n",  \
	    p_r_mean, p_r_var);
    strcpy(format, "%%dst p_r(%2d) = %18.16e\n");
    for(n=0; n<nreplica; n++) {
      fprintf(ofs, format, n, *(p_r+n));
    }
    if(k<3) /* not enough classes for a meaningful histogramm */ {
      fprintf(ofs, "# [uwerr]: k = %d is to small\n", k);
    }
    else {
      ABS_MAX_DBL(p_r, nreplica, &lobd); /* max{|p_r's|} */
      lobd = lobd *(1.0+TINY);
      delta = 2.0*lobd/(double)k;        /* expected distribution around mean=0 */
      lobd = -lobd;                      /* lower boundary of abscissa */
      bins = (double *)calloc(k, sizeof(double)); /* contains number of entries */
      SET_TO(bins, k, 0.0);                       /* for each class */
      for(n=0; n<nreplica; n++) /* inc. bins(i) by 1, if p_r(n) is in class i */ {
	i = (int)((*(p_r+n) - lobd)/delta);
	*(bins + i) = *(bins + i) + 1.0;
      }
      fprintf(ofs, "# number of entries:\tnreplica = %d\n" \
	      "# number of classes:\tk = %d\n"             \
	      "# lower boundary:\tlobd = %8.6e\n"          \
	      "# bin width:\tdelta = %8.6e\n",             \
	      nreplica, k, lobd, delta);
      strcpy(format, "%%hst %18.16e\t%18.16e\n");
      for(i=0; i<k; i++) {
	fprintf(ofs, format, lobd+((double)i+0.5)*delta, *(bins+i));
      }
    }
    fclose(ofs);
  }

  /**************************
   * output                 *
   **************************/

  /* (1) value, dvalue, ... */  
  strcpy(filename, obsname);
  strcat(filename,"_uwerr");
  ofs = fopen(filename, append);
  if ((void*)ofs==NULL) {
    fprintf(stderr, "[uwerr] Could not open file %s\n", filename);
    return(1);
  }
  strcpy(format, "%d\t%18.16e\t%18.16e\t%18.16e\t%18.16e\t%18.16e\t%18.16e\t%18.16e\t%18.16e\n");
  fprintf(ofs, format, label, value, dvalue, ddvalue, tau_intbb, dtau_intbb, Qval, v_Fbb, dv_Fbb);
  if (fclose(ofs)!=0) {
    fprintf(stderr, "[uwerr] Could not close file %s\n", filename);
    return(1);
  }

  /* (2) Gamma_F */
  strcpy(filename, obsname);
  strcat(filename, "_uwerr_Gamma");
  ofs = fopen(filename, append);
  if ((void*)ofs==NULL) {
    fprintf(stderr, "[uwerr] Could not open file %s\n", filename);
    return(1);
  }
  strcpy(format, "%d\t%18.16e\n");
  fprintf(ofs, "# obsname = %s \t ipo = %d", obsname, ipo);
  for(W=0; W<=Wopt; W++) {
    fprintf(ofs, format, W, *(Gamma_F+W));
  }
  if (fclose(ofs)!=0) {
    fprintf(stderr, "[uwerr] Could not close file %s\n", filename);
    return(1);
  }

  /* (3) tau_int */
  strcpy(filename, obsname);
  strcat(filename, "_uwerr_tauint");
  ofs = fopen(filename, append);
  fprintf(ofs, "# obsname = %s \t ipo = %d", obsname, ipo);
  for(W=0; W<=Wopt; W++) {
    fprintf(ofs, format, W, *(tau_int+W));
  }
  fclose(ofs);

  fprintf(stdout, "[uwerr]: output written\n");

  /*****************************
   * free allocated disk space *
   *****************************/
  free(F_b);
  free(F_bb);
  free(F_bw);
  free(Gamma_F);
  free(tau_int);
  if(ipo==0 && func!=NULL) {
    free(a_proj);
  }

  return(0);

}