<div dir="ltr"><div>Hi Tess,<br></div><div><br></div><div>I think the issue is the following:<br><br>Variable: data_seasonal_clim<br></div><div>[snip]<br></div><div>Number of Dimensions: 3<br>Dimensions and sizes:    [season | 4] x [latitude | 256] x [longitude | 512]<br>Coordinates: <br>            season: [DJF..SON]                       &lt;************************<br>            latitude: [-89.46294..89.46294]<br>            longitude: [ 0..359.2969]<br><br><br></div><div>By netCDF rule, a coordinate variable *must* be a numeric monotonic one-dimensional array.<br></div><div>You have the names as type string.<br><br></div><div>NCL will allow this construction to occur. However, when writing to a netCDF file, this structure is neither recognized or allowed. I am pretty sure this applies to both netCDF-3 and netCDF-4. (FYI: netCDF-4 is a subset of HDF-5 and is HDF-5 )  <br></div><div>  <br>data_seasonal_clim!0         = &quot;season&quot;<br>data_seasonal_clim!1         = &quot;latitude&quot;<br>data_seasonal_clim!2         = &quot;longitude&quot;<br>;;;data_seasonal_clim&amp;season    = season_names<br>data_seasonal_clim&amp;season    = ispan(0.3,1)        ; ispan(1,4,1)  .... whatever<br><br><br>season_names = (/ &quot;DJF&quot;,&quot;MAM&quot;,&quot;JJA&quot;,&quot;SON&quot;/)<br></div><div>season_names!0 = &quot;season&quot;<br></div><div>season_names&amp;season = ispan(0.3,1)        ; ispan(1,4,1)  .... whatever<br><br>===<br></div><div>NOTE: netCDF-3 does *not* allow string variables. It does allow character variables. Hence, if you want string variable output, I think you should precede the file write with:<br>    <br><pre><strong>setfileoption</strong>(&quot;nc&quot;,&quot;Format&quot;,&quot;NetCDF4&quot;)</pre><br></div><div>Good luck<br></div><div>D<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 7, 2016 at 5:25 AM, Tess Parker <span dir="ltr">&lt;<a href="mailto:tess.parker@monash.edu" target="_blank">tess.parker@monash.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi -<br><br></div>I would like to dynamically assign the variable name when writing output to a netcdf file. The attached script returns an error message, although the file does seem to write out the correctly named variable with values? Can you suggest a reason for the error message? - I think it may be associated with the coordinate variables, but I&#39;m not sure why this should be.<br><br></div><div>Thanks as always for your help!<br></div><div><br></div><b>NCL SCRIPT:</b><br>****************<br><br>load &quot;$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/gsn_code.ncl&quot;<br>load &quot;$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/gsn_csm.ncl&quot;<br>load &quot;$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/contributed.<wbr>ncl&quot;<br>load &quot;$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/contrib/ut_string.<wbr>ncl&quot;<br>;/Calc_seasonal_means_Jasmin.<wbr>ncl<br><br>begin<br>; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<wbr>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<wbr>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<wbr>xxxxxxxxxx<br><br>data_dir = &quot;/badc/ecmwf-era-interim/data/<wbr>gg/&quot;<br><br>years         = ispan(1979,2015,1)<br>clim_years    = years<br>seas_len      = 3<br>months        = ispan(1,12,1)<br>month_string  = new(12,string)<br>do aa = 0,11<br>   if(months(aa).lt.10) then<br>      month_string(aa) = &quot;0&quot;+months(aa)<br>   else<br>      month_string(aa) = &quot;&quot;+months(aa)<br>   end if<br>end do<br>month_names  = (/ &quot;Jan&quot;, &quot;Feb&quot;, &quot;Mar&quot;, &quot;Apr&quot;, &quot;May&quot;, &quot;Jun&quot;, &quot;Jul&quot;, &quot;Aug&quot;, &quot;Sep&quot;, &quot;Oct&quot;, &quot;Nov&quot;, &quot;Dec&quot; /)<br>month_array  = (/&quot;J&quot;,&quot;F&quot;,&quot;M&quot;,&quot;A&quot;,&quot;M&quot;,&quot;J&quot;,&quot;J&quot;,<wbr>&quot;A&quot;,&quot;S&quot;,&quot;O&quot;,&quot;N&quot;,&quot;D&quot;/)<br><br>season       = (/ (/12,1,2/),(/3,4,5/),(/6,7,8/)<wbr>,(/9,10,11/) /)<br>i_season     = season-1<br>season_names = (/ &quot;DJF&quot;,&quot;MAM&quot;,&quot;JJA&quot;,&quot;SON&quot;/)<br><br>input_var     = &quot;Z&quot;<br>input_lev     = 850<br>input_dir     = &quot;ap&quot;         ;ap, as, at, av<br><br>file_out    = True<br>out_file    = &quot;&quot;+input_var+&quot;_<a href="http://seasonal_means_1979_2015.nc" target="_blank">seasonal_means_<wbr>1979_2015.nc</a>&quot;<br>output_var  = str_lower(input_var)<br><br>if (file_out) then<br>   system(&quot;rm -f &quot;+out_file)<br>   ncdf = addfile(out_file, &quot;c&quot;)<br>end if<br><br>;; Test file for data dimensions<br>;;============================<wbr>==<br><br>test_file = systemfunc(&quot;ls &quot;+data_dir+input_dir+&quot;/1979/<wbr>01/01/<a href="http://ggap197901010000.nc" target="_blank">ggap197901010000.nc</a>&quot;)<br>testf     = addfile(test_file,&quot;r&quot;)<br>test_data = testf-&gt;$input_var$(:,{input_<wbr>lev},::-1,:)<br>test_dims = dimsizes(test_data)<br>printVarSummary(test_data)<br>print(test_dims)<br><br>data_monthly_mean           = new((/12,test_dims(1),test_<wbr>dims(2)/),float)<br>data_monthly_mean!0         = &quot;month&quot;<br>data_monthly_mean!1         = &quot;latitude&quot;<br>data_monthly_mean!2         = &quot;longitude&quot;<br>data_monthly_mean&amp;latitude  = test_data&amp;latitude<br>data_monthly_mean&amp;longitude = test_data&amp;longitude<br>printVarSummary(data_monthly_<wbr>mean)<br><br>;; Read in 6-hourly data and construct monthly means<br>;;============================<wbr>======================<br><br>do jj = 0, 1;dimsizes(months)-1<br>   in_files = systemfunc(&quot;ls &quot;+data_dir+input_dir+&quot;/19{79,<wbr>80}/&quot;+month_string(jj)+&quot;/*/*.<wbr>nc&quot;)<br>   ;in_files = systemfunc(&quot;ls &quot;+data_dir+input_dir+&quot;/*/&quot;+<wbr>month_string(jj)+&quot;/*/*.nc&quot;)<br>   printVarSummary(in_files)<br>   print(in_files)<br>   inf = addfiles(in_files,&quot;r&quot;)<br>   ListSetType(inf,&quot;cat&quot;)<br>   data = inf[:]-&gt;$input_var$(:,{input_<wbr>lev},::-1,:)<br>   printVarSummary(data)<br>   data_monthly_mean(jj,:,:) = dim_avg_n(data,0)<br>   delete([/in_files,inf,data/])<br>end do<br><br>printVarSummary(data_monthly_<wbr>mean)<br><br>data_seasonal_clim           = new((/4,test_dims(1),test_<wbr>dims(2)/),float)<br>data_seasonal_clim!0         = &quot;season&quot;<br>data_seasonal_clim!1         = &quot;latitude&quot;<br>data_seasonal_clim!2         = &quot;longitude&quot;<br>data_seasonal_clim&amp;season    = season_names<br>data_seasonal_clim&amp;latitude  = test_data&amp;latitude<br>data_seasonal_clim&amp;longitude = test_data&amp;longitude<br><br>printVarSummary(data_seasonal_<wbr>clim)<br><br>do ns = 0,3<br>   data_seasonal_clim(ns,:,:) = dim_avg_n(data_monthly_mean(i_<wbr>season(ns,:),:,:),0)<br>end do<br><br>printVarSummary(data_seasonal_<wbr>clim)<br><br>if (file_out) then<br>   varname = output_var+&quot;_seasonal_clim&quot;<br>   print(varname)<br>   ncdf-&gt;$varname$ = data_seasonal_clim<br>end if<br><br>;*********************<br>end<br><br></div><b>OUTPUT:</b><br><div>***********<br></div><div>[snip]<br></div><div>Variable: data<br>Type: float<br>Total Size: 119537664 bytes<br>            29884416 values<br>Number of Dimensions: 3<br>Dimensions and sizes:    [t | 228] x [latitude | 256] x [longitude | 512]<br>Coordinates: <br>            t: [ 0..393.75]<br>            latitude: [-89.46294..89.46294]<br>            longitude: [ 0..359.2969]<br>Number Of Attributes: 13<br>  p :    850<br>  source :    GRIB data<br>  name :    Z<br>  title :    Geopotential<br>  date :    01/02/79<br>  time :    00:00<br>  long_name :    Geopotential<br>  standard_name :    geopotential<br>  units :    m**2 s**-2<br>  missing_value :    2e+20<br>  _FillValue :    2e+20<br>  valid_min :    -4084.883<br>  valid_max :    487005.9<br><br>Variable: data_monthly_mean<br>Type: float<br>Total Size: 6291456 bytes<br>            1572864 values<br>Number of Dimensions: 3<br>Dimensions and sizes:    [month | 12] x [latitude | 256] x [longitude | 512]<br>Coordinates: <br>            latitude: [-89.46294..89.46294]<br>            longitude: [ 0..359.2969]<br>Number Of Attributes: 1<br>  _FillValue :    9.96921e+36<br><br>Variable: data_seasonal_clim<br>Type: float<br>Total Size: 2097152 bytes<br>            524288 values<br>Number of Dimensions: 3<br>Dimensions and sizes:    [season | 4] x [latitude | 256] x [longitude | 512]<br>Coordinates: <br>            season: [DJF..SON]<br>            latitude: [-89.46294..89.46294]<br>            longitude: [ 0..359.2969]<br>Number Of Attributes: 1<br>  _FillValue :    9.96921e+36<br><br>Variable: varname<br>Type: string<br>Total Size: 8 bytes<br>            1 values<br>Number of Dimensions: 1<br>Dimensions and sizes:    [1]<br>Coordinates: <br>(0)    z_seasonal_clim<br>fatal:[&quot;NclFile.c&quot;:432]:<wbr>FileAddVar: an error occurred while adding a variable to a file, check to make sure data type is supported by the output format<br>fatal:[&quot;Execute.c&quot;:8575]:<wbr>Execute: Error occurred at or near line 110 in file Calc_seasonal_means_Jasmin.ncl<br><br><div><b>NCL_FILEDUMP:</b><br>*********************<br></div><div><br>ncl_filedump Z_seasonal_means_1979_2015.nc <br><br>Variable: f<br>Type: file<br>filename:    Z_seasonal_means_1979_2015<br>path:    Z_seasonal_means_1979_2015.nc<br>   file global attributes:<br>   dimensions:<br>      season = 4<br>      latitude = 256<br>      longitude = 512<br>   variables:<br>      float z_seasonal_clim ( season, latitude, longitude )<br>         _FillValue :    9.96921e+36<span class="HOEnZb"><font color="#888888"><br><br><br clear="all"><div><div><div><div><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>-- <br>Tess Parker<br>Associate Researcher<br>School of Earth, Atmosphere and Environment<br>Room 225, Building 28<br></div><div>9 Rainforest Walk<br></div><div>Monash University, Clayton VIC 3800<br></div><br></div></div></div></div></div></div></div>
</div></div></div></font></span></div></div></div>
<br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>