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

gmt5syntax.in 1.6 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
  1. #!/usr/bin/env perl
  2. eval 'exec perl -x -wS $0 ${1+"$@"}'
  3. if 0;
  4. #
  5. # Copyright (c) 1991-2021 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
  6. # See LICENSE.TXT file for copying and redistribution conditions.
  7. #
  8. # gmt5syntax convert old GMT script to use new 'gmt <module>' syntax
  9. # usage: gmt5syntax old_script > new_script
  10. use strict;
  11. use warnings;
  12. # name of the main gmt executable
  13. my $progname = 'gmt@GMT_INSTALL_NAME_SUFFIX@';
  14. # words to prepend with $progname
  15. my @modulenames = `$progname --show-classic`;
  16. chomp (@modulenames);
  17. # add more compatibility modules
  18. my @compat_modules = split (";", "@GMT_COMPAT_MODULES@");
  19. push @modulenames, @compat_modules;
  20. # Regexp::Assemble creates a single efficient regexp from multiple regexp
  21. my $have_assemble = eval "use Regexp::Assemble; 1" ? 1 : 0;
  22. my $re;
  23. if ($have_assemble) {
  24. # build smart regexp from @modulenames
  25. my $ra = Regexp::Assemble->new(anchor_word_begin => 1, anchor_word_end => 1);
  26. $ra->add(@modulenames);
  27. #say $ra->as_string; # print assembled regexp
  28. $re = $ra->re;
  29. }
  30. else {
  31. # concatenate modulenames to '\b(backtracker|blockmean|blockmedian|...)\b'
  32. $re= '\b(' . (join '|', @modulenames) . ')\b';
  33. }
  34. # convert lines to new syntax
  35. while (<>) {
  36. s{(^[^#<>]+)}{ # skip anything after comment or I/O redirection
  37. my $str = $1;
  38. $str =~ s/($re)/$progname $1/g unless /$progname ($re)/; # prepend $progname
  39. $str
  40. }eg;
  41. s{(^[# ]+[^<>]+)}{ # convert gmt commands directly following a comment
  42. my $str = $1;
  43. $str =~ s/^([# ]+)($re)/$1$progname $2/g unless /$progname ($re)/; # prepend $progname
  44. $str
  45. }eg;
  46. print;
  47. }
Tip!

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

Comments

Loading...