Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows 下的 GMT 安装指南 #1203

Open
5 tasks
seisman opened this issue Sep 15, 2023 · 12 comments · Fixed by #1213
Open
5 tasks

Windows 下的 GMT 安装指南 #1203

seisman opened this issue Sep 15, 2023 · 12 comments · Fixed by #1213

Comments

@seisman
Copy link
Member

seisman commented Sep 15, 2023

Windows 下安装和使用 GMT 的方式有很多,包括:

  • GMT exe 安装包 + Batch
  • GMT exe 安装包 + Batch + UnixTools
  • GMT exe 安装包 + Git Bash
  • GMT exe 安装包 + WSL?
  • 直接 WSL 然后在 WSL 里安装 GMT

各个方法的优缺点是:

  • 方法 1:Batch 功能单一,无法实现很多功能
  • 方法 2:尚可,但只接受 Batch 语法
  • 方法 3:尚可,但只介绍 Bash 语法
  • 方法 4:不确定是否可以,只接受 Bash 语法
  • 方法 5:WSL 默认是 Ubuntu,而 Ubuntu 自带的 GMT 一般版本比较老,意味着用户想使用最新版本必须手动编译。有点太麻烦

目前手册中介绍了方法 1、2、3。 #911 中提出了方法 4。具体如何更新 Windows 下的安装指南还需要进一步讨论和验证。

@ZMAlt
Copy link
Member

ZMAlt commented Sep 16, 2023

我的看法:

1 和 2 还是 受制于 bat 弱鸡的功能
3 如果可行,可能是不错的选择;另外,我们 win 源码编译的部分以后也可以用,现在的 MSVC 有些重
4 在我印象中行不通
5 也是不错的选择,除了编译这部分,之前群里和陈老师都反馈出现跨文件系统的问题

@wangliang1989
Copy link
Member

劝说用户直接装Linux虚拟机就最为简单,但是你们可能会认为过于激进。但是无论怎么说,不应该引导新人去学batch。所以方法1和2应该舍弃。

@seisman
Copy link
Member Author

seisman commented Sep 18, 2023

我觉得:

  1. 我们不应该维护 UnixTools,所以舍弃方案2
  2. 在WSL里编译GMT源码太复杂,舍弃方案5
  3. 对于 GMT 使用而言,WSL 与 git bash 类似,而 WSL 要更复杂一些,所以舍弃方案4

最终保留方案1和3。即在 GMT 安装指南中推荐 Git Bash 或者类似的软件。在入门教程的 Windows 版本中 (https://docs.gmt-china.org/latest/tutorial/get-started/windows/) ,先介绍 Batch 执行 GMT 脚本,再介绍 Git Bash 执行脚本。

@ZMAlt
Copy link
Member

ZMAlt commented Sep 20, 2023

在 win 虚拟机上测试了一下 3(git bash),可以直接用 win 下的 gmt 安装包,挺方便的。但是中文还没试,不知道受不受影响。

WSL 的方法我建议也不要完全放弃,可以提一嘴,提醒想折腾的用户有这个选项。

@seisman
Copy link
Member Author

seisman commented Sep 20, 2023

所以最终就简化成两套方案:

  1. exe 安装包 + Batch 脚本
  2. exe 安装包 + Bash 脚本 + 配套的 Bash 环境

其中 Bash 环境可以有很多种选择,如 Git Bash, Mingw, msys2, WSL 等。

@ZMAlt
Copy link
Member

ZMAlt commented Sep 23, 2023

测试了下 git bash方式对中文的支持。

  1. git bash 下,gmt convert CN-faults.gmt -aL="断层名称" 这种形式的中文不能用,直接报段错误。
  2. 中文配置,用的仍然是 win gmt 的中文配置。在 git bash 下运行下面的 bash 脚本
#!/usr/bin/env bash
gmt begin GMT_Chinese png,pdf
# 设置中文字体配置文件 cidfmap 的目录
# gmt set PS_CONVERT="C-I${HOME}/.gmt/"

# GMT 处理中文存在一些已知BUG
# 需要设置 PS_CHAR_ENCODING 为 Standard+ 以绕过这一BUG
gmt set PS_CHAR_ENCODING Standard+
gmt set FONT_TITLE 25p,41,black
gmt set FONT_LABEL 15p,39,black

gmt text -R0/8/0/4 -JX12c/4c -Bxaf+l"X轴" -Byaf+l"Y轴" -BWSen+t"中文标题" -F+f << EOF
2 3.5 25p,39,black 中文宋体
2 2.5 25p,40,blue  中文仿宋
2 1.5 25p,41,red   中文黑体
2 0.5 25p,42,green 中文楷体
4 3.5 25p,43,black 中文宋体
5 3.5 25p,44,blue  中文仿宋
6 3.5 25p,45,red   中文黑体
7 3.5 25p,46,green 中文楷体
EOF
gmt end show

可以看到,放在文本里的中文成功了,但是在作为命令行参数的不行,这和情况 1 是一样的。

GMT_Chinese

@ZMAlt ZMAlt reopened this Sep 23, 2023
@seisman
Copy link
Member Author

seisman commented Sep 23, 2023

但是在作为命令行参数的不行

猜测 git bash 命令行的中文是 UTF8 编码,而 Windows 需要 EUC 编码。

@ZMAlt
Copy link
Member

ZMAlt commented Sep 23, 2023

git bash默认的编码不是 utf-8,改为 utf-8以后

  1. 仍然段错误
  2. 和上面的反过来了 :)
    GMT_Chinese

