/* ** outputLogo() - print out your logo */ void outputLogo(FILE *fo, Image the_image) { float xpos, ypos; /* KE: Was missing first argument */ printPS(fo,my_logo); /* print out the logo */ /* * set up the scaling factors */ fprintf(fo,"\nmatrix currentmatrix\n"); fprintf(fo,"newpath\n"); fprintf(fo,"0 0 moveto\n"); if(the_image.orientation == PORTRAIT) { xpos = 0; ypos = - LOGOHEIGHT; fprintf(fo,"%f inch %f inch translate\n", xpos,ypos); } else { xpos = the_image.height + (float)LOGOHEIGHT; ypos = 0; fprintf(fo,"%f inch %f inch translate\n", xpos,ypos); fprintf(fo,"90 rotate\n"); } /* * output the company name */ fprintf(fo,"/xlinepos 0 def\n"); fprintf(fo,"/ylinepos 0 def\n"); fprintf(fo,"/charheight .11 inch def\n"); fprintf(fo,"/logoheight %f inch def\n",LOGOHEIGHT); fprintf(fo,"/xlogopos xlinepos def\n"); fprintf(fo,"/ylogopos ylinepos logoheight 0.2 mul add def\n"); fprintf(fo,"/logosize logoheight 0.6 mul def\n"); fprintf(fo,"/xtextpos xlinepos logosize 2 charheight mul add add def\n"); fprintf(fo,"/ytextpos ylogopos charheight add def\n"); fprintf(fo,"/nextline {\n /ytextpos ytextpos charheight sub store\n"); fprintf(fo," xtextpos ytextpos moveto\n} def\n"); fprintf(fo,"/Helvetica-BoldOblique findfont\n"); fprintf(fo,"8 scalefont\n"); fprintf(fo,"setfont \n"); fprintf(fo,"xlogopos ylogopos logosize 1 0 %s \n", LOGONAME); fprintf(fo,"xtextpos ytextpos moveto %% locate lower left corner of image\n"); fprintf(fo,"(%s) show\n", COMPANYNAME1); fprintf(fo,"nextline\n"); fprintf(fo,"xtextpos ytextpos moveto\n"); fprintf(fo,"(%s) show\n", COMPANYNAME2); fprintf(fo,"1 0 0 setrgbcolor %% draw laser line\n"); fprintf(fo,"newpath\n"); fprintf(fo,"xlogopos ylinepos moveto\n"); fprintf(fo,"1.2 inch 0 rlineto\n"); fprintf(fo,"stroke\n"); fprintf(fo,"setmatrix\n\n"); }
/* ** outputColorImage() - output the code to support color ** image printing on monochrome devices */ void outputColorImage(FILE *fo) { printPS(fo, ColorImage); }
void GPViewPageNode::finalize() { int ii; const char *separator = "#------------------------------------------------\n"; const char *new_section = "\n\n"; string page_title; string page_legend; string page_fg_color; string page_bg_color; string page_font; /* X11 font naming convention */ char gp_template_file_name[512]; char outFileName[512]; string tmp_string; stringstream tmp_stream; stringstream cmd; string extension; string::size_type idx; int xx_geom = 850; //default gnuplot window width int yy_geom = 657; //default gnuplot window height int max_num_curves = 0; /*! * Gnuplot knows a limited number of color names. * To see the list of known color names, run... * % gnuplot -e 'show palette colornames' */ string plotColors[]= { "black", "red", "blue", "green", "magenta", "yellow", "cyan", "pink", "dark-green", "light-blue", "purple", "orange", "brown" }; int n_CustomColors = sizeof(plotColors)/sizeof(plotColors[0]); /**! * WARNING: getAttribute() returns a const char *, which may be null. * Assigning a null pointer to a string will crash the plot. * So, check the return value before making the assignment. */ page_title = (page->getTitle()) ? page->getTitle() : "Page"; page_legend = (page->getAttribute("legend")) ? page->getAttribute("legend") : ""; page_bg_color = (page->getAttribute("background_color")) ? page->getAttribute("background_color") : ""; page_fg_color = (page->getAttribute("foreground_color")) ? page->getAttribute("foreground_color") : ""; page_font = (page->getAttribute("font")) ? page->getAttribute("font") : ""; //! Nomultiplot command textbuf.print("\n"); textbuf.print("%s", new_section); textbuf.print("%s", separator); textbuf.print("# For some terminals, plots are not displayed\n"); textbuf.print("# until the command `unset multiplot` is given.\n"); textbuf.print("# Return to single plot mode to switch device\n"); textbuf.print("%s", separator); textbuf.print("unset multiplot\n"); //! Get Gnuplot Terminal setting terminalType_txt = (page->getAttribute("gnuplot_terminal")) ? page->getAttribute("gnuplot_terminal") : ""; if ( strcasecmp(terminalType_txt.c_str(), "X11") == 0 ) { terminalType = GPViewPageNode::X11; terminalType_txt = "x11"; } else if ( strcasecmp(terminalType_txt.c_str(), "PS") == 0 ) { terminalType = GPViewPageNode::PS; terminalType_txt = "postscript"; extension = ".ps"; } else if ( strcasecmp(terminalType_txt.c_str(), "PS_COLOR") == 0 ) { terminalType = GPViewPageNode::PS_COLOR; terminalType_txt = "postscript"; extension = ".ps"; } else if ( strcasecmp(terminalType_txt.c_str(), "PNG") == 0 ) { terminalType = GPViewPageNode::PNG; terminalType_txt = "png"; extension = ".png"; } else if ( strcasecmp(terminalType_txt.c_str(), "EPS") == 0 ) { terminalType = GPViewPageNode::EPS; terminalType_txt = "eps"; extension = ".eps"; } else if ( strcasecmp(terminalType_txt.c_str(), "AQUA") == 0 ) { terminalType = GPViewPageNode::AQUA; terminalType_txt = "x11"; } else { cerr << "ERROR: Bad terminal-type spec: \"" << tmp_string << "\"" << endl; cerr << "Defaulting terminal-type to \"x11.\"" << endl; terminalType = GPViewPageNode::X11 ; terminalType_txt = "x11"; } //! Get Destination setting device_txt = (page->getAttribute("device")) ? page->getAttribute("device") : ""; if ( strcasecmp(device_txt.c_str(), "TERMINAL") == 0 ) { device = GPViewPageNode::TERMINAL; } else if ( strncasecmp(device_txt.c_str(), "FILE", 4) == 0 ) { device = GPViewPageNode::DISK ; //! copy from first space character to end of string diskFileName = device_txt.substr( device_txt.find(" ") ); //! output may not redirect to file format with some terminal types switch ( terminalType ) { case GPViewPageNode::X11: case GPViewPageNode::AQUA: //! Force to a different format before going to file. terminalType_txt = "postscript"; extension = ".ps"; break; default: break; } } else if ( strcasecmp(device_txt.c_str(), "PRINTER") == 0 ) { device = GPViewPageNode::PRINTER; terminalType_txt = "postscript"; } else { cerr << "ERROR: Bad device spec: \"" << device_txt << "\"" << endl; cerr << "Defaulting device to \"Terminal.\"" << endl; device = GPViewPageNode::TERMINAL; } // ================================================== // POPULATE THE TEMPLATE // ================================================== tmp_stream.str(""); tmp_stream << GnuplotVersion() ; textbuf.subst_g("<GNUPLOT_VERSION>", tmp_stream.str().c_str() ); textbuf.subst_g("<PAGE_TITLE>", page_title.c_str()); textbuf.subst_g("<TERM_TYPE>", terminalType_txt.c_str()); if ( (plot_node_list.size()%5 == 2 || plot_node_list.size()%5 == 3) && plot_node_list.size() > 2 ) { xx_geom = 600; yy_geom = 720; } tmp_stream.str(""); tmp_stream << "size " << xx_geom << "," << yy_geom ; textbuf.subst_g("<CANVAS_SIZE>", tmp_stream.str().c_str() ); if ( strcasecmp(terminalType_txt.c_str(), "x11") == 0 ) { if ( GnuplotVersion() >= 4.0 ) { textbuf.subst_g("<TERM_OPTIONS>", "persist"); } } else { textbuf.subst_g("<TERM_OPTIONS>", ""); } //! Enable/Disable Grid textbuf.subst_g("<PAGE_GRID_SPEC>", "set grid"); if ( GnuplotVersion() >= 4.2 && ! page_fg_color.empty() && color_is_valid(&page_fg_color) ) { tmp_stream.str(""); tmp_stream << "linecolor rgb \"" << page_fg_color << "\"" ; //! Also change border color to match grid color tmp_stream << "\nset border linecolor rgb \"" << page_fg_color << "\"" ; textbuf.subst_g( "<PAGE_GRID_COLOR_SPEC>", tmp_stream.str().c_str() ); } else { textbuf.subst_g( "<PAGE_GRID_COLOR_SPEC>", "" ); } //! plotting style for Data plots textbuf.subst_g("<STYLE_DATA_SPEC>", "lines"); //! plotting style for Function plots textbuf.subst_g("<STYLE_FUNC_SPEC>", "lines"); textbuf.subst_g("<PAGE_X_AXIS_SCALING_SPEC>", "unset logscale x\n"); textbuf.subst_g("<PAGE_Y_AXIS_FORMAT_SPEC>", "set format y\n"); textbuf.subst_g("<PAGE_Y_AXIS_SCALING_SPEC>", "unset logscale y\n"); textbuf.subst_g("<PAGE_FOREGROUND_SPEC>", ""); textbuf.subst_g("<PAGE_BACKGROUND_SPEC>", ""); //! Enable/Disable key (legend). if ( page_legend.compare("No") == 0 ) { if ( GnuplotVersion() >= 4.0 ) { textbuf.subst_g("<PAGE_KEY_SPEC>", "set key off\n"); } else { textbuf.subst_g("<PAGE_KEY_SPEC>", "set nokey\n"); } } else { string vert_spacing_ = ""; if ( GnuplotVersion() < 4.2 ) { vert_spacing_ = " spacing 0.5"; } tmp_stream.str(""); tmp_stream << "set key below Left reverse" << vert_spacing_ << "\n" ; textbuf.subst_g( "<PAGE_KEY_SPEC>", tmp_stream.str().c_str() ); /* Increase window size so key doesn't cause graph to shrink */ for (ii = 0; ii < (int)plot_node_list.size(); ii++) { if ((int)plot_node_list[ii]->curve_node_list.size() > max_num_curves) { max_num_curves = plot_node_list[ii]->curve_node_list.size(); } } yy_geom += max_num_curves*10; // stretch 10 pixels per Y-var label } //! Set Font if ( ! page_font.empty() ) { tmp_stream.str(""); //! insert a backslash(\), newline & indent 4 spaces tmp_stream << "\\\n font \"" << page_font << "\"" ; textbuf.subst_g( "<PAGE_FONT_SPEC>", tmp_stream.str().c_str() ); } else { textbuf.subst_g("<PAGE_FONT_SPEC>", "\\\n font <DEFAULT_FONT>"); } textbuf.subst_g("<LINE_TYPE_1>", "-1 #black"); textbuf.subst_g("<LINE_TYPE_2>", " 1 #red"); textbuf.subst_g("<LINE_TYPE_3>", " 3 #blue"); textbuf.subst_g("<LINE_TYPE_4>", " 2 #green"); textbuf.subst_g("<LINE_TYPE_5>", " 0 #magenta"); textbuf.subst_g("<LINE_TYPE_6>", " 7 #yellow"); textbuf.subst_g("<LINE_TYPE_7>", " 5 #cyan"); textbuf.subst_g("<LINE_TYPE_8>", " 0 #pink"); textbuf.subst_g("<LINE_TYPE_9>", " 0 #dark-green"); textbuf.subst_g("<LINE_TYPE_10>", " 0 #light-blue"); textbuf.subst_g("<LINE_TYPE_11>", " 4 #purple"); textbuf.subst_g("<LINE_TYPE_12>", " 8 #orange"); textbuf.subst_g("<LINE_TYPE_13>", " 6 #brown"); textbuf.subst_g("<POINT_SHAPE_1>", " 1 #plus"); textbuf.subst_g("<POINT_SHAPE_2>", " 2 #cross"); textbuf.subst_g("<POINT_SHAPE_3>", " 3 #astrisk"); textbuf.subst_g("<POINT_SHAPE_4>", " 4 #open_square"); textbuf.subst_g("<POINT_SHAPE_5>", " 5 #filled_square"); textbuf.subst_g("<POINT_SHAPE_6>", " 6 #open_circle"); textbuf.subst_g("<POINT_SHAPE_7>", " 7 #filled_circle"); textbuf.subst_g("<POINT_SHAPE_8>", " 8 #open_triangle"); textbuf.subst_g("<POINT_SHAPE_9>", " 9 #filled_triangle"); textbuf.subst_g("<POINT_SHAPE_10>", "10 #open_inverse-triangle"); textbuf.subst_g("<POINT_SHAPE_11>", "11 #filled_inverse-triangle"); textbuf.subst_g("<POINT_SHAPE_12>", "12 #open_diamond"); textbuf.subst_g("<POINT_SHAPE_13>", "13 #filled_diamond"); textbuf.subst_g("<LINE_SPEC_1>", "lw 1.0 pt point_shape_1 ps Small"); textbuf.subst_g("<LINE_SPEC_2>", "lw 1.0 pt point_shape_2 ps Small"); textbuf.subst_g("<LINE_SPEC_3>", "lw 1.0 pt point_shape_3 ps Small"); textbuf.subst_g("<LINE_SPEC_4>", "lw 1.0 pt point_shape_4 ps Small"); textbuf.subst_g("<LINE_SPEC_5>", "lw 1.0 pt point_shape_5 ps Small"); textbuf.subst_g("<LINE_SPEC_6>", "lw 1.0 pt point_shape_6 ps Small"); textbuf.subst_g("<LINE_SPEC_7>", "lw 1.0 pt point_shape_7 ps Small"); textbuf.subst_g("<LINE_SPEC_8>", "lw 1.0 pt point_shape_8 ps Small"); textbuf.subst_g("<LINE_SPEC_9>", "lw 1.0 pt point_shape_9 ps Small"); textbuf.subst_g("<LINE_SPEC_10>","lw 1.0 pt point_shape_10 ps Small"); textbuf.subst_g("<LINE_SPEC_11>","lw 1.0 pt point_shape_11 ps Small"); textbuf.subst_g("<LINE_SPEC_12>","lw 1.0 pt point_shape_12 ps Small"); textbuf.subst_g("<LINE_SPEC_13>","lw 1.0 pt point_shape_13 ps Small"); if ( GnuplotVersion() >= 4.2 ) { for (ii = 0; ii < n_CustomColors; ii++) { //! build template (e.g. "<LINE_COLOR_1>") tmp_stream.str(""); tmp_stream << "<LINE_COLOR_" << ii+1 << ">" ; tmp_string = tmp_stream.str(); //! build string (e.g. "linecolor rgb \"black\"") tmp_stream.str(""); tmp_stream << "linecolor rgb \"" << plotColors[ii] << "\"" ; //! Replace template with string textbuf.subst_g( tmp_string.c_str(), tmp_stream.str().c_str() ); } } else { /*! * Change gnuplot's default line colors (1=red 2=green 3=blue * 4=magenta 5=cyan 6=sienna 7=orange 8=coral) for plot. * Note: This is only used when co-plotting multiple RUN_ dirs. */ for (ii = 0; ii < n_CustomColors; ii++) { tmp_stream.str(""); tmp_stream << "<LINE_COLOR_" << ii+1 << ">" ; //! Clear template; use new line#Color definitions from "-xrm" options textbuf.subst_g( tmp_stream.str().c_str(), "" ); } } tmp_stream.str(""); if ( GnuplotVersion() < 4.2 || page_fg_color.empty() || !page_fg_color.empty() ) { tmp_stream << "#" ; /* comment out the textcolor command */ } tmp_stream << "textcolor rgb \"" << page_fg_color << "\"" ; textbuf.subst_g("<PAGE_TEXT_COLOR_SPEC>", tmp_stream.str().c_str()); textbuf.subst_g("<LABEL_1_TAG>", "1"); textbuf.subst_g("<LABEL_1_NAME>", page_title.c_str()); textbuf.subst_g("<LABEL_1_XPOS>", "0.51"); textbuf.subst_g("<LABEL_1_YPOS>", "0.97"); textbuf.subst_g("<LABEL_1_JUST>", "center"); textbuf.subst_g("<LABEL_1_FONT>", "\"Helvetica,14\""); textbuf.subst_g("<LABEL_2_TAG>", "2"); textbuf.subst_g("<LABEL_2_NAME>", ""); textbuf.subst_g("<LABEL_2_XPOS>", "0.51"); textbuf.subst_g("<LABEL_2_YPOS>", "0.95"); textbuf.subst_g("<LABEL_2_JUST>", "center"); textbuf.subst_g("<LABEL_2_FONT>", "\"Helvetica,10\""); textbuf.subst_g("<LABEL_3_TAG>", "3"); textbuf.subst_g("<LABEL_3_NAME>", "`whoami`"); textbuf.subst_g("<LABEL_3_XPOS>", "0.99"); textbuf.subst_g("<LABEL_3_YPOS>", "0.99"); textbuf.subst_g("<LABEL_3_JUST>", "right"); textbuf.subst_g("<LABEL_3_FONT>", "\"Helvetica,8\""); textbuf.subst_g("<LABEL_4_TAG>", "4"); textbuf.subst_g("<LABEL_4_NAME>", "`date +%m/%d/%Y`"); textbuf.subst_g("<LABEL_4_XPOS>", "0.99"); textbuf.subst_g("<LABEL_4_YPOS>", "0.957"); textbuf.subst_g("<LABEL_4_JUST>", "right"); textbuf.subst_g("<LABEL_4_FONT>", "\"Helvetica,8\""); textbuf.subst_g("<PLOT_TITLE_XPOS>", "0.0"); textbuf.subst_g("<PLOT_TITLE_YPOS>", "0.2"); textbuf.subst_g("<X_AXIS_LABEL_XPOS_DECL>", "0.0"); textbuf.subst_g("<X_AXIS_LABEL_YPOS_DECL>", "0.6"); if ( GnuplotVersion() < 4.2 ) { textbuf.subst_g("<Y_AXIS_LABEL_XPOS_DECL>", "0.6"); } else { textbuf.subst_g("<Y_AXIS_LABEL_XPOS_DECL>", "1.4"); } textbuf.subst_g("<Y_AXIS_LABEL_YPOS_DECL>", "0.0"); textbuf.subst_g("<DEFAULT_FONT>", "\"Helvetica,12\""); layout_page ( this ); //! Figure out where we can create a temporary file. if (!access("/tmp", W_OK)) { strncpy(gp_template_file_name, "/tmp/dpx_gp_page_XXXXXX", sizeof(gp_template_file_name)); } else if (!access("/var/tmp", W_OK)) { strncpy(gp_template_file_name, "/var/tmp/dpx_gp_page_XXXXXX", sizeof(gp_template_file_name)); } else { post_dialog( toplevel, XmDIALOG_ERROR, "Unable to access /tmp or /var/tmp, where a temporary\n" "file (that represents gnuplot commands) needs\n" "to be created. Please check your permissions.\n"); return; } //! Create a name for our temporary gnuplot command file. if (mkstemp( gp_template_file_name) < 0) { post_dialog( toplevel, XmDIALOG_ERROR, "Unable to generate a temporary file" "name for some mind boggling reason." ); return; } if ( save_tmp_files ) { cout << "Keeping data associated with this gnuplot file : " << gp_template_file_name << endl; //! Comment out all commands that delete temp data files textbuf.subst_g("<SAVE_TMP_FILE_SPEC>", "#"); } else { //! Allow all temp data files to be deleted textbuf.subst_g("<SAVE_TMP_FILE_SPEC>", ""); } //! If user would like to see this template, print it to stdout //if (args.generate_template) { // cout << textbuf.getText() << endl; //} /*! * SAVE buffer TO FILE with given filename. * Note: must save to file prior to sending to PRINTER device. */ textbuf.writeFile( (const char*)gp_template_file_name ); cmd << "gnuplot"; if ( ! page_fg_color.empty() && color_is_valid(&page_fg_color) ) { cmd << " -xrm 'gnuplot*textColor:" << page_fg_color << "'" ; cmd << " -xrm 'gnuplot*borderColor:" << page_fg_color << "'" ; cmd << " -xrm 'gnuplot*axisColor:" << page_fg_color << "'" ; } if ( ! page_bg_color.empty() && color_is_valid(&page_bg_color) ) { cmd << " -xrm 'gnuplot*background:" << page_bg_color << "'" ; } /*! * Set X11 line colors. * Line colors are global per page in gnuplot. * And there are at max 8 default colors. (%man gnuplot) */ for (ii = 0; ii < n_CustomColors; ii++) { cmd << " -xrm 'gnuplot*line" << ii+1 << "Color:" << plotColors[ii] << "'" ; } if ( device > GPViewPageNode::NOT_SET ) { cerr << "ERROR: GPViewPageNode::finalize() called with invalid device.\n" << "Example devices are TERMINAL, DISK and PRINTER.\n" << "It is an enumerated type in the GPViewPageNode class.\n" ; exit(-1); } switch ( device ) { case GPViewPageNode::DISK: if ( diskFileName.empty() ) { cerr << "ERROR: GPViewPageNode::finalize() called without " << "setting output file. When you are sending data " << "to disk, you must set output file name." << endl ; exit(-1); } //! Remove any quotes from string while ( 1 ) { idx = diskFileName.find('"'); if ( idx != string::npos ) { diskFileName.erase(idx,1); } else { break ; } } /*! * The weird rfind(), substr() and erase() are used * to make sure that if the outfile name already * has an extension that we don't duplicate it */ idx = diskFileName.rfind('.'); if ( idx != string::npos ) { if (diskFileName.substr(idx) == extension) { diskFileName.erase(idx); } } tmp_stream.str(""); tmp_stream << instance_count ; diskFileName.append( tmp_stream.str() ); diskFileName.append( extension ); //! Complete command by generating an output file from the gnuplot file. cmd << " " << gp_template_file_name << " >& " << diskFileName; cout << "Generating " << diskFileName << "..." << endl; cout.flush(); if ( system(cmd.str().c_str()) > -1 ) { cout << "Done." << endl; } //! Run postscript file through a filter if ( terminalType == PS ) { filterPostScriptBW( diskFileName.c_str() ); } else if ( terminalType == PS_COLOR || terminalType == EPS) { filterPostScriptColor( diskFileName.c_str(), this ); } break; case GPViewPageNode::PRINTER: //! Figure out where we can create a temporary file. if (!access("/tmp", W_OK)) { strncpy(outFileName, "/tmp/dpx_gxplot_XXXXXX", sizeof(outFileName)); } else if (!access("/var/tmp", W_OK)) { strncpy(outFileName, "/var/tmp/dpx_gxplot_XXXXXX", sizeof(outFileName)); } else { post_dialog( toplevel, XmDIALOG_ERROR, "Unable to access /tmp or /var/tmp, where a temporary\n" "file for printing needs to be created.\n" "Please check your permissions.\n"); return; } //! Create a name for our temporary gnuplot command file. if (mkstemp(outFileName) < 0) { post_dialog( toplevel, XmDIALOG_ERROR, "Unable to generate a temporary file" "name for some mind boggling reason." ); return; } //! Complete command by generating an output file from the gnuplot file. cmd << " " << gp_template_file_name << " >& " << outFileName; cout << "Generating output file : " << outFileName << "..." << endl; if ( system(cmd.str().c_str()) > -1 ) { cout << "Done." << endl; } //! Run postscript file through a filter filterPostScriptBW(outFileName); //! Print the file if ( printPS((const char*)outFileName) > -1 ) { cout << "Complete." << endl; cout.flush(); } if ( !save_tmp_files ) { //! Clean up output file. tmp_stream.str(""); tmp_stream << "rm -f " << outFileName ; tmp_stream << "; rm -f " << gp_template_file_name; system( tmp_stream.str().c_str() ); } break; case GPViewPageNode::NOT_SET: break; case GPViewPageNode::TERMINAL: default: cmd << " -persist"; cmd << " -geometry " << xx_geom << "x" << yy_geom ; //e.g. 850x657 //! Complete the command by providing the gnuplot file name. cmd << " " << gp_template_file_name ; if ( !save_tmp_files ) { /*! * After the plot is drawn, add another command to delete * the temporary gnuplot file: '/tmp/dpx_gp_page_******'. */ cmd << "; rm -f " << gp_template_file_name; } /*! * Run the system command to create the plot. * Example: * % "gnuplot -persist -geometry 850x657 \ * -xrm 'gnuplot*textColor:black' /tmp/dpx_gp_page_******" */ system( cmd.str().c_str() ); break; } }