[ncl-talk] reading a file and writing the output to an array
Dave Allured - NOAA Affiliate
dave.allured at noaa.gov
Wed May 12 09:19:10 MDT 2021
Ali, your code is trying to assign type double values to a type float
array. Float is lower precision than double. That error is a guard
against losing numeric precision when you try to automatically convert one
data type to another type with lower precision or smaller range. Some
languages allow you to do this, but not NCL. Please read this section in
the NCL manual.
http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclDataTypes.shtml#Coercion
I can think of several ways to fix this. One is to read the original array
as type float, rather than type double. I do not see any reason why you
chose to read the original ascii file as type double.
However, if there is a reason to read the original as type double, then you
could change "Array" to also be type double. Another approach would be to
use the type conversion function "tofloat" in the assignment in line 14.
On Tue, May 11, 2021 at 10:50 PM ali mughal via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:
>
> Dear Ncl community
>
> I have written a short script to read the file
> https://we.tl/t-T5PZMRFStX
> and write it to an array. I am having trouble at line 14 where I get the
> following error.
>
> filename = "Basecase.txt"
> nvar=24
> data = readAsciiTable(filename, nvar, "double", -1)
> temp=reshape(data,(/24,27090/))
>
> Array = new((/24,129,210/),float)
>
> do it = 0, nvar-1,24
> temp1=temp(it,:)
>
> temp2=reshape(temp1,(/129,210/))
>
> Array(:,:,it)=temp2
> end do
>
>
> *Error*
> fatal:Assignment type mismatch, right hand side can't be coerced to type
> of left hand side
> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 13 in
> file test2.ncl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210512/f3ef104c/attachment.html>
More information about the ncl-talk
mailing list