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

Explore adding long-format GMT options #230

Merged
merged 94 commits into from
Dec 21, 2019
Merged

Conversation

PaulWessel
Copy link
Member

This branch is work in progress on adding long-format option parsing to GMT. E.g., --region=w/e/s/n instead of -Rw/e/s/n, --registration=pixel instead of -r, and so on. At the moment only the common options and their most basic forms have been implemented, as well as local options for blockmean.
I will write more later about how this all works and what is required to be added to each module - blockmean.c static variable local_kw shows how. Basically, for each short-format option we need to supply the corresponding long-form names. Many GMT options support modifiers of the form +[ which in long form will be +[=]. Finally, many GMT options have a directive character immediately following the option key and these will become [:] in long form. Thus, what is parsed and converted to short-format options are optinos like

--longoption[=[:]][+<mod1[=]][+<mod2[=]]...

This branch is work in progress on adding long-format option parsing to GMT.  E.g., --region=w/e/s/n instead of -Rw/e/s/n, --registration=pixel instead of -r, and so on.  At the moment only the common options and their most basic forms have been implemented, as well as local options for blockmean.
I will write more later about how this all works and what is required to be added to each module - blockmean.c static variable local_kw shows how.
@PaulWessel PaulWessel self-assigned this Dec 21, 2018
@PaulWessel
Copy link
Member Author

Sorry, got formatted. The general thing I am parsing is of the form

--longoption[=[<directive>:]<arg>][+<mod1[=<arg1>]][+<mod2[=<arg2>]]...

which will represent the vast number of module options.

Update long-syntax for -U and -s.
Merge from master missed the new NULL argument..
Needed to split parsing of options that are given as a series of arguments separated by slashes (e.g., xinc/yinc) or commas (e.g., input columns).
The -T and -C are dealing with the same issue: The text bounding box atrributes.  I have combined these with -T now being a modifer +t<shape> under -C.  Tests pass, documentation has been updated.
No point having this since this is a separate branch for testing anyway.
Added code to handle multi-section arguments such as --increments=30+e/50+n
Improve the documentation of the new gmtinit_kw_replace function that converts long-format GMT options to standard short-format options.
@joa-quim
Copy link
Member

Right, but look at this. The first option in a frame is called axes

image

@PaulWessel
Copy link
Member Author

Right, but that should actually say axis. i.e., either x, y, or z. The --frame option should specify which axes (--frame=west,south) while the --axes option should specify information about specific axes.

@PaulWessel
Copy link
Member Author

Sorry, I am wrong on that. Yes, the frame setting specifies which axes you want, then the axis setting deals with its settings. Perhaps we use --axis=x+ticks=afg or something.

@joa-quim
Copy link
Member

+ticks=afg makes no sense. +ticks can only be =yes or absent. Same for annot & grid.
And maybe now you understand why I created also the xaxis, yaxis, zaxis (instead of axis=x)

@PaulWessel
Copy link
Member Author

Yep. Well, I will experiment with something that works for the command line. It does not have to be identical to your solution. Since -B is broken into frame plus one or more axes calls I need to match that with the long-options as well.

Better docs for code, longer variables, fixing some bugs.
@PaulWessel
Copy link
Member Author

It will continue to be challenging to let people place "+x" strings as part of a longer title or string argument, such as the --timestamp="Time stamp +offset" example above. The quotes are not preserved inside C and I believe our options are as before:

  1. Escape such plus signs in free text so they are not a problem, e.g.,"+x"
  2. Place the entire string inside single quotes and then not split text based on modifier inside single quotes, i.e., --timestamp="'Time stamp +offset'"

I think using +p for those strings you do now want parsed as modifiers is the simplest. I have checked and the string inside C will have the + and hence we can simply (and temporarily) replace + with two non-text ascii codes, process things, and then if those two codes are present, adjust the text by removing the first and replacing the second with +.

@PaulWessel
Copy link
Member Author

Improved further. Added the --axes keyword to deal with axes and let --frame just deal with frame settings. ANy label/text that contains +? sequences that should not be seen as modifiers must be escaped with a backslash and the entire string must be quoted. WIth that, these work for me:

gmt basemap --region=0/40/0/50 --projection=M6i --frame=WSrt+title="Title"+fill=pink --axes=afg --timestamp="Time stamp" -pdf map
gmt basemap --region=0/40/0/50 --projection=M6i --frame=afg --timestamp="Time stamp \+offset" -pdf map
gmt basemap --region=0/40/0/50 --projection=M6i --frame=WSne --axes=x:afg --axes=y:af --timestamp="Time stamp"+command -pdf map

The --axes=x:agf follows the general longname=[directive[:arg]] general template since there are many GMT module options that requires this scheme, regardless if we decide to do --xaxis instead.

--frame=axes sets which axes to draw, and --axis specifies the settings of an axis.
Copy link
Member

@seisman seisman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Add one test before merging?

@PaulWessel
Copy link
Member Author

OK, will do that before committing. Wait, this requires a compilation switch so I dont think we easily can unless you want to add

add_definitions(-DUSE_COMMON_LONG_OPTIONS) 	# Turn on testing of upcoming long-option syntax for common GMT options
add_definitions(-DUSE_MODULE_LONG_OPTIONS) 	# Turn on testing of upcoming long-option syntax for module options

to the CI setup for master. Otherwise the long-parsing is deactivated.

@PaulWessel
Copy link
Member Author

Let me know if you can add those statements to the CI cmake config file and then we could add a test or two to the master branch, @seisman.

@seisman
Copy link
Member

seisman commented Dec 20, 2019

@PaulWessel Now you can add long-option tests to this branch.

@PaulWessel PaulWessel merged commit 0cc216c into master Dec 21, 2019
@PaulWessel PaulWessel deleted the longoptionsparsing branch December 21, 2019 06:42
@seisman
Copy link
Member

seisman commented Dec 21, 2019

@PaulWessel The long-option test fails due to the timestamp of the -U option.

@PaulWessel
Copy link
Member Author

I guess we cannot really have the time-step in these tests as it changes. I will remove it.

obaney pushed a commit to obaney/gmt that referenced this pull request Aug 18, 2021
Includes the packaging dependency and IPython listed as optional.
Create the environment and install dependencies in a single command.
Set the conda channel preference order before anything else.
Include sphinx and docutils as testing dependencies (GenericMappingTools#226).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants