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

Guido Cioni guidocioni at gmail.com
Fri Sep 8 02:53:45 MDT 2017


Generally there are no rules for comparing arrays because that would be pretty arbitrary depending on the language. That's why the most direct way of comparing array to array is to loop every index. Of course, that's not efficient...

But there are a few functions written in NCL to compare and work with arrays https://www.ncl.ucar.edu/Document/Functions/array_manip.shtml <https://www.ncl.ucar.edu/Document/Functions/array_manip.shtml>

> On 8. Sep 2017, at 10:40, Barry Lynn <barry.h.lynn at gmail.com> wrote:
> 
> Hi:
> 
> My apologies for not making that clear, but I thought it was obvious that the if statement was comparing array values.
> 
> I am hoping there is a more direct way to do this comparison than doing a loop, index by index.
> 
> Thank you helping to clarify the programming issues.  Much appreciated.
> 
> Barry
> 
> 
> 
> On Fri, Sep 8, 2017 at 11:32 AM, Marston Johnston <shejo284 at gmail.com <mailto:shejo284 at gmail.com>> wrote:
> 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 <mailto:marston.johnston at gu.se>
> SkypeID: marston.johnston 
> 
> Phone: +46-31-7864901 <tel:+46%2031%20786%2049%2001> 
> 
> Only the fruitful thing is true!
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
>  
> 
>  
> 
> From: Barry Lynn <barry.h.lynn at gmail.com <mailto:barry.h.lynn at gmail.com>>
> Date: Friday, 8 September 2017 at 10:01
> To: Marston Johnston <shejo284 at gmail.com <mailto:shejo284 at gmail.com>>
> Cc: ncl-talk <ncl-talk at ucar.edu <mailto: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 <mailto: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 <mailto:marston.johnston at gu.se>
> SkypeID: marston.johnston 
> 
> Phone: +46-31-7864901 <tel:+46%2031%20786%2049%2001> 
> 
> Only the fruitful thing is true!
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
>  
> 
>  
> 
> From: ncl-talk <ncl-talk-bounces at ucar.edu <mailto:ncl-talk-bounces at ucar.edu>> on behalf of Barry Lynn <barry.h.lynn at gmail.com <mailto:barry.h.lynn at gmail.com>>
> Date: Friday, 8 September 2017 at 09:33
> To: ncl-talk <ncl-talk at ucar.edu <mailto: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 <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 <tel:(914)%20432-3108>
> _______________________________________________ ncl-talk mailing list ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu> List instructions, subscriber options, unsubscribe: http://mailman.ucar.edu/mailman/listinfo/ncl-talk <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 <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 <tel:(914)%20432-3108>
> 
> 
> -- 
> 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 <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 <mailto:ncl-talk at ucar.edu>
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>

Guido Cioni
http://guidocioni.altervista <http://guidocioni.altervista/>.org

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


More information about the ncl-talk mailing list