[ncl-talk] Problems reading monthly files with systemfunc

Dennis Shea shea at ucar.edu
Thu Apr 25 13:50:43 MDT 2019


General programming comment: I 'really' like the reassignment operator *:=
:-)   :-)  :-)*

Some languages allow existing variables on the left-hand-side of the
assignment operator *=* to be replaced [over-written] by a variable on the
right handle side regardless of shape or type. My historical use of a
language that did allow this type of operation occasionally led to some
subtle errors. [ Of course, it could have been bad programming on my part! ]

Within NCL, a person could always use *:=* rather than the 'regular'
assignment operator *=*
There would only be a very small timing penalty. However, *I think this
would be bad coding style*. Kinda like hard-wiring numbers [123.987] into a
code rather than using a named constant ( con_name = 123.987).

To me, judicious use of  *:=* indicates to someone looking at the code that
a variable 'may' change shape and/or type.
A common case would be calculating a monthly mean from observations. Each
month has a different number of days.
So if there were (say) 6-hrly values, months with 28, 29, 30, 31 days [*4]
would have a different number of observations.

        x(ntim) ===> ntim=> all 6=hrly values

        nyrs   = yrLast-yrStrt+1
        NTIM  = nyrs*12                  ; total number of monthly values
to be calculated
        xAvg   = new ( (/NTIM/), typeof(x), getVarFillValue(x))

        do yyyy=yrStrt,yrLast
          do mm=1,12
               it  *:=* ind(yyyy.eq.year .and. mm.eq.month)   ; temporal
indices [*] of observations in current month & year
               if (*.not.all*(*ismissing*(it))) then
                   nit  *=* *dimsizes*(it)
; # of 6-hrly values [scalar]
                   nt   *=*
nt+1                                             ; index of current monthly
value [scalar]
                   xAvg(nt)  *=* *dim_avg_n*( x(it), nDim)    ; average all
values for the current month/year
               end if
          end do    ; end 'mm'
        end do      ; end 'yyyy'



On Tue, Apr 23, 2019 at 10:09 AM Laura Fowler <laura at ucar.edu> wrote:

> Hi Adriana:
> You may want to add "delete(file1)" below "print(file1)" since as you
> wrote file1 contains 30 files for June and 31 files for July?
> Laura
>
>
>
>
>
>
>
>
> On Tue, Apr 23, 2019 at 7:39 AM <adriana.bossolasco at cnrs-orleans.fr>
> wrote:
>
>> Hi Everyone
>>
>> I have a problem for read monthly files with systemfunc
>> I know that the problem is because the first month that I read is JUN
>> which have 30 days and the when I try to read JUL with 31 days my code
>> says:
>>
>> fatal:Dimension sizes of left hand side and right hand side of
>> assignment do not match
>>
>> How can I fix this? Maybe is very basic but I don't realize
>>
>> I copy my code here
>>
>> begin
>> ;************************************************
>> ; variable and file handling
>> ;************************************************
>>
>>
>> year1=2001
>> year2=2002
>> nyear=year2-year1
>> print(nyear)
>> month1=6
>> month2=8
>> nmonths=month2-month1
>>
>> do i = 1,nyear
>>   do j = 1,nmonths
>> print(nmonths)
>> print(nyear)
>> if (month1+j-1 .ge. 10) then
>>   mois=10
>> else
>>   mois="0"+(j-1+month1)  ;
>> end if
>> print(mois)
>>
>> file1 = systemfunc(" ls
>>
>> /PROJETS/MOUSSON-NEW/MAM_GEOS_8y_rest/MAM_GEOS_8y_rest.cam.h0.200"+i+"-"+mois+"*-
>> 43200.nc")
>> print(file1)
>>
>> end do
>> end do
>>
>> end
>>
>>
>> --
>> Adriana Bossolasco
>> LPC2E UMR 7328 (CNRS, Université d'Orléans)
>> 3A avenue de la Recherche Scientifique
>> 45071 Orléans Cedex 2 - FRANCE
>> Tel  +33 (0)2 38 25 52 85
>> e-mail: adriana.bossolasco at cnrs-orleans.fr
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
>
> --
>
> !-------------------------------------------------------------------------------------------------------------
> Laura D. Fowler
>
> Mesoscale and Microscale Meteorology Division (MMM)
> National Center for Atmospheric Research
> P.O. Box 3000, Boulder CO 80307-3000
>
> e-mail: laura at ucar.edu
> phone: 303-497-1628
>
>
> !-------------------------------------------------------------------------------------------------------------
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190425/fe6c1f31/attachment.html>


More information about the ncl-talk mailing list