Re: Help:How to read daily multi files by ncl?

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Tue Jan 05 2010 - 11:44:19 MST

When using

    ListSetType (f, "join")

the dimensions of a variable on each file *must* be the same.
In your case, the dimensions are (ntim,klvl,nlat,mlon) BUT
ntim=365 or 366 due to leap years.

If you want a "join" operation you will have to do it manually.
Further, if your data are type "short" than you have to convert
to float.

untested!

    latS = 0.0
    latN = 90.0
    lev = 500

    diri = "/media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/"
    fils = systemfunc ("ls "+diri+"hgt.196?.nc") ; file paths
    nfil = dimsizes(fils)

    f = addfile(fils(0), "r")
    lat = f->lat({latS:latN})
    lon = f->lon

    nlat = dimsizes( lat )
    mlon = dimsizes( lon )
    NTIM = 366

    h5 = new ( (/nfil,NTIM,nlat,mlon/), "float", 1e20)

    do nf=0,nfil-1
       f = addfile(fils(nf), "r")

       time = f->time(0) ; get 1st time to determine year
       yyyy = ut_calendar(time, -1)/100
       if (isleapyear(yyyy)) then
           ntim = 366
       else
           ntim = 365
       end if

      h5(nf,0:ntim-1,:,:)=(/ short2flt( f->hgt(:,{lev},{latS:latN},:)) /)
    end do

    h5!0 = "year"
    h5&year = ispan(1960,1969,1)
    h5!1 = "day_of_year"
    h5&day = ispan(1,366,1)
    h5!2 = "lat"
    h5&lat = lat
    h5!3 = "lon"
    h5&lon = lon
    h5@long_name = "Geopotential height"
    h5@units = "m"
    printVarSummary(h5)

====
I think the following [default "cat"] is the better approach

         diri = "/media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/"
         fils = systemfunc ("ls "+diri+"hgt.196?.nc") ; file paths
         print(fils)
         f = addfiles (fils, "r")

         h5 = short2flt( f[:]->hgt(:,{lev},{latS:latN},:) )

         printVarSummary (h5)

====
Good luck

lxf wrote:
> Hi,
> I want to read out a slice of netcdf data in multi daily files in the Netcdf format.However, it seems the the Leap Year with 366 days are skipped and the slice of the daily date is also can not be read out.
> So, my questions in details are:
> 1) Can NCL read multi daily NC formate data?
> 2) Can NCL read out a slice of multi daily NC formate datas?
> The following is my code & the error message (any help is appreciated):
> ;----------------------------------------------------------------------------
> $>ncl +x t.ncl
> Copyright (C) 1995-2009 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 5.1.1
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> Loading file "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> +
> Loading file "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> +
> Loading file "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> +
> Loading file "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
> +
> + begin
> + diri = "/media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/" ; input directory
> + fils = systemfunc ("ls "+diri+"hgt.196?.nc") ; file paths
> + print(fils)
> + f = addfiles (fils, "r")
> +
> + ListSetType (f, "join") ; join
> + print(f)
> +
> + h = f[:]->hgt ; in this step, it seems the the Leap Year with 366 days are skipped
> + printVarSummary (h)
> + h2 = f[:]->hgt(:,{500},{0:90},:) ; This is line 16 and shows :"fatal:Execute: Error occurred at or near line 16 in file t.ncl "
> + printVarSummary(h2)
> +
> + end
>
>
> Variable: fils
> Type: string
> Total Size: 80 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1960.nc
> (1) /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1961.nc
> (2) /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1962.nc
> (3) /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1963.nc
> (4) /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1964.nc
> (5) /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1965.nc
> (6) /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1966.nc
> (7) /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1967.nc
> (8) /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1968.nc
> (9) /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1969.nc
>
>
> Variable: f
> Type: list
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> warning:File /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1968.nc dimension sizes do not conform to others in list; skipping file
>
> warning:File /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1964.nc dimension sizes do not conform to others in list; skipping file
>
> warning:File /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1960.nc dimension sizes do not conform to others in list; skipping file
>
>
> Variable: h
> Type: short
> Total Size: 913177440 bytes
> 456588720 values
> Number of Dimensions: 5
> Dimensions and sizes: [ncl_join | 7] x [time | 365] x [level | 17] x [lat | 73] x [lon | 144]
> Coordinates:
> time: [17181048..17189784]
> level: [1000..10]
> lat: [90..-90]
> lon: [ 0..357.5]
> Number Of Attributes: 17
> long_name : mean Daily Geopotential height
> actual_range : ( -438, 32316 )
> valid_range : ( -700, 35000 )
> units : m
> add_offset : 32066
> scale_factor : 1
> missing_value : 32766
> precision : 0
> least_significant_digit : 0
> GRIB_id : 7
> GRIB_name : HGT
> var_desc : Geopotential height
> H
> dataset : NCEP Reanalysis Daily Averages
> AJ
> level_desc : Multiple levels
> F
> statistic : Mean
> M
> parent_stat : Individual Obs
> I
> _FillValue : 32766
> warning:File /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1968.nc dimension sizes do not conform to others in list; skipping file
>
> warning:File /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1964.nc dimension sizes do not conform to others in list; skipping file
>
> warning:File /media/DATA/NCEP/ncep.reanalysis.dailyavgs/pressure/hgt.1960.nc dimension sizes do not conform to others in list; skipping file
>
> fatal:Number of subscripts on rhs do not match number of dimensions of aggregated join type variable, (4) Subscripts used, (5) Subscripts expected
>
> fatal:Execute: Error occurred at or near line 16 in file t.ncl
>
> ;----------------------------------------------------------------------------
>
> Yours,
> Li
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Jan 5 11:45:49 2010

This archive was generated by hypermail 2.1.8 : Wed Jan 06 2010 - 17:07:09 MST