[ncl-talk] If statements and Fill_Values

Rashed Mahmood rashidcomsis at gmail.com
Fri Jan 10 03:27:52 MST 2020


Hi Barry,
I think in your case, Karin's suggestion would work best. Just make sure
that the variable " ratio_hr " has _FillValue attribute assigned to it.
Cheers,
Rashed

On Fri, Jan 10, 2020 at 2:18 AM Barry Lynn <barry.h.lynn at gmail.com> wrote:

> Hi Rashed:
>
> Thank you for your input (and to Beata).
>
> I need to check all values; if some are not missing, then I want to
> execute the loop.
>
> I will try the various suggestions and return.
>
> Have a nice weekend,
>
> Barry
>
> On Fri, Jan 10, 2020 at 12:09 PM Rashed Mahmood <rashidcomsis at gmail.com>
> wrote:
>
>> I think there is some logical issue(s) in your if statements:
>> Issues:
>> 1)  if(CL(n).eq.CL at _FillValue)then ; This would not work because the
>> "@_FillValue" attribute cannot be used inside if statements, I think. You
>> can define a missing value variable before hand, e.g:
>>
>> missV = CL at _FillValue
>> print(missV)
>>  if(CL(n).eq.missV)then
>> ...
>>
>> 2) if(all(ismissing(CL)))then : For this statement since you are asking
>> "if ALL Values  of CL are missing which might not be the case since some
>> values would be valid.
>>
>> Does your variable CL has _FillValue attribute assigned? What is
>> printVarSummary(CL) suggest?
>>
>> *The simplest statement would be( if CL has "_FillValue" attribute
>> assigned to it)*:
>>
>> *if(ismissing(CL(n)))then*
>>   continue
>> else
>>  ...
>> end if
>>
>> hope that helps.
>> Rashed
>>
>>
>>
>>
>>
>>
>> On Fri, Jan 10, 2020 at 1:21 AM Beáta Szabó-Takács via ncl-talk <
>> ncl-talk at ucar.edu> wrote:
>>
>>> Dear Karin and Barry,
>>>
>>> I checked different ways to skip the _FillValues. Here is my brief
>>> script:
>>>
>>>
>>>
>>> begin
>>>
>>>
>>>
>>>   input = addfile("NetCDF_2017_07_18.nc","r")
>>>
>>>   CL=input->cLayer1
>>>                                                   ;First cloud layer, its
>>> _FillValue is -9900
>>>
>>>   CL1 = new((/5400/), typeof(CL), 1e20)
>>>
>>>   CL2 = new((/5400/), typeof(CL), 1e20)
>>>
>>>   CL3 = new((/5400/), typeof(CL), 1e20)
>>>
>>>   CL4 = new((/5400/), typeof(CL), 1e20)
>>>
>>>
>>>
>>>    do n=1,5399
>>>
>>>
>>>
>>>              if(CL(n).eq.CL at _FillValue)then
>>>
>>>                   continue
>>>
>>>              else
>>>
>>>                  CL1(n) = CL(n)
>>>
>>>               end if
>>>
>>>
>>>
>>>             if(all(ismissing(CL)))then
>>>
>>>                    continue
>>>
>>>            else
>>>
>>>                   CL2(n) = CL(n)
>>>
>>>            end if
>>>
>>>
>>>
>>>             if(CL(n).ne.CL at _FillValue)then
>>>
>>>                   CL3(n) = CL(n)
>>>
>>>             end if
>>>
>>>
>>>
>>>            if(.not.ismissing(CL(n)))then
>>>
>>>                 CL4(n) = CL(n)
>>>
>>>            end if
>>>
>>>
>>>
>>>    end do
>>>
>>>
>>>
>>>    print(CL1(1:500))
>>>
>>>    print(CL2(1:500))
>>>
>>>    print(CL3(1:500))
>>>
>>>    print(CL4(1:500))
>>>
>>>
>>>
>>> end
>>>
>>>
>>>
>>> Unfortunately, none of the if statements skip the _FillValues. I do not
>>> understand why.
>>>
>>> Beata
>>>
>>>
>>>
>>> *From:* ncl-talk [mailto:ncl-talk-bounces at ucar.edu] *On Behalf Of *Karin
>>> Meier-Fleischer via ncl-talk
>>> *Sent:* Friday, January 10, 2020 9:26 AM
>>> *To:* ncl-talk at ucar.edu
>>> *Subject:* Re: [ncl-talk] If statements and Fill_Values
>>>
>>>
>>>
>>> Hi,
>>>
>>> what about
>>>
>>> if(all(ismissing(ratio_hr))) then
>>>    continue
>>> end if
>>>
>>> -Karin
>>>
>>> Am 10.01.20 um 09:17 schrieb Barry Lynn via ncl-talk:
>>>
>>> Hi:
>>>
>>>
>>>
>>> I will give it a try.
>>>
>>>
>>>
>>> In the meantime, I am wondering why you suggest the ne, rather than the
>>> equal to with a continue and an else?
>>>
>>>
>>>
>>> On Fri, Jan 10, 2020 at 9:52 AM Beáta Szabó-Takács <
>>> szabo.b at czechglobe.cz> wrote:
>>>
>>> Dear Barry,
>>>
>>> The continue will proceed directly to the next iteration. Try to skip
>>> the _FillValues by:
>>>
>>>
>>>
>>> if(max(ratio_hr).ne.ratio_hr at _FillValue.and. min(ratio_hr)
>>> .ne.ratio_hr at _FillValue)then
>>>
>>> statement(s)
>>>
>>> end if
>>>
>>>
>>>
>>> I hope it solves your issue.
>>>
>>> Kind regards,
>>>
>>> Beata
>>>
>>>
>>>
>>> *From:* ncl-talk [mailto:ncl-talk-bounces at ucar.edu] *On Behalf Of *Barry
>>> Lynn via ncl-talk
>>> *Sent:* Friday, January 10, 2020 7:40 AM
>>> *To:* ncl-talk <ncl-talk at ucar.edu>
>>> *Subject:* [ncl-talk] If statements and Fill_Values
>>>
>>>
>>>
>>> Hi:
>>>
>>>
>>>
>>> I am trying to skip a loop where all the numbers (min/max) are
>>> _FillValues.
>>>
>>>
>>>
>>> min=9.96921e+36   max=9.96921e+36
>>>
>>>
>>>
>>> However, I get this error, even though my if statement is checking this.
>>>
>>>
>>>
>>> fatal:The result of the conditional expression yields a missing value.
>>> NCL can not determine branch, see ismissing function
>>>
>>>
>>>
>>>   if (max(ratio_hr)
>>> .eq.ratio_hr at _FillValue.and.min(ratio_hr).eq.ratio_hr at _FillValue)then
>>>
>>>    continue
>>>
>>>   else
>>>
>>>
>>>
>>> Is there someway around this?
>>>
>>>
>>>
>>> Thank you
>>>
>>> --
>>>
>>> Barry H. Lynn, Ph.D
>>>
>>> Senior Associate Scientist, 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
>>>
>>>
>>>
>>>
>>> --
>>>
>>> Barry H. Lynn, Ph.D
>>>
>>> Senior Associate Scientist, 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
>>>
>>>
>>>
>>> _______________________________________________
>>>
>>> ncl-talk mailing list
>>>
>>> ncl-talk at ucar.edu
>>>
>>> List instructions, subscriber options, unsubscribe:
>>>
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>> _______________________________________________
>>> 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 Associate Scientist, 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200110/8fb61484/attachment.html>


More information about the ncl-talk mailing list