[ncl-talk] Wondering how to write this if statement

Marston Johnston shejo284 at gmail.com
Fri Sep 8 02:32:44 MDT 2017


Hi,

 

One of the first rules of programming is to READ the error statement.

 

In your case there is nothing wrong with the IF statement per se. The problem is that you do not understand what you are asking the IF statement to do. As you have written it, the IF statement needs a scalar (single value) or a boolean logical (true or false) in order to get the correct execution.

You are obviously passing an array of the sorts to the if statement.

 

When posting to NCL, it helps if you print out the meta data for the variables you are having trouble with (printVarSummary).

When checking the elements of an array you need to loop over the elements 1 at a time – if that is what you are trying to do.

It is difficult for us to know what you are trying to do without a good explanation from you.

 

/M

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Marston S. Ward, PhD

Department of Earth Sciences

University of Gothenburg, Sweden

Email: marston.johnston at gu.se

SkypeID: marston.johnston 

Phone: +46-31-7864901 

Only the fruitful thing is true!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

 

From: Barry Lynn <barry.h.lynn at gmail.com>
Date: Friday, 8 September 2017 at 10:01
To: Marston Johnston <shejo284 at gmail.com>
Cc: ncl-talk <ncl-talk at ucar.edu>
Subject: Re: [ncl-talk] Wondering how to write this if statement

 

Hi:

 

Thank you (but)...

 

It doesn't -- is there another "trick" we're leaving out?

 

I think there is another way to write it where you condition it, rathern than use an if statement.

 

fatal:Conditional statements (if and do while) require SCALAR logical values, see all and any functions

fatal:["Execute.c":8575]:Execute: Error occurred at or near line 41 in file ./radar_2.ncl

 

On Fri, Sep 8, 2017 at 10:35 AM, Marston Johnston <shejo284 at gmail.com> wrote:

As far as I can see that should work:
if(dbz.lt.0.0) then

Dbz = dbz + 256.0

end if

 

/M

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Marston S. Ward, PhD

Department of Earth Sciences

University of Gothenburg, Sweden

Email: marston.johnston at gu.se

SkypeID: marston.johnston 

Phone: +46-31-7864901 

Only the fruitful thing is true!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

 

From: ncl-talk <ncl-talk-bounces at ucar.edu> on behalf of Barry Lynn <barry.h.lynn at gmail.com>
Date: Friday, 8 September 2017 at 09:33
To: ncl-talk <ncl-talk at ucar.edu>
Subject: [ncl-talk] Wondering how to write this if statement

 

Hi:

 

I am wondering how to properly write this if statement in NCL language.

 

  if (dbz.lt.0)then

   dbz = dbz + 256

  end if

 

-- 

Barry H. Lynn, Ph.D

Senior Lecturer,

The Institute of the Earth Science, 
The Hebrew University of Jerusalem, 
Givat Ram, Jerusalem 91904, Israel 

Tel: 972 547 231 170
Fax: (972)-25662581

 

C.E.O, Weather It Is, LTD
Weather and Climate Focus
http://weather-it-is.com
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
US 914 432 3108

_______________________________________________ ncl-talk mailing list ncl-talk at ucar.edu List instructions, subscriber options, unsubscribe: http://mailman.ucar.edu/mailman/listinfo/ncl-talk 



 

-- 

Barry H. Lynn, Ph.D

Senior Lecturer,

The Institute of the Earth Science, 
The Hebrew University of Jerusalem, 
Givat Ram, Jerusalem 91904, Israel 

Tel: 972 547 231 170
Fax: (972)-25662581

 

C.E.O, Weather It Is, LTD
Weather and Climate Focus
http://weather-it-is.com
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
US 914 432 3108

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170908/530f3e71/attachment.html>


More information about the ncl-talk mailing list