plot *plot_create(void) { plot *p; MALLOC_ERRVAL(p,plot *,1,NULL); p->nplot = 0; p->plotbuf = NULL; p->nhead = 0; p->headbuf = NULL; p->datfname = NULL; strbufcpy(p->title,""); strbufcpy(p->term,DEFTERM); strbufcpy(p->output,""); p->scale = AUTO; p->log = NOLOG; p->xmin = 0.0; p->xmax = 0.0; strbufcpy(p->xlabel,""); p->ymin = 0.0; p->ymax = 0.0; strbufcpy(p->ylabel,""); return p; }
struct server *add_server(char *numeric, char *maxusers, char *name, int hops, time_t boot, time_t link, char *protocol, char *description) { struct server *s; s = zmalloc(sizeof(*s)); s->magic = MAGIC_SERVER; strbufcpy(s->numericstr, numeric); s->numeric = str2snum(numeric); s->maxusers = base64_decode_long(maxusers, 3); strbufcpy(s->name, name); s->hops = hops; s->boot = boot; s->link = link; s->lastnumeric = s->numeric * 64 * 64 * 64 + s->maxusers; strbufcpy(s->protocol, protocol); strbufcpy(s->description, description); /* first one is myself, second one is my uplink */ if (!me) me = s; else if (!uplink) { uplink = s; set_registered(1); } return jtableL_insert(&serverlist, s->numeric, s); }
void plot_add_plot(plot *p, const strbuf cmd, const strbuf datfname) { strbuf war_msg; (p->nplot)++; REALLOC_NOERRET(p->plotbuf,p->plotbuf,strbuf *,p->nplot); REALLOC_NOERRET(p->datfname,p->datfname,strbuf *,p->nplot); strbufcpy(p->plotbuf[p->nplot-1],cmd); strbufcpy(p->datfname[p->nplot-1],datfname); if (strlen(datfname)&&(access(datfname,R_OK) != 0)) { sprintf(war_msg,"cannot access datafile %s",datfname); LATAN_WARNING(war_msg,LATAN_ESYSTEM); } }
void plot_add_points(plot *p, const mat *x, const mat *y, const strbuf title,\ const strbuf color, const strbuf style) { FILE* tmpf; strbuf tmpfname, plotcmd, colorcmd; size_t i; sprintf(tmpfname,".latan_tmp_plot_%lu.dat",(long unsigned)ntmpf); ntmpf++; FOPEN_NOERRET(tmpf,tmpfname,"w"); for (i=0;i<nrow(y);i++) { fprintf(tmpf,"%.10e %.10e\n",mat_get(x,i,0),mat_get(y,i,0)); } fclose(tmpf); if (strlen(color) == 0) { strbufcpy(colorcmd,""); } else { sprintf(colorcmd,"lc %s",color); } sprintf(plotcmd,"u 1:2 t '%s' lt -1 %s w %s",title,\ colorcmd,style); plot_add_plot(p,plotcmd,tmpfname); }
static char * gnuplot_get_program_path(const char *pname) { int i, j, lg; char * path; static char buf[PATH_MAXNAMESZ]; /* Trivial case: try in CWD */ sprintf(buf,"./%s", pname) ; if (access(buf,X_OK) == 0) { sprintf(buf,"."); return buf ; } /* Try out in all paths given in the PATH variable */ buf[0] = 0; path = getenv("PATH") ; if (path != NULL) { for (i=0;path[i];) { for (j=i;(path[j])&&(path[j]!=':');j++); lg = j - i; strncpy(buf,path + i,(size_t)(lg)); if (lg == 0) { buf[lg++] = '.'; } buf[lg++] = '/'; strbufcpy(buf + lg, pname); if (access(buf, X_OK) == 0) { /* Found it! */ break ; } buf[0] = 0; i = j; if (path[i] == ':') i++ ; } } else { LATAN_ERROR_VAL("PATH variable not set",LATAN_ESYSTEM,NULL); } /* If the buffer is still empty, the command was not found */ if (buf[0] == 0) { LATAN_ERROR_VAL("cannot find gnuplot in your PATH",LATAN_ESYSTEM,NULL); } /* Otherwise truncate the command name to yield path only */ lg = (int)(strlen(buf) - 1); while (buf[lg]!='/') { buf[lg] = 0; lg--; } buf[lg] = 0; return buf ; }
static void correct_range(size_t range[2], const mat *prop, const mat *err,\ const qcd_options *opt) { size_t inrange[2],nt; strbuf buf; double rerr; inrange[0] = range[0]; inrange[1] = range[1]; nt = nrow(prop); if (inrange[0] <= nt/2) { strbufcpy(buf,""); for (range[1]=range[0];range[1]<=inrange[1];range[1]++) { rerr = mat_get(err,range[1],0)/fabs(mat_get(prop,range[1],0)); if (rerr > MAX_REL_ERR) { strbufcpy(buf," (rcut)"); break; } } range[1]--; } else if (inrange[0] >= nt/2) { range[1] = inrange[1]; strbufcpy(buf,""); for (range[0]=range[1];range[0]>=inrange[0];range[0]--) { rerr = mat_get(err,range[0],0)/fabs(mat_get(prop,range[0],0)); if (rerr > MAX_REL_ERR) { strbufcpy(buf," (lcut)"); break; } } range[0]++; } qcd_printf(opt,"[%d,%d]%s ",(int)range[0],(int)range[1],buf); }
void plot_add_datpoint(plot *p, const double x, const double y, \ const double xerr,const double yerr, \ const strbuf title, const strbuf color) { strbuf ucmd, echocmd, errcmd, plotcmd, colorcmd; unsigned int err_flag; err_flag = NO_ERR; err_flag |= (xerr > 0.0) ? X_ERR : NO_ERR; err_flag |= (yerr > 0.0) ? Y_ERR : NO_ERR; if ((err_flag & X_ERR)&&(err_flag & Y_ERR)) { strbufcpy(ucmd,"1:2:3:4"); strbufcpy(errcmd,"w xyerr"); sprintf(echocmd,"'< echo %e %e %e %e'",x,y,xerr,yerr); } else if (err_flag & X_ERR) { strbufcpy(ucmd,"1:2:3"); strbufcpy(errcmd,"w xerr"); sprintf(echocmd,"'< echo %e %e %e'",x,y,xerr); } else if (err_flag & Y_ERR) { strbufcpy(ucmd,"1:2:3"); strbufcpy(errcmd,"w yerr"); sprintf(echocmd,"'< echo %e %e %e'",x,y,yerr); } else { strbufcpy(ucmd,"1:2"); strbufcpy(errcmd,""); sprintf(echocmd,"'< echo %e %e'",x,y); } if (strlen(color) == 0) { strbufcpy(colorcmd,""); } else { sprintf(colorcmd,"lc %s",color); } sprintf(plotcmd,"%s u %s %s t '%s' lt -1 pt 1 %s",echocmd,ucmd,errcmd,\ title,colorcmd); plot_add_plot(p,plotcmd,""); }
void send_raw(char *str) { char buf[513]; ssize_t tosend, sent; tosend = strlen(str); logfmt(LOG_RAW, "-> %s", str); strbufcpy(buf, str); while (tosend) { sent = send(conn, str, tosend, 0); if (sent < 0) POSIXERR("Error in sending data"); tosend -= sent; } handle_input(buf); }
/* MPI friendly printf function */ void mpi_printf(const strbuf fmt, ...) { va_list args; int proc,nproc; strbuf buf; #ifdef HAVE_MPI MPI_Comm_size(MPI_COMM_WORLD,&nproc); if (nproc > 1) { MPI_Comm_rank(MPI_COMM_WORLD,&proc); sprintf(buf,"[%d] %s",proc,fmt); } else { strbufcpy(buf,fmt); } #else strbufcpy(buf,fmt); #endif va_start(args,fmt); vprintf(buf,args); va_end(args); }
void plot_add_hline(plot *p, const double y, const strbuf color) { strbuf plotcmd,colorcmd; if (strlen(color) == 0) { strbufcpy(colorcmd,""); } else { sprintf(colorcmd,"lc %s",color); } sprintf(plotcmd,"%.10e lt -1 %s notitle",y,colorcmd); plot_add_plot(p,plotcmd,""); }
void plot_add_vlineaerr(plot *p, const double x, const double xerr[2],\ const strbuf color) { strbuf plotcmd,colorcmd; if (strlen(color) == 0) { strbufcpy(colorcmd,""); } else { sprintf(colorcmd,"lc %s",color); } sprintf(plotcmd,"sprintf(\"< printf ' %e %%e\\n%e %%e\\n%e %%e\\n%e %%e\\n%e %%e\\n'\",ymin,ymax,ymax,ymin,ymin) %s w filledcurve fs transparent solid 0.25 noborder notitle",x-xerr[0],x-xerr[0],x+xerr[1],x+xerr[1],x-xerr[0],colorcmd); plot_add_plot(p,plotcmd,""); plot_add_vline(p,x,color); }
void plot_add_hlineerr(plot *p, const double y, const double err,\ const strbuf color) { strbuf plotcmd,colorcmd; if (strlen(color) == 0) { strbufcpy(colorcmd,""); } else { sprintf(colorcmd,"lc %s",color); } sprintf(plotcmd,"%.10e %s w filledcurve y1=%.10e fs transparent solid 0.25 noborder notitle",\ y+err,colorcmd,y-err); plot_add_plot(p,plotcmd,""); plot_add_hline(p,y,color); }
void plot_add_vline(plot *p, const double x, const strbuf color) { strbuf plotcmd,colorcmd; if (!(p->scale & YMANUAL)) { LATAN_WARNING("vertical line will not work without manual y-scale setting",\ LATAN_EINVAL); } if (strlen(color) == 0) { strbufcpy(colorcmd,""); } else { sprintf(colorcmd,"lc %s",color); } sprintf(plotcmd,"sprintf(\"< printf ' %e %%e\\n%e %%e\\n'\",ymin,ymax) lt -1 %s w lines notitle",\ x,x,colorcmd); plot_add_plot(p,plotcmd,""); }
void plot_set_term(plot *p, const strbuf term) { strbufcpy(p->term,term); }
void plot_set_title(plot *p, const strbuf title) { strbufcpy(p->title,title); }
void plot_add_dat(plot *p, const mat *x, const mat *dat, const mat *xerr,\ const mat *yerr, const strbuf title, const strbuf color) { FILE* tmpf; strbuf tmpfname, ucmd, errcmd, plotcmd, colorcmd; unsigned int err_flag; size_t i; err_flag = NO_ERR; err_flag |= (xerr != NULL) ? X_ERR : NO_ERR; err_flag |= (yerr != NULL) ? Y_ERR : NO_ERR; sprintf(tmpfname,".latan_tmp_plot_%lu.dat",(long unsigned)ntmpf); ntmpf++; FOPEN_NOERRET(tmpf,tmpfname,"w"); if ((err_flag & X_ERR)&&(err_flag & Y_ERR)) { strbufcpy(ucmd,"1:2:3:4"); strbufcpy(errcmd,"w xyerr"); for (i=0;i<nrow(dat);i++) { fprintf(tmpf,"%.10e %.10e %.10e %.10e\n",mat_get(x,i,0),\ mat_get(dat,i,0),mat_get(xerr,i,0), \ mat_get(yerr,i,0)); } } else if (err_flag & X_ERR) { strbufcpy(ucmd,"1:2:3"); strbufcpy(errcmd,"w xerr"); for (i=0;i<nrow(dat);i++) { fprintf(tmpf,"%.10e %.10e %.10e\n",mat_get(x,i,0),mat_get(dat,i,0),\ mat_get(xerr,i,0)); } } else if (err_flag & Y_ERR) { strbufcpy(ucmd,"1:2:3"); strbufcpy(errcmd,"w yerr"); for (i=0;i<nrow(dat);i++) { fprintf(tmpf,"%.10e %.10e %.10e\n",mat_get(x,i,0),mat_get(dat,i,0),\ mat_get(yerr,i,0)); } } else { strbufcpy(ucmd,"1:2"); strbufcpy(errcmd,""); for (i=0;i<nrow(dat);i++) { fprintf(tmpf,"%.10e %.10e\n",mat_get(x,i,0),mat_get(dat,i,0)); } } fclose(tmpf); if (strlen(color) == 0) { strbufcpy(colorcmd,""); } else { sprintf(colorcmd,"lc %s",color); } sprintf(plotcmd,"u %s %s t '%s' lt -1 pt 1 %s",ucmd,errcmd,title,\ colorcmd); plot_add_plot(p,plotcmd,tmpfname); }
void plot_add_head(plot *p, const strbuf cmd) { (p->nhead)++; REALLOC_NOERRET(p->headbuf,p->headbuf,strbuf*,p->nhead); strbufcpy(p->headbuf[p->nhead-1],cmd); }
void plot_set_xlabel(plot *p, const strbuf xlabel) { strbufcpy(p->xlabel,xlabel); }
void plot_set_output(plot *p, const strbuf output) { strbufcpy(p->output,output); }
void plot_parse(FILE* outstr, const plot *p) { strbuf begin, end, fname; size_t i; gnuplot_cmd(outstr,"set term %s",p->term); if (strlen(p->output) != 0) { gnuplot_cmd(outstr,"set output '%s'",p->output); } gnuplot_cmd(outstr,"xmin=%e",p->xmin); gnuplot_cmd(outstr,"xmax=%e",p->xmax); gnuplot_cmd(outstr,"ymin=%e",p->ymin); gnuplot_cmd(outstr,"ymax=%e",p->ymax); if (p->scale & XMANUAL) { gnuplot_cmd(outstr,"set xrange [xmin:xmax]"); } if (p->scale & YMANUAL) { gnuplot_cmd(outstr,"set yrange [ymin:ymax]"); } if (p->log & XLOG) { gnuplot_cmd(outstr,"set log x"); } if (p->log & YLOG) { gnuplot_cmd(outstr,"set log y"); } gnuplot_cmd(outstr,"set title '%s'",p->title); gnuplot_cmd(outstr,"set xlabel '%s'",p->xlabel); gnuplot_cmd(outstr,"set ylabel '%s'",p->ylabel); for (i=0;i<p->nhead;i++) { gnuplot_cmd(outstr,p->headbuf[i]); } for (i=0;i<p->nplot;i++) { if (i == 0) { strbufcpy(begin,"plot "); } else { strbufcpy(begin," "); } if (i == p->nplot-1) { strbufcpy(end,""); } else { strbufcpy(end,",\\"); } if (strlen(p->datfname[i])) { sprintf(fname,"'%s' ",p->datfname[i]); } else { strbufcpy(fname,""); } gnuplot_cmd(outstr,"%s%s%s%s",begin,fname,p->plotbuf[i],end); } }
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; }
void plot_set_ylabel(plot *p, const strbuf ylabel) { strbufcpy(p->ylabel,ylabel); }
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]); } }
int main(int argc, char *argv[]) { int i,j; rs_sample *s1,*s2,*res; size_t s1_dim[2],s2_dim[2],s1_nsample,s2_nsample; mat *sig; bool do_save_res, show_usage; strbuf out_elname,out_fname,in_elname[2],in_fname[2],in_path[2],out_path; char *spt[2]; io_fmt_no fmt; /* argument parsing */ i = 1; j = 0; show_usage = false; do_save_res = false; fmt = io_get_fmt(); if (argc <= 1) { show_usage = true; } else { while (i < argc) { if (strcmp(argv[i],"-o") == 0) { if (i == argc - 1) { show_usage = true; break; } else { strbufcpy(out_path,argv[i+1]); do_save_res = true; i += 2; } } else if (strcmp(argv[i],"-f") == 0) { if (i == argc - 1) { show_usage = true; break; } else { if (strcmp(argv[i+1],"xml") == 0) { fmt = IO_XML; } else if (strcmp(argv[i+1],"ascii") == 0) { fmt = IO_ASCII; } else { fprintf(stderr,"error: format %s unknown\n",argv[i+1]); return EXIT_FAILURE; } i += 2; } } else { if (j < 2) { strbufcpy(in_path[j],argv[i]); j++; i++; } else { show_usage = true; break; } } } } if (show_usage) { fprintf(stderr,"usage: %s <in sample 1> <in sample 2> [-o <out sample>] [-f {ascii|xml}]\n",\ argv[0]); return EXIT_FAILURE; } /* I/O init */ io_set_fmt(fmt); io_init(); /* getting sizes */ rs_sample_load(NULL,&s1_nsample,s1_dim,in_path[0]); rs_sample_load(NULL,&s2_nsample,s2_dim,in_path[1]); /* allocation */ s1 = rs_sample_create(s1_dim[0],s1_dim[1],s1_nsample); s2 = rs_sample_create(s2_dim[0],s2_dim[1],s2_nsample); res = rs_sample_create(s1_dim[0],s1_dim[1],s1_nsample); sig = mat_create(s1_dim[0],s1_dim[1]); /* loading samples */ printf("-- loading sample from %s...\n",in_path[0]); rs_sample_load(s1,NULL,NULL,in_path[0]); printf("-- loading sample from %s...\n",in_path[1]); rs_sample_load(s2,NULL,NULL,in_path[1]); /* multiplying samples */ printf("-- executing operation on samples...\n"); rs_sample_binop(res,s1,s2,&BINOP); /* result output */ rs_sample_varp(sig,res); mat_eqsqrt(sig); printf("central value:\n"); mat_print(rs_sample_pt_cent_val(res),"%e"); printf("standard deviation:\n"); mat_print(sig,"%e"); if (do_save_res) { get_elname(out_fname,out_elname,out_path); if (strlen(out_elname) == 0) { get_elname(in_fname[0],in_elname[0],in_path[0]); get_elname(in_fname[1],in_elname[1],in_path[1]); spt[0] = (strlen(in_elname[0]) == 0) ? in_fname[0] : in_elname[0]; spt[1] = (strlen(in_elname[1]) == 0) ? in_fname[1] : in_elname[1]; sprintf(out_path,"%s%c%s_%s_%s",out_fname,LATAN_PATH_SEP,argv[0],\ spt[0],spt[1]); } rs_sample_save(out_path,'w',res); } /* desallocation */ rs_sample_destroy(s1); rs_sample_destroy(s2); rs_sample_destroy(res); mat_destroy(sig); /* I/O finish */ io_finish(); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { rs_sample *s1,*res,*buf; size_t s1_dim[2],res_dim[2],s1_nsample,a,b,s,k,l; int i,j; mat *sig; bool do_save_res, show_usage, have_s; char *spt; strbuf out_elname,out_fname,in_elname,in_fname,in_path,out_path; io_fmt_no fmt; /* argument parsing */ i = 1; j = 0; a = 0; b = 0; s = 1; show_usage = false; do_save_res = false; have_s = false; fmt = io_get_fmt(); if (argc <= 3) { show_usage = true; } else { while (i < argc) { if (strcmp(argv[i],"-o") == 0) { if (i == argc - 1) { show_usage = true; break; } else { strbufcpy(out_path,argv[i+1]); do_save_res = true; i += 2; } } else if (strcmp(argv[i],"-f") == 0) { if (i == argc - 1) { show_usage = true; break; } else { if (strcmp(argv[i+1],"xml") == 0) { fmt = IO_XML; } else if (strcmp(argv[i+1],"ascii") == 0) { fmt = IO_ASCII; } else { fprintf(stderr,"error: format %s unknown\n",argv[i+1]); return EXIT_FAILURE; } i += 2; } } else if (strcmp(argv[i],"-s") == 0) { if (i == argc - 1) { show_usage = true; break; } else { s = (size_t)atol(argv[i+1]); have_s = true; i += 2; } } else { if (j == 0) { strbufcpy(in_path,argv[i]); j++; i++; } else if (j == 1) { a = (size_t)atol(argv[i]); j++; i++; } else if (j == 2) { b = (size_t)atol(argv[i]); j++; i++; } else { show_usage = true; break; } } } } if (show_usage) { fprintf(stderr,"usage: %s <in sample> <a> <b> [-o <out sample>] [-f {ascii|xml}]\n",\ argv[0]); return EXIT_FAILURE; } /* I/O init */ io_set_fmt(fmt); io_init(); /* getting sizes */ rs_sample_load(NULL,&s1_nsample,s1_dim,in_path); l = b - a + 1; s = (have_s) ? s : l; res_dim[0] = s; res_dim[1] = s1_dim[1]; /* allocation */ s1 = rs_sample_create(s1_dim[0],s1_dim[1],s1_nsample); buf = rs_sample_create(1,s1_dim[1],s1_nsample); res = rs_sample_create(res_dim[0],res_dim[1],s1_nsample); sig = mat_create(res_dim[0],res_dim[1]); /* loading samples */ printf("-- loading sample from %s...\n",in_path); rs_sample_load(s1,NULL,NULL,in_path); /* multiplying samples */ printf("-- taking subsample [%d,%d]...\n",(int)a,(int)b); for (k=0;k<s;k++) { rs_sample_get_subsamp(buf,s1,a+(k%l),0,a+(k%l),s1_dim[1]-1); rs_sample_set_subsamp(res,buf,k,0,k,s1_dim[1]-1); } /* result output */ rs_sample_varp(sig,res); mat_eqsqrt(sig); printf("central value:\n"); mat_print(rs_sample_pt_cent_val(res),"%e"); printf("standard deviation:\n"); mat_print(sig,"%e"); if (do_save_res) { get_elname(out_fname,out_elname,out_path); if (strlen(out_elname) == 0) { get_elname(in_fname,in_elname,in_path); spt = (strlen(in_elname) == 0) ? in_fname : in_elname; sprintf(out_path,"%s%c%s_%s",out_fname,LATAN_PATH_SEP,argv[0],spt); } rs_sample_save(out_path,'w',res); } /* desallocation */ rs_sample_destroy(s1); rs_sample_destroy(res); rs_sample_destroy(buf); mat_destroy(sig); /* I/O finish */ io_finish(); return EXIT_SUCCESS; }
/** access **/ void fit_model_get_name(strbuf name, const fit_model *model) { strbufcpy(name,model->name); }
latan_errno plot_save(const strbuf dirname, plot *p) { strbuf path,buf,*datfname_bak,term_bak,output_bak; FILE *outf; size_t i,j,lc; mode_t mode_755; strbuf name,ver,err_msg; MALLOC_ERRVAL(datfname_bak,strbuf *,p->nplot,LATAN_ENOMEM); mode_755 = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; /* backup I/O parameters */ strbufcpy(term_bak,p->term); strbufcpy(output_bak,p->output); for (i=0;i<p->nplot;i++) { strbufcpy(datfname_bak[i],p->datfname[i]); } /* generate directory */ if (access(dirname,R_OK|W_OK|X_OK)) { if (mkdir(dirname,mode_755)) { sprintf(err_msg,"impossible to create directory %s",dirname); LATAN_ERROR(err_msg,LATAN_ESYSTEM); } } /* save pdf */ sprintf(path,"%s/plot.pdf",dirname); plot_set_term(p,"pdf"); plot_set_output(p,path); plot_disp(p); plot_set_term(p,term_bak); plot_set_output(p,output_bak); /* save script and datafiles */ j = 0; for (i=0;i<p->nplot;i++) { if (strlen(p->datfname[i])) { sprintf(p->datfname[i],"points_%lu.dat",(long unsigned)(j)); j++; sprintf(path,"%s/%s",dirname,p->datfname[i]); FOPEN(outf,path,"w"); BEGIN_FOR_LINE(buf,datfname_bak[i],lc) { fprintf(outf,"%s\n",buf); } END_FOR_LINE fclose(outf); }