<div dir="ltr">This omits the double loop.  It probably runs faster if the array is large.  This also omits leading spaces (%0.1f), because they are not usually wanted with tab formatted text files.<div><br></div><div><span style="font-size:14px">  do nr=0,nrow-1</span><br style="font-size:14px"><span style="font-size:14px">        TabData(nr+1) = str_join (sprintf("%0.1f",x(nr,:)))</span><br style="font-size:14px"><span style="font-size:14px">  end do</span><br></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">--Dave</span></div><div><span style="font-size:14px"><br></span></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 24, 2018 at 5:18 PM, Dennis Shea <span dir="ltr"><<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>The 'write_matrix' only handles numeric data types. No characters.<br><br>--<br>   diro  = "./"<br>   filo  = "example.txt"<br>   ptho  = diro +filo<br>  <br>;---Bogus data<br>   nrow  = 5<br>   ncol  = 7<br>   x     = new((/nrow,ncol/),float, -999.9)<br>   x     = 9.9<br>  <br>;---Tab character<br>   tab = str_get_tab()<br>  <br>;---Array to hold data; Initialize<br>   NROW       = nrow+1<br>   TabData    = new( NROW, "string") ; , "No_FillValue")  ; extra 'row' for title<br>   TabData    = ""<br>  <br>;---First a title (optional)<br>   TabData(0) = "                         Title                        "<br>  <br>;---Loop over ech row (line) and appended values<br>   do nr=0,nrow-1<br>     do nc=0,ncol-1<br>        TabData(nr+1) = TabData(nr+1) + tab + sprintf("%5.1f",x(nr,nc)) ; append<br>     end do<br>   end do<br>  <br>;---Create the file<br>   system("/bin/rm -f "+ptho)<br>   asciiwrite(ptho, TabData)<br><br></div>++++++++ OUTPUT ++++++++++++++<br><br>                         Title                        <br>          9.9     9.9     9.9     9.9     9.9     9.9     9.9<br>          9.9     9.9     9.9     9.9     9.9     9.9     9.9<br>          9.9     9.9     9.9     9.9     9.9     9.9     9.9<br>          9.9     9.9     9.9     9.9     9.9     9.9     9.9<br>          9.9     9.9     9.9     9.9     9.9     9.9     9.9<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 23, 2018 at 8:52 PM, wen <span dir="ltr"><<a href="mailto:wenguanhuan@163.com" target="_blank">wenguanhuan@163.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;color:#000000;font-size:10px;font-family:Arial"><div>Hi Dennis,</div><div>  Thank you for help. I have check the suggested method. It didn't work. I came up with  error message. Following is the ncl code and error message. Do you have any other idea?</div><div><br></div><div> <span style="font-size:10px">load "$NCARG_ROOT/lib/ncarg/nclscri<wbr>pts/csm/gsn_code.ncl"</span></div><div><span style="font-size:10px">load "$NCARG_ROOT/lib/ncarg/nclscri<wbr>pts/csm/gsn_csm.ncl"</span></div><div><span style="font-size:10px">load "$NCARG_ROOT/lib/ncarg/nclscri<wbr>pts/csm/contributed.ncl"</span></div><div><br></div><div>begin</div><div><span style="font-size:10px"></span>x = new((/5,5/),float)</div><div><span style="font-size:10px">x = 9.9</span></div><div>opt = True</div><div><span style="font-size:10px">opt@fout = "test.txt"</span></div><div><span style="font-size:10px">opt@title  = "Normal"</span></div><div><span style="font-size:10px">tab = str_get_tab()</span></div><div><span style="font-size:10px">fmt = "5("+tab+",f4.1)"</span></div><div><span style="font-size:10px">write_matrix (x, fmt , opt)</span></div><div> end</div><div><span style="white-space:pre-wrap;font-size:10px">        </span></div><div><br></div><div> <span style="font-size:10px">"writematrix.f", line 110: 1525-078 An extra comma was found in a format specification.  The program will recover by ignoring the extra comma.</span></div><div><span style="font-size:10px">"writematrix.f", line 110: 1525-078 An extra comma was found in a format specification.  The program will recover by ignoring the extra comma.</span></div><div><span style="font-size:10px">"writematrix.f", line 110: 1525-078 An extra comma was found in a format specification.  The program will recover by ignoring the extra comma.</span></div><div><span style="font-size:10px">"writematrix.f", line 110: 1525-078 An extra comma was found in a format specification.  The program will recover by ignoring the extra comma.</span></div><div><span style="font-size:10px">"writematrix.f", line 110: 1525-078 An extra comma was found in a format specification.  The program will recover by ignoring the extra comma.</span></div><span><br><div style="zoom:1">--<br><div>Best regards,</div><div>Guanhuan Wen</div><div style="clear:both"></div></div><div id="m_-7546620049120663406m_287126331858172027divNeteaseMailCard"></div><br></span><div><div class="m_-7546620049120663406h5">At 2018-04-24 00:43:52, "Dennis Shea" <<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>> wrote:<br> <blockquote id="m_-7546620049120663406m_287126331858172027isReplyContent" style="PADDING-LEFT:1ex;MARGIN:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid"><div dir="ltr"><div><div><a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/str_get_tab.shtml" target="_blank">https://www.ncl.ucar.edu/Docum<wbr>ent/Functions/Built-in/str_<wbr>get_tab.shtml</a><br><br></div><b>UNTESTED</b>:  Lets say you want 10 numbers for each row with all numbers preceded by a <b>tab.<br></b></div><b>Note: </b><br><dl><dt><i>fout</i>
</dt><dd>String specifying the output file name. If not present, the data
is sent to standard out. <br></dd><dd><b>The maximum length of <i>fout</i> is 96
characters.</b></dd></dl><p>I think the fortran character variable is set at 96<br></p><b></b><div><b>---<br></b><div><pre><span style="font-family:arial,helvetica,sans-serif">tab = <strong>str_get_tab</strong>()<br></span></pre><pre><span style="font-family:arial,helvetica,sans-serif">fmt = </span>"10("+tab+",f7.1)"   ; clarity<br></pre><pre>print("fmt="+fmt)<br></pre><pre>opt = True<br></pre><pre>opt@fout "./TEXT_with_TAB"        ; "./test/text_with_tab/"<br></pre><pre>system("/bin/rm -f "+opt@fout)    ; rm any pre-existing file</pre><pre><span style="font-family:arial,helvetica,sans-serif"></span></pre>write_matrix (x,  fmt, False)<br><br></div><div>Let ncl-talk know if this works.<br><br></div><div>THX<br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 22, 2018 at 8:20 PM, wen <span dir="ltr"><<a href="mailto:wenguanhuan@163.com" target="_blank">wenguanhuan@163.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;color:#000000;font-size:10px;font-family:Arial"><div>Hi all,</div><div>    I want to write a 2 dimensional data into a file using function write_matrix. I expect to separate data with character tab. How can I realize that?  Hope you can help. Thank you!</div><br><div style="zoom:1">--<br><div>Best regards,</div><div>Guanhuan Wen</div></div></div></blockquote></div></div></blockquote></div></div></div></blockquote></div></div></blockquote></div></div></div>