int histc(double *data, int length, double *xmesh, int n , double *bins) { XML_IN; printf("-1\n"); gsl_histogram * h = gsl_histogram_alloc(n-1); printf("0\n"); gsl_histogram_set_ranges (h, xmesh, n); double h_max = gsl_histogram_max(h); double h_min = gsl_histogram_min(h); printf("h_min: %g h_max: %g\n",h_min,h_max); for (int i=0; i<length; i++) gsl_histogram_increment (h, data[i]); printf("2\n"); for (int i=0;i<n-1;i++) bins[i] = gsl_histogram_get (h, i); printf("3\n"); gsl_histogram_fprintf (stdout, h, "%g", "%g"); /*...*/ gsl_histogram_free(h); XML_OUT; return 0; }
/* ==== */ static void output_dos(const gsl_histogram *x, const char T) { int i,fnlen; FILE *dos_fp=NULL; char *dos_fn=NULL, *lDoS_suffix="lDoS", *sDoS_suffix="sDoS"; char s[50]; double val,lo,hi; sprintf(s,"%li",steps); fnlen = strlen(out_prefix)+strlen(lDoS_suffix)+64; dos_fn = (char*)calloc(fnlen,sizeof(char)); strcpy(dos_fn, out_prefix); strcat(dos_fn, s); strcat(dos_fn,"."); switch (T){ case 'l': /* output logarithmic g, usually during the calculation */ strcat(dos_fn, lDoS_suffix); break; case 's': /* output scaled g, eg for in-process convergence checks */ strcat(dos_fn, sDoS_suffix); break; default: fprintf (stderr, "%s:%d output_dos(): No handler for type %c", __FILE__, __LINE__, T); exit(EXIT_FAILURE); } dos_fp = fopen(dos_fn, "w+"); fprintf(dos_fp, "# estimated DOS after %li steps\n",steps); fprintf(dos_fp, "# sampling range: %6.2f -- %6.2f\n", gsl_histogram_min(g),gsl_histogram_max(g)); fprintf(dos_fp, "# bin resolution: %g\n",wanglandau_opt.res); /* loop over histogram g */ for (i=0;i<=maxbin;i++){ val = gsl_histogram_get(x,i); if (val == 0.){continue;} gsl_histogram_get_range(x,i,&lo,&hi); fprintf(dos_fp,"%6.2f\t%20.6f\n",lo+(hi-lo)/2,val); } fclose(dos_fp); free(dos_fn); return; }