zhenghui2915的个人博客分享 http://blog.sciencenet.cn/u/zhenghui2915

博文

【GMT】ps2raster命令设定GMT绘图图片输出格式

已有 17860 次阅读 2012-10-16 16:45 |个人分类:GMT|系统分类:科研笔记

通常情况下,GMT默认的图片输出格式是以*ps为后缀的ps文件,需要使用专门的PS查看器ghostview浏览图片。我们在用word写文章或做PPT的时候,PS格式的图片不方便插入到这些文件中。因此,需要将GMT输出的图片转化为常用的图片格式,满足各种要求。
 
1.首先在命令提示符下敲入ps2raster命令,查看ps2raster命令的帮助信息:
(提示,为了把帮助信息重定向到文件,使用了ps2raster >c:ps2raster_help.txt,发现dos终端还是把帮助信息输出到提示符终端中,没有输出到文件。后来尝试用方法:ps2raster 1>c:out.txt 2>c:err.txt,查后C盘根目录下的文件后发现,out.txt中的内容为空,err.txt中的内容为需要的帮助信息。原来是GMT中把不带参数的ps2raster的帮助信息当做标准错误输出了,由此可以推断,其他的GMT命令应该也是采用类似的约定。)
ps2raster 4.5.7 - Converts one or several [E]PS file(s) to raster formats using GhostScript.
usage: ps2raster <psfile1> <psfile2> <...> [-A[u][-]] [-C<gs_command>] [-D<dir>]
       [-E<resolution>] [-F<out_name>] [-G<ghost_path>] [-L<listfile>] [-N] [-P]
       [-Q[g|t]1|2|4] [-S] [-Tb|e|f|g|G|j|m|t] [-V]
       [-W[+g][+k][+t<title>][+n<name>][+a<mode>[<alt]][+l<lodmin>/<lodmax>][+f<minfade>/<maxfade>][+u<URL>]]
Works by modifying the page size in order that the resulting
image will have the size specified by the BoundingBox.
As an option, a tight BoundingBox may be computed.
 <psfile(s)> postscript file(s) to be converted.
 OPTIONS:
 -A Adjust the BoundingBox to the minimum required by the image contents
    Append u to strip out time-stamps (produced by GMT -U options)
    Append - to make sure -A is NOT activated by -W
 -C Specify a single, custom option that will be passed on to GhostScript
    as is. Repeat to add several options [none].
 -D Sets an alternative output directory (which must exist) [Default is same directory as PS files]
    Use -D. to place the output in the current directory.
 -E Set raster resolution in dpi [default = 720 for PDF, 300 for others]
 -F Force the output file name. By default output names are constructed
    using the input names as base, which are appended with an appropriate
    extension. Use this option to provide a different name, but WITHOUT
    extension. Extension is still determined automatically.
 -G Full path to your ghostscript executable.
    NOTE: Under Unix systems this is generally not necessary.
    Under Windows, ghostscript is not added to the system's path.
    So either you do it yourself, or give the full path here.
    (e.g. -Gc:programsgsgs7.05bingswin32c).
 -L The <listfile> is an ASCII file with names of ps files to be converted
 -N OBSOLETE. Use -S and/or -Te instead.
 -P Force Portrait mode. All Landscape mode plots will be rotated back
    so that they show unrotated in Portrait mode.
    This is practical when converting to image formats or preparing
    EPS or PDF plots for inclusion in documents.
 -Q Anti-aliasing setting for (g)raphics or (t)ext; append size (1,2,4) of sub-sampling box
    Default is no anti-aliasing, which is the same as specifying size 1.
 -S Apart from executing it, also writes the ghostscript command to standard output.
 -T Set output format [default is jpeg]
     b means BMP
    e means EPS
    f means PDF
    g means PNG
    G means PNG (with transparency)
    j means JPEG
    m means PPM
    t means TIF
    For b, g, j, t, append - to get a grayscale image [24-bit color].
    The EPS format can be combined with any of the other formats.
    For example, -Tef creates both an EPS and PDF file.
 -V Provides progress report [default is silent] and shows the gdal_translate
    command, in case you want to use this program to create a geoTIFF file.
 -W Write a ESRI type world file suitable to make (e.g.) .tif files be
    recognized as geotiff by softwares that know how to do it.
Be aware,
    however, that different results are obtained depending on the image
    contents and if the -B option has been used or not. The trouble with
    -B is that it creates a frame and very likely its annotations and that
    introduces pixels outside the map data extent. As a consequence, the
    map extents estimation will be wrong. To avoid this problem, use the
    --BASEMAP_TYPE=inside option which plots all annotations related stuff
    inside the image and does not compromise the coordinate computations.
    The world file naming follows the convention of jamming a 'w' in the
    file extension. So, if the output is tif (-Tt) the world file is a .tfw,
    for jpeg a .jgw, and so on.
    Use -W+g to do a system call to gdal_translate and produce a true geoTIFF
    image right away. The output file will have the extension .tiff
    See the man page for other 'gotchas'. Automatically sets -A -P.
    Use -W+k to create a minimalist KML file that allows loading the image in
    Google Earth.
