<div dir="ltr"><div>I think what is happening is, NCL does not understand the intent to synchronize the two subscript ranges.  It tries to run them independently, which means a 2621442 x 2621442 array.  Boom!</div><div><br></div><div>There might be an array syntax for this, but I can't think of one right now.  Synchronized ranges work well for separate terms in an expression, but I think not within a single 2+ dimensional subscript expression.  You might be stuck with that loop.  Just code that as compactly as possible, when N is large.  Or maybe, resort to an external helper function.</div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 11, 2022 at 8:11 PM Laura Fowler <<a href="mailto:laura@ucar.edu">laura@ucar.edu</a>> wrote:<br></div><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 dir="ltr"><div style="font-size:small">Hi Dave:</div><div style="font-size:small">Thanks for your reply. I did get the same segmentation fault (see below). I do not know what you mean by "replacement operator".</div><div style="font-size:small">Thanks,</div><div style="font-size:small">Laura</div><div style="font-size:small"><br></div><div style="font-size:small"><br></div><div>





<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,128);background-color:rgb(204,204,204)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">(0)<span style="white-space:pre-wrap"> </span>--- nCells<span>  </span>= 2621442</font></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,128);background-color:rgb(204,204,204)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">(0)<span style="white-space:pre-wrap"> </span>--- nLevels = 55</font></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,128);background-color:rgb(204,204,204)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">fatal:NclMalloc Failed:[errno=12]</font></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,128);background-color:rgb(204,204,204)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Segmentation fault (core dumped)</font></span></p></div><div style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 11, 2022 at 6:03 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:<br></div><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 dir="ltr"><div>Laura, I am not sure that will work.  But if it does, assign the result to a new variable, not a predefined one.  Or else use the replacement operator.  Try this, see if you get the expected result dimensions:<br><br>      pp = pres(:,kpbl(:))</div><div><br></div><div>Also, it is simply <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>.<br><br></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 11, 2022 at 7:06 PM Laura Fowler via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><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 dir="ltr"><div><div style="font-size:small"><font face="arial, sans-serif" size="1">Hello:</font></div><div style="font-size:small"><font face="arial, sans-serif" size="1">I have an integer array that includes the index of the PBL top (kpbl). I would like to get the pressure (press) corresponding to the index of the PBL top. A printVarSummary provides the following information:</font></div><div style="font-size:small"><br></div><div style="font-size:small"><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Variable: kpbl</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Type: integer</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Total Size: 10485768 bytes</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">            2621442 values</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Number of Dimensions: 1</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Dimensions and sizes:<span style="white-space:pre-wrap">    </span>[nCells | 2621442]</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Coordinates: </font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Number Of Attributes: 2</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">  units :<span style="white-space:pre-wrap">   </span>unitless</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">  long_name :<span style="white-space:pre-wrap">        </span>index level of PBL top</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><br></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Variable: pres</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Type: float</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Total Size: 576717240 bytes</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">            144179310 values</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Number of Dimensions: 2</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Dimensions and sizes:<span style="white-space:pre-wrap">        </span>[nCells | 2621442] x [nVertLevels | 55]</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Coordinates: </font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">Number Of Attributes: 3</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">  _FillValue :<span style="white-space:pre-wrap"> </span>9.96921e+36</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">  units :<span style="white-space:pre-wrap"> </span>hPa</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1"></font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">  long_name :<span style="white-space:pre-wrap">    </span>Pressure at layer midpoint</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1"><br></font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font face="arial, sans-serif"><font size="1">where nCells is the number of grid columns and nVertLevels is the number of vertical levels. Below is the loop that I would like to convert to a more compact array syntax:</font><font size="1"><br></font></font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font face="arial, sans-serif"><br></font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font face="arial, sans-serif" size="1">do n = 0,nCells-1</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font face="arial, sans-serif" size="1">   pp(n) = pres(n,kpbl(n))</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font face="arial, sans-serif" size="1">   print("--- n = "+n +" "+kpbl(n) +"  "+pres(n,kpbl(n)) +"  "+pp(n))</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font face="arial, sans-serif" size="1">end do</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><br></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><font size="1" face="arial, sans-serif">When I convert the loop above to the following array syntax (see below), I unfortunately get a "Segmentation Fault".</font></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">pp(:) = pres(:,kpbl(:))</font></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:14px;line-height:normal;font-family:Courier;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></p></div><div><p style="font-size:small;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;margin:0px;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">fatal:VarVarWrite: Number of dimensions on left hand side does not match right hand side</font></span></p><p style="font-size:small;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;margin:0px;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1">fatal:["Execute.c":8637]:Execute: Error occurred at or near line 207 in file plot.pressure.ncl</font></span></p><p style="font-size:small;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;margin:0px;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1"><br></font></span></p><p style="font-size:small;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;margin:0px;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1"><br></font></span></p><p style="font-size:small;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;margin:0px;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1"><span class="gmail_default" style="font-size:small"></span><span class="gmail_default">Can somebody help me figure this out. I would really appreciate it.</span></font></span></p><p style="font-size:small;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;margin:0px;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1"><span class="gmail_default">Thanks,</span></font></span></p><p style="font-size:small;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;margin:0px;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1"><span class="gmail_default">Laura</span></font></span></p><p style="font-size:small;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Courier;margin:0px;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font size="1"><span class="gmail_default"><br></span></font></span></p><p style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;margin:0px;color:rgb(0,0,0)"><font face="arial, sans-serif" size="1"><span style="font-variant-ligatures:no-common-ligatures"><span class="gmail_default">note: I posted the same email this morning, but to the address </span></span><a href="mailto:ncl-talk-request@ucar.edu" aria-label="ncl-talk-request@ucar.edu (From your Google Contacts)" style="text-decoration-line:none;color:rgb(60,64,67);overflow:hidden;text-overflow:ellipsis;white-space:nowrap" target="_blank">ncl-talk-request@ucar.edu</a>. Not sure which email to use for posts. Sorry about the double email message.</font></p></div></div><div><br></div><div dir="ltr"><div dir="ltr"><font face="arial, helvetica, sans-serif" color="#0000ff" style="background-color:rgb(255,255,255)">!-------------------------------------------------------------------------------------------------------------</font><div><font face="arial, helvetica, sans-serif" color="#0000ff" style="background-color:rgb(255,255,255)">Laura D. Fowler                                                                                       </font></div><div><font face="arial, helvetica, sans-serif" color="#0000ff" style="background-color:rgb(255,255,255)">Mesoscale and Microscale Meteorology Division (MMM)         </font></div><div><font face="arial, helvetica, sans-serif" color="#0000ff" style="background-color:rgb(255,255,255)">National Center for Atmospheric Research<br></font></div><div><font face="arial, helvetica, sans-serif" color="#0000ff" style="background-color:rgb(255,255,255)">P.O. Box 3000, Boulder CO 80307-3000</font></div><div><font face="arial, helvetica, sans-serif" color="#0000ff" style="background-color:rgb(255,255,255)"><br></font></div><div><font face="arial, helvetica, sans-serif" color="#0000ff" style="background-color:rgb(255,255,255)">e-mail: <a href="mailto:laura@ucar.edu" target="_blank">laura@ucar.edu</a></font></div><div><font face="arial, helvetica, sans-serif" color="#0000ff" style="background-color:rgb(255,255,255)">phone: 303-497-1628</font></div></div></div></div></blockquote></div></div></blockquote></div>
</blockquote></div></div>