Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

switching.rst 6.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
  1. Switching between different versions
  2. ====================================
  3. We encourage all GMT users to start using version 5 immediately; it
  4. has been tested extensively by the GMT team and has benefitted from
  5. bug reports for the 4.5.x versions. Users who still worry about the new
  6. version breaking things may install GMT 4.5.x and 5 side by side.
  7. Because GMT 5 is backwards compatible with the 4.5.x series
  8. (provided you configured it that way) yet maintains its parameters and
  9. history in separate files (e.g. ``.gmtdefaults4``, versus ``gmt.conf``)
  10. it is possible to install and use both versions on the same workstation.
  11. Switching between different GMT versions can be accomplished in several
  12. ways, two of which will be addressed here:
  13. #. By using the :doc:`gmtswitch` utility to select the current working version.
  14. **Pro:** easy, interactive way to switch versions on the command line; works with
  15. previous GMT syntax. **Con:** editing of shell startup files required; needs write
  16. access in ``$HOME``-directory; manual intervention necessary if symlink
  17. ``$HOME/this_gmt`` is broken.
  18. #. By using the recommended ``gmt <module>``-syntax in conjunction with a shell
  19. helper function that points to the desired GMT executable. **Pro:** no need to
  20. create symlinks and edit shell startup files; scripts are more portable.
  21. **Con:** different syntax required.
  22. Setup of gmtswitch
  23. ------------------
  24. Run :doc:`gmtswitch` after you have finished installing all
  25. GMT versions of interest. The first time you run :doc:`gmtswitch` it
  26. will try to find all the available versions installed on your file
  27. system. The versions found will be listed in the file ``.gmtversions`` in your home
  28. directory; each line is the full path to a GMT root directory (e.g.,
  29. /usr/local/GMT4.5.9). You may manually add or remove entries there at
  30. any time. You are then instructed to make two changes to your
  31. environment (the details are shell-dependent but explained by :doc:`gmtswitch`):
  32. #. :doc:`gmtswitch` creates and maintains a symbolic link ``this_gmt`` in your home
  33. directory that will point to a directory with one of the installed
  34. GMT versions.
  35. #. Make sure ``$HOME/this_gmt/bin`` is in your executable PATH.
  36. Make those edits, logout, and login again. The next time you
  37. run :doc:`gmtswitch` you will be able to switch between versions. Typing
  38. :doc:`gmtswitch` with no argument will list the available versions in a
  39. numerical menu and prompt you to choose one, whereas :doc:`gmtswitch`
  40. *version* will immediately switch to that version (*version* must be a
  41. piece of unique text making up the full path to a version, e.g., 4.5.9).
  42. If you use **bash**, **tcsh**, or **csh** you may have to type ``hash -r`` or
  43. ``rehash`` to initiate the path changes.
  44. On Windows, the process is somewhat similar. The GMT bin directory has one batch file
  45. ``gmtswitch.bat`` that works by changing the Windows PATH variable so that the BIN
  46. directory of the preferred version always comes first. To do that the batch works in two
  47. alternative modes.
  48. #. Permanent mode
  49. #. Temporary mode
  50. The permanent mode makes use of the free executable program `EditPath
  51. <http://www.softpedia.com/get/Tweak/Registry-Tweak/EditPath.shtml>`_
  52. to change the user path in the registry. It's called permanent because the changes
  53. remains until ... next change.
  54. Off course the editpath.exe binary must be in your system's path as well.
  55. WARNING: The path change will not be visible on the shell cmd where it was executed.
  56. For the change to be active you will need to open a new cmd window.
  57. The second mode is temporary because the path to the selected GMT binary dir is
  58. prepended to previous path via a shell command line. This modification disappears
  59. when the shell cmd window where it was executes is deleted.
  60. For further details the user should read the entire help section at the header of the
  61. ``gmtswitch.bat``.
  62. The ``gmtswitch.bat`` solution, however, has the drawback that the batch file must be located
  63. elsewhere and in a directory that is on the user's PATH, otherwise it won't be located after
  64. first use unless the other GMT bin directory has a similar batch file. A better solution is to install the
  65. `Windows console enhancement <http://sourceforge.net/projects/console>`_
  66. that includes multiple tabs and configure the different tabs to start the different GMT versions.
  67. All it takes is in the Tab setting to call a batch that modifies the PATH locally. That PATH
  68. modifying batch will have a single line with something like:
  69. ::
  70. set path=C:\programs\gmt5\bin;%PATH%
  71. Version selection with helper function
  72. --------------------------------------
  73. A shell function can be used as a wrapper around the gmt executable. This even
  74. works when a gmt application is in the search PATH as it would shadow the real
  75. command. This method can easily be applied on the command line or in scripts
  76. when the recommended ``gmt <module>``-syntax is used. Shell scripts using
  77. old-style GMT commands would have to be converted first. The syntax conversion
  78. can be accomplished with the :doc:`gmt5syntax` utility. A suitable bash wrapper
  79. function for GMT 5 would look like this:
  80. .. code-block:: bash
  81. function gmt() { /path/to/gmt5/bin/gmt "$@"; }
  82. export -f gmt
  83. Exporting the function is necessary to make it available to subshells and
  84. scripts. This wrapper function can be either set in your working shell or
  85. inside a GMT shell script. The latter is useful to switch to a certain GMT
  86. version on a per-script basis.
  87. For GMT releases prior to GMT 5 which only provide the module commands,
  88. we need a slightly modified version of the wrapper script:
  89. .. code-block:: bash
  90. function gmt() { module=$1; shift; /path/to/gmt4/bin/${module} "$@"; }
  91. export -f gmt
  92. On the command line this might be too much typing to switch between
  93. versions. So we might as well put everything together in a script file
  94. ``gmtfun``:
  95. .. code-block:: bash
  96. case $1 in
  97. 4)
  98. function gmt() {
  99. module=$1; shift; /path/to/gmt4/bin/${module} "$@"
  100. }
  101. ;;
  102. 5)
  103. function gmt() {
  104. /path/to/gmt5/bin/gmt "$@"
  105. }
  106. ;;
  107. *)
  108. return
  109. ;;
  110. esac
  111. export -f gmt
  112. Source the file with either ``. gmtfun 4`` or ``. gmtfun 5`` to switch
  113. between versions.
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...