<div dir="ltr">Jiali Wang,<div><br></div><div>Here is efficient code that uses vector subscripting to select the desired values. This is untested. Give this a try:</div><div><br>a = addfile("200303101200.CHRTOUT_<wbr>DOMAIN3"+".nc","r")<br>st = a->streamflow<br>lat = a->latitude<br>lon = a->longitude<br>ord = a->order ;;do filter based on this number, we only want order>2<div><br></div><div>ind_valid = ind (ord(:) .gt. 2)</div><div><br></div><div>if (.not. ismissing (ind_valid(0))) then<br> system("/bin/rm -f <a href="http://simple.nc" target="_blank">simple.nc</a>")<br> ncdf = addfile("<a href="http://simple.nc" target="_blank">simple.nc</a>" ,"c")<br> ncdf->streamflow = st(ind_valid)<br> ncdf->lat = lat(ind_valid)<br> ncdf->lon = lon(ind_valid)</div><div><br>;;;;;;or output in txt format<br> opt = True<br> opt@fout = "foo.txt"<br> write_matrix(st(ind_valid), "10f7.2", opt)<br>end if<div><br></div><div>--Dave</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 15, 2017 at 3:54 PM, Wang, Jiali <span dir="ltr"><<a href="mailto:jialiwang@anl.gov" target="_blank">jialiwang@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div lang="EN-US">
<div class="m_-7689758543664951642gmail-m_7660315737739689073WordSection1">
<p class="MsoNormal">Dear NCL group,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I am having a similar question as this post <a href="https://www.ncl.ucar.edu/Support/talk_archives/2011/1499.html" target="_blank">
https://www.ncl.ucar.edu/Suppo<wbr>rt/talk_archives/2011/1499.<wbr>html</a> but unfortunately i didn’t get it..<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I have a 1D data set (station data) as shown below. I would like to filter out the lower orders (order smaller than 2). I do this using “where”, so I get lots of missing values for those stations with lower orders. But these values take
lots of space, so I want to get rid of them and output a much lighter data only for the stations with non-missing values. Below is what my data and my NCL script look like. Could you please take a look and advice? With my script I am still having all the
missing value in my output.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">ncdump -c 200303091200.CHRTOUT_DOMAIN3<u></u><u></u></p>
<p class="MsoNormal">netcdf \200303091200 {<u></u><u></u></p>
<p class="MsoNormal">dimensions:<u></u><u></u></p>
<p class="MsoNormal"> station = 3678397 ;<u></u><u></u></p>
<p class="MsoNormal"> time = 1 ;<u></u><u></u></p>
<p class="MsoNormal">variables:<u></u><u></u></p>
<p class="MsoNormal"> float latitude(station) ;<u></u><u></u></p>
<p class="MsoNormal"> latitude:long_name = "Station latitude" ;<u></u><u></u></p>
<p class="MsoNormal"> latitude:units = "degrees_north" ;<u></u><u></u></p>
<p class="MsoNormal"> float longitude(station) ;<u></u><u></u></p>
<p class="MsoNormal"> longitude:long_name = "Station longitude" ;<u></u><u></u></p>
<p class="MsoNormal"> longitude:units = "degrees_east" ;<u></u><u></u></p>
<p class="MsoNormal"> float streamflow(station) ;<u></u><u></u></p>
<p class="MsoNormal"> streamflow:units = "meter^3 / sec" ;<u></u><u></u></p>
<p class="MsoNormal"> streamflow:long_name = "River Flow" ;<u></u><u></u></p>
<p class="MsoNormal"> int order(station) ;<u></u><u></u></p>
<p class="MsoNormal"> order:long_name = "Strahler Stream Order" ;<u></u><u></u></p>
<p class="MsoNormal">=============<u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">a = addfile("200303101200.CHRTOUT_<wbr>DOMAIN3"+".nc","r")<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">st = a->streamflow<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">lat = a->latitude<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">lon = a->longitude<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">ord = a->order ;;do filter based on this number, we only want order>2<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">st1 = new(dimsizes(st),typeof(st))<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">lat1 = new(dimsizes(lat),typeof(lat))<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">lon1 = new(dimsizes(lon),typeof(lon))<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">st@_FillValue = -9999<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">st1 = where(ord .gt. 2, st, st@_FillValue)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">lat1 = where(ord .gt. 2, lat, st@_FillValue)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">lon1 = where(ord .gt. 2, lon, st@_FillValue)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">if (.not.all(ismissing(st1))) then ;;I think this “if” statement has some problem, but I am not sure what’s the right one should be..<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"> system("/bin/rm -f <a href="http://simple.nc" target="_blank">simple.nc</a>")
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"> ncdf = addfile("<a href="http://simple.nc" target="_blank">simple.nc</a>" ,"c")
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"> ncdf->streamflow = st1<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"> ncdf->lat = lat1<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"> ncdf->lon = lon1<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">;;;;;;or output in txt format<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"> opt = True<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"> opt@fout = "foo.txt"<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"> write_matrix(st1, "10f7.2", opt)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">end if<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">==============<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">Thanks!<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">Jiali Wang, Ph. D<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">Environmental Science Division<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">Argonne National Laboratory<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif">Tel: 630-252-2848<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:"Times New Roman",serif"><a href="http://www.evs.anl.gov/about-evs/staff/detail/index.cfm?/Wang/Jiali" target="_blank">http://www.evs.anl.gov/about-e<wbr>vs/staff/detail/index.cfm?/Wan<wbr>g/Jiali</a></span></p></div></div></blockquote></div></div></div></div></div>