Re: How to use write_matrix function to output table separated with comma

From: Dave Allured - NOAA Affiliate <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Mon Jan 21 2013 - 15:47:15 MST

write_matrix does not support non-numeric characters or strings in
output. Example 2 in the new write_table function in NCL 6.1.0 is
probably what you want. You could also do your own line formatting,
which will work with older NCL versions:

outfile = "out.txt"
x = (/ (/ 4.35, 4.36, 9.73, 4.91 /), \
       (/ 4.39, 4.66, -5.84, 4.59 /), \
       (/ 0.27, 3.77, 0.89, -3.09 /) /)

nrows = dimsizes (x(:,0))
lines = new (nrows, string)

do i = 0, nrows-1
  lines(i) = str_concat (sprintf ("%7.2f,", x(i,:)))
end do

asciiwrite (outfile, lines)

To conserve space, you can remove all spaces between numbers by
changing the format string to "%0.2f,". This is standard CSV format
as used by spreadsheet software. For single space between numbers,
use " %0.2f,".

--Dave

On Sat, Jan 19, 2013 at 3:51 PM, Guangshan Chen <gchen9@gmail.com> wrote:
> Dear all,
>
> I would like to use write_matrix function to output a table as the following:
>
> 4.35, 4.36, 9.73, 4.91, 1.77, -0.63, -4.29,
> 4.39, 4.66, -5.84, 4.59, 3.68, -14.12, 0.07,
> 0.27, 3.77, 0.89, -3.09, 5.08, -2.51, 5.85,
> -3.35, -1.66, 8.46, 7.55, 0.14, 1.76, 0.87,
> -6.90, 4.06, 10.39, 4.56, -5.63, -1.43, 8.65,
>
> This table is almost same as the example 1b (http://www.ncl.ucar.edu/Document/Functions/Built-in/write_matrix.shtml), except that there is a comma "," after each value.
>
> If you have any clue, please let me know.
> Thanks.
>
> Guangshan
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jan 21 15:47:25 2013

This archive was generated by hypermail 2.1.8 : Wed Jan 23 2013 - 20:38:31 MST