@seisman
Copy link
Member Author

seisman commented Sep 23, 2023

新建一个Bash脚本,内容如下:

cat > test.txt << EOF
2 3.5 25p,39,black 中文宋体
2 2.5 25p,40,blue  中文仿宋
2 1.5 25p,41,red   中文黑体
2 0.5 25p,42,green 中文楷体
4 3.5 25p,43,black 中文宋体
5 3.5 25p,44,blue  中文仿宋
6 3.5 25p,45,red   中文黑体
7 3.5 25p,46,green 中文楷体
EOF
  1. 确认 Bash 脚本是什么编码
  2. 执行脚本之后,生成的文件是什么编码

猜测这两个是不一样的

@ZMAlt
Copy link
Member

ZMAlt commented Sep 23, 2023

现在的环境是

  1. git bash 编码设置为 utf-8
  2. bash 脚本的编码为 utf-8
  3. 使用 heredoc 生成的文本也是 utf-8
  4. 在 cmd 中 chcp 的结果是 936

结果仍然是这样:

  1. 仍然段错误

GMT_Chinese


我搜了下,感觉可能是 4 的影响。按照 https://cloud.tencent.com/developer/article/1913712 改了以后:1-3不变,4 CMD 下 chcp 显示 65001 了。

  1. 段错误好了,也能正常输出结果。
  2. 结果比上面更槽,轴,标题,文本中文都不行了。

@seisman
Copy link
Member Author

seisman commented Sep 23, 2023

  • git bash 编码设置为 utf-8
  • bash 脚本的编码为 utf-8
  • 使用 heredoc 生成的文本也是 utf-8

感觉 UTF8 的情况下是不应该有正常显示的中文的,因为在做中文配置的时候使用的是 GB-EUC.

@ZMAlt
Copy link
Member

ZMAlt commented Sep 23, 2023

又测试了一下,总结一下。

  1. 中文图的显示,确实应该保证 git bash、脚本编码、系统的 unicode 用和字体一样的编码。
  2. convert 的行为很奇怪,主要受系统的 unicode 的设置的影响。

以下默认都先做 GMT 的中文配置,包括

  1. 安装 gs 自动设置的 cidfmap
  2. GMT 的 PSL_custom_fonts 文件

1

环境
1 git bash 设置为 GBK
2 bash 脚本的编码 ANSI
3 heredoc 编码 ISO-8859 应该是 ANSI 的别名
4 chcp 为 936

结果

  1. gmt convert CN-faults.gmt -aL="断层名称"段错误
  2. 中文一切正常

2

环境
1 - 3 不变
4 chcp 为 65001

结果

  1. gmt convert CN-faults.gmt -aL="断层名称"不报错,可以输出结果,如下
> -L闃垮反瀹柇瑁~B
87.9042243748   48.0553749163
87.9570964616   48.0162540323
...
  1. 中文全部出错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants