[ncl-talk] Error writing strings to netcdf
Andrew Kren - NOAA Affiliate
andrew.kren at noaa.gov
Sat May 5 15:30:23 MDT 2018
Dave,
I originally did not have the constructors, and it didn't work when I
didn't have them. I just tried them to see if it would work but it didn't.
The strings I actually need for reading in a separate program. So the
wind_dir_top_string is an array of wind directions (N, S, E, W) so if I
saved it as an attribute would I still be able to access the array?
Here is the output from the ncl_filedump of the file.
Variable: f
Type: file
filename: saved_foothills_variables_nam
path: saved_foothills_variables_nam.nc
file global attributes:
title : Saved Foothills Variables for comparison page
source : /home/arsenic1/scripts/nam/00z/
saved_foothills_variables_nam.nc
creation_date : Sat May 5 15:26:37 MDT 2018
dimensions:
time = 0 // unlimited
ncl0 = 26
ncl1 = 53
ncl4 = 26
ncl5 = 53
ncl17 = 26
ncl18 = 53
ncl29 = 26
ncl30 = 53
ncl15 = 26
ncl16 = 53
ncl13 = 26
ncl14 = 53
ncl11 = 26
ncl12 = 53
variables:
float temperature_top ( ncl0, ncl1 )
_FillValue : 9.96921e+36
float wnd_spd_top ( ncl4, ncl5 )
_FillValue : 9.96921e+36
float clouds ( ncl17, ncl18 )
_FillValue : 9.96921e+36
float lightning ( ncl29, ncl30 )
_FillValue : 9.96921e+36
float precip_chance ( ncl15, ncl16 )
_FillValue : 9.96921e+36
float precip_type_top ( ncl13, ncl14 )
_FillValue : 9.96921e+36
float precip_amount ( ncl11, ncl12 )
_FillValue : 9.96921e+36
On Fri, May 4, 2018 at 1:23 PM, Dave Allured - NOAA Affiliate <
dave.allured at noaa.gov> wrote:
> 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
>> <https://maps.google.com/?q=325+Broadway,+Boulder,+CO+80305&entry=gmail&source=g>
>> (303) 497-5418
>>
>
--
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/20180505/32ed463d/attachment.html>
More information about the ncl-talk
mailing list