NOAA-PMEL / Ferret

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

string addition quirks #1968

Closed AnsleyManke closed 4 years ago

AnsleyManke commented 4 years ago

Marco van Hulton noticed this. Addition can be used to concatenate strings, but depending on the syntax, it's returning incorrect results.

yes? let/units="m/s" v1 = 1.1
yes? let/units="mmol C m-3" v2 = 2.2

! this is ok
yes? list/nohead v1.units + "XYZ"
         "m/sXYZ"

! this is wrong -- v1.units repeated twice instead of picking up v2.units.
yes? list/nohead v1.units + v2.units
         "m/sm/s"

! this is ok
yes? list/nohead "`v1.units`" + "`v2.units`"
         "m/smmol C m-3" 

@AndrewWittenberg

AnsleyManke commented 4 years ago

This is fixed in is_attrib_val.F

It's a bug in evaluating expressions that involve getting the value of more than one attribute.

Marco's example is now correct:

yes? let/units="m/s" v1 = 1.1
yes? let/units="mmol C m-3" v2 = 2.2
yes? list/nohead v1.units + v2.units
        "m/smmol C m-3"

For numeric results using the attribute-getting syntax, previously it did the same thing - using ..nvars twice!

yes? use coads_climatology
yes? list/nohead ..nvars
          7.000
yes? list/nohead ..ndims
          3.000
yes? list/nohead ..nvars + ..ndims
          14.00

but now,

yes? list/nohead ..nvars + ..ndims
          10.00

and, back to another example with string results:

yes? list/nohead slp.long_name + " (" + slp.units + ") " + slp.history
        "SEA LEVEL PRESSURE (MB) From coads_climatology"