[ncl-talk] Define and populate plev_bnds in NetCDF

Hertz, Judith A. (GSFC-606.0)[INTERNATIONAL TECHNOLOGY COALITION, INC] judith.a.hertz at nasa.gov
Sat Oct 24 08:15:34 MDT 2015


Hi Dennis,

Thanks so much for your replies. I’ve read through these scripts and some docs, here’s what I’ve tried:

;=============================================================
; https://www.ncl.ucar.edu/Applications/method_1.shtml
;=============================================================
   typeof(plev) => double

  plev_bnds = (/ (/ 100000, 98750/) \
               , (/  98750, 96250/) \
               , (/  91250, 88750/) \
               , (/   1000,   500/) /)  *1d0          ; last line

              ; name dimensions using NCL syntax
   plev_bnds!0 = "bnds0"   ; ... whatever is appropriate
   plev_bnds!1 = "bnds1"
   if (isatt(plev_bnds,"units")) then
       plev_bnds at units = plev at units
   end if
   printVarSummary(plev_bnds)

   dirNc = "./"
   filNc = "plev_bnds.nc"
   pthNc =  dirNc+filNc

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

;===================================================================
; create global attributes of the file (optional)
;===================================================================
   fAtt               = True            ; assign file attributes
   fAtt at title         = "plev bound file"
   fAtt at Conventions   = "None"
   fAtt at creation_date = systemfunc ("date")
   fileattdef( ncdf, fAtt )            ; copy file attributes

;===================================================================
; Write to file
;===================================================================

   ncdf->plev_bnds = plev_bnds

But I’m getting an error on the size of the right hand dimension I can’t fix. Thanks in advance if you can help:

 Copyright (C) 1995-2015 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.3.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
fatal:syntax error: typeof is a function not a procedure; return value must be referenced
fatal:error at line 4 in file mk_plev_bnd.ncl

fatal:syntax error: line 4 in file mk_plev_bnd.ncl before or near =
   typeof(plev) =
----------------^

fatal:error in statement

Variable: plev_bnds
Type: double
Total Size: 64 bytes
            8 values
Number of Dimensions: 2
Dimensions and sizes: [bnds0 | 4] x [bnds1 | 2]
Coordinates:
fatal:Variable (bnds1) is undefined
fatal:["Execute.c":8575]:Execute: Error occurred at or near line 39 in file mk_plev_bnd.ncl

judy

On Oct 21, 2015, at 3:55 PM, Dennis Shea <shea at ucar.edu<mailto:shea at ucar.edu>> wrote:

Also .... another recommendation ...

It is not required but I recommend the type of the 'plev_bnds' should
be the same type as 'plev'

=====================
typeof(plev) => Integer

  plev_bnds = (/ (/ 100000, 98750/) \
               , (/  98750, 96250/) \
               , (/  91250, 88750/) \
               , (/   1000,   500/) /)          ; last line
=================
typeof(plev) => float

  plev_bnds = (/ (/ 100000.0, 98750.0/) \
                        , (/  98750.0, 96250.0/) \
                        , (/  91250.0, 88750.0/) \
                        , (/   1000.0,   500.0/) /)          ; last line

or, easier

typeof(plev) => float

  plev_bnds = (/ (/ 100000, 98750/) \
               , (/  98750, 96250/) \
               , (/  91250, 88750/) \
               , (/   1000,   500/) /)  *1.0           ; last line

=================

typeof(plev) => double

  plev_bnds = (/ (/ 100000d0, 98750d0/) \
                        , (/  98750d0, 96250d0/) \
                        , (/  91250d0, 88750d0/) \
                        , (/    1000d0,    500d0/) /)          ; last line

or, easier

typeof(plev) => double

  plev_bnds = (/ (/ 100000, 98750/) \
               , (/  98750, 96250/) \
               , (/  91250, 88750/) \
               , (/   1000,   500/) /)  *1d0          ; last line


On Tue, Oct 20, 2015 at 4:30 PM, Dennis Shea <shea at ucar.edu<mailto:shea at ucar.edu>> wrote:
NCL .... A general place to go to get file IO information.

Click 'Examples' .... then 'File I/O' .... Click 'Change netCDF file'

For 'fun' look at other examples also.

===


===

Two approaches:

[1]
If you are familiar withe the netCDF Operators (not associated with
NCL). Use netCDF Operator: ncks   [Use WWW to search for
documentation]

(a) Create a netCDF with the plev_bnds variable:   plev_bnd.nc
     See attached script. Of, course the 'plev' should be changed
     to the appropriate variable name.

(b)  If 'foo.nc' is your base file:
               ncks -O plev.nc  foo.nc
     will append the bounds variable to the file.


[2] NCL direct

  plev_bnds = (/ (/100000, 98750/) \
                        , (/  98750, 96250/) \
                        , (/  91250, 88750/) \

                        , (/ ...  ,    ...   /)  /)          ; last line

             ; name dimensions using NCL syntax
  plev_bnds!0 = "plev"   ; ... whatever is appropriate
  plev_bnds!1 = "pbnd"
  plev_bnds at units = plev at units
  printVarSummary(plev_bnds)


  f = addfile("foo.nc", "w")   ; NOTE the 'w'
  f->plev_bnds = plev_bnds

===
Either way, I would create test files in case there is a problem.

On Tue, Oct 20, 2015 at 12:44 PM, Hertz, Judith A.
(GSFC-606.0)[INTERNATIONAL TECHNOLOGY COALITION, INC]
<judith.a.hertz at nasa.gov<mailto:judith.a.hertz at nasa.gov>> wrote:
Greetings, NCL’ers

I’m new to NCL. I want to add a variable, plev_bnds, to NetCDF files so that:

double plev_bnds(plev, bnds) ;

data:

plev_bnds =
 100000, 98750,
 98750, 96250,
 96250, 93750,
 93750, 91250,
 91250, 88750,…..

I’ve found addfile, which looks to be a good way to populate the data but the docs say the variable must already exist. Do you know what is the NCL way to create/define a new variable?

thanks,

judy
_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto: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/20151024/6b8026bc/attachment.html 


More information about the ncl-talk mailing list