Re: save calculated 2D array as 3D array

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Mon Nov 21 2011 - 15:43:15 MST

As noted in the documentation, if the last argument is -1,
it reads all times.

  slp = wrf_user_getvar(data,"slp",-1); slp for all times in file

  printVarSummary(slp) ; [Time] x [south_north] x [west_east]

If you want the leftmost dimension to be named 'time'

  slp!0 = "time"
  printVarSummary(slp) ; [time] x [south_north] x [west_east]

You should add a 'time' variable to your output variable(s)

load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
   Times = f->Times ; Times(Time, DateStrLen) (type character)
   time = wrf_times_c( Times, 0 )

   slp&time = time

====
        system("/bin/rm -f simple.nc") ; remove any pre-existing file
        ncdf = addfile("simple.nc" ,"c") ; open output netCDF file

     ; make time and UNLIMITED dimension
        filedimdef(ncdf,"time",-1,True)

     ; output variables directly

        ncdf->SLP = slp

On 11/21/11 3:22 PM, Joseph Zambon wrote:
> Kelly,
>
> wrf_user_getvar only calculates over 1 time period. So when you're
> issuing the command...
>> SLP = wrf_user_getvar(data,"slp",0)
>
> You're telling NCL to calculate SLP the data at t=0. As a result, you're
> getting data in west_east X south_north dimensions. You would probably
> want to create a new array over the 109 timesteps in your data. Snippets
> from a script I had written to do this...
>
> ; define dimensions
> T = a->T(1,:,:,:) ;load 3 dims of 4-d variable to get dimension sizes
> (lev, sn, we)
> b=dimsizes(T) ;
> bottom_top = b(0) ;lev
> south_north = b(1) ;s_n
> west_east = b(2) ;w_e
> DateStrLen = 19 ;
> time = -1 ;time = unlimited
>
> ;find max time
> maxtime=wrf_user_list_times(a);
> ntimes = dimsizes(maxtime);
>
> do time = 0,ntimes-1,1
> ncf->slp(time,:,:) = (/wrf_user_getvar(a,"slp",time)/) ;SLP
> print(time)
> end do
>
> Also, a best practice to follow... Don't load 4-D variables, they take
> up a lot of memory and take forever to load! In my code above I find
> bottom_up, south_north, west_east from the WRF variable T and then find
> time dimension using wrf_user_list_times.
>
> Hopefully this helps.
>
> -Joe
>
>
>
>
> On Nov 21, 2011, at 4:11 PM, kelly lombardo wrote:
>
>> I am trying to calculate SLP using NCL and save it in a separate NCL
>> file with similar attributes to the 2D variables in the original file.
>> I am having some problems having the dimensions and sizes match up.
>> For the original 2D data, there are 3 coordinates for time, latitude
>> and longitude but for the calculated 2D SLP data, I can only seem to
>> get 2 coordinates latitude and longitude. I have tried 2 ways to solve
>> this:
>>
>> The first way I tried to calculate SLP and define the variable as
>> having 3 dimensions, time, latitude, and longitude, but that didn't work:
>> --------------------------------------------------
>> begin
>>
>> system("/bin/rm -f /R0/kelly/WRF/1985/slp.nc <http://slp.nc/>")
>> out = addfile("/R0/kelly/WRF/1985/slp.nc <http://slp.nc/>","c")
>>
>> fileAtt = True
>> fileAtt@creation_date = systemfunc("date")
>> fileattdef(out,fileAtt)
>>
>> data = addfile("/R0/kelly/WRF/1985/wrfout_d01_1985-10-16_00:00:00.nc
>> <http://00.nc/>", "r")
>>
>> T2 = wrf_user_getvar(data,"T2",0)
>> SLP = wrf_user_getvar(data,"slp",0)
>> U10 = wrf_user_getvar(data,"U10",0)
>>
>> dims = dimsizes(data->T2)
>> print (dims)
>>
>> SLP = new((/dims(0),dims(1),dims(2)/),"float")
>>
>> dimNames = (/"time", "south_north", "west_east"/) ; coordinate variables
>> dimSizes = (/ -1, dims(1), dims(2) /) ; coordinate dimensions
>> dimUnlim = (/ True , False, False/) ; define unlimited t
>> filedimdef(out, dimNames , dimSizes, dimUnlim )
>>
>> out->SLP=SLP
>>
>> end
>> ----------------------------------------------------------------------
>> For the second, I tried to conform the already calculated 2D SLP data
>> to the coordinates of U10 of the original file, but that didn't work
>> either and I still get only 2 coordinates:
>>
>> begin
>>
>> system("/bin/rm -f /R0/kelly/WRF/1985/slp.nc <http://slp.nc/>")
>> out = addfile("/R0/kelly/WRF/1985/slp.nc <http://slp.nc/>","c")
>>
>> fileAtt = True
>> fileAtt@creation_date = systemfunc("date")
>> fileattdef(out,fileAtt)
>>
>> data = addfile("/R0/kelly/WRF/1985/wrfout_d01_1985-10-16_00:00:00.nc
>> <http://00.nc/>", "r")
>>
>> T2 = wrf_user_getvar(data,"T2",0)
>> SLP = wrf_user_getvar(data,"slp",0)
>> U10 = wrf_user_getvar(data,"U10",0)
>>
>> dims = dimsizes(data->T2)
>> print (dims)
>>
>> filedimdef(out, "time", -1, True)
>>
>> out->SLP=SLP
>> SLP2=conform(U10,SLP,(/0,1/))
>> out->SLP2=SLP2
>>
>> end
>> ----------------------------------------
>>
>> Does anyone know how to fix this?
>> Thanks so much
>> _______________________________________________
>> 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
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Nov 21 15:43:25 2011

This archive was generated by hypermail 2.1.8 : Tue Nov 22 2011 - 14:17:52 MST