Пример #1
0
/* when done collecting data, calculate average, percentiles, etc */
void calcstats (struct event_statss *event) {
  u_int p, i, n;
  n=0;
  p=1;

  event->avg = AVG(event->sum, event->num);
  event->stddev = STDDEV(event->sum, event->sum2, event->num);

  /* scan histogram, calculating percentiles */  
  for (i = 0; i < NUM_BINS; i++) {
    n += event->hist[i];
    while (n > (event->num * p / 100)) {
      assert(p<=100);
      event->perc[p] = (i + 0.5) * BIN_WIDTH;
      p++;
      }
    }
  }  
Пример #2
0
static void
dump (void)
{
  double min, avg, stddev, delta;
  int i;
  if (summary)
    return;

  delta = test_time_stop - test_time_start;

  avg = 0;
  stddev = 0;
  if (delta > 0)
    avg = st.num_completed / delta;
  if (st.num_rate_samples > 1)
    stddev = STDDEV (st.rate_sum, st.rate_sum2, st.num_rate_samples);

  if (st.num_rate_samples > 0)
    min = st.rate_min;
  else
    min = 0.0;
  printf ("\nSession rate [sess/s]: min %.2f avg %.2f max %.2f "
	  "stddev %.2f (%u/%u)\n", min, avg, st.rate_max, stddev,
	  st.num_completed, st.num_completed + st.num_failed);

  printf ("Session: avg %.2f connections/session\n",
	  st.num_completed > 0 ? st.num_conns/(double) st.num_completed : 0.0);

  avg = 0.0;
  if (st.num_completed > 0)
    avg = st.lifetime_sum/st.num_completed;
  printf ("Session lifetime [s]: %.1f\n", avg);

  avg = 0.0;
  if (st.num_failed > 0)
    avg = st.failtime_sum/st.num_failed;
  printf ("Session failtime [s]: %.1f\n", avg);

  printf ("Session length histogram:");
  for (i = 0; i <= st.longest_session; ++i)
    printf (" %u", st.len_hist[i]);
  putchar ('\n');
}
Пример #3
0
static void
dump (void)
{
  #ifdef EXTENDED_STATS
    FILE *concurrent;
    FILE *reply;
  #endif
  Time conn_period = 0.0, call_period = 0.0;
  Time conn_time = 0.0, resp_time = 0.0, xfer_time = 0.0;
  Time call_size = 0.0, hdr_size = 0.0, reply_size = 0.0, footer_size = 0.0;
  Time lifetime_avg = 0.0, lifetime_stddev = 0.0, lifetime_median = 0.0;
  double reply_rate_avg = 0.0, reply_rate_stddev = 0.0;
  int i, total_replies = 0;
  Time delta, user, sys;
  u_wide total_size;
  Time time;
  u_int n;

  for (i = 1; i < NELEMS (basic.num_replies); ++i)
    total_replies += basic.num_replies[i];

  delta = test_time_stop - test_time_start;

  if (verbose > 1)
    {
      printf ("\nConnection lifetime histogram (time in ms):\n");
      for (i = 0; i < NUM_BINS; ++i)
	if (basic.conn_lifetime_hist[i])
	  {
	    if (i > 0 && basic.conn_lifetime_hist[i - 1] == 0)
	      printf ("%14c\n", ':');
	    time = (i + 0.5)*BIN_WIDTH;
	    printf ("%16.1f %u\n", 1e3*time, basic.conn_lifetime_hist[i]);
	  }
    }

  printf ("\nTotal: connections %u requests %u replies %u "
	  "test-duration %.3f s\n",
	  basic.num_conns_issued, basic.num_sent, total_replies,
	  delta);

  putchar ('\n');

  if (basic.num_conns_issued)
    conn_period = delta/basic.num_conns_issued;
  printf ("Connection rate: %.1f conn/s (%.1f ms/conn, "
	  "<=%u concurrent connections)\n",
	  basic.num_conns_issued / delta, 1e3*conn_period, basic.max_conns);

  if (basic.num_lifetimes > 0)
    {
      lifetime_avg = (basic.conn_lifetime_sum / basic.num_lifetimes);
      if (basic.num_lifetimes > 1)
	lifetime_stddev = STDDEV (basic.conn_lifetime_sum,
				  basic.conn_lifetime_sum2,
				  basic.num_lifetimes);
      n = 0;
      for (i = 0; i < NUM_BINS; i++)
	{
	  n += basic.conn_lifetime_hist[i];
	  if (n >= 0.5*basic.num_lifetimes)
	    {
	      lifetime_median = (i + 0.5)*BIN_WIDTH;
	      break;
	    }
	}
    }  
  printf ("Connection time [ms]: min %.1f avg %.1f max %.1f median %.1f "
	  "stddev %.1f\n",
	  basic.num_lifetimes > 0 ? 1e3 * basic.conn_lifetime_min : 0.0,
	  1e3 * lifetime_avg,
	  1e3 * basic.conn_lifetime_max, 1e3 * lifetime_median,
	  1e3 * lifetime_stddev);
  if (basic.num_connects > 0)
    conn_time = basic.conn_connect_sum / basic.num_connects;
  printf ("Connection time [ms]: connect %.1f\n", 1e3*conn_time);
  printf ("Connection length [replies/conn]: %.3f\n",
	  basic.num_lifetimes > 0
	  ? total_replies/ (double) basic.num_lifetimes : 0.0);
  putchar ('\n');

  if (basic.num_sent > 0)
    call_period = delta/basic.num_sent;
  printf ("Request rate: %.1f req/s (%.1f ms/req)\n",
	  basic.num_sent / delta, 1e3*call_period);

  if (basic.num_sent)
    call_size = basic.req_bytes_sent / basic.num_sent;
  printf ("Request size [B]: %.1f\n", call_size);

  putchar ('\n');

  if (basic.num_reply_rates > 0)
    {
      reply_rate_avg = (basic.reply_rate_sum / basic.num_reply_rates);
      if (basic.num_reply_rates > 1)
	reply_rate_stddev = STDDEV (basic.reply_rate_sum,
				    basic.reply_rate_sum2,
				    basic.num_reply_rates);
    }
  printf ("Reply rate [replies/s]: min %.1f avg %.1f max %.1f stddev %.1f "
	  "(%u samples)\n",
	  basic.num_reply_rates > 0 ? basic.reply_rate_min : 0.0,
	  reply_rate_avg, basic.reply_rate_max,
	  reply_rate_stddev, basic.num_reply_rates);

  if (basic.num_responses > 0)
    resp_time = basic.call_response_sum / basic.num_responses;
  if (total_replies > 0)
    xfer_time = basic.call_xfer_sum / total_replies;
  printf ("Reply time [ms]: response %.3f transfer %.3f\n",
	  1e3*resp_time, 1e3*xfer_time);

  if (total_replies)
    {
      hdr_size = basic.hdr_bytes_received / total_replies;
      reply_size = basic.reply_bytes_received / total_replies;
      footer_size = basic.footer_bytes_received / total_replies;
    }
  printf ("Reply size [B]: header %.1f content %.1f footer %.1f "
	  "(total %.1f)\n", hdr_size, reply_size, footer_size,
	  hdr_size + reply_size + footer_size);

  printf ("Reply status: 1xx=%u 2xx=%u 3xx=%u 4xx=%u 5xx=%u\n",
	  basic.num_replies[1], basic.num_replies[2], basic.num_replies[3],
	  basic.num_replies[4], basic.num_replies[5]);

  putchar ('\n');

  user = (TV_TO_SEC (test_rusage_stop.ru_utime)
	  - TV_TO_SEC (test_rusage_start.ru_utime));
  sys = (TV_TO_SEC (test_rusage_stop.ru_stime)
	  - TV_TO_SEC (test_rusage_start.ru_stime));
  printf ("CPU time [s]: user %.2f system %.2f (user %.1f%% system %.1f%% "
	  "total %.1f%%)\n", user, sys, 100.0*user/delta, 100.0*sys/delta,
	  100.0*(user + sys)/delta);

  total_size = (basic.req_bytes_sent
		+ basic.hdr_bytes_received + basic.reply_bytes_received);
  printf ("Net I/O: %.1f KB/s (%.1f*10^6 bps)\n",
	  total_size/delta / 1024.0, 8e-6*total_size/delta);

  putchar ('\n');

  printf ("Errors: total %u client-timo %u socket-timo %u "
	  "connrefused %u connreset %u\n"
	  "Errors: fd-unavail %u addrunavail %u ftab-full %u other %u\n",
	  (basic.num_client_timeouts + basic.num_sock_timeouts
	   + basic.num_sock_fdunavail + basic.num_sock_ftabfull
	   + basic.num_sock_refused + basic.num_sock_reset
	   + basic.num_sock_addrunavail + basic.num_other_errors),
	  basic.num_client_timeouts, basic.num_sock_timeouts,
	  basic.num_sock_refused, basic.num_sock_reset,
	  basic.num_sock_fdunavail, basic.num_sock_addrunavail,
	  basic.num_sock_ftabfull, basic.num_other_errors);
 /*diwa*/

#ifdef EXTENDED_STATS

  concurrent=fopen("concurrent.txt","w");
  if(!concurrent)
	   printf("\nError: Unable to Open the Concurrent File\nFailed to save Concurrent Connections Data\n");
  reply=fopen(param.rfile_name,"w");
   
   if(concurrent)
   {
     
     for (i = 0; i < CONC_NUM_BINS; i++)
     {
        fprintf(concurrent,"%d,%d\n",(i+1),basic.conc_conn_hist[i]);
     }
     fclose(concurrent);
   }

   if(reply)
   {
      for (i = 0; i < measure_index; i++)
      {
        if(basic.measurement[i].connect==-1)
			basic.measurement[i].connect=-1/1e3;
		/* RSH : Precisions increased to microsecond*/
        fprintf(reply,"%.3f,%.3f,%.3f,%.3f,%d,%d,%d\n",basic.measurement[i].start*1e3,basic.measurement[i].connect*1e3,basic.measurement[i].reply*1e3,basic.measurement[i].xfer*1e3,basic.measurement[i].num_active_conns,basic.measurement[i].response_size,basic.measurement[i].id);
      }
      fclose(reply);
   }

#endif

}
Пример #4
0
static void
dump(void) {
    Time conn_period = 0.0, call_period = 0.0;
    Time conn_time = 0.0, resp_time = 0.0, xfer_time = 0.0;
    Time call_size = 0.0, hdr_size = 0.0, reply_size =
            0.0, footer_size = 0.0;
    Time lifetime_avg = 0.0, lifetime_stddev =
            0.0, lifetime_median = 0.0;
    double reply_rate_avg = 0.0, reply_rate_stddev = 0.0;
    int i, total_replies = 0;
    Time delta, user, sys;
    u_wide total_size;
    Time time;
    u_int n;

    for (i = 1; i < NELEMS(basic.num_replies); ++i)
        total_replies += basic.num_replies[i];

    delta = test_time_stop - test_time_start;

    if (verbose > 1) {
        printf("\nConnection lifetime histogram (time in ms):\n");
        for (i = 0; i < NUM_BINS; ++i)
            if (basic.conn_lifetime_hist[i]) {
                if (i > 0 && basic.conn_lifetime_hist[i - 1] == 0)
                    printf("%14c\n", ':');
                time = (i + 0.5) * BIN_WIDTH;
                printf("%16.1f %u\n", 1e3 * time,
                       basic.conn_lifetime_hist[i]);
            }
    }

    printf("\nTotal: connections %u requests %u replies %u "
                   "test-duration %.3f s\n",
           basic.num_conns_issued, basic.num_sent, total_replies, delta);

    putchar('\n');

    if (basic.num_conns_issued)
        conn_period = delta / basic.num_conns_issued;
    printf("Connection rate: %.1f conn/s (%.1f ms/conn, "
                   "<=%u concurrent connections)\n",
           basic.num_conns_issued / delta, 1e3 * conn_period,
           basic.max_conns);

    if (basic.num_lifetimes > 0) {
        lifetime_avg = (basic.conn_lifetime_sum / basic.num_lifetimes);
        if (basic.num_lifetimes > 1)
            lifetime_stddev = STDDEV(basic.conn_lifetime_sum,
                                     basic.conn_lifetime_sum2,
                                     basic.num_lifetimes);
        n = 0;
        for (i = 0; i < NUM_BINS; ++i) {
            n += basic.conn_lifetime_hist[i];
            if (n >= 0.5 * basic.num_lifetimes) {
                lifetime_median = (i + 0.5) * BIN_WIDTH;
                break;
            }
        }
    }
    printf("Connection time [ms]: min %.1f avg %.1f max %.1f median %.1f "
                   "stddev %.1f\n",
           basic.num_lifetimes > 0 ? 1e3 * basic.conn_lifetime_min : 0.0,
           1e3 * lifetime_avg,
           1e3 * basic.conn_lifetime_max, 1e3 * lifetime_median,
           1e3 * lifetime_stddev);
    if (basic.num_connects > 0)
        conn_time = basic.conn_connect_sum / basic.num_connects;
    printf("Connection time [ms]: connect %.1f\n", 1e3 * conn_time);
    printf("Connection length [replies/conn]: %.3f\n",
           basic.num_lifetimes > 0
           ? total_replies / (double) basic.num_lifetimes : 0.0);
    putchar('\n');

    if (basic.num_sent > 0)
        call_period = delta / basic.num_sent;
    printf("Request rate: %.1f req/s (%.1f ms/req)\n",
           basic.num_sent / delta, 1e3 * call_period);

    if (basic.num_sent)
        call_size = basic.req_bytes_sent / basic.num_sent;
    printf("Request size [B]: %.1f\n", call_size);

    putchar('\n');

    if (basic.num_reply_rates > 0) {
        reply_rate_avg = (basic.reply_rate_sum / basic.num_reply_rates);
        if (basic.num_reply_rates > 1)
            reply_rate_stddev = STDDEV(basic.reply_rate_sum,
                                       basic.reply_rate_sum2,
                                       basic.num_reply_rates);
    }
    printf
            ("Reply rate [replies/s]: min %.1f avg %.1f max %.1f stddev %.1f "
                     "(%u samples)\n",
             basic.num_reply_rates > 0 ? basic.reply_rate_min : 0.0,
             reply_rate_avg, basic.reply_rate_max, reply_rate_stddev,
             basic.num_reply_rates);

    if (basic.num_responses > 0)
        resp_time = basic.call_response_sum / basic.num_responses;
    if (total_replies > 0)
        xfer_time = basic.call_xfer_sum / total_replies;
    printf("Reply time [ms]: response %.1f transfer %.1f\n",
           1e3 * resp_time, 1e3 * xfer_time);

    if (total_replies) {
        hdr_size = basic.hdr_bytes_received / total_replies;
        reply_size = basic.reply_bytes_received / total_replies;
        footer_size = basic.footer_bytes_received / total_replies;
    }
    printf("Reply size [B]: header %.1f content %.1f footer %.1f "
                   "(total %.1f)\n", hdr_size, reply_size, footer_size,
           hdr_size + reply_size + footer_size);

    printf("Reply status: 1xx=%u 2xx=%u 3xx=%u 4xx=%u 5xx=%u\n",
           basic.num_replies[1], basic.num_replies[2],
           basic.num_replies[3], basic.num_replies[4], basic.num_replies[5]);

    putchar('\n');

    user = (TV_TO_SEC(test_rusage_stop.ru_utime)
            - TV_TO_SEC(test_rusage_start.ru_utime));
    sys = (TV_TO_SEC(test_rusage_stop.ru_stime)
           - TV_TO_SEC(test_rusage_start.ru_stime));
    printf
            ("CPU time [s]: user %.2f system %.2f (user %.1f%% system %.1f%% "
                     "total %.1f%%)\n", user, sys, 100.0 * user / delta,
             100.0 * sys / delta, 100.0 * (user + sys) / delta);

    total_size = (basic.req_bytes_sent
                  + basic.hdr_bytes_received + basic.reply_bytes_received);
    printf("Net I/O: %.1f KB/s (%.1f*10^6 bps)\n",
           total_size / delta / 1024.0, 8e-6 * total_size / delta);

    putchar('\n');

    printf("Errors: total %u client-timo %u socket-timo %u "
                   "connrefused %u connreset %u\n"
                   "Errors: fd-unavail %u addrunavail %u ftab-full %u other %u\n",
           (basic.num_client_timeouts + basic.num_sock_timeouts
            + basic.num_sock_fdunavail + basic.num_sock_ftabfull
            + basic.num_sock_refused + basic.num_sock_reset
            + basic.num_sock_addrunavail + basic.num_other_errors),
           basic.num_client_timeouts, basic.num_sock_timeouts,
           basic.num_sock_refused, basic.num_sock_reset,
           basic.num_sock_fdunavail, basic.num_sock_addrunavail,
           basic.num_sock_ftabfull, basic.num_other_errors);
}
Пример #5
0
static void
dump (void)
{
  Time conn_period = 0.0, call_period = 0.0;
  Time call_size = 0.0, hdr_size = 0.0, reply_size = 0.0, footer_size = 0.0;
  double reply_rate_avg = 0.0, reply_rate_stddev = 0.0;
  int i, total_replies = 0;
  Time delta, user, sys;
  u_wide total_size;

  calcstats(&es_lifetime);
  calcstats(&es_connect);
  calcstats(&es_response);
  calcstats(&es_transfer);

  for (i = 1; i < NELEMS (basic.num_replies); ++i)
    total_replies += basic.num_replies[i];

  delta = test_time_stop - test_time_start;


  if (percentiles) {
    printf("\nPercentiles [ms] - lifetime  connect  response  transfer:\n");
    for (i=1;i<=100;i++)
      printf("%6d%% %6.0f %6.0f %6.0f %6.0f\n",
             i,
	     1e3 * es_lifetime.perc[i],
             1e3 * es_connect.perc[i],
             1e3 * es_response.perc[i],
             1e3 * es_transfer.perc[i]);
  }
       
  /* One line summary output with --summary */
  if (summary) {
    printf ("%8.1f ", 1e3 * es_connect.avg);
    if (es_response.num != es_connect.num) 
      printf("******");
    else 
      printf ("%6.1f ", 1e3 * es_response.avg);
    if (total_replies != es_connect.num)
      printf("******");
    else 
      printf ("%6.1f ", 1e3 * es_transfer.avg);
    if (es_lifetime.num != es_connect.num)
      printf("******");
    else 
      printf ("%6.1f ", 1e3 * es_lifetime.avg);
    if (total_replies != es_connect.num)
      printf("   * * *   * * * * *"); 
    else {
      hdr_size = basic.hdr_bytes_received / total_replies;
      reply_size = basic.reply_bytes_received / total_replies;
      footer_size = basic.footer_bytes_received / total_replies;
      printf ("   %d %d %d",(int) hdr_size, (int) reply_size, (int) footer_size);
      printf ("   %d %d %d %d %d",
	      basic.num_replies[1], 
	      basic.num_replies[2], 
	      basic.num_replies[3],
	      basic.num_replies[4], 
	      basic.num_replies[5]);
    }
    printf("\n");
    return;
  }

  if (verbose > 1)
    {
      printf ("\nHistogram - connection lifetime (ms):\n");
      hist_print(es_lifetime.hist);
      printf ("\nHistogram - connect time (ms):\n");
      hist_print(es_connect.hist);
      printf ("\nHistogram - response time (ms):\n");
      hist_print(es_response.hist);
      printf ("\nHistogram - transfer time (ms):\n");
      hist_print(es_transfer.hist);
    }

  printf ("\nTotal: connections %u requests %u replies %u "
	  "test-duration %.3f s\n",
	  basic.num_conns_issued, basic.num_sent, total_replies,
	  delta);

  putchar ('\n');

  if (basic.num_conns_issued)
    conn_period = delta/basic.num_conns_issued;
  printf ("Connection rate: %.1f conn/s (%.1f ms/conn, "
	  "<=%u concurrent connections)\n",
	  basic.num_conns_issued / delta, 1e3*conn_period, basic.max_conns);

  printf ("Connection length [replies/conn]: %.3f\n",
	  es_lifetime.num > 0
	  ? total_replies/ (double) es_lifetime.num : 0.0);

  printf("\n                       num    avg stddev    min  10%%  25%%  50%%  75%%  90%%  95%%  99%% max");
  printf("\nConnection life [ms]");
  printstats(&es_lifetime);
  printf("\nHandshake time  [ms]");
  printstats(&es_connect);
  printf("\nResponse time   [ms]");
  printstats(&es_response);
  printf("\nTransfer time   [ms]");
  printstats(&es_transfer);
  printf("\n\n");

  if (basic.num_sent > 0)
    call_period = delta/basic.num_sent;
  printf ("Request rate: %.1f req/s (%.1f ms/req)\n",
	  basic.num_sent / delta, 1e3*call_period);

  if (basic.num_sent)
    call_size = basic.req_bytes_sent / basic.num_sent;
  printf ("Request size [B]: %.1f\n", call_size);

  putchar ('\n');

  if (basic.num_reply_rates > 0)
    {
      reply_rate_avg = (basic.reply_rate_sum / basic.num_reply_rates);
      if (basic.num_reply_rates > 1)
	reply_rate_stddev = STDDEV (basic.reply_rate_sum,
				    basic.reply_rate_sum2,
				    basic.num_reply_rates);
    }
  printf ("Reply rate [replies/s]: min %.1f avg %.1f max %.1f stddev %.1f "
	  "(%u samples)\n",
	  basic.num_reply_rates > 0 ? basic.reply_rate_min : 0.0,
	  reply_rate_avg, basic.reply_rate_max,
	  reply_rate_stddev, basic.num_reply_rates);

  if (total_replies)
    {
      hdr_size = basic.hdr_bytes_received / total_replies;
      reply_size = basic.reply_bytes_received / total_replies;
      footer_size = basic.footer_bytes_received / total_replies;
    }
  printf ("Reply size [B]: header %.1f content %.1f footer %.1f "
	  "(total %.1f)\n", hdr_size, reply_size, footer_size,
	  hdr_size + reply_size + footer_size);

  printf ("Reply status: 1xx=%u 2xx=%u 3xx=%u 4xx=%u 5xx=%u\n",
	  basic.num_replies[1], basic.num_replies[2], basic.num_replies[3],
	  basic.num_replies[4], basic.num_replies[5]);

  putchar ('\n');

  user = (TV_TO_SEC (test_rusage_stop.ru_utime)
	  - TV_TO_SEC (test_rusage_start.ru_utime));
  sys = (TV_TO_SEC (test_rusage_stop.ru_stime)
	  - TV_TO_SEC (test_rusage_start.ru_stime));
  printf ("CPU time [s]: user %.2f system %.2f (user %.1f%% system %.1f%% "
	  "total %.1f%%)\n", user, sys, 100.0*user/delta, 100.0*sys/delta,
	  100.0*(user + sys)/delta);

  total_size = (basic.req_bytes_sent
		+ basic.hdr_bytes_received + basic.reply_bytes_received);
  printf ("Net I/O: %.1f KB/s (%.1f*10^6 bps)\n",
	  total_size/delta / 1024.0, 8e-6*total_size/delta);

  putchar ('\n');

  printf ("Errors: total %u client-timo %u socket-timo %u "
	  "connrefused %u connreset %u\n"
	  "Errors: fd-unavail %u addrunavail %u ftab-full %u other %u\n",
	  (basic.num_client_timeouts + basic.num_sock_timeouts
	   + basic.num_sock_fdunavail + basic.num_sock_ftabfull
	   + basic.num_sock_refused + basic.num_sock_reset
	   + basic.num_sock_addrunavail + basic.num_other_errors),
	  basic.num_client_timeouts, basic.num_sock_timeouts,
	  basic.num_sock_refused, basic.num_sock_reset,
	  basic.num_sock_fdunavail, basic.num_sock_addrunavail,
	  basic.num_sock_ftabfull, basic.num_other_errors);
}
Пример #6
0
Файл: uwerr.c Проект: 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);

}