[ncl-talk] Error writing strings to netcdf

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Fri May 4 13:23:15 MDT 2018


Andrew,

The constructors (/ /) around the tochar function should be unnecessary in
that context.  Try removing them.

A workaround is to write the string as an attribute instead of a data
variable.  This is the more usual way of storing single descriptive
strings.  This should completely avoid the mysterious ncdimdef error, and
the code is more straightforward.  Will this work for your application?

    p at wnd_dir_top_string = wnd_dir_top_string

If you need to debug the original statement, then more information is
needed.  Insert an exit statement right before line 806, and show us the
full output from ncdump -hs on the vestigial output file.

--Dave


On Fri, May 4, 2018 at 11:19 AM, Andrew Kren - NOAA Affiliate <
andrew.kren at noaa.gov> wrote:

> Hi,
>
> In my previous programs I have used the tochar function to convert strings
> to characters for writing string data to netcdf using NCL. However, for
> some reason, its not working for me this time. It fails with this error:
>
> ncdimdef: ncid 65536: NetCDF: String match to name in use
>
> fatal:["Execute.c":8575]:Execute: Error occurred at or near line 806 in
> file nam_foothills.ncl
>
> My section to write the netcdf file is here:
>
> filo = "/home/arsenic1/scripts/nam/00z/saved_foothills_variables_nam.nc"
>
> system("rm -rf "+filo) ; remove any pre-existing file
>
> p = addfile(filo,"c")
>
> p at title = "Saved Foothills Variables for comparison page"
>
> p at source = filo
>
> p at creation_date = systemfunc("date")
>
> filedimdef(p,"time",-1,True) ; make time unlimited dimension
>
>
> p->temperature_top = temperature_top
>
> p->wnd_spd_top = wnd_spd_top
>
> p->clouds = clouds
>
> p->lightning = lightning
>
> p->precip_chance = precip_chance
>
> p->precip_type_top = precip_type_top
>
> p->precip_amount = precip_6hr_top
>
> p->wnd_dir_top_string = (/tochar(wnd_dir_top_string)/)
>
> p->day_of_week_string = (/tochar(day_of_week_string)/)
>
> p->months = (/tochar(months)/)
>
> p->valid_day = (/tochar(valid_day)/)
>
> Line 806 is the first line where it tries to write the wind direction
> string:
>
> p->wnd_dir_top_string = (/tochar(wnd_dir_top_string)/)
>
> Is there any remedy to this? I've looked online, but have not found much
> help.
>
> Thanks,
>
> --
> Andrew Kren
> Assistant Scientist
> CIMAS & NOAA/AOML
> 325 Broadway, Boulder, CO 80305
> (303) 497-5418
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180504/5d32ea2c/attachment.html>


More information about the ncl-talk mailing list