Ejemplo n.º 1
0
YT_PLOT *
plot_test_prepare ()
{
  int     /* ti=0, */ fi=0/* , xi=0 */, i;
  YT_PLOT *plot;
  double  *f_line;

  int fnum = 2;
  int xnum = 10;
  int tnum = 1; // ??

  plot = plot_create (fnum, xnum, tnum/* , tmax */);
  sprintf (P_TITLE (plot,/* ti */0), "PLOT_TEST:");


  for (fi=0 ; fi < plot->fnum ; fi++) {
    P_NAME(plot, fi) = "TestPlot";

    YMALLOC (f_line, double, xnum);
    P_LINE (plot,fi,0) = f_line;

    for (i=0 ; i<plot->xnum; i++) {
      plot->x[i] = i;
      f_line[i]  = (fi+1)*i;
    }
  }
	
  return (plot);
}
Ejemplo n.º 2
0
void plot_chi2_comp(const fit_data *d, const fit_param *param, const size_t k,\
                    const strbuf title)
{
    strbuf *tmpfname,plotcmd;
    size_t nbeta,nens,nydim,bind;
    size_t i;
    FILE **tmpf;
    plot *p;
    
    nbeta    = param->nbeta;
    nens     = param->nens;
    nydim    = fit_data_get_nydim(d);
    
    tmpf     = (FILE **)malloc(nbeta*nydim*sizeof(FILE *));
    tmpfname = (strbuf *)malloc(nbeta*nydim*sizeof(strbuf));
    p        = plot_create();
    
    for (i=0;i<nbeta;i++)
    {
        sprintf(tmpfname[i],".qcd_phyfit_tmp_%d",(int)i);
        tmpf[i] = fopen(tmpfname[i],"w");
    }
    for (i=0;i<nens;i++)
    {
        bind = (size_t)ind_beta(param->point[i].beta,param);
        fprintf(tmpf[bind],"%s %e %e\n",param->point[i].dir,(double)(i),\
                mat_get(d->chi2_comp,i+k*nens,0));
    }
    for (i=0;i<nbeta;i++)
    {
        fclose(tmpf[i]);
        sprintf(plotcmd,"u 2:3:xtic(1) t '%s' w impulse",param->beta[i]);
        plot_add_plot(p,plotcmd,tmpfname[i]);
    }
    plot_add_head(p,"set xtics rotate by -90 font 'courier, 10'");
    plot_set_scale_manual(p,-1.0,(double)(param->nens+1),-5.0,5.0);
    plot_add_plot(p,"0.0 lt -1 lc rgb 'black' notitle","");
    plot_add_plot(p,"1.0 lt -1 lc rgb 'black' notitle","");
    plot_add_plot(p,"-1.0 lt -1 lc rgb 'black' notitle","");
    plot_add_plot(p,"2.0 lt -1 lc rgb 'dark-gray' notitle","");
    plot_add_plot(p,"-2.0 lt -1 lc rgb 'dark-gray' notitle","");
    plot_add_plot(p,"3.0 lt -1 lc rgb 'gray' notitle","");
    plot_add_plot(p,"-3.0 lt -1 lc rgb 'gray' notitle","");
    plot_add_plot(p,"4.0 lt -1 lc rgb 'light-gray' notitle","");
    plot_add_plot(p,"-4.0 lt -1 lc rgb 'light-gray' notitle","");
    plot_set_ylabel(p,"standard deviations");
    plot_set_title(p,title);
    plot_disp(p);
    
    free(tmpf);
    free(tmpfname);
    plot_destroy(p);
}
Ejemplo n.º 3
0
YT_PLOT*
make_test (int tnum, 
           int xnum, double fi_min, double fi_max)
{
  YT_PLOT *plot;
  int     i;
  double  fi_step, *f_sin, *f_cos;

  int fnum = 2;
  //int tnum = 5;
  int ti;
  plot = plot_create (fnum, xnum, tnum);

  for (ti=0 ; ti < tnum ; ti++) {
    // выделяем память под графики
    f_sin = (double*) malloc (xnum * sizeof(double));
    f_cos = (double*) malloc (xnum * sizeof(double));

    fi_step = (fi_max - fi_min) / (xnum - 1);

    // формируем значения "x, y"
    for (i=0 ; i < xnum ; i++) {
      plot->x[i] = fi_min + fi_step * i;
      f_sin[i] = sin ((ti+1)*plot->x[i]);
      f_cos[i] = cos (plot->x[i]);
    }

    // теперь сами графики:
    P_LINE (plot, /*fi*/0, ti) = f_sin;
    P_NAME (plot, /*fi*/0) = "Sinus";

    P_LINE (plot, /*fi*/1, ti) = f_cos;
    P_NAME (plot, /*fi*/1) = "Cosin";

    // общий титл ..
    sprintf (P_TITLE (plot,ti), "ti = %d", ti);
  }

  return (plot);
}
Ejemplo n.º 4
0
int main(int argc, char* argv[])
{
    /*              parsing arguments           */
    /********************************************/
    double latspac_nu;
    qcd_options *opt;
    strbuf name[3],manf_name,unit,sink[3],source[3];
    size_t binsize,nboot,propdim[2],nt;
    char *cpt1,*cpt2;
    corr_no lastc;
    fit_model *fm_pt;
    
    opt = qcd_arg_parse(argc,argv,A_PLOT|A_SAVE_RS|A_LOAD_RG|A_PROP_NAME\
                        |A_PROP_LOAD|A_LATSPAC|A_QCOMP|A_FIT,2,0);
    cpt1 = strtok(opt->ss,"/");
    printf("%s\n",cpt1);
    if (cpt1)
    {
        cpt2 = strchr(cpt1,':');
        if (cpt2 == NULL)
        {
            fprintf(stderr,"error: sink/source option %s is invalid\n",\
                    cpt1);
            exit(EXIT_FAILURE);
        }
        strbufcpy(source[PP],cpt2+1);
        *cpt2 = '\0';
        strbufcpy(sink[PP],cpt1);
    }
    else
    {
        fprintf(stderr,"error: sink/source option %s is invalid\n",\
                opt->ss);
        exit(EXIT_FAILURE);
    }
    cpt1 = strtok(NULL,"/");
    if (cpt1)
    {
        cpt2 = strchr(cpt1,':');
        if (cpt2 == NULL)
        {
            fprintf(stderr,"error: sink/source option %s is invalid\n",\
                    cpt1);
            exit(EXIT_FAILURE);
        }
        strbufcpy(source[AP],cpt2+1);
        *cpt2 = '\0';
        strbufcpy(sink[AP],cpt1);
    }
    else
    {
        strbufcpy(sink[AP],sink[PP]);
        strbufcpy(source[AP],source[PP]);
    }
    cpt1 = strtok(NULL,"/");
    if (cpt1)
    {
        cpt2 = strchr(cpt1,':');
        if (cpt2 == NULL)
        {
            fprintf(stderr,"error: sink/source option %s is invalid\n",\
                    cpt1);
            exit(EXIT_FAILURE);
        }
        strbufcpy(source[AA],cpt2+1);
        *cpt2 = '\0';
        strbufcpy(sink[AA],cpt1);
    }
    else
    {
        strbufcpy(sink[AA],sink[PP]);
        strbufcpy(source[AA],source[PP]);
    }
    cpt1 = strtok(opt->channel[0],"/");
    if (cpt1)
    {
        sprintf(name[PP],"%s_%s_%s_%s",cpt1,opt->quark[0],sink[PP],source[PP]);
    }
    else
    {
        fprintf(stderr,"error: channel option %s is invalid\n",\
                opt->channel[0]);
        exit(EXIT_FAILURE);
    }
    cpt1 = strtok(NULL,"/");
    if (cpt1)
    {
        sprintf(name[AP],"%s_%s_%s_%s",cpt1,opt->quark[0],sink[AP],source[AP]);
    }
    else
    {
        fprintf(stderr,"error: channel option %s is invalid\n",\
                opt->channel[0]);
        exit(EXIT_FAILURE);
    }
    cpt1 = strtok(NULL,"/");
    if (cpt1)
    {
        sprintf(name[AA],"%s_%s_%s_%s",cpt1,opt->quark[0],sink[AA],source[AA]);
        lastc = AA;
        fm_pt = &fm_pseudosc3;
    }
    else
    {
        lastc = AP;
        fm_pt = &fm_pseudosc2;
    }
    strbufcpy(manf_name,opt->manf_name);
    binsize    = opt->binsize;
    nboot      = opt->nboot;
    latspac_nu = opt->latspac_nu;
    if (opt->have_latspac)
    {
        strbufcpy(unit," (MeV)");
    }
    else
    {
        strbufcpy(unit,"");
    }
    latan_set_verb(opt->latan_verb);
    minimizer_set_alg(opt->minimizer);
    mat_ar_loadbin(NULL,propdim,manf_name,name[PP],1);
    nt = propdim[0];
    io_set_fmt(opt->latan_fmt);
    io_init();
    
    /*              loading datas               */
    /********************************************/
    size_t ndat,nbdat;
    mat **prop[3];
    corr_no c;

    ndat    = (size_t)get_nfile(manf_name);
    nbdat   = ndat/binsize + ((ndat%binsize == 0) ? 0 : 1);
    
    for (c=PP;c<=lastc;c++)
    {
        prop[c] = mat_ar_create(nbdat,propdim[0],propdim[1]);
        qcd_printf(opt,"-- loading %s datas from %s...\n",name[c],manf_name);
        mat_ar_loadbin(prop[c],NULL,manf_name,name[c],binsize);
    }
    
    /*                propagator                */
    /********************************************/
    rs_sample *s_mprop[3];
    mat *mprop[3],*sigmprop[3];
    
    for (c=PP;c<=lastc;c++)
    {
        s_mprop[c]  = rs_sample_create(propdim[0],propdim[1],nboot);
        sigmprop[c] = mat_create(propdim[0],propdim[1]);
        qcd_printf(opt,"-- resampling %s mean propagator...\n",name[c]);
        randgen_set_state(opt->state);
        resample(s_mprop[c],prop[c],nbdat,&rs_mean,BOOT,NULL);
        mprop[c] = rs_sample_pt_cent_val(s_mprop[c]);
        rs_sample_varp(sigmprop[c],s_mprop[c]);
        mat_eqsqrt(sigmprop[c]);
    }
    
    /*           effective mass                 */
    /********************************************/
    rs_sample *s_effmass[3];
    mat *tem,*em[3],*sigem[3];
    size_t emdim[2];
    
    get_effmass_size(emdim,mprop[PP],1,EM_ACOSH);
    
    tem = mat_create(emdim[0],1);
    
    for (c=PP;c<=lastc;c++)
    {
        s_effmass[c] = rs_sample_create(emdim[0],emdim[1],nboot);
        sigem[c]     = mat_create(emdim[0],emdim[1]);
        qcd_printf(opt,"-- resampling %s effective mass...\n",name[c]);
        rs_sample_effmass(s_effmass[c],tem,s_mprop[c],1,EM_ACOSH);
        em[c] = rs_sample_pt_cent_val(s_effmass[c]);
        rs_sample_varp(sigem[c],s_effmass[c]);
        mat_eqsqrt(sigem[c]);
    }
    
    /*                  fit mass                */
    /********************************************/
    fit_data *d;
    rs_sample *s_fit;
    mat *fit,*limit,*sigfit,*scanres_t,*scanres_chi2,*scanres_mass,\
    *scanres_masserr;
    size_t npar,nti,tibeg,range[2],ta;
    size_t i,j;
    strbuf buf,range_info,latan_path;
    double pref_i,mass_i;
    
    d        = fit_data_create(nt,1,(size_t)(lastc+1));
    tibeg    = (size_t)(opt->range[0][0]);
    range[0] = 0;
    range[1] = 0;
    npar     = fit_model_get_npar(fm_pt,&nt);
    
    s_fit    = rs_sample_create(npar,1,nboot);
    fit      = rs_sample_pt_cent_val(s_fit);
    limit    = mat_create(npar,2);
    sigfit   = mat_create(npar,1);
    
    /** print operation **/
    if (!opt->do_range_scan)
    {
        qcd_printf(opt,"-- fitting and resampling...\n");
    }
    else
    {
        qcd_printf(opt,"-- scanning ranges [ti,%u] from ti= %u\n",\
                   opt->range[0][1],opt->range[0][0]);
        opt->nmanrange   = 1;
    }
    
    /** check ranges **/
    strbufcpy(range_info,"");
    qcd_printf(opt,"%-20s: ","corrected range(s)");
    fit_data_fit_all_points(d,false);
    for (i=0;i<opt->nmanrange;i++)
    {
        sprintf(buf,"_%u_%u",opt->range[i][0],opt->range[i][1]);
        strbufcat(range_info,buf);
        range[0] = (size_t)(opt->range[i][0]);
        range[1] = (size_t)(opt->range[i][1]);
        correct_range(range,mprop[PP],sigmprop[PP],opt);
        fit_data_fit_range(d,range[0],range[1],true);
    }
    qcd_printf(opt,"\n");
    
    nti             = MAX(range[1] - 1 - tibeg,1);
    scanres_t       = mat_create(nti,1);
    scanres_chi2    = mat_create(nti,1);
    scanres_mass    = mat_create(nti,1);
    scanres_masserr = mat_create(nti,1);
    
    /** set model **/
    fit_data_set_model(d,fm_pt,&nt);
    
    /** set correlation filter **/
    if (opt->corr == NO_COR)
    {
        for (i=0;i<nt;i++)
            for (j=0;j<nt;j++)
            {
                if (i != j)
                {
                    fit_data_set_data_cor(d,i,j,false);
                }
            }
    }
    
    /** set initial parameter values **/
    ta     = nt/8-(size_t)(mat_get(tem,0,0));
    mass_i = mat_get(em[PP],ta,0);
    if (latan_isnan(mass_i))
    {
        mass_i = 0.3;
    }
    mat_set(fit,0,0,mass_i);
    pref_i = mat_get(mprop[PP],ta,0)/(exp(-mass_i*ta)+exp(-mass_i*(nt-ta)));
    if (latan_isnan(pref_i))
    {
        pref_i = 1.0;
    }
    mat_set(fit,1,0,sqrt(pref_i));
    mat_set(fit,2,0,sqrt(pref_i));
    qcd_printf(opt,"%-22smass= %e -- prefactor_0= %e\n","initial parameters: ",\
               mat_get(fit,0,0),pref_i);
    
    /** set parameter limits **/
    mat_cst(limit,latan_nan());
    mat_set(limit,0,0,0.0);
    mat_set(limit,1,0,0.0);
    mat_set(limit,2,0,0.0);
    
    /** positive AP correlator **/
    rs_sample_eqabs(s_mprop[AP]);
    
    /** set x **/
    for (i=0;i<nt;i++)
    {
        fit_data_set_x(d,i,0,(double)(i)-opt->tshift);
    }
    
    /** regular correlator fit... **/
    if (!opt->do_range_scan)
    {
        latan_set_warn(false);
        rs_data_fit(s_fit,limit,NULL,s_mprop,d,NO_COR,NULL);
        latan_set_warn(true);
        rs_data_fit(s_fit,limit,NULL,s_mprop,d,opt->corr,NULL);
        rs_sample_varp(sigfit,s_fit);
        mat_eqsqrt(sigfit);
        if (fit_data_get_chi2pdof(d) > 2.0)
        {
            fprintf(stderr,"warning: bad final fit (chi^2/dof= %.2e)\n",\
                    fit_data_get_chi2pdof(d));
        }
        qcd_printf(opt,"-- results:\n");
        qcd_printf(opt,"%-10s= %.8f +/- %.8e %s\n","mass",\
                   mat_get(fit,0,0)/latspac_nu,       \
                   mat_get(sigfit,0,0)/latspac_nu,unit);
        qcd_printf(opt,"%-10s= %.8f +/- %.8e %s\n","decay",\
                   mat_get(fit,1,0)/latspac_nu,       \
                   mat_get(sigfit,1,0)/latspac_nu,unit);
        qcd_printf(opt,"%-10s= %.8f +/- %.8e %s\n","norm",\
                   mat_get(fit,2,0)/latspac_nu,       \
                   mat_get(sigfit,2,0)/latspac_nu,unit);
        qcd_printf(opt,"%-10s= %d\n","dof",fit_data_get_dof(d));
        qcd_printf(opt,"%-10s= %e\n","chi^2/dof",fit_data_get_chi2pdof(d));
        if (opt->do_save_rs_sample)
        {
            sprintf(latan_path,"%s_pseudosc_fit%s_%s.boot:%s_pseudosc_fit%s_%s",\
                    opt->quark[0],range_info,manf_name,opt->quark[0],\
                    range_info,manf_name);
            rs_sample_save_subsamp(latan_path,'w',s_fit,0,0,1,0);
        }
    }
    /** ...or fit range scanning **/
    else
    {
        qcd_printf(opt,"\n%-5s %-12s a*M_%-8s %-12s","ti/a","chi^2/dof",\
                   opt->quark[0],"error");
        for (i=tibeg;i<range[1]-1;i++)
        {
            latan_set_warn(false);
            rs_data_fit(s_fit,limit,NULL,s_mprop,d,NO_COR,NULL);
            latan_set_warn(true);
            rs_data_fit(s_fit,limit,NULL,s_mprop,d,opt->corr,NULL);
            rs_sample_varp(sigfit,s_fit);
            mat_eqsqrt(sigfit);
            mat_set(scanres_t,i-tibeg,0,(double)(i));
            mat_set(scanres_chi2,i-tibeg,0,fit_data_get_chi2pdof(d));
            mat_set(scanres_mass,i-tibeg,0,mat_get(fit,0,0));
            mat_set(scanres_masserr,i-tibeg,0,mat_get(sigfit,0,0));
            qcd_printf(opt,"\n% -4d % -.5e % -.5e % -.5e",(int)(i),\
                       fit_data_get_chi2pdof(d),mat_get(fit,0,0), \
                       mat_get(sigfit,0,0));
            fit_data_fit_point(d,i,false);
        }
        qcd_printf(opt,"\n\n");
    }
    
    /*                  plot                    */
    /********************************************/
    if (opt->do_plot)
    {
        mat *mbuf,*em_i,*sigem_i,*par,*ft[3],*comp[3];
        plot *p;
        strbuf key,dirname,color;
        size_t maxt,t,npoint;
        double dmaxt,nmass;
        
        mbuf    = mat_create(1,1);
        em_i    = mat_create(nrow(em[PP]),1);
        sigem_i = mat_create(nrow(em[PP]),1);
        par     = mat_create(2,1);
        
        if (!opt->do_range_scan)
        {
            maxt   = nt;
            dmaxt  = (double)maxt;
            npoint = fit_data_fit_point_num(d);
            
            /** chi^2 plot **/
            p = plot_create();
            i = 0;
            for (c=PP;c<=lastc;c++)
            {
                ft[c]   = mat_create(npoint,1);
                comp[c] = mat_create(npoint,1);
                for (t=0;t<nt;t++)
                {
                    if (fit_data_is_fit_point(d,t))
                    {
                        mat_set(ft[c],i%npoint,0,(double)(t)+0.33*(double)(c));
                        mat_set(comp[c],i%npoint,0,mat_get(d->chi2_comp,i,0));
                        i++;
                    }
                }
            }
            plot_set_scale_manual(p,-1.0,dmaxt,-5.0,5.0);
            plot_add_plot(p,"0.0 lt -1 lc rgb 'black' notitle","");
            plot_add_plot(p,"1.0 lt -1 lc rgb 'black' notitle","");
            plot_add_plot(p,"-1.0 lt -1 lc rgb 'black' notitle","");
            plot_add_plot(p,"2.0 lt -1 lc rgb 'dark-gray' notitle","");
            plot_add_plot(p,"-2.0 lt -1 lc rgb 'dark-gray' notitle","");
            plot_add_plot(p,"3.0 lt -1 lc rgb 'gray' notitle","");
            plot_add_plot(p,"-3.0 lt -1 lc rgb 'gray' notitle","");
            plot_add_plot(p,"4.0 lt -1 lc rgb 'light-gray' notitle","");
            plot_add_plot(p,"-4.0 lt -1 lc rgb 'light-gray' notitle","");
            plot_set_ylabel(p,"standard deviations");
            for (c=PP;c<=lastc;c++)
            {
                sprintf(color,"%d",(int)(c)+1);
                plot_add_points(p,ft[c],comp[c],c_name[c],color,"impulses");
            }
            plot_disp(p);
            if (opt->do_save_plot)
            {
                sprintf(dirname,"%s_dev",opt->save_plot_dir);
                plot_save(dirname,p);
            }
            plot_destroy(p);
        
            for (c=PP;c<=lastc;c++)
            {
                /** propagator plot **/
                p = plot_create();
                fit_data_fit_all_points(d,true);
                plot_set_scale_ylog(p);
                plot_set_scale_xmanual(p,0,dmaxt);
                sprintf(key,"%s %s propagator",opt->quark[0],c_name[c]);
                mat_eqabs(mprop[c]);
                plot_add_fit(p,d,c,mbuf,0,fit,0,dmaxt,1000,false,\
                             PF_FIT|PF_DATA,key,"","rgb 'red'","rgb 'red'");
                plot_disp(p);
                if (opt->do_save_plot)
                {
                    sprintf(dirname,"%s_prop_%s",opt->save_plot_dir,c_name[c]);
                    plot_save(dirname,p);
                }
                plot_destroy(p);
                
                /** effective mass plot **/
                p = plot_create();
                mat_eqmuls(em[c],1.0/latspac_nu);
                mat_eqmuls(sigem[c],1.0/latspac_nu);
                nmass = mat_get(fit,0,0)/latspac_nu;
                plot_add_hlineerr(p,nmass, mat_get(sigfit,0,0)/latspac_nu,\
                                  "rgb 'red'");
                sprintf(key,"%s %s effective mass",opt->quark[0],c_name[c]);
                plot_add_dat(p,tem,em[c],NULL,sigem[c],key,"rgb 'blue'");
                plot_disp(p);
                if (opt->do_save_plot)
                {
                    sprintf(dirname,"%s_em_%s",opt->save_plot_dir,c_name[c]);
                    plot_save(dirname,p);
                }
                plot_destroy(p);
            }
        }
        else
        {
            /* chi^2 plot */
            p = plot_create();
            plot_set_scale_manual(p,0,(double)(nt/2),0,5.0);
            plot_add_hline(p,1.0,"rgb 'black'");
            plot_add_dat(p,scanres_t,scanres_chi2,NULL,NULL,"chi^2/dof",\
                         "rgb 'blue'");
            plot_disp(p);
            if (opt->do_save_plot)
            {
                sprintf(dirname,"%s_chi2",opt->save_plot_dir);
                plot_save(dirname,p);
            }
            plot_destroy(p);
            
            /* mass plot */
            p = plot_create();
            plot_set_scale_xmanual(p,0,(double)(nt/2));
            sprintf(key,"a*M_%s",opt->quark[0]);
            plot_add_dat(p,scanres_t,scanres_mass,NULL,scanres_masserr,key,\
                         "rgb 'red'");
            plot_disp(p);
            if (opt->do_save_plot)
            {
                sprintf(dirname,"%s_mass",opt->save_plot_dir);
                plot_save(dirname,p);
            }
            plot_destroy(p);
        }
        
        mat_destroy(em_i);
        mat_destroy(sigem_i);
        mat_destroy(mbuf);
        mat_destroy(par);
        for (c=PP;c<=lastc;c++)
        {
            mat_destroy(ft[c]);
            mat_destroy(comp[c]);
        }
    }
    
    /*              desallocation               */
    /********************************************/
    free(opt);
    io_finish();
    mat_ar_destroy(prop[0],nbdat);
    mat_ar_destroy(prop[1],nbdat);
    for (c=PP;c<=lastc;c++)
    {
        rs_sample_destroy(s_mprop[c]);
        mat_destroy(sigmprop[c]);
        rs_sample_destroy(s_effmass[c]);
        mat_destroy(sigem[c]);
    }
    mat_destroy(tem);
    fit_data_destroy(d);
    rs_sample_destroy(s_fit);
    mat_destroy(limit);
    mat_destroy(sigfit);
    mat_destroy(scanres_t);
    mat_destroy(scanres_chi2);
    mat_destroy(scanres_mass);
    mat_destroy(scanres_masserr);
    
    return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
void plot_fit(const rs_sample *s_fit, fit_data *d, fit_param *param, const plot_flag f)
{
    plot *p[N_EX_VAR];
    double *xb[N_EX_VAR] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
    double x_range[N_EX_VAR][2],b_int[2],dbind,a;
    size_t bind,vind,eind,k,phy_ind,s;
    strbuf color,gtitle,title,xlabel,ylabel;
    mat *phy_pt,*x_k,*fit,*cordat,**vol_av_corr,*yerrtmp;
    ens *ept;
    
    phy_pt     = mat_create(N_EX_VAR,1);
    x_k        = mat_create(param->nens,1);
    cordat     = mat_create(param->nens,1);
    MALLOC(vol_av_corr,mat **,param->nbeta);
    for (bind=0;bind<param->nbeta;bind++)
    {
        vol_av_corr[bind] = mat_create(param->nvol[bind],1);
    }

    for (k=0;k<N_EX_VAR;k++)
    {
        p[k] = plot_create();
    }
    
    param->scale_model = 1;
    fit = rs_sample_pt_cent_val(s_fit);
    if (IS_AN(param,AN_PHYPT)&&IS_AN(param,AN_SCALE))
    {
        phy_ind = 1;
        s       = fm_scaleset_taylor_npar(param);
    }
    else
    {
        phy_ind = 0;
        s       = 0;
    }
    for (k=0;k<N_EX_VAR;k++)
    {
        if (k == i_vind)
        {
            fit_data_get_x_k(x_k,d,i_Linv);
        }
        else
        {
            fit_data_get_x_k(x_k,d,k);
        }
        if ((k == i_a)||(k == i_ud)||(k == i_Linv)||(k == i_alpha)\
            ||(k == i_vind))
        {
            x_range[k][0] = 0.0;
        }
        else
        {
            x_range[k][0] = mat_get_min(x_k)-0.15*fabs(mat_get_min(x_k));
        }
        x_range[k][1] = mat_get_max(x_k)+0.15*fabs(mat_get_min(x_k));
        plot_set_scale_xmanual(p[k],x_range[k][0],x_range[k][1]);
    }
    if (f == Q)
    {
        sprintf(gtitle,"quantity: %s -- scale: %s -- datasets: %s -- ensembles: %s",\
                param->q_name,param->scale_part,param->dataset_cat,param->manifest);
        mat_set(phy_pt,i_ud,0,SQ(param->M_ud));
        mat_set(phy_pt,i_s,0,SQ(param->M_s));
        mat_set(phy_pt,i_umd,0,param->M_umd_val);
        mat_set(phy_pt,i_alpha,0,param->alpha);
        mat_set(phy_pt,i_bind,0,0.0);
        mat_set(phy_pt,i_vind,0,0.0);
        mat_set(phy_pt,i_a,0,0.0);
        mat_set(phy_pt,i_Linv,0,0.0);
        mat_set(phy_pt,i_fvM,0,param->qed_fvol_mass);
        /* regular plots */
        PLOT_ADD_FIT(PF_FIT,i_ud,phy_ind,"","rgb 'black'");
        PLOT_ADD_PB(i_ud,phy_ind,"rgb 'black'");
        PLOT_ADD_FIT(PF_FIT,i_s,phy_ind,"","rgb 'black'");
        PLOT_ADD_PB(i_s,phy_ind,"rgb 'black'");
        PLOT_ADD_FIT(PF_FIT,i_umd,phy_ind,"","rgb 'black'");
        PLOT_ADD_PB(i_umd,phy_ind,"rgb 'black'");
        PLOT_ADD_FIT(PF_FIT,i_alpha,phy_ind,"","rgb 'black'");
        PLOT_ADD_PB(i_alpha,phy_ind,"rgb 'black'");
        PLOT_ADD_FIT(PF_FIT,i_a,phy_ind,"","rgb 'black'");
        PLOT_ADD_PB(i_a,phy_ind,"rgb 'black'");
        PLOT_ADD_FIT(PF_FIT,i_Linv,phy_ind,"","rgb 'black'");
        PLOT_ADD_PB(i_Linv,phy_ind,"rgb 'black'");
        for (bind=0;bind<param->nbeta;bind++)
        {
            dbind      = (double)(bind);
            b_int[0]   = dbind - 0.1;
            b_int[1]   = dbind + 0.1;
            xb[i_bind] = b_int;
            fit_data_fit_region(d,xb);
            sprintf(color,"%d",1+(int)bind);
            sprintf(title,"beta = %s",param->beta[bind]);
            PLOT_ADD_FIT(PF_DATA,i_ud,phy_ind,title,color);
            PLOT_ADD_FIT(PF_DATA,i_s,phy_ind,title,color);
            PLOT_ADD_FIT(PF_DATA,i_umd,phy_ind,title,color);
            PLOT_ADD_FIT(PF_DATA,i_alpha,phy_ind,title,color);
            PLOT_ADD_FIT(PF_DATA,i_a,phy_ind,title,color);
            PLOT_ADD_FIT(PF_DATA,i_Linv,phy_ind,title,color);
            fit_data_fit_all_points(d,true);
        }
        /* volume averages plot */
        plot_add_fit(p[i_vind],d,phy_ind,phy_pt,i_Linv,fit,x_range[i_Linv][0],\
                     x_range[i_Linv][1],MOD_PLOT_NPT,true,PF_FIT,"","",       \
                     "rgb 'black'","rgb 'black'");
        plot_add_fit_predband(p[i_vind],d,phy_ind,phy_pt,i_Linv,s_fit,\
                              x_range[i_Linv][0],x_range[i_Linv][1],  \
                              MOD_PLOT_NPT/4,"rgb 'black'");
        fit_partresidual(cordat,d,phy_ind,phy_pt,i_Linv,fit);
        for(bind=0;bind<param->nbeta;bind++)
        {
            mat_zero(vol_av_corr[bind]);
        }
        for(eind=0;eind<param->nens;eind++)
        {
            ept  = param->point + eind;
            bind = (size_t)ind_beta(ept->beta,param);
            vind = (size_t)ind_volume((unsigned int)ept->L,(int)bind,param);
            mat_inc(vol_av_corr[bind],vind,0,mat_get(cordat,eind,0));
        }
        for (bind=0;bind<param->nbeta;bind++)
        for (vind=0;vind<param->nvol[bind];vind++)
        {
            mat_set(vol_av_corr[bind],vind,0,               \
                    mat_get(vol_av_corr[bind],vind,0)       \
                    /((double)(param->nenspvol[bind][vind])));
        }
        for(bind=0;bind<param->nbeta;bind++)
        {
            yerrtmp = mat_create(param->nvol[bind],1);
            
            rs_sample_varp(yerrtmp,param->s_vol_av[bind]);
            mat_eqsqrt(yerrtmp);
            sprintf(color,"%d",1+(int)bind);
            sprintf(title,"beta = %s",param->beta[bind]);
            plot_add_dat_yerr(p[i_vind],                                     \
                              rs_sample_pt_cent_val(param->s_vol_Linv[bind]),\
                              vol_av_corr[bind],yerrtmp,title,color);
            
            mat_destroy(yerrtmp);
        }

        /* display plots */
        switch (param->q_dim)
        {
            case 0:
                strbufcpy(ylabel,param->q_name);
                break;
            case 1:
                sprintf(ylabel,"%s (MeV)",param->q_name);
                break;
            default:
                sprintf(ylabel,"%s^%d (MeV^%d)",param->q_name,param->q_dim,\
                        param->q_dim);
                break;
        }
        
        sprintf(xlabel,"M_%s^2 (MeV^2)",param->ud_name);
        PLOT_ADD_EX(i_ud,s);
        PLOT_DISP(i_ud,"ud");
        sprintf(xlabel,"M_%s^2 (MeV^2)",param->s_name);
        PLOT_ADD_EX(i_s,s);
        PLOT_DISP(i_s,"s");
        strbufcpy(xlabel,"a (MeV^-1)");
        PLOT_ADD_EX(i_a,s);
        PLOT_DISP(i_a,"a");
        if (param->have_umd)
        {
            sprintf(xlabel,"%s (MeV^2)",param->umd_name);
            PLOT_ADD_EX(i_umd,s);
            PLOT_DISP(i_umd,"umd");
        }
        if (param->have_alpha)
        {
            strbufcpy(xlabel,"alpha");
            PLOT_ADD_EX(i_alpha,s);
            PLOT_DISP(i_alpha,"alpha");
        }
        strbufcpy(xlabel,"1/L (MeV)");
        PLOT_ADD_EX(i_Linv,s);
        PLOT_DISP(i_Linv,"Linv");
        PLOT_ADD_EX(i_vind,s);
        PLOT_DISP(i_vind,"Linv_av");
    }
    else if (f == SCALE)
    {
        sprintf(gtitle,"scale setting: %s -- datasets: %s -- ensembles: %s",
                param->scale_part,param->dataset_cat,param->manifest);
        for (bind=0;bind<param->nbeta;bind++)
        {
            dbind      = (double)(bind);
            b_int[0]   = dbind - 0.1;
            b_int[1]   = dbind + 0.1;
            xb[i_bind] = b_int;
            a          = mat_get(fit,bind,0);
            fit_data_fit_region(d,xb);
            mat_set(phy_pt,i_ud,0,SQ(a*param->M_ud));
            mat_set(phy_pt,i_s,0,SQ(a*param->M_s));
            mat_set(phy_pt,i_umd,0,SQ(a)*param->M_umd_val);
            mat_set(phy_pt,i_bind,0,bind);
            mat_set(phy_pt,i_a,0,a);
            mat_set(phy_pt,i_Linv,0,0.0);
            sprintf(color,"%d",1+(int)bind);
            sprintf(title,"beta = %s",param->beta[bind]);
            PLOT_ADD_FIT(PF_DATA|PF_FIT,i_ud,0,title,color);
            PLOT_ADD_FIT(PF_DATA|PF_FIT,i_s,0,title,color);
            PLOT_ADD_FIT(PF_DATA|PF_FIT,i_umd,0,title,color);
            PLOT_ADD_FIT(PF_DATA|PF_FIT,i_Linv,0,title,color);
            fit_data_fit_all_points(d,true);
        }
        sprintf(ylabel,"(a*M_%s)^2",param->scale_part);
        sprintf(xlabel,"(a*M_%s)^2",param->ud_name);
        PLOT_DISP(i_ud,"ud");
        sprintf(xlabel,"(a*M_%s)^2",param->s_name);
        PLOT_DISP(i_s,"s");
        if (param->have_umd)
        {
            sprintf(xlabel,"a^2*%s",param->umd_name);
            PLOT_DISP(i_umd,"umd");
        }
        strbufcpy(xlabel,"a/L");
        PLOT_DISP(i_Linv,"Linv");
    }
    param->scale_model = 0;
    
    mat_destroy(phy_pt);
    mat_destroy(x_k);
    mat_destroy(cordat);
    for (bind=0;bind<param->nbeta;bind++)
    {
        mat_destroy(vol_av_corr[bind]);
    }
    free(vol_av_corr);
    for (k=0;k<N_EX_VAR;k++)
    {
        plot_destroy(p[k]);
    }
}