[ncl-talk] Minor problem when parsing an expression with double constants

Gus Correa gus at ldeo.columbia.edu
Wed May 3 10:58:10 MDT 2017


Dear NCL Pros

I have noticed a minor problem when using constants of double
type in an arithmetic expression.
When I separate the tokens with spaces,
NCL parses the expression properly, and gives the correct result.
When I write the expresion tightly, without spaces, I get
a syntax error.

Am I doing something wrong, or does the parser really expect
spaces between the tokens?

Of course I can continue to write the expressions with spaces,
but the problem may propagate to, say, automatically
generated NCL code, etc.

I enclose a simple example below.
As you can see, I am using NCL 6.4.0,
pre-compiled with gcc on CentOS, and downloaded from ESG.

Thank you,
Gus Correa

*** syntax error in arithmetic expression with constant doubles ***

[gus at master ~]$ ncl
  Copyright (C) 1995-2017 - All Rights Reserved
  University Corporation for Atmospheric Research
  NCAR Command Language Version 6.4.0
  The use of this software is governed by a License Agreement.
  See http://www.ncl.ucar.edu/ for more details.
ncl 0> a=3.2d + 4.5d
ncl 1> print("a="+sprintf("%g",a))
(0)	a=7.7
ncl 2> delete(a)
ncl 3> a=3.2d+4.5d
fatal:syntax error: line 3 before or near .5d
a=3.2d+4.5d
----------^

ncl 4> b=3.2d+4.5d
fatal:syntax error: line 4 before or near .5d
b=3.2d+4.5d
----------^

ncl 5> b=3.2d +4.5d
ncl 6> print("b="+sprintf("%g",b))
(0)	b=7.7


[Note that the "d" (for double) needs a space after it, and before the 
next token. Maybe that is the behavior one should expect,
but I was surprised.]

**********************************************************************


More information about the ncl-talk mailing list