NOAA-PMEL / Ferret

The Ferret program from NOAA/PMEL
https://ferret.pmel.noaa.gov/Ferret/
The Unlicense
55 stars 20 forks source link

Handle quotes in Ferret parsing using non-special characters _DQ_, _SQ_ #1508

Open karlmsmith opened 6 years ago

karlmsmith commented 6 years ago

Reported by @AnsleyManke on 19 Feb 2015 00:11 UTC This came up in discussion of LAS ticket 1632. http://dunkel.pmel.noaa.gov/trac/las/ticket/1632 -- including here, slightly edited, a portion of an email dated 12/10/14 from Steve to Roland and Ansley:

A suggestion that comes to mind is to commandeer the solution that is already used in LAS/F-TDS. Suppose that we added DQ and SQ (*) to Ferret's internal parsing. They would be syntactically equivalent to " and ' and behave as expected -- i.e. whenever one of them is encountered, the parser skips over all characters until the matching DQ or SQ is found. We could use these uniformly in all LAS Ferret scripts and all communications between LAS-Java and Ferret. On the face of it, this seems like a 99.99% solution -- i.e. the only time the solution would fail is if we encountered "DQ" or "SQ" embedded in a text string or variable/attribute name. (Can either of you recall ever having seen such a string or name?)

Migrated-From: http://dunkel.pmel.noaa.gov/trac/ferret/ticket/2236

karlmsmith commented 6 years ago

Comment by @AnsleyManke on 19 Feb 2015 00:12 UTC Steve has finished this.

karlmsmith commented 6 years ago

Comment by @AnsleyManke on 19 Feb 2015 01:23 UTC Trying some more examples of the kinds of things we might do for LAS,

yes? Here, a full date-string in quotes. Make an LAS_like definition:

yes? use monthly_navy_winds
yes? let uwnd_region = uwnd[x=180,y=0,t="16-JAN-1982 20:00:00":"19-feb-1982 19:30:00"]
yes? list/noheader uwnd_region
 16-JAN-1982 / 1: -2.738
 16-FEB-1982 / 2: -2.331

yes?  ! replace double quotes with _DQ_
yes? let uwnd_region = uwnd[x=180,y=0,t=_DQ_16-JAN-1982 20:00:00_DQ_:_DQ_19-feb-1982 19:30:00_DQ_]
yes? list/noheader uwnd_region
 **ERROR: command syntax: T=_DQ_16-JAN-1982 20:00:00_DQ_:_DQ_19-feb-1982 19:30:00_DQ_
          ":" is used incorrectly. A correct example is "L=1:100:10".

yes? ! A"ships" variable would be in a dataset, names possibly containing single-quotes

yes? let ships = {"Polar Star", "Discovery", "Ship Ka'imimoana"}
yes? define symbol constraint_ship = "Ship Ka'imimoana"
yes? list/noheader/norow IS_ELEMENT_OF_STR(ships, ($constraint_ship)) 
 !-> list/noheader/norow IS_ELEMENT_OF_STR(ships, "Ship Ka'imimoana")
   1.000

yes?  ! With the string that can be passed in the url. It does not match
yes?  ! what's in the string variable list of "ships"

yes? define symbol constraint_ship = _DQ_Ship Ka_SQ_imimoana_DQ_
yes? list/noheader/norow IS_ELEMENT_OF_STR(ships, ($constraint_ship)) 
 !-> list/noheader/norow IS_ELEMENT_OF_STR(ships, _DQ_Ship Ka_SQ_imimoana_DQ_)
   0.0000

yes?  ! The first puts the single-quote on the plot.
yes?  ! The second labels the plot with Ship Ka_SQ_imimoana

yes? plot/title="Ship Ka'imimoana"/i=1:15 1./i
yes? plot/title=_DQ_Ship Ka_SQ_imimoana_DQ_/i=1:15 1./i