[ncl-talk] Writing to NETCDF4 HDF5 files

Barry Lynn barry.h.lynn at gmail.com
Sun Apr 21 21:24:13 MDT 2019


Dave:

Thank you.  You hit the nail on the head.  I only tried your first
suggestion, opening the file once with "w").



  filename="../RUN/wrfinput_d03.nc"

  a_asc = (/"fort.80.d03"/)

  a = addfile(filename,"w")

  l_obs_new := a->L_OBS

  a->L_OBS = l_obs_new


works just fine, passing the last line (as you surmised it did not before).

On Mon, Apr 22, 2019 at 1:53 AM Dave Allured - NOAA Affiliate <
dave.allured at noaa.gov> wrote:

> Barry,
>
> Are you reading and writing the same file in the same script run?  If so,
> it is strange to have the same file open at the same time on two different
> file handles "a" and "f".  Try opening the file on only one file handle,
> one time only per run, and mode "w".  "w" supports both read and write on
> the same file.  (See addfile docs.)  Alternatively, it might be sufficient
> to have two addfiles, but use the same file handle both times.
>
> Otherwise, I need more diagnostics.  Identify the exact line that gave the
> error.  I think it is the second addfile, but we shouldn't rely on a
> guess.  Also show ncdump -hs, preferably in a text attachment with .txt
> suffix.  Also show your NCL version and the versions of netcdf and HDF5
> libraries linked to NCL.  Also ensure the file on disk is not write
> protected.
>
>
> On Sun, Apr 21, 2019 at 12:06 PM Barry Lynn <barry.h.lynn at gmail.com>
> wrote:
>
>> Hi:
>>
>> Back to this problem again, but not like before. I can read my wrf output
>> files without any difficulty.
>>
>> I compiled WRF with netcdf4 and hdf5 compression.  I ran real.exe to
>> produce wrfinput_d03.nc
>>
>> I read a variable L_OBS from the file without any problem.
>>
>> filename="../RUN/wrfinput_d03.nc"
>>
>>   a_asc = (/"fort.80.d03"/)
>>
>>   a = addfile(filename,"r")
>>
>>   l_obs_new := a->L_OBS
>>
>>
>> But, I cannot write it back (after modifying it -- this works fine with
>> classic netcdf.
>>
>>
>>   f = addfile(filename,"w")
>>
>>   f->L_OBS = l_obs_new
>>
>>
>> I get this error (the file is definitely present, as I read from it):
>>
>>
>> fatal:["NclNetCDF4.c":2746]:NetCDF: HDF error
>>
>> fatal:["NclAdvancedFile.c":2871]:_NclFileFillHLFS: Error opening file
>> <../RUN/wrfinput_d03.nc>
>>
>>
>> Thank you.
>>
>

-- 
Barry H. Lynn, Ph.D
Senior Associate Scientist, Lecturer,
The Institute of the Earth Science,
The Hebrew University of Jerusalem,
Givat Ram, Jerusalem 91904, Israel
Tel: 972 547 231 170
Fax: (972)-25662581

C.E.O, Weather It Is, LTD
Weather and Climate Focus
http://weather-it-is.com
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190422/bc142d87/attachment.html>


More information about the ncl-talk mailing list