Re: ascii output problem

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Fri, 10 Nov 2006 07:12:33 -0700 (MST)

> i need to write a 2d(2 x 3) array to a ascii file which
type is "string" like below format :
>
> abc efg hij
> klm mop env
>
> i would like to use a function like write_matrix() ,but it can't output type of "string"
>
> any suggestion ?
-----------------------------------

Writing arrays of strings to a file is a definite weak point of NCL.

For your case, there is an "end-around" solution:

ncl 0> s = new ( (/2,3/), "string")
ncl 2> s(0,0) = "abc"
ncl 3> s(0,1) = "efg"
ncl 4> s(0,2) = "hij"
ncl 5> s(1,0) = "klm"
ncl 6> s(1,1) = "nop"
ncl 7> s(1,2) = "qrs"

ncl 8> S0 = s(0,0)+" "+s(0,1)+" "+s(0,2)
ncl 9> S1 = s(1,0)+" "+s(1,1)+" "+s(1,2)

ncl 10> S = (/ S0,S1 /)
ncl 11> print(S)

Variable: S
Type: string
Total Size: 16 bytes
            2 values
Number of Dimensions: 1
Dimensions and sizes: [2]
Coordinates:
(0) abc efg hij
(1) klm nop qrs

ncl 12> asciiwrite("jerry.txt", S )
==================================

The file "jerry.txt" will contain:

abc efg hij
klm nop qrs

Good luck
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Nov 10 2006 - 07:12:33 MST

This archive was generated by hypermail 2.2.0 : Thu Nov 16 2006 - 13:32:38 MST