Re: str_get_field function

From: Wei Huang <huangwei_at_nyahnyahspammersnyahnyah>
Date: Wed Mar 28 2012 - 08:25:35 MDT

Guo Zhang,

By put your data into a file and tried with str_get_field(…), and it shows the function works right.

The problem could be from your file, which in your file you have tab ('\t') in your file.
It looks like spaces, but really are tab.

You may try set your delimiter to " " (a 'tab', and a space), and then invoke str_get_field(strs, field, delimiters).
In NCL, you can also try:

tab = str_get_tab()
delimiters = tab + " "

to make delimiters are tab and space.

Regards,

Wei

huangwei@ucar.edu
VETS/CISL
National Center for Atmospheric Research
P.O. Box 3000 (1850 Table Mesa Dr.)
Boulder, CO 80307-3000 USA
(303) 497-8924

---------
cisl-huelva:/Users/huangwei/test/ncltest/ncl_xxxx 978 > cat tst.txt
winter min max mean
Rnet -15.40 -4.23 -9.80
H -24.37 -7.04 -12.84
LE -20.14 2.32 -8.30
G -0.11 0.43 0.14
Rnet 0.80 8.62 5.97
H -25.91 -9.00 -17.62
LE -16.02 2.50 -6.26
G 3.03 3.22 3.14
cisl-huelva:/Users/huangwei/test/ncltest/ncl_xxxx 979 > cat tst.ncl
 strs = asciiread("tst.txt", -1, "string")
 cols = str_get_field(strs(1:),2," ")

 print(strs)
 print(cols)

cisl-huelva:/Users/huangwei/test/ncltest/ncl_xxxx 980 > ncl tst.ncl
 Copyright (C) 1995-2012 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.1.0-beta
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.

Variable: strs
Type: string
Total Size: 72 bytes
            9 values
Number of Dimensions: 1
Dimensions and sizes: [9]
Coordinates:
Number Of Attributes: 1
  _FillValue : missing
(0) winter min max mean
(1) Rnet -15.40 -4.23 -9.80
(2) H -24.37 -7.04 -12.84
(3) LE -20.14 2.32 -8.30
(4) G -0.11 0.43 0.14
(5) Rnet 0.80 8.62 5.97
(6) H -25.91 -9.00 -17.62
(7) LE -16.02 2.50 -6.26
(8) G 3.03 3.22 3.14

Variable: cols
Type: string
Total Size: 64 bytes
            8 values
Number of Dimensions: 1
Dimensions and sizes: [8]
Coordinates:
(0) -15.40
(1) -24.37
(2) -20.14
(3) -0.11
(4) 0.80
(5) -25.91
(6) -16.02
(7) 3.03

On Mar 27, 2012, at 11:40 PM, Guo Zhang wrote:

> Hi,
> I'm trying to plot a bar chart uing example bar_13.ncl at http://www.ncl.ucar.edu/Applications/bar.shtml.
> It seems I got field 2 returning to colomn 3 using str_get_field function. Can anyone tell me how to fix it? Thanks.
>
> Guo Zhang
>
> My data is as below:
> winter
> min max mean
> Rnet -15.40 -4.23 -9.80
> H -24.37 -7.04 -12.84
> LE -20.14 2.32 -8.30
> G -0.11 0.43 0.14
>
> Rnet 0.80 8.62 5.97
> H -25.91 -9.00 -17.62
> LE -16.02 2.50 -6.26
> G 3.03 3.22 3.14
>
> 'do i=0,nmons-1
> do j=0,nmodels-1
> istart = ((nmodels+1)*i)+j+2 ; the +1 is the title
> do k=0,2
> data(i,j,k) = tofloat(str_get_field(lines(istart),k+2," "))
> print(data) ; print data here
> end do
> end do
> end do'
>
> fatal:tofloat: A bad value was passed to (string) tofloat, input strings must contain numeric digits, replacing with missing value
>
> Variable: data
> Type: float
> Total Size: 120 bytes
> 30 values
> Number of Dimensions: 3
> Dimensions and sizes: [2] x [5] x [3]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : 9.96921e+36
> (0,0,0) -4.23
> (0,0,1) -9.8
> (0,0,2) 9.96921e+36
> (0,1,0) -7.04
> (0,1,1) -12.84
> (0,1,2) 9.96921e+36
> (0,2,0) 2.32
> (0,2,1) -8.3
> (0,2,2) 9.96921e+36
> (0,3,0) 0.43
> (0,3,1) 0.14
> (0,3,2) 9.96921e+36
> (0,4,0) 9.96921e+36
> (0,4,1) 9.96921e+36
> (0,4,2) 9.96921e+36
> (1,0,0) 8.62
> (1,0,1) 5.97
> (1,0,2) 9.96921e+36
> (1,1,0) -9
> (1,1,1) -17.62
> (1,1,2) 9.96921e+36
> (1,2,0) 2.5
> (1,2,1) -6.26
> (1,2,2) 9.96921e+36
> (1,3,0) 3.22
> (1,3,1) 3.14
> (1,3,2) 9.96921e+36
> (1,4,0) 9.96921e+36
> (1,4,1) 9.96921e+36
> (1,4,2) 9.96921e+36
> fatal:Variable (base_plot) is undefined
> fatal:Execute: Error occurred at or near line 225 in file bar.ncl
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Mar 28 08:25:51 2012

This archive was generated by hypermail 2.1.8 : Mon Apr 09 2012 - 13:43:03 MDT