Re: str_split

From: Saji N Hameed <saji_at_nyahnyahspammersnyahnyah>
Date: Mon Nov 30 2009 - 23:04:36 MST

Hi Mark,

You uncovered a bug in that code. Could you replace the function named
string_to_array(org_str) with the following, please?
This function is defined just above "str_split". Note that you
need to use NCL version 5.1.1 or later, as I am using the built in
function "str_fields_count" in this version to get the number of
fields.

Thanks for letting me know about the problem..

saji

--
function string_to_array(org_str)
begin
  str=org_str
  if .not.isatt(str,"separator")
    str@separator=","
    cmd="echo "+str+" | tr [:blank:] ',' "
    str=systemfunc(cmd)
  end if
  if str@separator .eq. " "
    sep="\ "
  else
    sep=str@separator
  end if
  istr = stringtoint(str_fields_count(str,sep))
  str_arr=new((/istr/),"string")
  do i = 0, istr-1
    CMD="echo "+str+" | awk -F"
    CMD=CMD+sep+" '{print $"+(i+1)+"}'"
    str_arr(i)=systemfunc(CMD)
  end do
  return(str_arr)
end
* mark collier <Mark.Collier@csiro.au> [2009-11-30 09:57:35 +1100]:
> Hi Saji,
> I am trying your string tools until the next release of NCL.
> 
> If my strings are seperated by a "," then it works fine, if I put in
> " " as the delimeter, I can an error.
> 
> xxx="abc def ghi"
> yyy=str_split(xxx," ")
> print(yyy)
> 
> tr: missing operand after `\\n'
> Two strings must be given when translating.
> Try `tr --help' for more information.
> fatal:New: a zero or negative value has been passed in in the
> dimension size parameter
> 
> it could be a difference in our versions of tr?
> 
> Regards,
> Mark.
> 
-- 
Saji N. Hameed
APEC Climate Center          				
1463 U-dong, Haeundae-gu,                               +82 51 745 3951
BUSAN 612-020, KOREA                    		saji@apcc21.net
Fax: +82-51-745-3999
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Nov 30 23:04:05 2009

This archive was generated by hypermail 2.1.8 : Thu Dec 03 2009 - 09:53:22 MST