Re: Problem with saving data without long-lag into NetCDF file

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed Dec 23 2009 - 16:35:15 MST

NCL will do whatever *you* tell it to do.

On 12/23/2009 03:46 PM, Arnold.Sullivan@csiro.au wrote:
> Hi,
> Try to make this clear
> I have variable SQ_VAR in 2-D (without long and lat, only level and time)
> I would like to save this into Netcdf file. However, the result give
> me level in x axis rather then level axis.

It gave you exactly what you specified.
> say:
> SQ_VAR should be long lat level and time
> somehow it becomes
> SQ_VAR level long lat and time
In the previous email you indicated that you are viewing
the created netCDF file through ferret??? I have never
used this tool. Does this import a variable into some predefined
structure? It is best to use the output from 'ncdump -h'
to discuss the results.

However, if you want to create a 4-dimensional array

   SO_VAR(time,lev,lat,lon) ===> SO_VAR(time,lev,1,1)

the you can have NCL do that. The above ordering is the
de-facto standard. Note: in fortran the above array
would be ordered SO_VAR(nlat,mlon,klvl,ntim)

> The code are shown as bellow.
> Cheers,
> Arnold
Note: I find your use of (/Nmodel,Nseason/) and the subsequent
redefinition in the netCDF definition confusing.

  dimNames = (/"time","level"/)
  dimSizes = (/-1,Nseason/)
  dimUnlim = (/True,False/)

> ;************************************************
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> begin
> diri =
> "/cs/datastore/csdar/sul086/ipcc_workst/all/enso_iod_sam/enso/var/" ;
> directory where files reside
> fili = systemfunc ("ls "+diri+"*_var.nc")
> fin = addfiles (fili, "r") ; note the "s" of addfile
> ListSetType (fin, "cat") ; concatenate or "merge"
> Nmodel = 24
> Nseason = 4
Nlat = 1
Nlon = 1
> SQ_VAR = new((/Nmodel,Nseason/),float)
SQ_VAR = new((/Nmodel,Nseason,Nlat,Nlon/),float)
> SQ_VAR(:,0) = fin[:]->SQ_VAR_DJF
> SQ_VAR(:,1) = fin[:]->SQ_VAR_MAM
> SQ_VAR(:,2) = fin[:]->SQ_VAR_JJA
> SQ_VAR(:,3) = fin[:]->SQ_VAR_SON
  SQ_VAR(:,0,0,0) = fin[:]->SQ_VAR_DJF
  SQ_VAR(:,1,0,0) = fin[:]->SQ_VAR_MAM
  SQ_VAR(:,2,0,0) = fin[:]->SQ_VAR_JJA
  SQ_VAR(:,3,0,0) = fin[:]->SQ_VAR_SON

> diro = "./" ; Output directory
> filo = "merge_out.nc" ; Output file
> system("/bin/rm -f " + diro + filo) ; remove if exists
> fout = addfile (diro + filo, "c") ; open output file
> fout@title <mailto:fout@title> = "enso var from model files"
> time = new(Nmodel,"integer") ; create time array
> do i=0,Nmodel-1
> time(i)=i ; combine to strings
> end do
> level = new(Nseason,"integer") ; create time array
> do i=0,Nseason-1
> level(i)=i ; combine to strings
> end do
lat = 0. ; place holder
lon = 0.
lat@units = "degrees_north"
lon@units = "degrees_east"

> delete (time@_FillValue <mailto:time@_FillValue>)
> delete (level@_FillValue <mailto:level@_FillValue>)
> ; make time and UNLIMITED dimension ; recommended for most
> applications
> dimNames = (/"time","level"/)
> dimSizes = (/-1,Nseason/)
> dimUnlim = (/True,False/)
> filedimdef(fout,dimNames,dimSizes,dimUnlim)
  dimNames = (/"time","level","lat",lon"/)
  dimSizes = (/-1,Nseason,Nlat,Nlon/)
  dimUnlim = (/True,False,Fasle,False/)

> filevardef(fout, "time" ,typeof(time) ,"time")
> filevardef(fout, "level" ,typeof(level) ,"level")
filevardef(fout, "lat" ,typeof(lat) ,"lat")
filevardef(fout, "lon" ,typeof(lon) ,"lon")
> filevardef(fout, "SQ_VAR" ,typeof(SQ_VAR) ,(/"time","level"/))
  filevardef(fout, "SQ_VAR" ,typeof(SQ_VAR) ,(/"time","level","lat","lon"/))
> filevarattdef(fout,"time" ,time)
> filevarattdef(fout,"level" ,level)
filevarattdef(fout,"lat" ,lat)
filevarattdef(fout,"lon" ,lon)
> filevarattdef(fout,"SQ_VAR",SQ_VAR)
> fout->time = (/time/) ; write SQ_VAR to a file
> fout->level = (/level/) ; write SQ_VAR to a file
  fout->lat = (/lat/)
  fout->lon = (/lon/)
> fout->SQ_VAR = (/SQ_VAR/) ; write SQ_VAR to a file
>
> end

Good luck

-- 
======================================================
Dennis J. Shea                  tel: 303-497-1361    |
P.O. Box 3000                   fax: 303-497-1333    |
Climate Analysis Section                             |
Climate&  Global Dynamics Div.                       |
National Center for Atmospheric Research             |
Boulder, CO  80307                                   |
USA                        email: shea 'at' ucar.edu |
======================================================

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Dec 23 16:36:32 2009

This archive was generated by hypermail 2.1.8 : Tue Dec 29 2009 - 10:29:16 MST