<div dir="ltr">Hi Daniel,<div><br></div><div>That&#39;s an excellent point. It looks like the function is designed to try and call a random file name with the &#39;echo tmp$$&#39; call, but that returns a single number for each shell. I assume if multiple sub-processes are being run from a single shell, this would cause the files to overlap.</div><div><br></div><div>However, since this function is in the contributed.ncl file, you can change it on your system as a temporary fix. Although NCL does have a rand() function, it is always seeded with the same numbers upon initialization of a new NCL process and therefore can be expected to produce predictable numbers with each call. You could try to use srand(x) or random_setallseed(x,y) with some component of the time, but for the sake of producing consistently unique numbers, I would recommend using a component of the date as the actual random number. </div><div><br></div><div>I&#39;ve used the nanosecond return from the UNIX date function, systemfunc(&quot;date +%N&quot;) in NCL, to get the job done. Producing a very large number of random numbers a day and up to five simultaneously and I have yet to have any issues with duplicate numbers. If you are using NCL on Mac OS X, you can get the same result by installing the GNU-compatible version of date, typically referenced as &quot;gdate&quot; in MacPort or Homebrew or similar UNIX-ish package manager.</div><div><br></div><div>Anyway, the fix you&#39;d be looking for is below. It&#39;s not particularly robust, but it should fix your problem while the developers might look to address this in the future. This can be used in place of the line</div><div><br></div><div>tmpfile = <span class="">systemfunc</span>(<span class="">&quot;echo tmp$$&quot;</span>) </div><div><br></div><div>near the end of the readAsciiTable function. This is line 9062 in <span style="color:rgb(0,0,0);font-family:courier;font-size:13.3333330154419px;line-height:16px">$NCARG_ROOT/lib/ncarg/nclscripts/csm/</span><a href="https://www.ncl.ucar.edu/Document/Functions/Contributed/contrib.shtml" style="font-size:13.3333330154419px;line-height:16px;margin:0px;padding:0px;text-decoration:none;color:rgb(133,45,133);font-family:verdana,sans-serif">contributed.ncl</a> if you&#39;re using version 6.2.1 and have write permissions in the directory where NCL is installed. If not, find the readAsciiTable function in the contributed.ncl file, copy it into a new file and make the changes. Then you can &quot;load&quot; the new file at the top of your script after your loading of the contributed.ncl file.</div>







<div><br></div><div>







<p class=""><font face="monospace, monospace">      tmpnum = <span class="">systemfunc</span>(<span class="">&quot;date +%N&quot;</span>)</font></p>
<p class=""><font face="monospace, monospace">      <span class="">if</span>(tmpnum<span class="">.eq.</span><span class="">&quot;N&quot;</span>)<span class="">then</span></font></p>
<p class=""><font face="monospace, monospace">        <span class="">delete</span>(tmpnum)</font></p>
<p class=""><font face="monospace, monospace"><span class="">        </span>srand<span class="">(</span>toint<span class="">(</span>systemfunc<span class="">(</span><span class="">&quot;date +%s&quot;</span><span class="">)))</span></font></p>
<p class=""><font face="monospace, monospace">        tmpnum = <span class="">rand</span>()</font></p>
<p class=""><font face="monospace, monospace">      <span class="">end</span> <span class="">if</span></font></p>
<p class=""><font face="monospace, monospace">      tmpfile = <span class="">&quot;tmp&quot;</span>+tmpnum</font></p><p class=""><font face="monospace, monospace"><br></font></p><p class=""><font face="arial, helvetica, sans-serif">Hope this has made sense. If not, feel free to reply back and include the list with questions. I&#39;m sure the developers will look at this a bit closer in the future, as making functions parallel-safe appears to be one of the things they are working on alongside the ongoing development.</font></p><p class=""><font face="arial, helvetica, sans-serif"><br></font></p><p class="">Kyle</p></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr">----------------------------------------<div>Kyle S. Griffin</div><div>Department of Atmospheric and Oceanic Sciences</div><div>University of Wisconsin - Madison</div><div>Room 1421</div><div>1225 W Dayton St, Madison, WI 53706</div><div>Email: <a href="mailto:ksgriffin2@wisc.edu" target="_blank">ksgriffin2@wisc.edu</a></div></div></div></div>
<br><div class="gmail_quote">On Tue, Mar 10, 2015 at 9:46 AM,  <span dir="ltr">&lt;<a href="mailto:Daniel.Leuenberger@meteoswiss.ch" target="_blank">Daniel.Leuenberger@meteoswiss.ch</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="DE-CH" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span lang="EN-US">Dear NCL Team,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">When running a large number of parallel NCL jobs using the readAsciiTable function (contributed.ncl) I realized that the function is not thread safe, e.g. may fail. The reason is that it writes a temporary ascii file
 and deletes it again at the end of the function. If now two parallel jobs want to write to the temporary file at exactly the same time, one is not allowed and will crash. One method to circumvent the problem would be to use a random number and/or the process
 ID in the file name of the temporary file.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Best regards<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Daniel Leuenberger</span></b><span lang="EN-US" style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Federal Department of Home Affairs FDHA</span><span lang="EN-US" style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><u></u><u></u></span></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Federal Office of Meteorology and Climatology MeteoSwiss</span></b><span lang="EN-US" style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">All about weather and climate, please visit our new website</span><span lang="EN-US" style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"><a href="http://www.meteoschweiz.admin.ch/web/en.html" title="Web" target="_blank"><span lang="EN-US" style="color:blue">www.meteoswiss.ch</span></a></span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">
 and </span><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"><a href="http://www.meteoswiss.admin.ch/home/services-and-publications/beratung-und-service/meteoswiss-app.html" title="Web" target="_blank"><span lang="EN-US" style="color:blue">MeteoSwiss
 App</span></a></span><span lang="EN-US" style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
</div>
</div>

<br>_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>