Note that for this option the image must be in geographical
    coordinates. If not, a warning is issued but the KML file is created anyway.
    Several modifiers allow you to specify the content in the KML file:
    +t<doctitle> sets the document name ["GMT KML Document"]
    +n<layername> sets the name of this particular layer ["GMT Image Overlay"]
    +a<altmode>[<altitude>] sets the altitude mode of this layer, where
       <altmode> is one of 5 recognized by Google Earth:
       G clamped to the ground [Default]
       g Append altitude (in m) relative to ground
       A Append absolute altitude (in m)
       s Append altitude (in m) relative to seafloor
       S clamped to the seafloor
    +l<minLOD>/<maxLOD>] sets Level Of Detail when layer should be active [always active]
      Image goes inactive when there are fewer than minLOD pixels or more
      than maxLOD pixels visible.  -1 means never invisible.
    +f<minfade>/<maxfade>] sets distances over which we fade from opaque to transparent [no fading]
    +u<URL> prepands this URL to the name of the image referenced in the KML [local file]
 
查看帮助信息后,需要注意的参数主要用红色加粗标示。
 
2.编写绘图脚本:
Rem xyz2grd ETOPO5.DAT -Getopo5.grd -I5m -Rg -ZTLxyhw
makecpt -Cglobe -T-10000/10000/1000 -Z > colors.cpt
REM Robinson投影
Rem grdimage etopo5.grd -Ba60g30 -Rg -JN180/25c -Ccolors.cpt -K  > world.ps
REM Eckert IV 投影
grdimage etopo5.grd -Ba60g30 -Rg -JKf180/25c -Ccolors.cpt -K -Y2i > world.ps 
REM Sinusoidal 投影
Rem grdimage etopo5.grd -Ba60g30 -R-180/180/-90/90 -JI0/25c -Ccolors.cpt -K -Y2i > world.ps
REM Interrupted Sinusoidal projection 投影
Rem grdimage etopo5.grd -Ba60g30 -R-160/-20/-90/90 -Ji-90/0.02i -Ccolors.cpt -K > world.ps
Rem grdimage etopo5.grd -Ba60g30 -R-20/60/-90/90 -Ji20/0.02i -X2.8i -Ccolors.cpt -K -O>> world.ps
Rem grdimage etopo5.grd -Ba60g30 -R60/200/-90/90 -Ji130/0.02i -X1.6i -Ccolors.cpt -K -O>> world.ps
psscale -Ba2500f500::/:"m": -Ccolors.cpt -D12.5c/0.3c/15c/.35ch -Y-0.75i -O -U"Author:YangLei">> world.ps

REM 墨卡托投影
rem grdimage etopo5.grd -Ba60g30 -R0/360/-80/80 -JM20c -X2i -Y1.7i -Ccolors.cpt -K > world.ps
rem psscale -Ba2500f500::/:"m": -Ccolors.cpt -D10c/0.3c/20c/.35ch -Y-0.75i -O -U"Author:YangLei">> world.ps
 
ps2raster world.ps -Tt -V
Rem ps2raster world.ps -Tt -V -Gc:ProgramsGMT4bingswin32c
pause
 
说明:
ps2raster 命令后面跟上需要转换的PS文件文件名,-T选项指定输出的图片的格式,-G选项指定gswin32c.exe文件的路径(请注意该路径中不能包含空格,例如C盘根目录"C:Programs file"中间就有空格,出现空格就会找不到gswin32c.exe文件。建议在安装完ghostview以后,拷贝安装目录下的gswin32c.exe到GMT安装目录下的bin文件夹中。)
 
 
3.查看绘图结果
 
PS: GMT Window版本配套的软件:
    1.gawk也是window下常用程序,可以在下面网站下载

 http://gnuwin32.sourceforge.net/packages/gawk.htm 

 下载后,安装在D:GMT 目录下(可以安装在任何目录下),只要把D:GMTGnuWin32bin下面的所有文件拷贝到 D:GMTbin 下就可以了。

2.PS查看器ghostview的安装 

在安装Ghostview前先安装Ghostscript,这两个软件都可以网上自由获取 http://pages.cs.wisc.edu/~ghost/

按先后顺序依次安装,可以安装在任何一个文件夹。安装后把gsgs8.63bin 下的gswin32.exe可执行文件和Ghostgumgsview下的gsview32.exe可执行文件拷贝到D:GMTbin下即可。



https://wap.sciencenet.cn/blog-51026-623199.html

上一篇:【Fortran】Fortran程序带参数运行方法总结
下一篇:【GMT】pstext 通过文件绘制脚本指定区域外的文字
收藏 IP: 159.226.162.*| 热度|

1 张鹏飞

该博文允许注册用户评论 请点击登录 评论 (5 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-19 20:27

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部