<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">It is still not quite clear to me what you are trying to do.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">For example, why is the variable being called "pmask" on the file? The original variable name is "dox", and I see that you also used "oxygen", so wouldn't one of these be a better variable name?</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">You don't need a do loop in order to mask all the data across time steps.  Instead, create the 2D mask, and then you can apply this mask across your 4D dox variable using "conform_dims" to convert your 2D mask variable to a 4D mask variable:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">   pmask2d    = shapefile_mask_data(dox(0,0,:,:),shp_fname,opt)                      </font></div><div class="gmail_default"><font face="monospace, monospace">   pmask4d    = conform_dims(dox_dims,pmask2d,(/2,3/))</font></div><div class="gmail_default"><font face="monospace, monospace">   dox_masked = mask(dox,pmask4d,1)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div>You could also create pmask4d with one line, but it's not as readable:</div><div class="gmail_default"><br><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">   pmask4d = </font><span style="font-family:monospace,monospace">conform_dims(dox_dims,</span><span style="font-family:monospace,monospace">shapefile_mask_data(dox(0,0,:,:),shp_fname,opt)</span><span style="font-family:monospace,monospace">,(/2,3/))</span><span style="font-family:monospace,monospace">                      </span></div><div class="gmail_default"><font face="monospace, monospace">   dox_masked = mask(dox,pmask4d,1)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div>The dox_masked variable is now a 4D variable that you can write to a file. No looping required.  See attached script.</div><div class="gmail_default"><br></div><div class="gmail_default">--Mary</div><div class="gmail_default"><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Nov 29, 2018 at 11:18 AM Amal Inge <<a href="mailto:amalingenieur89@gmail.com">amalingenieur89@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Thank you so much Prof!!You understood me perfectly!<br></div><div><br></div><div>Last question, i made the loop just to add the time steps to the 2D mask and after i will concatenate them to have one nc file for all the time steps.</div><div>Is there another way to have directly ncfile without passing by the loop and having ncfile for each time step?</div><div>(this morning i made this ncfile attached but i didn't succeed to have the ncfile 4D)</div><div><br></div><div>thanks again</div><div>best regards<br></div></div><br><div class="gmail_quote"><div dir="ltr">Le jeu. 29 nov. 2018 à 18:10, Mary Haley <<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">In the future, it would help if you tell us what you mean by the files being wrong.  I had to run your script and look at different variables in order to determine what exactly was wrong.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">It looks your "pmask" variable is all missing in each of the output files.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">It gets calculated correctly with these lines:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><div class="gmail_default" style="font-size:small">;---Create masked data array                                                                                                                   </div><div class="gmail_default" style="font-size:small">   pmask = where(oxygen.eq.1,f,f@_FillValue)</div><div class="gmail_default" style="font-size:small">   copy_VarMeta(f,pmask)</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">But then later, before "pmask" is written to a NetCDF file, it is reset to a 4D array with missing values with this line:</div><div class="gmail_default" style="font-size:small"><br></div> pmask=new((/1,1,nlat,nlon/), float)</div><div class="gmail_default"><br></div><div class="gmail_default">pmask is never repopulated with values, and hence when it is written to the file it is all missing.</div><div class="gmail_default"><br></div><div class="gmail_default">I think what you meant to do was convert pmask to a 4D array, where time and depth each have one dimension, and then copy the 2D pmask to this new 4D pmask array, correct?</div><div class="gmail_default"><br></div><div class="gmail_default">If so, then instead of the "new" command, you should create a new variable, say "pmask4d", as follows:</div><div class="gmail_default"><br></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace"> pmask4d = reshape(pmask,(/1,1,nlat,nlon/))</font></div><div class="gmail_default"><font face="monospace, monospace"> copy_VarAtts(pmask,pmask4d)    ; IMPORTANT, YOU MAY WANT TO ADJUST SOME</font></div><div class="gmail_default"><font face="monospace, monospace">                                ; ATTRIBUTES BEFORE WRITING TO FILE</font></div><div class="gmail_default"><font face="monospace, monospace">  pmask4d!0         = "time"</font></div><div class="gmail_default"><font face="monospace, monospace">  pmask4d!1         = "depth"</font></div><div class="gmail_default"><font face="monospace, monospace">  pmask4d!2         = "latitude"</font></div><div class="gmail_default"><font face="monospace, monospace">  pmask4d!3         = "longitude"</font></div><div class="gmail_default"><font face="monospace, monospace">  pmask4d&time      = time</font></div><div class="gmail_default"><font face="monospace, monospace">  pmask4d&depth     = lev</font></div><div class="gmail_default"><font face="monospace, monospace">  pmask4d&latitude  = lat</font></div><div class="gmail_default"><font face="monospace, monospace">  pmask4d&longitude = lon</font></div></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">and then change "pmask" to "pmask4d" in all the code that follows that writes stuff to the file. For example:</div><div class="gmail_default" style="font-size:small"><br></div><font face="monospace, monospace">   filevardef(fout, "pmask"    ,typeof(pmask4d)  ,getvardims(pmask4d))</font></div><div dir="ltr"><font face="monospace, monospace"><br>   filevarattdef(fout,"pmask",pmask4d)      </font></div><div dir="ltr"><font face="monospace, monospace"> </font></div><div dir="ltr"><font face="monospace, monospace"><span class="gmail_default" style="font-size:small">   </span>fout->pmask      = (/pmask4d/)</font><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I've attached a modified version of your script.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">--Mary</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Nov 29, 2018 at 5:39 AM Amal Inge <<a href="mailto:amalingenieur89@gmail.com" target="_blank">amalingenieur89@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>i want to have a time series from an ncfile (<a href="http://bbio.nc" target="_blank">bbio.nc</a> attached) for each subarea of a shapefilen(pic and zip attached)</div><div>i tried the script attached newtest.ncl to do the mask and produce ncfile output for each time step</div><div>but i get  wrong ncfiles</div><div>could you help please?</div><div><br></div><div><br></div><div></div><div class="gmail_chip gmail_drive_chip" style="width:396px;height:18px;max-height:18px;background-color:rgb(245,245,245);padding:5px;color:rgb(34,34,34);font-family:arial;font-style:normal;font-weight:bold;font-size:13px;border:1px solid rgb(221,221,221);line-height:1"><a href="https://drive.google.com/file/d/1B0Y5bU6_hMcdYROmP4p-BJoGHUxo9FDH/view?usp=drive_web" style="display:inline-block;max-width:366px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-decoration:none;padding:1px 0;border:none" target="_blank"><img style="vertical-align:bottom;border:none" src="https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png"> <span dir="ltr" style="color:rgb(17,85,204);text-decoration:none;vertical-align:bottom">bbio.nc</span></a><img style="opacity:0.55;float:right;display:none"></div></div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">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/mailman/listinfo/ncl-talk</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div>