72 const cpl_parameterlist *parlist)
99 const cpl_parameter *cp;
103 p = cpl_parameter_new_value(
"plot_title",CPL_TYPE_STRING,
"",
"",title);
104 cpl_parameterlist_append(plottags, p);
105 p = cpl_parameter_new_value(
"xlabel",CPL_TYPE_STRING,
"",
"",x_label);
106 cpl_parameterlist_append(plottags, p);
107 p = cpl_parameter_new_value(
"ylabel",CPL_TYPE_STRING,
"",
"",y_label);
108 cpl_parameterlist_append(plottags, p);
109 p = cpl_parameter_new_value(
"xcol",CPL_TYPE_STRING,
"",
"",x_column);
110 cpl_parameterlist_append(plottags, p);
111 p = cpl_parameter_new_value(
"ycol",CPL_TYPE_STRING,
"",
"",y_column);
112 cpl_parameterlist_append(plottags, p);
114 cp = cpl_parameterlist_find_const(parlist,
"plot_type");
115 sprintf(terminal,
"%s",cpl_parameter_get_string(cp));
116 p = cpl_parameter_new_value(
"terminal",CPL_TYPE_STRING,
"",
"",terminal);
117 cpl_parameterlist_append(plottags, p);
119 cp = cpl_parameterlist_find_const(parlist,
"inst_dir");
120 sprintf(basedir,
"%s",cpl_parameter_get_string(cp));
121 p = cpl_parameter_new_value(
"inst_dir",CPL_TYPE_STRING,
"",
"",basedir);
122 cpl_parameterlist_append(plottags, p);
124 cp = cpl_parameterlist_find_const(parlist,
"output_dir");
125 sprintf(outdir,
"%s",cpl_parameter_get_string(cp));
126 p = cpl_parameter_new_value(
"output_dir",CPL_TYPE_STRING,
"",
"",outdir);
127 cpl_parameterlist_append(plottags, p);
129 cp = cpl_parameterlist_find_const(parlist,
"output_name");
130 sprintf(outname,
"%s",cpl_parameter_get_string(cp));
131 p = cpl_parameter_new_value(
"output_name",CPL_TYPE_STRING,
"",
"",outname);
132 cpl_parameterlist_append(plottags, p);
140 cpl_parameterlist *plottags)
170 char filename[
SC_MAXLEN]=
"sci_single_spec.dat";
171 char gnuname1[
SC_MAXLEN]=
"single_gnufile_wxt.gnu";
172 char gnuname2[
SC_MAXLEN]=
"single_gnufile_ps.gnu";
173 char gnuname3[
SC_MAXLEN]=
"single_gnufile_x11.gnu";
189 int dir_exist_flag=0;
191 double plot_xmin=0., plot_xmax=0.;
199 cpl_parameter *basedirpar, *outdirpar, *filenamepar, *par;
206 par=cpl_parameterlist_find(plottags,
"plot_title");
207 sprintf(title,
"%s",cpl_parameter_get_string(par));
208 par=cpl_parameterlist_find(plottags,
"xlabel");
209 sprintf(x_label,
"%s",cpl_parameter_get_string(par));
210 par=cpl_parameterlist_find(plottags,
"ylabel");
211 sprintf(y_label,
"%s",cpl_parameter_get_string(par));
213 par=cpl_parameterlist_find(plottags,
"xcol");
214 sprintf(x_col,
"%s",cpl_parameter_get_string(par));
215 par=cpl_parameterlist_find(plottags,
"ycol");
216 sprintf(y_col,
"%s",cpl_parameter_get_string(par));
218 par=cpl_parameterlist_find(plottags,
"terminal");
219 sprintf(plot_type,
"%s",cpl_parameter_get_string(par));
221 basedirpar = cpl_parameterlist_find(plottags,
"inst_dir");
222 outdirpar = cpl_parameterlist_find(plottags,
"output_dir");
223 filenamepar = cpl_parameterlist_find(plottags,
"output_name");
226 len=cpl_table_get_nrow(spec);
228 plot_xmin=cpl_table_get_double(spec,x_col,0,NULL);
229 plot_xmax=cpl_table_get_double(spec,x_col,len-1,NULL);
232 sprintf(tmpdir,
"__tmpDIRtmp__");
233 dir_exist_flag=access(tmpdir,EXIST);
234 if (dir_exist_flag == 0){
235 cpl_msg_warning(cpl_func,
"Directory %s already exists!",tmpdir);
239 if (mkdir(tmpdir,0777)) {};
243 sprintf(tmpfilename,
"%s/%s",tmpdir,filename);
244 specfile = fopen(tmpfilename,
"w");
245 for (run=0;run<len;run++)
247 lambda=cpl_table_get_double(spec,x_col,run,NULL);
248 y_value=cpl_table_get_double(spec,y_col,run,NULL);
249 fprintf(specfile,
"%5.6g\t%5.6g\n",lambda,y_value);
254 if ( (strcmp(plot_type,
"W") == 0) || (strcmp(plot_type,
"WX") == 0) ||
255 (strcmp(plot_type,
"XW") == 0) )
258 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname1);
259 gnufile = fopen(tmpfilename,
"w");
260 fprintf(gnufile,
"set term wxt\n");
261 fprintf(gnufile,
"set termoption enhanced \n");
262 fprintf(gnufile,
"set nokey\n");
263 fprintf(gnufile,
"set tmargin 2\n");
264 fprintf(gnufile,
"set bmargin 5\n");
265 fprintf(gnufile,
"set lmargin 13\n");
266 fprintf(gnufile,
"set rmargin 3\n");
267 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
268 fprintf(gnufile,
"set title \"%s\"\n",title);
269 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label);
270 fprintf(gnufile,
"set ylabel \"%s\"\n",y_label);
271 fprintf(gnufile,
"plot '%s/%s' using 1:2 with lines\n",tmpdir,
273 fprintf(gnufile,
"\n");
277 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname1);
278 if (system(system_call)) {};
281 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname1);
282 if (remove(tmpfilename)) {};
286 sprintf(ps_filename,
"%s/%s/%s_%s_singleplot.ps",
287 cpl_parameter_get_string(basedirpar),
288 cpl_parameter_get_string(outdirpar),
289 cpl_parameter_get_string(filenamepar),title);
292 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname2);
293 gnufile = fopen(tmpfilename,
"w");
294 fprintf(gnufile,
"set term postscript enhanced color\n");
295 fprintf(gnufile,
"set output \"%s\"\n",ps_filename);
296 fprintf(gnufile,
"set nokey\n");
297 fprintf(gnufile,
"set tmargin 2\n");
298 fprintf(gnufile,
"set bmargin 5\n");
299 fprintf(gnufile,
"set lmargin 13\n");
300 fprintf(gnufile,
"set rmargin 3\n");
301 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
302 fprintf(gnufile,
"set title \"%s\"\n",title);
303 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label);
304 fprintf(gnufile,
"set ylabel \"%s\"\n",y_label);
305 fprintf(gnufile,
"plot '%s/%s' using 1:2 with lines\n",tmpdir,
307 fprintf(gnufile,
"\n");
311 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname2);
312 if (system(system_call)) {};
315 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname2);
316 if (remove(tmpfilename)) {};
319 if ( (strcmp(plot_type,
"X") == 0) || (strcmp(plot_type,
"WX") == 0) ||
320 (strcmp(plot_type,
"XW") == 0) )
323 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname3);
324 gnufile = fopen(tmpfilename,
"w");
325 fprintf(gnufile,
"set term x11\n");
326 fprintf(gnufile,
"set termoption enhanced \n");
327 fprintf(gnufile,
"set nokey\n");
328 fprintf(gnufile,
"set tmargin 2\n");
329 fprintf(gnufile,
"set bmargin 5\n");
330 fprintf(gnufile,
"set lmargin 13\n");
331 fprintf(gnufile,
"set rmargin 3\n");
332 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
333 fprintf(gnufile,
"set title \"%s\"\n",title);
334 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label);
335 fprintf(gnufile,
"set ylabel \"%s\"\n",y_label);
336 fprintf(gnufile,
"plot '%s/%s' using 1:2 with lines\n",tmpdir,
338 fprintf(gnufile,
"\n");
342 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname3);
343 if (system(system_call)) {};
346 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname3);
347 if (remove(tmpfilename)) {};
352 sprintf(tmpfilename,
"%s/%s",tmpdir,filename);
353 if (remove(tmpfilename)) {};
354 if (rmdir(tmpdir)) {};
356 return CPL_ERROR_NONE;
367 const char *x_column1,
368 const char *y_column1,
370 const char *x_label1,
371 const char *y_label1,
372 const char *x_column2,
373 const char *y_column2,
375 const char *x_label2,
376 const char *y_label2,
377 const cpl_parameterlist *parlist)
413 const cpl_parameter *cp;
417 p = cpl_parameter_new_value(
"title1",CPL_TYPE_STRING,
"",
"",title1);
418 cpl_parameterlist_append(plottags, p);
419 p = cpl_parameter_new_value(
"xlabel1",CPL_TYPE_STRING,
"",
"",x_label1);
420 cpl_parameterlist_append(plottags, p);
421 p = cpl_parameter_new_value(
"ylabel1",CPL_TYPE_STRING,
"",
"",y_label1);
422 cpl_parameterlist_append(plottags, p);
423 p = cpl_parameter_new_value(
"xcol1",CPL_TYPE_STRING,
"",
"",x_column1);
424 cpl_parameterlist_append(plottags, p);
425 p = cpl_parameter_new_value(
"ycol1",CPL_TYPE_STRING,
"",
"",y_column1);
426 cpl_parameterlist_append(plottags, p);
428 p = cpl_parameter_new_value(
"title2",CPL_TYPE_STRING,
"",
"",title2);
429 cpl_parameterlist_append(plottags, p);
430 p = cpl_parameter_new_value(
"xlabel2",CPL_TYPE_STRING,
"",
"",x_label2);
431 cpl_parameterlist_append(plottags, p);
432 p = cpl_parameter_new_value(
"ylabel2",CPL_TYPE_STRING,
"",
"",y_label2);
433 cpl_parameterlist_append(plottags, p);
434 p = cpl_parameter_new_value(
"xcol2",CPL_TYPE_STRING,
"",
"",x_column2);
435 cpl_parameterlist_append(plottags, p);
436 p = cpl_parameter_new_value(
"ycol2",CPL_TYPE_STRING,
"",
"",y_column2);
437 cpl_parameterlist_append(plottags, p);
439 cp = cpl_parameterlist_find_const(parlist,
"plot_type");
440 sprintf(terminal,
"%s",cpl_parameter_get_string(cp));
441 p = cpl_parameter_new_value(
"terminal",CPL_TYPE_STRING,
"",
"",terminal);
442 cpl_parameterlist_append(plottags, p);
444 cp = cpl_parameterlist_find_const(parlist,
"inst_dir");
445 sprintf(basedir,
"%s",cpl_parameter_get_string(cp));
446 p = cpl_parameter_new_value(
"inst_dir",CPL_TYPE_STRING,
"",
"",basedir);
447 cpl_parameterlist_append(plottags, p);
449 cp = cpl_parameterlist_find_const(parlist,
"output_dir");
450 sprintf(outdir,
"%s",cpl_parameter_get_string(cp));
451 p = cpl_parameter_new_value(
"output_dir",CPL_TYPE_STRING,
"",
"",outdir);
452 cpl_parameterlist_append(plottags, p);
454 cp = cpl_parameterlist_find_const(parlist,
"output_name");
455 sprintf(outname,
"%s",cpl_parameter_get_string(cp));
456 p = cpl_parameter_new_value(
"output_name",CPL_TYPE_STRING,
"",
"",outname);
457 cpl_parameterlist_append(plottags, p);
465 const cpl_table *spec2,
466 cpl_parameterlist *plottags)
487 cpl_error_code err_code=CPL_ERROR_NONE;
491 char filename1[
SC_MAXLEN]=
"plot_spec1.dat";
492 char filename2[
SC_MAXLEN]=
"plot_spec2.dat";
493 char gnuname1[
SC_MAXLEN] =
"double_gnufile_wxt.gnu";
494 char gnuname2[
SC_MAXLEN] =
"double_gnufile_ps.gnu";
495 char gnuname3[
SC_MAXLEN] =
"double_gnufile_x11.gnu";
509 int dir_exist_flag=0;
512 double plot_xmin1=0., plot_xmax1=0., plot_xmin2=0., plot_xmax2=0.;
526 cpl_parameter *basedirpar, *outdirpar, *filenamepar, *par;
533 par=cpl_parameterlist_find(plottags,
"title1");
534 sprintf(title1,
"%s",cpl_parameter_get_string(par));
535 par=cpl_parameterlist_find(plottags,
"xlabel1");
536 sprintf(x_label1,
"%s",cpl_parameter_get_string(par));
537 par=cpl_parameterlist_find(plottags,
"ylabel1");
538 sprintf(y_label1,
"%s",cpl_parameter_get_string(par));
539 par=cpl_parameterlist_find(plottags,
"xcol1");
540 sprintf(x_col1,
"%s",cpl_parameter_get_string(par));
541 par=cpl_parameterlist_find(plottags,
"ycol1");
542 sprintf(y_col1,
"%s",cpl_parameter_get_string(par));
544 par=cpl_parameterlist_find(plottags,
"title2");
545 sprintf(title2,
"%s",cpl_parameter_get_string(par));
546 par=cpl_parameterlist_find(plottags,
"xlabel2");
547 sprintf(x_label2,
"%s",cpl_parameter_get_string(par));
548 par=cpl_parameterlist_find(plottags,
"ylabel2");
549 sprintf(y_label2,
"%s",cpl_parameter_get_string(par));
550 par=cpl_parameterlist_find(plottags,
"xcol2");
551 sprintf(x_col2,
"%s",cpl_parameter_get_string(par));
552 par=cpl_parameterlist_find(plottags,
"ycol2");
553 sprintf(y_col2,
"%s",cpl_parameter_get_string(par));
555 par=cpl_parameterlist_find(plottags,
"terminal");
556 sprintf(plot_type,
"%s",cpl_parameter_get_string(par));
557 basedirpar = cpl_parameterlist_find(plottags,
"inst_dir");
558 outdirpar = cpl_parameterlist_find(plottags,
"output_dir");
559 filenamepar = cpl_parameterlist_find(plottags,
"output_name");
572 len1=cpl_table_get_nrow(spec1);
575 len2=cpl_table_get_nrow(spec2);
578 plot_xmin1=cpl_table_get_double(spec1,x_col1,0,NULL);
579 plot_xmax1=cpl_table_get_double(spec1,x_col1,len1-1,NULL);
580 plot_xmin2=cpl_table_get_double(spec2,x_col2,0,NULL);
581 plot_xmax2=cpl_table_get_double(spec2,x_col2,len2-1,NULL);
586 cpl_msg_warning(cpl_func,
"Input spectra do not have the same size.");
590 if ( cpl_table_compare_structure(spec1,spec2) )
592 cpl_msg_warning(cpl_func,
"Input spectra do not have the same "
598 for (run=0;run<len1;run++)
600 if (cpl_table_get_double(spec1,x_col1,run,NULL) !=
601 cpl_table_get_double(spec2,x_col2,run,NULL) )
608 cpl_msg_warning(cpl_func,
"Input spectra have differing wavelength "
613 sprintf(tmpdir,
"__tmpDIRtmp__");
614 dir_exist_flag=access(tmpdir,EXIST);
615 if (dir_exist_flag == 0){
616 cpl_msg_warning(cpl_func,
"Directory %s already exists!",tmpdir);
620 if (mkdir(tmpdir,0777)) {};
625 sprintf(tmpfilename,
"%s/%s",tmpdir,filename1);
626 specfile = fopen(tmpfilename,
"w");
627 for (run=0;run<len1;run++)
629 lambda=cpl_table_get_double(spec1,x_col1,run,NULL);
630 y_value=cpl_table_get_double(spec1,y_col1,run,NULL);
631 fprintf(specfile,
"%5.6g\t%5.6g\n",lambda,y_value);
636 sprintf(tmpfilename,
"%s/%s",tmpdir,filename2);
637 specfile = fopen(tmpfilename,
"w");
638 for (run=0;run<len2;run++)
640 lambda=cpl_table_get_double(spec2,x_col2,run,NULL);
641 y_value=cpl_table_get_double(spec2,y_col2,run,NULL);
642 fprintf(specfile,
"%5.6g\t%5.6g\n",lambda,y_value);
649 if ( (strcmp(plot_type,
"W") == 0) || (strcmp(plot_type,
"WX") == 0) ||
650 (strcmp(plot_type,
"XW") == 0) )
653 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname1);
654 gnufile = fopen(tmpfilename,
"w");
655 fprintf(gnufile,
"set term wxt\n");
656 fprintf(gnufile,
"set termoption enhanced \n");
657 fprintf(gnufile,
"# Plotting\n");
658 fprintf(gnufile,
"set nokey\n");
659 fprintf(gnufile,
"set tmargin 2\n");
660 fprintf(gnufile,
"set bmargin 5\n");
661 fprintf(gnufile,
"set lmargin 12\n");
662 fprintf(gnufile,
"set rmargin 3\n");
663 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin1,plot_xmax1);
664 fprintf(gnufile,
"set termoption font \"Times,7\"\n");
665 fprintf(gnufile,
"set multiplot layout 2,1 \n");
666 fprintf(gnufile,
"set title \"%s\"\n",title1);
667 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label1);
668 fprintf(gnufile,
"set ylabel \"%s\" offset 1,0\n",y_label1);
669 fprintf(gnufile,
"set style data boxes\n");
670 fprintf(gnufile,
"plot '%s/%s' using 1:2 title "
671 " \"%s\" with lines \n",tmpdir,filename1,title1);
672 fprintf(gnufile,
"set nokey\n");
673 fprintf(gnufile,
"set ylabel \"%s\" offset 1,0\n",y_label2);
674 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label2);
675 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin2,plot_xmax2);
677 fprintf(gnufile,
"set title \"%s\"\n",title2);
678 fprintf(gnufile,
"plot '%s/%s' "
679 "using 1:2 title \"%s\" with lines \n",
680 tmpdir,filename2,title2);
681 fprintf(gnufile,
"unset multiplot \n");
685 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname1);
686 if (system(system_call)) {};
689 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname1);
690 if (remove(tmpfilename)) {};
694 sprintf(ps_filename,
"%s/%s/%s_doubleplot.ps",
695 cpl_parameter_get_string(basedirpar),
696 cpl_parameter_get_string(outdirpar),
697 cpl_parameter_get_string(filenamepar));
700 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname2);
701 gnufile = fopen(tmpfilename,
"w");
703 fprintf(gnufile,
"set term postscript enhanced color\n");
704 fprintf(gnufile,
"set output \"%s\"\n", ps_filename);
705 fprintf(gnufile,
"# Plotting\n");
706 fprintf(gnufile,
"set nokey\n");
707 fprintf(gnufile,
"set tmargin 2\n");
708 fprintf(gnufile,
"set bmargin 5\n");
709 fprintf(gnufile,
"set lmargin 12\n");
710 fprintf(gnufile,
"set rmargin 3\n");
711 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin1,plot_xmax1);
712 fprintf(gnufile,
"set termoption font \"Times,12\"\n");
713 fprintf(gnufile,
"set multiplot layout 2,1 \n");
714 fprintf(gnufile,
"set title \"%s\"\n",title1);
715 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label1);
716 fprintf(gnufile,
"set ylabel \"%s\" offset 1,0\n",y_label1);
717 fprintf(gnufile,
"set style data boxes\n");
718 fprintf(gnufile,
"plot '%s/%s' using 1:2 title "
719 " \"%s\" with lines \n",tmpdir,filename1,title1);
720 fprintf(gnufile,
"set nokey\n");
721 fprintf(gnufile,
"set ylabel \"%s\" offset 1,0\n",y_label2);
722 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label2);
723 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin2,plot_xmax2);
725 fprintf(gnufile,
"set title \"%s\"\n",title2);
726 fprintf(gnufile,
"plot '%s/%s' "
727 "using 1:2 title \"%s\" with lines \n",
728 tmpdir,filename2,title2);
729 fprintf(gnufile,
"unset multiplot \n");
733 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname2);
734 if (system(system_call)) {};
737 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname2);
738 if (remove(tmpfilename)) {};
741 if ( (strcmp(plot_type,
"X") == 0) || (strcmp(plot_type,
"WX") == 0) ||
742 (strcmp(plot_type,
"XW") == 0) )
745 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname3);
746 gnufile = fopen(tmpfilename,
"w");
747 fprintf(gnufile,
"set term x11\n");
748 fprintf(gnufile,
"set termoption enhanced \n");
749 fprintf(gnufile,
"# Plotting\n");
750 fprintf(gnufile,
"set nokey\n");
751 fprintf(gnufile,
"set tmargin 2\n");
752 fprintf(gnufile,
"set bmargin 5\n");
753 fprintf(gnufile,
"set lmargin 12\n");
754 fprintf(gnufile,
"set rmargin 3\n");
755 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin1,plot_xmax1);
756 fprintf(gnufile,
"set termoption font \"Times,7\"\n");
757 fprintf(gnufile,
"set multiplot layout 2,1 \n");
758 fprintf(gnufile,
"set title \"%s\"\n",title1);
759 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label1);
760 fprintf(gnufile,
"set ylabel \"%s\" offset 1,0\n",y_label1);
761 fprintf(gnufile,
"set style data boxes\n");
762 fprintf(gnufile,
"plot '%s/%s' using 1:2 title "
763 " \"%s\" with lines \n",tmpdir,filename1,title1);
764 fprintf(gnufile,
"set nokey\n");
765 fprintf(gnufile,
"set ylabel \"%s\" offset 1,0\n",y_label2);
766 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label2);
767 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin2,plot_xmax2);
768 fprintf(gnufile,
"set title \"%s\"\n",title2);
769 fprintf(gnufile,
"plot '%s/%s' "
770 "using 1:2 title \"%s\" with lines \n",
771 tmpdir,filename2,title2);
772 fprintf(gnufile,
"unset multiplot \n");
776 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname3);
777 if (system(system_call)) {};
780 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname3);
781 if (remove(tmpfilename)) {};
786 sprintf(tmpfilename,
"%s/%s",tmpdir,filename1);
787 if (remove(tmpfilename)) {};
788 sprintf(tmpfilename,
"%s/%s",tmpdir,filename2);
789 if (remove(tmpfilename)) {};
790 if (rmdir(tmpdir)) {};
803 const char *x_column,
804 const char *y_column1,
805 const char *y_column2,
806 const char *specname1,
807 const char *specname2,
811 const cpl_parameterlist *parlist)
844 const cpl_parameter *cp;
848 p = cpl_parameter_new_value(
"xcol",CPL_TYPE_STRING,
"",
"",x_column);
849 cpl_parameterlist_append(plottags, p);
850 p = cpl_parameter_new_value(
"ycol1",CPL_TYPE_STRING,
"",
"",y_column1);
851 cpl_parameterlist_append(plottags, p);
852 p = cpl_parameter_new_value(
"ycol2",CPL_TYPE_STRING,
"",
"",y_column2);
853 cpl_parameterlist_append(plottags, p);
855 p = cpl_parameter_new_value(
"specname1",CPL_TYPE_STRING,
"",
"",specname1);
856 cpl_parameterlist_append(plottags, p);
857 p = cpl_parameter_new_value(
"specname2",CPL_TYPE_STRING,
"",
"",specname2);
858 cpl_parameterlist_append(plottags, p);
859 p = cpl_parameter_new_value(
"title",CPL_TYPE_STRING,
"",
"",title);
860 cpl_parameterlist_append(plottags, p);
861 p = cpl_parameter_new_value(
"xlabel",CPL_TYPE_STRING,
"",
"",x_label);
862 cpl_parameterlist_append(plottags, p);
863 p = cpl_parameter_new_value(
"ylabel",CPL_TYPE_STRING,
"",
"",y_label);
864 cpl_parameterlist_append(plottags, p);
866 cp=cpl_parameterlist_find_const(parlist,
"plot_type");
867 sprintf(terminal,
"%s",cpl_parameter_get_string(cp));
868 p = cpl_parameter_new_value(
"terminal",CPL_TYPE_STRING,
"",
"",terminal);
869 cpl_parameterlist_append(plottags, p);
871 cp=cpl_parameterlist_find_const(parlist,
"inst_dir");
872 sprintf(basedir,
"%s",cpl_parameter_get_string(cp));
873 p = cpl_parameter_new_value(
"inst_dir",CPL_TYPE_STRING,
"",
"",basedir);
874 cpl_parameterlist_append(plottags, p);
876 cp=cpl_parameterlist_find_const(parlist,
"output_dir");
877 sprintf(outdir,
"%s",cpl_parameter_get_string(cp));
878 p = cpl_parameter_new_value(
"output_dir",CPL_TYPE_STRING,
"",
"",outdir);
879 cpl_parameterlist_append(plottags, p);
881 cp=cpl_parameterlist_find_const(parlist,
"output_name");
882 sprintf(outname,
"%s",cpl_parameter_get_string(cp));
883 p = cpl_parameter_new_value(
"output_name",CPL_TYPE_STRING,
"",
"",outname);
884 cpl_parameterlist_append(plottags, p);
894 cpl_parameterlist *plottags)
918 cpl_error_code err_code=CPL_ERROR_NONE;
922 char filename1[
SC_MAXLEN]=
"sci_spec.dat";
923 char filename2[
SC_MAXLEN]=
"fit_spec.dat";
924 char filename3[
SC_MAXLEN]=
"resi_spec.dat";
925 char gnuname1[
SC_MAXLEN]=
"overplot_gnufile_wxt.gnu";
926 char gnuname2[
SC_MAXLEN]=
"overplot_gnufile_ps.gnu";
927 char gnuname3[
SC_MAXLEN]=
"overplot_gnufile_x11.gnu";
933 int dir_exist_flag=0;
936 double plot_xmin=0., plot_xmax=0., plot_ymin=0., plot_ymax=0., tmp1=0.,
949 cpl_parameter *basedirpar, *outdirpar, *filenamepar, *par;
956 par=cpl_parameterlist_find(plottags,
"xcol");
957 sprintf(x_col,
"%s",cpl_parameter_get_string(par));
958 par=cpl_parameterlist_find(plottags,
"ycol1");
959 sprintf(y_col1,
"%s",cpl_parameter_get_string(par));
960 par=cpl_parameterlist_find(plottags,
"ycol2");
961 sprintf(y_col2,
"%s",cpl_parameter_get_string(par));
963 par=cpl_parameterlist_find(plottags,
"specname1");
964 sprintf(specname1,
"%s",cpl_parameter_get_string(par));
965 par=cpl_parameterlist_find(plottags,
"specname2");
966 sprintf(specname2,
"%s",cpl_parameter_get_string(par));
967 par=cpl_parameterlist_find(plottags,
"title");
968 sprintf(title,
"%s",cpl_parameter_get_string(par));
969 par=cpl_parameterlist_find(plottags,
"xlabel");
970 sprintf(x_label,
"%s",cpl_parameter_get_string(par));
971 par=cpl_parameterlist_find(plottags,
"ylabel");
972 sprintf(y_label,
"%s",cpl_parameter_get_string(par));
974 par=cpl_parameterlist_find(plottags,
"terminal");
975 sprintf(plot_type,
"%s",cpl_parameter_get_string(par));
976 basedirpar = cpl_parameterlist_find(plottags,
"inst_dir");
977 outdirpar = cpl_parameterlist_find(plottags,
"output_dir");
978 filenamepar = cpl_parameterlist_find(plottags,
"output_name");
982 len1=cpl_table_get_nrow(spec);
985 sprintf(tmpdir,
"__tmpDIRtmp__");
986 dir_exist_flag=access(tmpdir,EXIST);
987 if (dir_exist_flag == 0){
988 cpl_msg_warning(cpl_func,
"Directory %s already exists!",tmpdir);
992 if (mkdir(tmpdir,0777)) {};
998 sprintf(tmpfilename,
"%s/%s",tmpdir,filename1);
999 specfile = fopen(tmpfilename,
"w");
1000 for (run=0;run<len1;run++)
1002 fprintf(specfile,
"%5.6g\t%5.6g\n",
1003 cpl_table_get_double(spec,x_col,run,NULL),
1004 cpl_table_get_double(spec,y_col1,run,NULL));
1010 sprintf(tmpfilename,
"%s/%s",tmpdir,filename2);
1011 specfile = fopen(tmpfilename,
"w");
1012 for (run=0;run<len1;run++)
1014 fprintf(specfile,
"%5.6g\t%5.6g\n",
1015 cpl_table_get_double(spec,x_col,run,NULL),
1016 cpl_table_get_double(spec,y_col2,run,NULL));
1022 sprintf(tmpfilename,
"%s/%s",tmpdir,filename3);
1023 specfile = fopen(tmpfilename,
"w");
1024 for (run=0;run<len1;run++)
1027 if (cpl_table_get_double(spec,
"weight",run,NULL) > 0) {
1028 y_value=cpl_table_get_double(spec,y_col1,run,NULL)-
1029 cpl_table_get_double(spec,y_col2,run,NULL);
1033 fprintf(specfile,
"%5.6g\t%5.6g\n",
1034 cpl_table_get_double(spec,x_col,run,NULL),y_value);
1036 if (y_value < ymin) {
1043 plot_xmin=cpl_table_get_double(spec,x_col,0,NULL);
1044 plot_xmax=cpl_table_get_double(spec,x_col,len1-1,NULL);
1045 tmp1=cpl_table_get_column_min(spec,y_col1);
1046 tmp2=cpl_table_get_column_min(spec,y_col2);
1055 if (ymin < plot_ymin) {
1058 tmp1=cpl_table_get_column_max(spec,y_col1);
1059 tmp2=cpl_table_get_column_max(spec,y_col2);
1069 dy = plot_ymax - plot_ymin;
1070 plot_ymin = plot_ymin - 0.05 *dy;
1071 plot_ymax = plot_ymax + 0.05 *dy;
1077 if ( (strcmp(plot_type,
"W") == 0) || (strcmp(plot_type,
"WX") == 0) ||
1078 (strcmp(plot_type,
"XW") == 0) )
1081 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname1);
1082 gnufile = fopen(tmpfilename,
"w");
1084 fprintf(gnufile,
"set term wxt\n");
1085 fprintf(gnufile,
"set termoption enhanced \n");
1086 fprintf(gnufile,
"# Plotting\n");
1087 fprintf(gnufile,
"set key at screen 0.76, 0.55 autotitle column box "
1088 "samplen 1 left\n");
1089 fprintf(gnufile,
"set tmargin 0\n");
1090 fprintf(gnufile,
"set bmargin 5\n");
1091 fprintf(gnufile,
"set lmargin 12\n");
1092 fprintf(gnufile,
"set rmargin 14\n");
1093 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
1094 fprintf(gnufile,
"set yrange [ %g : %g ]\n",plot_ymin,plot_ymax);
1095 fprintf(gnufile,
"unset title\n");
1096 fprintf(gnufile,
"set termoption font \"Times,7\"\n");
1097 fprintf(gnufile,
"set multiplot layout 2,1 title \"%s\" \n",title);
1098 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label);
1099 fprintf(gnufile,
"set ylabel \"%s\" offset 1,0\n",y_label);
1100 fprintf(gnufile,
"set style data boxes\n");
1101 fprintf(gnufile,
"plot '%s/%s' using 1:2 title \"%s\" "
1102 "with lines lt -1, '%s/%s' "
1103 "using 1:2 title \"%s\" with lines lt 8\n",
1104 tmpdir,filename1,specname1,tmpdir,filename2,specname2);
1105 fprintf(gnufile,
"set key at screen 0.73, 0.1 autotitle column box "
1106 "samplen 1 left\n");
1107 fprintf(gnufile,
"set ylabel \"Residual (%s-%s)\" offset 1,0\n",
1108 specname1,specname2);
1109 fprintf(gnufile,
"set y2tics border out scale 1,0.5 nomirror norotate"
1110 " offset character 0, 0, 0 autofreq \n");
1111 fprintf(gnufile,
"set ytics nomirror\n");
1112 fprintf(gnufile,
"set y2tics nomirror textcolor lt 2\n");
1113 fprintf(gnufile,
"set ylabel \"Residual (input-best-fit sky)\" offset"
1115 fprintf(gnufile,
"set y2label \"Residual (input-best-fit sky)\" "
1116 "textcolor lt 2\n");
1118 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label);
1119 fprintf(gnufile,
"plot '__tmpDIRtmp__/resi_spec.dat' using 1:2 title"
1120 " \"original scaling\" with lines lw 2 lt -1 "
1121 "axes x1y1,'__tmpDIRtmp__/resi_spec.dat' using 1:2 title "
1122 "\"optimal scaling\" with lines lt 2 axes x2y2\n");
1125 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
1126 fprintf(gnufile,
"set yrange [ %g : %g ]\n",plot_ymin,plot_ymax);
1127 fprintf(gnufile,
"set autoscale y2\n");
1128 fprintf(gnufile,
"set title \n");
1129 fprintf(gnufile,
"unset multiplot \n");
1133 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname1);
1134 if (system(system_call)) {};
1137 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname1);
1138 if (remove(tmpfilename)) {};
1143 if ( strncmp(cpl_parameter_get_string(outdirpar),
"/", 1) == 0 )
1145 sprintf(ps_filename,
"%s/%s_overplot.ps",
1146 cpl_parameter_get_string(outdirpar),
1147 cpl_parameter_get_string(filenamepar));
1151 sprintf(ps_filename,
"%s/%s/%s_overplot.ps",
1152 cpl_parameter_get_string(basedirpar),
1153 cpl_parameter_get_string(outdirpar),
1154 cpl_parameter_get_string(filenamepar));
1158 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname2);
1159 gnufile = fopen(tmpfilename,
"w");
1161 fprintf(gnufile,
"set term postscript enhanced color\n");
1162 fprintf(gnufile,
"set output \"%s\"\n",ps_filename);
1163 fprintf(gnufile,
"# Plotting\n");
1164 fprintf(gnufile,
"set key at screen 0.70, 0.55 autotitle column box "
1165 "samplen 1 left\n");
1166 fprintf(gnufile,
"set tmargin 0\n");
1167 fprintf(gnufile,
"set bmargin 5\n");
1168 fprintf(gnufile,
"set lmargin 12\n");
1169 fprintf(gnufile,
"set rmargin 14\n");
1170 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
1171 fprintf(gnufile,
"set yrange [ %g : %g ]\n",plot_ymin,plot_ymax);
1172 fprintf(gnufile,
"unset title\n");
1173 fprintf(gnufile,
"set termoption font \"Times,12\"\n");
1174 fprintf(gnufile,
"set multiplot layout 2,1 title \"%s\" \n",title);
1175 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label);
1176 fprintf(gnufile,
"set ylabel \"%s\" offset 1,0\n",y_label);
1177 fprintf(gnufile,
"set style data boxes\n");
1178 fprintf(gnufile,
"plot '%s/%s' using 1:2 title \"%s\" "
1179 "with lines lt -1, '%s/%s' "
1180 "using 1:2 title \"%s\" with lines lt 8\n",
1181 tmpdir,filename1,specname1,tmpdir,filename2,specname2);
1183 fprintf(gnufile,
"set key at screen 0.66, 0.07 autotitle column box "
1184 "samplen 1 left\n");
1185 fprintf(gnufile,
"set ylabel \"Residual (%s-%s)\" offset 1,0\n",
1186 specname1,specname2);
1187 fprintf(gnufile,
"set y2tics border out scale 1,0.5 nomirror norotate"
1188 " offset character 0, 0, 0 autofreq \n");
1189 fprintf(gnufile,
"set style line 1 lt 2 lc rgb \"red\" lw 3\n");
1190 fprintf(gnufile,
"set style line 2 lt 1 lc rgb \"green\" lw 1\n");
1191 fprintf(gnufile,
"set ytics nomirror\n");
1192 fprintf(gnufile,
"set y2tics nomirror textcolor lt 2\n");
1193 fprintf(gnufile,
"set ylabel \"Residual (input-best-fit sky)\" offset"
1195 fprintf(gnufile,
"set y2label \"Residual (input-best-fit sky)\" "
1196 "textcolor lt 2\n");
1198 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label);
1199 fprintf(gnufile,
"plot '__tmpDIRtmp__/resi_spec.dat' using 1:2 title"
1200 " \"original scaling\" with lines lw 2 lt -1 "
1201 "axes x1y1,'__tmpDIRtmp__/resi_spec.dat' using 1:2 title "
1202 "\"optimal scaling\" with lines ls 2 axes x2y2\n");
1205 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
1206 fprintf(gnufile,
"set yrange [ %g : %g ]\n",plot_ymin,plot_ymax);
1207 fprintf(gnufile,
"set autoscale y2\n");
1208 fprintf(gnufile,
"set title \n");
1209 fprintf(gnufile,
"unset multiplot \n");
1244 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname2);
1245 if (system(system_call)) {};
1248 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname2);
1249 if (remove(tmpfilename)) {};
1252 if ( (strcmp(plot_type,
"X") == 0) || (strcmp(plot_type,
"WX") == 0) ||
1253 (strcmp(plot_type,
"XW") == 0) )
1256 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname3);
1257 gnufile = fopen(tmpfilename,
"w");
1259 fprintf(gnufile,
"set term x11\n");
1260 fprintf(gnufile,
"set termoption enhanced \n");
1261 fprintf(gnufile,
"# Plotting\n");
1262 fprintf(gnufile,
"set key at screen 0.72, 0.55 autotitle column box "
1263 "samplen 1 left\n");
1264 fprintf(gnufile,
"set tmargin 0\n");
1265 fprintf(gnufile,
"set bmargin 5\n");
1266 fprintf(gnufile,
"set lmargin 12\n");
1267 fprintf(gnufile,
"set rmargin 14\n");
1268 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
1269 fprintf(gnufile,
"set yrange [ %g : %g ]\n",plot_ymin,plot_ymax);
1270 fprintf(gnufile,
"unset title\n");
1271 fprintf(gnufile,
"set termoption font \"Times,15\"\n");
1272 fprintf(gnufile,
"set multiplot layout 2,1 title \"%s\" \n",title);
1273 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label);
1274 fprintf(gnufile,
"set ylabel \"%s\" offset 1,0\n",y_label);
1275 fprintf(gnufile,
"set style data boxes\n");
1276 fprintf(gnufile,
"plot '%s/%s' using 1:2 title \"%s\" "
1277 "with lines lt -1, '%s/%s' "
1278 "using 1:2 title \"%s\" with lines lt 8\n",
1279 tmpdir,filename1,specname1,tmpdir,filename2,specname2);
1280 fprintf(gnufile,
"set key at screen 0.68, 0.1 autotitle column box "
1281 "samplen 1 left\n");
1282 fprintf(gnufile,
"set ylabel \"Residual (%s-%s)\" offset 1,0\n",
1283 specname1,specname2);
1284 fprintf(gnufile,
"set y2tics border out scale 1,0.5 nomirror norotate"
1285 " offset character 0, 0, 0 autofreq \n");
1286 fprintf(gnufile,
"set ytics nomirror\n");
1287 fprintf(gnufile,
"set y2tics nomirror textcolor lt 3\n");
1288 fprintf(gnufile,
"set ylabel \"Residual (input-best-fit sky)\" offset"
1290 fprintf(gnufile,
"set y2label \"Residual (input-best-fit sky)\" "
1291 "textcolor lt 3\n");
1293 fprintf(gnufile,
"set xlabel \"%s\"\n",x_label);
1294 fprintf(gnufile,
"plot '__tmpDIRtmp__/resi_spec.dat' using 1:2 title"
1295 " \"original scaling\" with lines lw 2 lt -1 "
1296 "axes x1y1,'__tmpDIRtmp__/resi_spec.dat' using 1:2 title "
1297 "\"optimal scaling\" with lines lt 3 axes x2y2\n");
1300 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
1301 fprintf(gnufile,
"set yrange [ %g : %g ]\n",plot_ymin,plot_ymax);
1302 fprintf(gnufile,
"set autoscale y2\n");
1303 fprintf(gnufile,
"set title \n");
1304 fprintf(gnufile,
"unset multiplot \n");
1339 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname3);
1340 if (system(system_call)) {};
1343 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname3);
1344 if (remove(tmpfilename)) {};
1349 sprintf(tmpfilename,
"%s/%s",tmpdir,filename1);
1350 if (remove(tmpfilename)) {};
1351 sprintf(tmpfilename,
"%s/%s",tmpdir,filename2);
1352 if (remove(tmpfilename)) {};
1353 sprintf(tmpfilename,
"%s/%s",tmpdir,filename3);
1354 if (remove(tmpfilename)) {};
1355 if (rmdir(tmpdir)) {};
1367 const char *x_label,
const char *y_label,
1368 const cpl_parameterlist *parlist)
1394 const cpl_parameter *cp;
1398 p = cpl_parameter_new_value(
"plot_title",CPL_TYPE_STRING,
"",
"",title);
1399 cpl_parameterlist_append(plottags, p);
1400 p = cpl_parameter_new_value(
"xlabel",CPL_TYPE_STRING,
"",
"",x_label);
1401 cpl_parameterlist_append(plottags, p);
1402 p = cpl_parameter_new_value(
"ylabel",CPL_TYPE_STRING,
"",
"",y_label);
1403 cpl_parameterlist_append(plottags, p);
1405 cp = cpl_parameterlist_find_const(parlist,
"plot_type");
1406 sprintf(terminal,
"%s",cpl_parameter_get_string(cp));
1407 p = cpl_parameter_new_value(
"terminal",CPL_TYPE_STRING,
"",
"",terminal);
1408 cpl_parameterlist_append(plottags, p);
1410 cp = cpl_parameterlist_find_const(parlist,
"inst_dir");
1411 sprintf(basedir,
"%s",cpl_parameter_get_string(cp));
1412 p = cpl_parameter_new_value(
"inst_dir",CPL_TYPE_STRING,
"",
"",basedir);
1413 cpl_parameterlist_append(plottags, p);
1415 cp = cpl_parameterlist_find_const(parlist,
"output_dir");
1416 sprintf(outdir,
"%s",cpl_parameter_get_string(cp));
1417 p = cpl_parameter_new_value(
"output_dir",CPL_TYPE_STRING,
"",
"",outdir);
1418 cpl_parameterlist_append(plottags, p);
1420 cp = cpl_parameterlist_find_const(parlist,
"output_name");
1421 sprintf(outname,
"%s",cpl_parameter_get_string(cp));
1422 p = cpl_parameter_new_value(
"output_name",CPL_TYPE_STRING,
"",
"",outname);
1423 cpl_parameterlist_append(plottags, p);
1431 cpl_parameterlist *plottags)
1450 cpl_error_code err_code=CPL_ERROR_NONE;
1454 char filename1[
SC_MAXLEN]=
"hist_data.dat";
1455 char gnuname1[
SC_MAXLEN]=
"hist_plot_wxt.gnu";
1456 char gnuname2[
SC_MAXLEN]=
"hist_plot_ps.gnu";
1457 char gnuname3[
SC_MAXLEN]=
"hist_plot_x11.gnu";
1464 int dir_exist_flag=0;
1476 int len1=0, ncol1=0;
1479 cpl_parameter *basedirpar, *outdirpar, *filenamepar, *par;
1481 cpl_array *column_names1;
1488 par=cpl_parameterlist_find(plottags,
"plot_title");
1489 sprintf(plot_title,
"%s",cpl_parameter_get_string(par));
1490 par=cpl_parameterlist_find(plottags,
"xlabel");
1491 sprintf(x_colname,
"%s",cpl_parameter_get_string(par));
1492 par=cpl_parameterlist_find(plottags,
"ylabel");
1493 sprintf(y_colname,
"%s",cpl_parameter_get_string(par));
1494 par=cpl_parameterlist_find(plottags,
"terminal");
1495 sprintf(plot_type,
"%s",cpl_parameter_get_string(par));
1502 len1=cpl_table_get_nrow(histdat);
1503 ncol1=cpl_table_get_ncol(histdat);
1504 column_names1 = cpl_table_get_column_names(histdat);
1509 sprintf(err_msg,
"Number of columns not equal 2 in data file...");
1510 return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1515 sprintf(tmpdir,
"__tmpDIRtmp__");
1516 dir_exist_flag=access(tmpdir,EXIST);
1517 if (dir_exist_flag == 0){
1518 cpl_msg_warning(cpl_func,
"Directory %s already exists!",tmpdir);
1522 if (mkdir(tmpdir,0777)) {};
1528 sprintf(tmpfilename,
"%s/%s",tmpdir,filename1);
1529 specfile = fopen(tmpfilename,
"w");
1530 for (run=0;run<len1;run++)
1532 binlims=cpl_table_get_double(histdat,
"bins",run,NULL);
1533 cts=cpl_table_get_int(histdat,
"counts",run,NULL);
1534 fprintf(specfile,
"%5.3g\t%i\n",binlims,cts);
1541 if ( (strcmp(plot_type,
"W") == 0) || (strcmp(plot_type,
"WX") == 0) ||
1542 (strcmp(plot_type,
"XW") == 0) )
1545 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname1);
1546 gnufile = fopen(tmpfilename,
"w");
1547 fprintf(gnufile,
"set term wxt\n");
1548 fprintf(gnufile,
"set termoption enhanced\n");
1549 fprintf(gnufile,
"set title \"%s\"\n",plot_title);
1550 fprintf(gnufile,
"set termoption font \"Times,9\"\n");
1551 fprintf(gnufile,
"set xlabel '%s'\n",x_colname);
1552 fprintf(gnufile,
"set ylabel '%s'\n",y_colname);
1553 fprintf(gnufile,
"set boxwidth 0.75 absolute\n");
1554 fprintf(gnufile,
"set style fill solid 1.00 border -1\n");
1555 fprintf(gnufile,
"set style histogram rowstacked\n");
1556 fprintf(gnufile,
"set style data histograms\n");
1557 fprintf(gnufile,
"plot '%s/%s' u 1:2 smooth frequency with histeps"
1558 " t \"%s\"\n",tmpdir,filename1,y_colname);
1559 fprintf(gnufile,
"unset xlabel\n");
1560 fprintf(gnufile,
"unset ylabel\n");
1561 fprintf(gnufile,
"\n");
1565 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname1);
1566 if (system(system_call)) {};
1569 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname1);
1570 if (remove(tmpfilename)) {};
1574 basedirpar = cpl_parameterlist_find(plottags,
"inst_dir");
1575 outdirpar = cpl_parameterlist_find(plottags,
"output_dir");
1576 filenamepar = cpl_parameterlist_find(plottags,
"output_name");
1578 sprintf(ps_filename,
"%s/%s/%s_histogram.ps",
1579 cpl_parameter_get_string(basedirpar),
1580 cpl_parameter_get_string(outdirpar),
1581 cpl_parameter_get_string(filenamepar));
1584 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname2);
1585 gnufile = fopen(tmpfilename,
"w");
1586 fprintf(gnufile,
"set term postscript enhanced color\n");
1587 fprintf(gnufile,
"set output \"%s\"\n",ps_filename);
1588 fprintf(gnufile,
"set title \"%s\"\n",plot_title);
1589 fprintf(gnufile,
"set termoption font \"Times,9\"\n");
1590 fprintf(gnufile,
"set xlabel '%s'\n",x_colname);
1591 fprintf(gnufile,
"set ylabel '%s'\n",y_colname);
1592 fprintf(gnufile,
"set boxwidth 0.9 absolute\n");
1593 fprintf(gnufile,
"set style fill solid 1.00 border -1\n");
1594 fprintf(gnufile,
"set style data histograms\n");
1595 fprintf(gnufile,
"plot '%s/%s' u 1:2 smooth frequency with histeps"
1596 " t \"%s\"\n",tmpdir,filename1,y_colname);
1597 fprintf(gnufile,
"unset xlabel\n");
1598 fprintf(gnufile,
"unset ylabel\n");
1599 fprintf(gnufile,
"\n");
1603 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname2);
1604 if (system(system_call)) {};
1607 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname2);
1608 if (remove(tmpfilename)) {};
1611 if ( (strcmp(plot_type,
"X") == 0) || (strcmp(plot_type,
"WX") == 0) ||
1612 (strcmp(plot_type,
"XW") == 0) )
1615 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname3);
1616 gnufile = fopen(tmpfilename,
"w");
1617 fprintf(gnufile,
"set term x11\n");
1618 fprintf(gnufile,
"set termoption enhanced\n");
1620 fprintf(gnufile,
"set title \"%s\"\n",plot_title);
1621 fprintf(gnufile,
"set termoption font \"Times,9\"\n");
1622 fprintf(gnufile,
"set xlabel '%s'\n",x_colname);
1623 fprintf(gnufile,
"set ylabel '%s'\n",y_colname);
1624 fprintf(gnufile,
"set boxwidth 0.75 absolute\n");
1625 fprintf(gnufile,
"set style fill solid 1.00 border -1\n");
1626 fprintf(gnufile,
"set style histogram rowstacked\n");
1627 fprintf(gnufile,
"set style data histograms\n");
1628 fprintf(gnufile,
"plot '%s/%s' u 1:2 smooth frequency with histeps"
1629 " t \"%s\"\n",tmpdir,filename1,y_colname);
1630 fprintf(gnufile,
"unset xlabel\n");
1631 fprintf(gnufile,
"unset ylabel\n");
1632 fprintf(gnufile,
"\n");
1636 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname3);
1637 if (system(system_call)) {};
1640 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname3);
1641 if (remove(tmpfilename)) {};
1646 sprintf(tmpfilename,
"%s/%s",tmpdir,filename1);
1647 if (remove(tmpfilename)) {};
1648 if (rmdir(tmpdir)) {};
1650 cpl_array_delete(column_names1);
1666 const char *x_label,
1667 const char *y_label,
1668 const cpl_parameterlist *parlist)
1693 const cpl_parameter *cp;
1697 p = cpl_parameter_new_value(
"plot_title",CPL_TYPE_STRING,
"",
"",title);
1698 cpl_parameterlist_append(plottags, p);
1699 p = cpl_parameter_new_value(
"xlabel",CPL_TYPE_STRING,
"",
"",x_label);
1700 cpl_parameterlist_append(plottags, p);
1701 p = cpl_parameter_new_value(
"ylabel",CPL_TYPE_STRING,
"",
"",y_label);
1702 cpl_parameterlist_append(plottags, p);
1704 cp = cpl_parameterlist_find_const(parlist,
"plot_type");
1705 sprintf(terminal,
"%s",cpl_parameter_get_string(cp));
1706 p = cpl_parameter_new_value(
"terminal",CPL_TYPE_STRING,
"",
"",terminal);
1707 cpl_parameterlist_append(plottags, p);
1709 cp = cpl_parameterlist_find_const(parlist,
"inst_dir");
1710 sprintf(basedir,
"%s",cpl_parameter_get_string(cp));
1711 p = cpl_parameter_new_value(
"inst_dir",CPL_TYPE_STRING,
"",
"",basedir);
1712 cpl_parameterlist_append(plottags, p);
1714 cp = cpl_parameterlist_find_const(parlist,
"output_dir");
1715 sprintf(outdir,
"%s",cpl_parameter_get_string(cp));
1716 p = cpl_parameter_new_value(
"output_dir",CPL_TYPE_STRING,
"",
"",outdir);
1717 cpl_parameterlist_append(plottags, p);
1719 cp = cpl_parameterlist_find_const(parlist,
"output_name");
1720 sprintf(outname,
"%s",cpl_parameter_get_string(cp));
1721 p = cpl_parameter_new_value(
"output_name",CPL_TYPE_STRING,
"",
"",outname);
1722 cpl_parameterlist_append(plottags, p);
1732 cpl_parameterlist *plottags)
1757 char filename[
SC_MAXLEN]=
"sci_single_plot_with_lines_spec.dat";
1758 char gnuname1[
SC_MAXLEN]=
"single_plot_with_lines_gnufile_wxt.gnu";
1759 char gnuname2[
SC_MAXLEN]=
"single_plot_with_lines_gnufile_ps.gnu";
1760 char gnuname3[
SC_MAXLEN]=
"single_plot_with_lines_gnufile_x11.gnu";
1778 int dir_exist_flag=0;
1780 double plot_xmin=0., plot_xmax=0.;
1781 double plot_ymin=0., plot_ymax=0.;
1782 double plot_dist_min=0., plot_dist_min_local=0., plot_dist_max=0.;
1783 double plot_label=0.;
1791 cpl_parameter *basedirpar, *outdirpar, *filenamepar, *par;
1798 par=cpl_parameterlist_find(plottags,
"plot_title");
1799 sprintf(plot_title,
"%s",cpl_parameter_get_string(par));
1800 par=cpl_parameterlist_find(plottags,
"xlabel");
1801 sprintf(x_colname,
"%s",cpl_parameter_get_string(par));
1802 par=cpl_parameterlist_find(plottags,
"ylabel");
1803 sprintf(y_colname,
"%s",cpl_parameter_get_string(par));
1804 par=cpl_parameterlist_find(plottags,
"terminal");
1805 sprintf(plot_type,
"%s",cpl_parameter_get_string(par));
1808 len=cpl_table_get_nrow(spec);
1810 plot_xmin=cpl_table_get_double(spec,
"lambda",0,NULL);
1811 plot_xmax=cpl_table_get_double(spec,
"lambda",len-1,NULL);
1812 corrfac=(plot_xmax-plot_xmin)/100;
1814 plot_ymin=cpl_table_get_column_min(spec,
"flux");
1815 plot_ymax=1.5*cpl_table_get_column_max(spec,
"flux");
1818 plot_dist_max=plot_ymax-(plot_ymax-plot_ymin)/4;
1819 plot_dist_min=(plot_ymax-plot_ymin)/50;
1821 plot_label=plot_dist_max+plot_dist_min;
1826 sprintf(tmpdir,
"__tmpDIRtmp__");
1827 dir_exist_flag=access(tmpdir,EXIST);
1828 if (dir_exist_flag == 0){
1829 cpl_msg_warning(cpl_func,
"Directory %s already exists!",tmpdir);
1833 if (mkdir(tmpdir,0777)) {};
1837 sprintf(tmpfilename,
"%s/%s",tmpdir,filename);
1838 specfile = fopen(tmpfilename,
"w");
1839 for (run=0;run<len;run++)
1841 lambda=cpl_table_get_double(spec,
"lambda",run,NULL);
1842 y_value=cpl_table_get_double(spec,
"flux",run,NULL);
1843 fprintf(specfile,
"%5.6g\t%5.6g\n",lambda,y_value);
1848 for(run=0;run<len-1;run++)
1850 n_lines=n_lines+cpl_table_get_int(spec,
"class",run,NULL);
1854 cpl_msg_warning(cpl_func,
"Input spectrum contains no lines "
1859 if ( (strcmp(plot_type,
"W") == 0) || (strcmp(plot_type,
"WX") == 0) ||
1860 (strcmp(plot_type,
"XW") == 0) )
1863 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname1);
1864 gnufile = fopen(tmpfilename,
"w");
1865 fprintf(gnufile,
"set term wxt\n");
1866 fprintf(gnufile,
"set termoption enhanced \n");
1867 fprintf(gnufile,
"set nokey\n");
1868 fprintf(gnufile,
"set tmargin 2\n");
1869 fprintf(gnufile,
"set bmargin 5\n");
1870 fprintf(gnufile,
"set lmargin 13\n");
1871 fprintf(gnufile,
"set rmargin 3\n");
1872 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
1873 fprintf(gnufile,
"set yrange [ %g : %g ]\n",plot_ymin,plot_ymax);
1874 fprintf(gnufile,
"set title \"%s\"\n",plot_title);
1875 fprintf(gnufile,
"set xlabel '%s'\n",x_colname);
1876 fprintf(gnufile,
"set ylabel '%s'\n",y_colname);
1877 fprintf(gnufile,
"set parametric\n");
1880 for(run=0;run<len-1;run++)
1882 if (cpl_table_get_int(spec,
"class",run,NULL) == 2)
1884 plot_dist_min_local=cpl_table_get_double(spec,
"flux",run,NULL)
1886 line=cpl_table_get_double(spec,
"lambda",run,NULL);
1887 fprintf(gnufile,
"line%i=%g\n",line_run,line);
1888 fprintf(gnufile,
"set arrow from %g,%g to %g,%g nohead "
1889 "lw 0.5 lc -1\n",line,plot_dist_min_local,
1890 line,plot_dist_max);
1891 fprintf(gnufile,
"line%i=%g\n",line_run,line+corrfac);
1892 fprintf(gnufile,
"set label \"{/=4 %2.5g}\" at "
1893 "line%i,%g rotate\n",line,line_run,plot_label);
1896 if (cpl_table_get_int(spec,
"class",run,NULL) == 3)
1898 plot_dist_min_local=cpl_table_get_double(spec,
"flux",run,NULL)
1900 line=cpl_table_get_double(spec,
"lambda",run,NULL);
1901 fprintf(gnufile,
"line%i=%g\n",line_run,line);
1902 fprintf(gnufile,
"set arrow from %g,%g to %g,%g nohead lw 1 "
1903 "lc 3\n",line,plot_dist_min_local,
1904 line,plot_dist_max);
1905 fprintf(gnufile,
"line%i=%g\n",line_run,line+corrfac);
1906 fprintf(gnufile,
"set label \"{/=4 %2.5g}\" at "
1907 "line%i,%g rotate\n",line,line_run,plot_label);
1912 fprintf(gnufile,
"plot '%s/%s' using 1:2 with lines\n",
1915 fprintf(gnufile,
"\n");
1919 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname1);
1920 if (system(system_call)) {};
1923 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname1);
1924 if (remove(tmpfilename)) {};
1928 basedirpar = cpl_parameterlist_find(plottags,
"inst_dir");
1929 outdirpar = cpl_parameterlist_find(plottags,
"output_dir");
1930 filenamepar = cpl_parameterlist_find(plottags,
"output_name");
1932 sprintf(ps_filename,
"%s/%s/%s_with_lines.ps",
1933 cpl_parameter_get_string(basedirpar),
1934 cpl_parameter_get_string(outdirpar),
1935 cpl_parameter_get_string(filenamepar));
1939 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname2);
1940 gnufile = fopen(tmpfilename,
"w");
1941 fprintf(gnufile,
"set term postscript enhanced color\n");
1942 fprintf(gnufile,
"set output \"%s\"\n",ps_filename);
1943 fprintf(gnufile,
"set nokey\n");
1944 fprintf(gnufile,
"set tmargin 2\n");
1945 fprintf(gnufile,
"set bmargin 5\n");
1946 fprintf(gnufile,
"set lmargin 13\n");
1947 fprintf(gnufile,
"set rmargin 3\n");
1948 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
1949 fprintf(gnufile,
"set yrange [ %g : %g ]\n",plot_ymin,plot_ymax);
1950 fprintf(gnufile,
"set title \"%s\"\n",plot_title);
1951 fprintf(gnufile,
"set xlabel '%s'\n",x_colname);
1952 fprintf(gnufile,
"set ylabel '%s'\n",y_colname);
1953 fprintf(gnufile,
"set parametric\n");
1954 for(run=0;run<len-1;run++)
1956 if (cpl_table_get_int(spec,
"class",run,NULL) == 2)
1958 plot_dist_min_local=cpl_table_get_double(spec,
"flux",run,NULL)
1960 line=cpl_table_get_double(spec,
"lambda",run,NULL);
1961 fprintf(gnufile,
"line%i=%g\n",line_run,line);
1962 fprintf(gnufile,
"set arrow from %g,%g to %g,%g nohead lw 0.5"
1963 " lc -1\n",line,plot_dist_min_local,line,
1965 fprintf(gnufile,
"line%i=%g\n",line_run,line-corrfac/2);
1966 fprintf(gnufile,
"set label \"{/=8 %2.5g}\" at "
1967 "line%i,%g rotate\n",line,line_run,plot_label);
1970 if (cpl_table_get_int(spec,
"class",run,NULL) == 3)
1972 plot_dist_min_local=cpl_table_get_double(spec,
"flux",run,NULL)
1974 line=cpl_table_get_double(spec,
"lambda",run,NULL);
1975 fprintf(gnufile,
"line%i=%g\n",line_run,line);
1976 fprintf(gnufile,
"set arrow from %g,%g to %g,%g nohead lw 1 "
1977 "lc 3\n",line,plot_dist_min_local,
1978 line,plot_dist_max);
1979 fprintf(gnufile,
"line%i=%g\n",line_run,line-corrfac/2);
1980 fprintf(gnufile,
"set label \"{/=8 %2.5g}\" at "
1981 "line%i,%g rotate\n",line,line_run,plot_label);
1986 fprintf(gnufile,
"plot '%s/%s' using 1:2 with lines\n",
1989 fprintf(gnufile,
"\n");
1993 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname2);
1994 if (system(system_call)) {};
1997 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname2);
1998 if (remove(tmpfilename)) {};
2001 if ( (strcmp(plot_type,
"X") == 0) || (strcmp(plot_type,
"WX") == 0) ||
2002 (strcmp(plot_type,
"XW") == 0) )
2005 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname3);
2006 gnufile = fopen(tmpfilename,
"w");
2007 fprintf(gnufile,
"set term x11\n");
2008 fprintf(gnufile,
"set termoption enhanced \n");
2009 fprintf(gnufile,
"set nokey\n");
2010 fprintf(gnufile,
"set tmargin 2\n");
2011 fprintf(gnufile,
"set bmargin 5\n");
2012 fprintf(gnufile,
"set lmargin 13\n");
2013 fprintf(gnufile,
"set rmargin 3\n");
2014 fprintf(gnufile,
"set xrange [ %g : %g ]\n",plot_xmin,plot_xmax);
2015 fprintf(gnufile,
"set yrange [ %g : %g ]\n",plot_ymin,plot_ymax);
2016 fprintf(gnufile,
"set title \"%s\"\n",plot_title);
2017 fprintf(gnufile,
"set xlabel '%s'\n",x_colname);
2018 fprintf(gnufile,
"set ylabel '%s'\n",y_colname);
2019 fprintf(gnufile,
"set parametric\n");
2020 for(run=0;run<len-1;run++)
2022 if (cpl_table_get_int(spec,
"class",run,NULL) == 2)
2024 plot_dist_min_local=cpl_table_get_double(spec,
"flux",run,NULL)
2026 line=cpl_table_get_double(spec,
"lambda",run,NULL);
2027 fprintf(gnufile,
"line%i=%g\n",line_run,line);
2028 fprintf(gnufile,
"set arrow from %g,%g to %g,%g nohead lw 0.5 "
2029 "lc -1\n",line,plot_dist_min_local,line,
2031 fprintf(gnufile,
"line%i=%g\n",line_run,line);
2032 fprintf(gnufile,
"set label \"{/=4 %2.5g}\" at "
2033 "line%i,%g rotate\n",line,line_run,plot_label);
2036 if (cpl_table_get_int(spec,
"class",run,NULL) == 3)
2038 plot_dist_min_local=cpl_table_get_double(spec,
"flux",run,NULL)
2040 line=cpl_table_get_double(spec,
"lambda",run,NULL);
2041 fprintf(gnufile,
"line%i=%g\n",line_run,line);
2042 fprintf(gnufile,
"set arrow from %g,%g to %g,%g nohead lw 1 "
2043 "lc 3\n",line,plot_dist_min_local,
2044 line,plot_dist_max);
2045 fprintf(gnufile,
"line%i=%g\n",line_run,line);
2046 fprintf(gnufile,
"set label \"{/=4 %2.5g}\" at "
2047 "line%i,%g rotate\n",line,line_run,plot_label);
2052 fprintf(gnufile,
"plot '%s/%s' using 1:2 with lines\n",
2054 fprintf(gnufile,
"\n");
2058 sprintf(system_call,
"gnuplot -persist %s/%s",tmpdir,gnuname3);
2059 if (system(system_call)) {};
2062 sprintf(tmpfilename,
"%s/%s",tmpdir,gnuname3);
2063 if (remove(tmpfilename)) {};
2068 sprintf(tmpfilename,
"%s/%s",tmpdir,filename);
2069 if (remove(tmpfilename)) {};
2070 if (rmdir(tmpdir)) {};
2072 return CPL_ERROR_NONE;
void sc_basic_initstring(char *str, const long n)
cpl_error_code sc_plot_single_spec_with_lines(const cpl_table *spec, cpl_parameterlist *plottags)
void sc_setplottags_overplot_spec(cpl_parameterlist *plottags, const char *x_column, const char *y_column1, const char *y_column2, const char *specname1, const char *specname2, const char *title, const char *x_label, const char *y_label, const cpl_parameterlist *parlist)
void sc_setplottags_single_spec_lines(cpl_parameterlist *plottags, const char *title, const char *x_label, const char *y_label, const cpl_parameterlist *parlist)
cpl_error_code sc_overplot_spec(const cpl_table *spec, cpl_parameterlist *plottags)
cpl_error_code sc_plot_double_spec(const cpl_table *spec1, const cpl_table *spec2, cpl_parameterlist *plottags)
cpl_error_code sc_plot_single_spec(const cpl_table *spec, cpl_parameterlist *plottags)
void sc_setplottags_double_spec(cpl_parameterlist *plottags, const char *x_column1, const char *y_column1, const char *title1, const char *x_label1, const char *y_label1, const char *x_column2, const char *y_column2, const char *title2, const char *x_label2, const char *y_label2, const cpl_parameterlist *parlist)
void sc_setplottags_hist(cpl_parameterlist *plottags, const char *title, const char *x_label, const char *y_label, const cpl_parameterlist *parlist)
cpl_error_code sc_plot_hist(const cpl_table *histdat, cpl_parameterlist *plottags)
void sc_setplottags_single_spec(cpl_parameterlist *plottags, const char *x_column, const char *y_column, const char *title, const char *x_label, const char *y_label, const cpl_parameterlist *parlist)
Header for plotting library.