# Re: 'string parsing'

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed Oct 19 2011 - 21:04:35 MDT

As indicated in NCL documentation, there is no 'else if' or 'elseif'

Also, as indicated by the comment, the str_get_field return strings
You can *not* perform an addition with a string value.

ncl 0> x = "15"
ncl 1> x = x+1
ncl 2> print(x) ===> 151 ... the + acts to concatenate a string
ncl 3> y = "15"
ncl 4> y = toint(y) +1 ===> 16 on right hand side; string "16" on left
ncl 5> print(y)

For less confusion step over each element.
==============================================

[SNIP]
mn = str_get_field(ts, 5, delim)

nts = dimsizes(ts)
do nt=0,nts-1
if (toint(mn(nt)) .le. 30) then
mn(nt) = "00"
else
mn(nt) = "00"
hhi = toint(hh(nt))+1 ; convert to integer
if (hhi .eq. 24) then
hh(nt) = "00"
ddi = toint(dd(nt))+1
if (ddi.eq. 32) then
dd(nt) = "1"
mmi = toint(mm(nt))+1
mm(nt) = tostring(mmi)
end if
end if
end if

hhi = toint(hh(nt))
ddi = toint(dd(nt))

if (hhi.le. 8) then
hhi = hhi-8
else
if (hhi .le. 8 .and. ddi .ne. 1) then
hhi = hhi+24-8
ddi = ddi-1
else
if (hhi .le. 8 .and. ddi .eq. 1) then
hhi = hhi+24-8
dd(nt) = "31"
mmi = mmi-1
mm(nt) = tostring(mmi)
end if
end if
end if
end do

On 10/19/11 8:21 PM, cnl88 wrote:
> ;************************************************
> ;************************************************
> begin
> ts = (/ "3-31-11 23:00" \
> , "3-31-11 23:05" \
> , "3-31-11 23:10" \
> , "3-31-11 23:15" \
> , "3-31-11 23:20" \
> , "3-31-11 23:25" \
> , "3-31-11 23:30" \
> , "3-31-11 23:35" \
> &nb sp; , "3-31-11 23:40" \
> , "3-31-11 23:45" \
> , "3-31-11 23:50" /)
> delim = "- :"
> tsfc = str_fields_count(ts, delim)
> print(" number of fields: tsfc="+tsfc(0))
> mm = str_get_field(ts, 1, delim) ; array of strings
> dd = str_get_field(ts, 2, delim)
> yy = str_get_field(ts, 3, delim)
> hh = str_get_field(ts, 4, delim)
> mn = str_get_field(ts, 5, delim)
>
> if(mn .le. 30) then
> mn =00
> else
> mn=00
> hh=hh+1
> else if(hh .eq. 24) then
> hh=00
> dd=dd+1
> else if(dd .eq. 32) then
> dd =1
> mm=mm+1
> end if
> if (hh .le. 8)then
> hh=hh-8
> else if(hh .le. 8 .and. dd .not. 1)then
> hh=hh+24-8
> dd=dd-1
> else if(hh .le. 8 .and. dd .eq. 1)then
> hh=hh+24-8
> dd=31
> mm=mm-1
> end if
> print(mm+" "+dd+" "+yy+" "+hh+" "+mn)
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Oct 19 21:04:41 2011

This archive was generated by hypermail 2.1.8 : Mon Oct 24 2011 - 09:29:35 MDT