[ncl-talk] bar charts (error in the loop)
Mary Haley
haley at ucar.edu
Thu Dec 27 08:57:11 MST 2018
Amal,
The error message is telling you what the problem is:
fatal:Assignment type mismatch, right hand side can't be coerced to type
of left hand side
This is telling you that the variable you have on the left side of the "="
sign is not of the correct type of the calculation being done on the right
side. Here's what you have:
data(n,0) = (/"y_a"+n/)
data(n,1) = (/"y_b","+n"/)
data(n,2) = (/"y_c","+n"/)
On the right side of this equation, you are appending an integer to a
string, which is going to result in a string. The type of "data" however,
was defined as a float a few lines above:
data = new((/28,3/),"float")
I think I see what you are trying to do, however. You have variables
called y_a1, y_a2, etc defined earlier in the code, and you want to put
these into "data". The way you are doing is not going to work, however. You
would have to list out the variables by hand:
data(0,0) = y_a1
data(0,1) = y_b1
data(0,2) = y_c1
data(010) = y_a2
data(1,1) = y_b2
data(1,2) = y_c2
I don't have time to look at your code in detail to understand the full
scope of it, but the best thing to do is figure out how to put all of these
calculations inside a do loop, instead of calculating all 28 quantities
individually.
For example: (THIS IS UNTESTED AND IS MEANT AS AN EXAMPLE ONLY):
dir = /home/netapp-clima/scratch/asalhi/mask/GSA01/"
files1 = systemfunc("ls " + dir + "dox*_med_0-52_timemean.nc")
files2 = systemfunc("ls " + dir + "dox*_med_52-101_timemean.nc")
files3 = systemfunc("ls " + dir + "dox*_med_101-209_timemean.nc")
nfiles = dimsizes(files1)
data = new((/nfiles,3/),"float")
do nf = 0,nfiles-1
a = addfile(files1(nf),"r")
b = addfile(files2(nf),"r")
c = addfile(files3(nf),"r")
dox_a = a->dox
dox_b = b->dox
dox_c = c->dox
dox_ave_a = dim_avg_wgt_n_Wrap(dox_a, (/dox_a&lev/), 0, 1 )
dox_ave_b = dim_avg_wgt_n_Wrap(dox_b, (/dox_b&lev/), 0, 1 )
dox_ave_c = dim_avg_wgt_n_Wrap(dox_c, (/dox_c&lev/), 0, 1 )
data(nf,0) = dim_avg_n_Wrap(dox_ave_a,(/1,2/))
data(nf,1) = dim_avg_n_Wrap(dox_ave_b,(/1,2/))
data(nf,2) = dim_avg_n_Wrap(dox_ave_c,(/1,2/))
. . .
end do
Hopefully this helps you get started...
--Mary
On Mon, Dec 24, 2018 at 2:58 AM Amal Inge <amalingenieur89 at gmail.com> wrote:
> Dear NCL experts,
>
> i'm trying to plot bar charts for a variable 4 dimension for 28 subareas,
> and for each subarea i have 3 depths (3 ncfiles).
> i had this error:
> fatal:Assignment type mismatch, right hand side can't be coerced to type
> of left hand side
> fatal:["Execute.c":8575]:Execute: Error occurred at or near line 587 in
> file dox_gsa.ncl
> i'm not sure if i did well the loop, Could you help me to correct it
> please?
> here is the variable and the script in attachement
>
> many thanks
> amal
> netcdf dox01_med_0-52_timemean {
> dimensions:
> lon = 670 ;
> lat = 253 ;
> lev = 13 ;
> time = UNLIMITED ; // (1 currently)
> bnds = 2 ;
> variables:
> float lon(lon) ;
> lon:standard_name = "longitude" ;
> lon:long_name = "longitude" ;
> lon:units = "degrees_east" ;
> lon:axis = "X" ;
> float lat(lat) ;
> lat:standard_name = "latitude" ;
> lat:long_name = "latitude" ;
> lat:units = "degrees_north" ;
> lat:axis = "Y" ;
> float lev(lev) ;
> lev:standard_name = "depth" ;
> lev:long_name = "depth" ;
> lev:units = "m" ;
> lev:positive = "down" ;
> lev:axis = "Z" ;
> lev:_CoordinateZisPositive = "down" ;
> lev:_CoordinateAxisType = "Height" ;
> double time(time) ;
> time:standard_name = "time" ;
> time:long_name = "time" ;
> time:bounds = "time_bnds" ;
> time:units = "seconds since 1970-01-01 00:00:00" ;
> time:calendar = "standard" ;
> time:axis = "T" ;
> double time_bnds(time, bnds) ;
> float dox(time, lev, lat, lon) ;
> dox:standard_name =
> "mole_concentration_of_dissolved_molecular_oxygen_in_sea_water" ;
> dox:long_name = "Mole concentration of Dissolved Molecular Oxygen in sea
> water" ;
> dox:units = "millimol m-3" ;
> dox:_FillValue = 1.e+20f ;
> dox:missing_value = 1.e+20f ;
> dox:_ChunkSizes = 1, 22, 84, 161 ;
>
> // global attributes:
> :CDI = "Climate Data Interface version 1.9.0 (http://mpimet.mpg.de/cdi)" ;
> :Conventions = "None" ;
> :history = "Thu Dec 20 13:29:55 2018: cdo timmean dox01_med_0-52.nc
> dox01_med_0-52_timemean.nc" ;
> :creation_date = "Tue Dec 4 23:27:50 CET 2018" ;
> :source_file = "dox_med_0-52.nc" ;
> :title = "NCL Efficient Approach to netCDF Creation" ;
> :CDO = "Climate Data Operators version 1.9.0 (http://mpimet.mpg.de/cdo)" ;
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> 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/20181227/c4a3acac/attachment.html>
More information about the ncl-talk
mailing list