[ncl-talk] iteration over files

Kyle Griffin ksgriffin2 at wisc.edu
Mon Feb 23 22:16:42 MST 2015


Look at what the error message is telling you. In this case, it says
"variable OLR1 is undefined" - which is your problem. OLR1 does not exist
anywhere else in your script! It appears you are trying to write it out to
the output file correctly, but there is no data to output because you never
read that variable in!

Some info on reading (and writing, but that's not relevant for you at the
moment) HDF5 files is available here:

http://www.ncl.ucar.edu/Applications/hdf5.shtml

It is not the most organized of pages, but you can get the general gist of
things if you have a more complicated HDF5 file with groups. Otherwise,
note that the typical notation for reading in a variable from file(s) is
like this, using your code from above:

f    = addfile(diri+fili(nf), "r")     ;same as above
OLR1 = f->OLR_var_name    ;change to match the variable name desired from
your file

You may need/want other coordinate variables from the file as well. I don't
have much experience with HDF5 myself, but if you have some issues, you can
look into resolving them with some tips from the general file I/O page as
well:

http://www.ncl.ucar.edu/Applications/list_io.shtml

Please respond back to the list if you have more questions!


Kyle

----------------------------------------
Kyle S. Griffin
Department of Atmospheric and Oceanic Sciences
University of Wisconsin - Madison
Room 1421
1225 W Dayton St, Madison, WI 53706
Email: ksgriffin2 at wisc.edu

On Mon, Feb 23, 2015 at 10:56 PM, Steeven Paul Yerraguntla <
steevenpaul at gmail.com> wrote:

> Dear NCL users,
>           I wanted to convert number of OLR hdf(.h5) files to netcdf files
> and to get it done i used the following script and facing error at the line
> marked in the following script. I could not make out how to solve it.
> Please help me in solving out it.  Thanks in advance.
>
> =================================================================
> 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 = "./"
>   diro = "./"
>
>   fili = systemfunc("cd "+diri+" ; ls *.h5")
>   nfil = dimsizes(fili)
>   print("nfil="+nfil)
>
>   do nf=0,nfil-1
>      print("===========================")
>     f    = addfile(diri+fili(nf), "r")
>
>      print("---")
>      fbase = str_get_field(fili(nf),1,".")
>      print("fbase="+fbase)
>
>      diro = "./"
>      filo = fbase+".nc"
>      ptho = diro+filo
>
>      system("/bin/rm -f "+ptho) ; remove any pre-existing file
>      ncdf = addfile(ptho ,"c")  ; open output netCDF file
>
>                                           ; create global attributes of
> the file
>      fAtt               = True            ; assign file attributes
>      fAtt at title         = "NCL: H5 to netCDF"
>      fAtt at source        = "MOSDAC: Meteorological & Oceanographic
> Satellite Data Archival Center (India)"
>      fAtt at source_file   =  fili(nf)
>      fAtt at Conventions   = "None"
>      fAtt at creation_date = systemfunc ("date")
>      fileattdef( ncdf, fAtt )            ; copy file attributes
>
>     *ncdf->OLR = OLR1     <==============  This is where error is
> occuring*
>   end do
>  end
> =====================================
> *Error message as follows:*
>
> (0) nfil=31
> (0) ===========================
> (0) ---
> (0) fbase=K1VHR_05OCT2013_DAILY_L03_OLR
> fatal:Variable (OLR1) is undefined
> fatal:["Execute.c":7743]:Execute: Error occurred at or near line 41 in
> file nfiles_conversion_h5_to_nc.ncl
>
> _______________________________________________
> ncl-talk mailing list
> 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/20150223/7a1da42a/attachment.html 


More information about the ncl-talk mailing list