<div dir="ltr"><div dir="ltr"><div dir="ltr">Hello ncl-users.</div><div dir="ltr"><br></div><div dir="ltr">I'm converting a csv file in netcdf and apparently my script, although not very efficient (I'm a begginer) was working fine. But for some points it dindn't write correctly. I've checked everything and I supose the problem is converting string to float, but I can't figure out how can I solve this problem.</div><div dir="ltr"><br></div><div dir="ltr">I don't understand why it shows me a value like 42.6 but it is like it was 42.600002. It causes me trouble when I compare it with another variable equal to 42.6, it returns a false result. Also, it only happen to some values, like 42.6 (but not with 50.2) as you can see below.</div><div dir="ltr"><br></div><div dir="ltr">I've tried to use decimalPlaces, but it results the same.</div><div dir="ltr">I'd apreciate any information. Thanks in advance.</div><div dir="ltr"><br></div><div dir="ltr">uname-a: Linux Tower2 4.15.0-45-generic #48~16.04.1-Ubuntu SMP Tue Jan 29 18:03:48 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux</div><div dir="ltr"><br></div><div dir="ltr">Graziela.</div><div dir="ltr"><br></div><div dir="ltr">---</div><div dir="ltr">lines = asciiread("resultado.csv",-1,"string")</div><div dir="ltr">data = lines(1:) ; exclude line 0 header</div><div dir="ltr"><br></div><div dir="ltr">;xlon = decimalPlaces(tofloat(str_get_field(data,1,",")),1,True)</div><div dir="ltr">xlon=tofloat(str_get_field(data,1,","))</div><div dir="ltr"><br></div><div dir="ltr">xlon1 = new(600,"float",-999)</div><div dir="ltr">   do i=0,599</div><div dir="ltr">      xlon1(i)=xlon(i*8)+0.1</div><div dir="ltr">   end do</div><div dir="ltr"><br></div><div dir="ltr">print(xlon1(0:29))</div><div dir="ltr"><br></div><div dir="ltr">a=xlon1(23)-xlon1(24)</div><div dir="ltr">print(a)</div><div dir="ltr"><br></div><div dir="ltr">b=ind(xlon1(0:29).eq.-50.2)</div><div dir="ltr">c=ind(xlon1(0:29).eq.-42.6)</div><div dir="ltr">print(b)</div><div dir="ltr">print(c)</div><div dir="ltr"><br></div><div dir="ltr">----</div><div dir="ltr">labren@Tower2:~/Documentos/Produto3$ ncl teste.ncl </div><div dir="ltr"> Copyright (C) 1995-2015 - All Rights Reserved</div><div dir="ltr"> University Corporation for Atmospheric Research</div><div dir="ltr"> NCAR Command Language Version 6.3.0</div><div dir="ltr"> The use of this software is governed by a License Agreement.</div><div dir="ltr"> See <a href="http://www.ncl.ucar.edu/" target="_blank">http://www.ncl.ucar.edu/</a> for more details.</div><div dir="ltr"><br></div><div dir="ltr">Variable: xlon1 (subsection)</div><div dir="ltr">Type: float</div><div dir="ltr">Total Size: 120 bytes</div><div dir="ltr">            30 values</div><div dir="ltr">Number of Dimensions: 1</div><div dir="ltr">Dimensions and sizes:<span style="white-space:pre-wrap">       </span>[30]</div><div dir="ltr">Coordinates: </div><div dir="ltr">Number Of Attributes: 1</div><div dir="ltr">  _FillValue :<span style="white-space:pre-wrap">       </span>-999</div><div dir="ltr">(0)<span style="white-space:pre-wrap">      </span>-50.2</div><div dir="ltr">(1)<span style="white-space:pre-wrap">     </span>-50.2</div><div dir="ltr">(2)<span style="white-space:pre-wrap">     </span>-50.2</div><div dir="ltr">(3)<span style="white-space:pre-wrap">     </span>-50.2</div><div dir="ltr">(4)<span style="white-space:pre-wrap">     </span>-50.2</div><div dir="ltr">(5)<span style="white-space:pre-wrap">     </span>-50.2</div><div dir="ltr">(6)<span style="white-space:pre-wrap">     </span>-50.2</div><div dir="ltr">(7)<span style="white-space:pre-wrap">     </span>-50.2</div><div dir="ltr">(8)<span style="white-space:pre-wrap">     </span>-50.2</div><div dir="ltr">(9)<span style="white-space:pre-wrap">     </span>-50.2</div><div dir="ltr">(10)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(11)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(12)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(13)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(14)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(15)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(16)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(17)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(18)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(19)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(20)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(21)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(22)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(23)<span style="white-space:pre-wrap">    </span>-50.2</div><div dir="ltr">(24)<span style="white-space:pre-wrap">    </span>-42.6</div><div dir="ltr">(25)<span style="white-space:pre-wrap">    </span>-42.6</div><div dir="ltr">(26)<span style="white-space:pre-wrap">    </span>-42.6</div><div dir="ltr">(27)<span style="white-space:pre-wrap">    </span>-42.6</div><div dir="ltr">(28)<span style="white-space:pre-wrap">    </span>-42.6</div><div dir="ltr">(29)<span style="white-space:pre-wrap">    </span>-42.6</div><div dir="ltr"><br></div><div dir="ltr">Variable: a</div><div dir="ltr">Type: float</div><div dir="ltr">Total Size: 4 bytes</div><div dir="ltr">            1 values</div><div dir="ltr">Number of Dimensions: 1</div><div dir="ltr">Dimensions and sizes:<span style="white-space:pre-wrap">     </span>[1]</div><div dir="ltr">Coordinates: </div><div dir="ltr">Number Of Attributes: 1</div><div dir="ltr">  _FillValue :<span style="white-space:pre-wrap">        </span>-999</div><div dir="ltr">(0)<span style="white-space:pre-wrap">      </span>-7.599998</div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr">Variable: b</div><div dir="ltr">Type: integer</div><div dir="ltr">Total Size: 96 bytes</div><div dir="ltr">            24 values</div><div dir="ltr">Number of Dimensions: 1</div><div dir="ltr">Dimensions and sizes:<span style="white-space:pre-wrap">        </span>[24]</div><div dir="ltr">Coordinates: </div><div dir="ltr">(0)<span style="white-space:pre-wrap">     </span>0</div><div dir="ltr">(1)<span style="white-space:pre-wrap"> </span>1</div><div dir="ltr">(2)<span style="white-space:pre-wrap"> </span>2</div><div dir="ltr">(3)<span style="white-space:pre-wrap"> </span>3</div><div dir="ltr">(4)<span style="white-space:pre-wrap"> </span>4</div><div dir="ltr">(5)<span style="white-space:pre-wrap"> </span>5</div><div dir="ltr">(6)<span style="white-space:pre-wrap"> </span>6</div><div dir="ltr">(7)<span style="white-space:pre-wrap"> </span>7</div><div dir="ltr">(8)<span style="white-space:pre-wrap"> </span>8</div><div dir="ltr">(9)<span style="white-space:pre-wrap"> </span>9</div><div dir="ltr">(10)<span style="white-space:pre-wrap">        </span>10</div><div dir="ltr">(11)<span style="white-space:pre-wrap">       </span>11</div><div dir="ltr">(12)<span style="white-space:pre-wrap">       </span>12</div><div dir="ltr">(13)<span style="white-space:pre-wrap">       </span>13</div><div dir="ltr">(14)<span style="white-space:pre-wrap">       </span>14</div><div dir="ltr">(15)<span style="white-space:pre-wrap">       </span>15</div><div dir="ltr">(16)<span style="white-space:pre-wrap">       </span>16</div><div dir="ltr">(17)<span style="white-space:pre-wrap">       </span>17</div><div dir="ltr">(18)<span style="white-space:pre-wrap">       </span>18</div><div dir="ltr">(19)<span style="white-space:pre-wrap">       </span>19</div><div dir="ltr">(20)<span style="white-space:pre-wrap">       </span>20</div><div dir="ltr">(21)<span style="white-space:pre-wrap">       </span>21</div><div dir="ltr">(22)<span style="white-space:pre-wrap">       </span>22</div><div dir="ltr">(23)<span style="white-space:pre-wrap">       </span>23</div><div dir="ltr"><br></div><div dir="ltr">Variable: c</div><div dir="ltr">Type: integer</div><div dir="ltr">Total Size: 4 bytes</div><div dir="ltr">            1 values</div><div dir="ltr">Number of Dimensions: 1</div><div dir="ltr">Dimensions and sizes:<span style="white-space:pre-wrap">      </span>[1]</div><div dir="ltr">Coordinates: </div><div dir="ltr">Number Of Attributes: 1</div><div dir="ltr">  _FillValue :<span style="white-space:pre-wrap">        </span>-2147483647</div><div dir="ltr">(0)<span style="white-space:pre-wrap">       </span>-2147483647</div><div dir="ltr"><br></div><div>My csv file contain values like this:</div><div><br></div><div><div>xlon,ylat,ano,mes,direcao,v1,v2,v3,v4</div><div>-50.3,-30.4,2016,1,45,0,0.0020206556,0.0017961383</div><div>-50.3,-30.4,2016,1,90,0.0002245173,0.0004490346,0.0049393803,0.0246969017</div><div>-50.3,-30.4,2016,1,135,0.0011225864,0.0029187247,0.0114503817,0.0177368657</div><div>-50.3,-30.4,2016,1,180,0,0.0017961383,0.0038167939,0.0141445891 (...)</div></div></div></div>