[85] | 1 | ;+ |
---|
| 2 | ; NAME: |
---|
| 3 | ; PS_START/PS_END |
---|
| 4 | ; |
---|
| 5 | ; PURPOSE: |
---|
| 6 | ; |
---|
| 7 | ; The purpose of PS_START and PS_END is to make it easy to set-up |
---|
| 8 | ; for and close a PostScript file. The programs work in close conjunction |
---|
| 9 | ; with PSCONFIG, another program from the Coyote Library. |
---|
| 10 | ; |
---|
| 11 | ; If ImageMagick (http://www.imagemagick.org/script/index.php) is installed |
---|
| 12 | ; on your computer, you can easily convert PostScript output to JPEG, PNG, and TIFF |
---|
| 13 | ; image output. (See the keywords to PS_END.) |
---|
| 14 | ; |
---|
| 15 | ; AUTHOR: |
---|
| 16 | ; |
---|
| 17 | ; FANNING SOFTWARE CONSULTING |
---|
| 18 | ; David Fanning, Ph.D. |
---|
| 19 | ; 1645 Sheely Drive |
---|
| 20 | ; Fort Collins, CO 80526 USA |
---|
| 21 | ; Phone: 970-221-0438 |
---|
| 22 | ; E-mail: davidf@dfanning.com |
---|
| 23 | ; Coyote's Guide to IDL Programming: http://www.dfanning.com/ |
---|
| 24 | ; |
---|
| 25 | ; CATEGORY: |
---|
| 26 | ; |
---|
| 27 | ; Graphics, File Output, PostScript |
---|
| 28 | ; |
---|
| 29 | ; CALLING SEQUENCE: |
---|
| 30 | ; |
---|
| 31 | ; PS_START |
---|
| 32 | ; Various graphics commands here... |
---|
| 33 | ; PS_END |
---|
| 34 | ; |
---|
| 35 | ; KEYWORD PARAMETERS FOR PS_START: |
---|
| 36 | ; |
---|
| 37 | ; GUI: The default behavior is to use PSCONFIG to configure the |
---|
| 38 | ; PostScript device silently. If you wish to allow the user |
---|
| 39 | ; to interatively configure the PostScript device, set this |
---|
| 40 | ; keyword. |
---|
| 41 | ; |
---|
| 42 | ; SCALE_FACTOR: Set this to the PostScript scale factor. By default: 1. |
---|
| 43 | ; |
---|
| 44 | ; Any keyword supported by PSCONFIG can be used to configure the PostScript device. |
---|
| 45 | ; Common keywords would include FILENAME, XSIZE, YSIZE, XOFFSET, YOFFSET, etc. See |
---|
| 46 | ; the PSCONFIG documentation for details. |
---|
| 47 | ; |
---|
| 48 | ; KEYWORD PARAMETERS FOR PS_END: |
---|
| 49 | ; |
---|
| 50 | ; All keywords for PS_END require that ImageMagick is installed on your computer |
---|
| 51 | ; and is configured correctly. Image conversion is done by spawning a "convert" |
---|
| 52 | ; command to ImageMagick. |
---|
| 53 | ; |
---|
| 54 | ; JPEG: Set this keyword to convert the PostScript output file to a JPEG image. |
---|
| 55 | ; PNG: Set this keyword to convert the PostScript output file to a PNG image. |
---|
| 56 | ; TIFF: Set this keyword to convert the PostScript output file to a TIFF image. |
---|
| 57 | ; |
---|
| 58 | ; COMMON BLOCKS: |
---|
| 59 | ; |
---|
| 60 | ; _$FSC_PS_START_ Contains the PS_STRUCT structure for communication between |
---|
| 61 | ; PS_START and PS_END. |
---|
| 62 | ; |
---|
| 63 | ; SIDE EFFECTS: |
---|
| 64 | ; |
---|
| 65 | ; When PS_START is called, the current graphics device is set to "PS" (the PostScript |
---|
| 66 | ; device). When PS_END is called the current graphics device is returned to the device |
---|
| 67 | ; in effect when PS_START was called. |
---|
| 68 | ; |
---|
| 69 | ; RESTRICTIONS: |
---|
| 70 | ; |
---|
| 71 | ; Requires numerous programs from the Coyote Library. To convert PostScript files |
---|
| 72 | ; to PNG, JPEG, and TIFF files requires ImageMagick be installed on your |
---|
| 73 | ; computer and configured correctly. You can download Coyote Library programs here: |
---|
| 74 | ; |
---|
| 75 | ; http://www.dfanning.com/programs/coyoteprograms.zip |
---|
| 76 | ; |
---|
| 77 | ; ImageMagick can be found here: |
---|
| 78 | ; |
---|
| 79 | ; http://www.imagemagick.org/script/index.php |
---|
| 80 | ; |
---|
| 81 | ; EXAMPLE: |
---|
| 82 | ; |
---|
| 83 | ; To create a line plot in a PostScript file named lineplot.ps and |
---|
| 84 | ; also create a PNG file named lineplot.png for display in a browser, |
---|
| 85 | ; type these commands. |
---|
| 86 | ; |
---|
| 87 | ; PS_Start, FILENAME='lineplot.ps' |
---|
| 88 | ; Plot, Findgen(11), COLOR=FSC_Color('navy'), /NODATA, XTITLE='Time', YTITLE='Signal' |
---|
| 89 | ; OPlot, Findgen(11), COLOR=FSC_Color('indian red') |
---|
| 90 | ; OPlot, Findgen(11), COLOR=FSC_Color('olive'), PSYM=2 |
---|
| 91 | ; PS_End, /PNG |
---|
| 92 | ; |
---|
| 93 | ; NOTES: |
---|
| 94 | ; |
---|
| 95 | ; You can easily configure any modifications you like for your PostScript output |
---|
| 96 | ; by setting fields in the plot and axis system variables (!P, !X, !Y, and !Z). |
---|
| 97 | ; The modifications currently made by default in this program are these: |
---|
| 98 | ; |
---|
| 99 | ; !P.Charsize = 1.5 |
---|
| 100 | ; !P.Thick = 2 |
---|
| 101 | ; !X.Thick = 2 |
---|
| 102 | ; !Y.Thick = 2 |
---|
| 103 | ; !Z.Thick = 2 |
---|
| 104 | ; !P.Symsize = 1.25 |
---|
| 105 | ; !P.Font = 1 |
---|
| 106 | ; |
---|
| 107 | ; MODIFICATION HISTORY: |
---|
| 108 | ; |
---|
| 109 | ; Written by: David W. Fanning, 20 May 2008. |
---|
| 110 | ;- |
---|
| 111 | ; |
---|
| 112 | ;########################################################################### |
---|
| 113 | ; |
---|
| 114 | ; LICENSE |
---|
| 115 | ; |
---|
| 116 | ; This software is OSI Certified Open Source Software. |
---|
| 117 | ; OSI Certified is a certification mark of the Open Source Initiative. |
---|
| 118 | ; |
---|
| 119 | ; Copyright 2008 Fanning Software Consulting. |
---|
| 120 | ; |
---|
| 121 | ; This software is provided "as-is", without any express or |
---|
| 122 | ; implied warranty. In no event will the authors be held liable |
---|
| 123 | ; for any damages arising from the use of this software. |
---|
| 124 | ; |
---|
| 125 | ; Permission is granted to anyone to use this software for any |
---|
| 126 | ; purpose, including commercial applications, and to alter it and |
---|
| 127 | ; redistribute it freely, subject to the following restrictions: |
---|
| 128 | ; |
---|
| 129 | ; 1. The origin of this software must not be misrepresented; you must |
---|
| 130 | ; not claim you wrote the original software. If you use this software |
---|
| 131 | ; in a product, an acknowledgment in the product documentation |
---|
| 132 | ; would be appreciated, but is not required. |
---|
| 133 | ; |
---|
| 134 | ; 2. Altered source versions must be plainly marked as such, and must |
---|
| 135 | ; not be misrepresented as being the original software. |
---|
| 136 | ; |
---|
| 137 | ; 3. This notice may not be removed or altered from any source distribution. |
---|
| 138 | ; |
---|
| 139 | ; For more information on Open Source Software, visit the Open Source |
---|
| 140 | ; web site: http://www.opensource.org. |
---|
| 141 | ; |
---|
| 142 | ;########################################################################### |
---|
| 143 | PRO FSC_PS_SETUP__DEFINE |
---|
| 144 | |
---|
| 145 | struct = { FSC_PS_SETUP, $ |
---|
| 146 | currentDevice: "", $ |
---|
| 147 | setup: 0, $ |
---|
| 148 | convert: "", $ |
---|
| 149 | filename: "", $ |
---|
| 150 | p: !P, $ |
---|
| 151 | x: !X, $ |
---|
| 152 | y: !Y, $ |
---|
| 153 | z: !Z $ |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | END ;--------------------------------------------------------------- |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | PRO PS_END, JPEG=jpeg, PNG=png, TIFF=tiff |
---|
| 161 | |
---|
| 162 | COMMON _$FSC_PS_START_, ps_struct |
---|
| 163 | |
---|
| 164 | ON_ERROR, 2 ; Return to caller. |
---|
| 165 | |
---|
| 166 | ; Close the PostScript file, if this is PostScript device. |
---|
| 167 | IF !D.Name EQ 'PS' THEN Device, /CLOSE_FILE |
---|
| 168 | |
---|
| 169 | ; Need to convert with ImageMagick? |
---|
| 170 | IF Keyword_Set(png) THEN ps_struct.convert = 'PNG' |
---|
| 171 | IF Keyword_Set(jpeg) THEN ps_struct.convert = 'JPEG' |
---|
| 172 | IF Keyword_Set(tiff) THEN ps_struct.convert = 'TIFF' |
---|
| 173 | IF ps_struct.convert NE "" THEN BEGIN |
---|
| 174 | |
---|
| 175 | basename = FSC_Base_Filename(ps_struct.filename, DIRECTORY=theDir, EXTENSION=theExtension) |
---|
| 176 | CASE 1 OF |
---|
| 177 | ps_struct.convert EQ 'PNG': outfilename = Filepath(ROOT_DIR=theDir, basename + '.png') |
---|
| 178 | ps_struct.convert EQ 'JPEG': outfilename = Filepath(ROOT_DIR=theDir, basename + '.jpg') |
---|
| 179 | ps_struct.convert EQ 'TIFF': outfilename = Filepath(ROOT_DIR=theDir, basename + '.tif') |
---|
| 180 | ENDCASE |
---|
| 181 | IF N_Elements(outfilename) NE "" THEN BEGIN |
---|
| 182 | ; cmd = 'convert -density 300 ' + ps_struct.filename + ' -resize 25% ' + outfilename |
---|
| 183 | cmd = 'convert -density 300 +antialias ' + ps_struct.filename + ' -resize 50% ' + outfilename |
---|
| 184 | cmd = cmd + ' ; convert '+ ps_struct.filename + ' ' + Filepath(ROOT_DIR=theDir, basename + '.eps') |
---|
| 185 | SPAWN, cmd |
---|
| 186 | ENDIF |
---|
| 187 | |
---|
| 188 | ENDIF |
---|
| 189 | |
---|
| 190 | ; Clean up. |
---|
| 191 | Set_Plot, ps_struct.currentDevice |
---|
| 192 | !P = ps_struct.p |
---|
| 193 | !X = ps_struct.x |
---|
| 194 | !Y = ps_struct.y |
---|
| 195 | !Z = ps_struct.z |
---|
| 196 | ps_struct.setup = 0 |
---|
| 197 | ps_struct.currentDevice = "" |
---|
| 198 | ps_struct.filename = "" |
---|
| 199 | ps_struct.convert = "" |
---|
| 200 | |
---|
| 201 | END ;--------------------------------------------------------------- |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | PRO PS_START, SCALE_FACTOR=scale_factor, GUI=gui, _EXTRA=extra |
---|
| 206 | |
---|
| 207 | COMMON _$FSC_PS_START_, ps_struct |
---|
| 208 | |
---|
| 209 | ; Define the PS structure. |
---|
| 210 | IF N_Elements(ps_struct) EQ 0 THEN ps_struct = {FSC_PS_SETUP} |
---|
| 211 | |
---|
| 212 | ; If the setup flag is on, then we have to close the previous |
---|
| 213 | ; start command before we can continue. |
---|
| 214 | IF ps_struct.setup EQ 1 THEN PS_END |
---|
| 215 | |
---|
| 216 | ; Save current setup information in the PS_STRUCT structure. |
---|
| 217 | ps_struct.setup = 1 |
---|
| 218 | ps_struct.currentDevice = !D.Name |
---|
| 219 | ps_struct.p = !P |
---|
| 220 | ps_struct.x = !X |
---|
| 221 | ps_struct.y = !Y |
---|
| 222 | ps_struct.z = !Z |
---|
| 223 | |
---|
| 224 | ; Change any parameters you feel like changing. |
---|
| 225 | !P.Charsize = 1.75 |
---|
| 226 | !P.Thick = 2 |
---|
| 227 | !X.Thick = 2 |
---|
| 228 | !Y.Thick = 2 |
---|
| 229 | !Z.Thick = 2 |
---|
| 230 | !P.Symsize = 1.25 |
---|
| 231 | !P.Font = 1 |
---|
| 232 | Device, Set_Font='Helvetica', /TT_FONT |
---|
| 233 | |
---|
| 234 | ; Configure the PostScript Device |
---|
| 235 | cancelled = 0 |
---|
| 236 | sizes = PSWindow(_Extra=extra) |
---|
| 237 | keywords = PSConfig(_Extra=extra, INCHES=sizes.inches, XSIZE=sizes.xsize, YSIZE=sizes.ysize, $ |
---|
| 238 | XOFFSET=sizes.xoffset, YOFFSET=sizes.yoffset, Cancel=cancelled, NOGUI=(1-Keyword_Set(gui))) |
---|
| 239 | IF cancelled THEN BEGIN |
---|
| 240 | PS_END |
---|
| 241 | RETURN |
---|
| 242 | ENDIF |
---|
| 243 | Set_Plot, 'PS' |
---|
| 244 | Device, _EXTRA=keywords |
---|
| 245 | |
---|
| 246 | ; What about scale factor? |
---|
| 247 | IF N_Elements(scale_factor) NE 0 THEN $ |
---|
| 248 | DEVICE, SCALE_FACTOR=scale_factor ELSE $ |
---|
| 249 | DEVICE, SCALE_FACTOR=1 |
---|
| 250 | |
---|
| 251 | ; Store filename. |
---|
| 252 | ps_struct.filename = keywords.filename |
---|
| 253 | |
---|
| 254 | END |
---|