Re: Using systemfunc and Unix date utility: problems with compound strings

From: Jonathan Vigh <vigh_at_nyahnyahspammersnyahnyah>
Date: Thu, 09 Mar 2006 11:11:41 -0700

Okay, following the philosophy of Dennis' approach, adding the quotes to
the outside of the string as it as concatenated worked:

Stimedate = "'"+Sdate+" "+Stime +" "+SAMorPM+"'"
print(Stimedate) gives:
(0) '2/26/2006 9:14:37 AM'

Then when the string gets passed through to 'date', date already sees
the single quotes and can handle it properly.

Thanks.

Jonathan

On Wed, 2006-03-08 at 22:31, Dennis Shea wrote:
> Hi Jonathan
>
> How about ....
>
> ncl 0> Sdatetime = "'2/26/2006 9:14:37 AM'"
> ncl 1> time = systemfunc("date -d " +Sdatetime+ " '+%s'")
> ncl 2> print(time)
>
> Variable: time
> Type: string
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 1140970477
>
>
> :-)
> D
>
>
> On Wed, 8 Mar 2006, Jonathan Vigh wrote:
>
> > Greetings,
> > I'm trying to use systemfunc with the Unix utility 'date' to return
> > a formatted date (seconds since 1970) from a compound string that
> > contains the date. The string has the form: "2/26/2006 9:14:37 AM". At
> > the command line, the date command is invoked:
> >
> > prompt> date -d "2/26/2006 9:14:37 AM" +%s
> >
> > which returns:
> > 1140970477
> > as desired.
> >
> > I would like to get NCL's systemfunc to do the same thing using the
> > string "2/26/2006 9:14:37 AM". Because the string is compound, Unix date
> > interprets the second part 9:14:37 as the format specifier. I can get
> > around this by putting the compound string in single quotes:
> >
> > in NCL> time = systemfunc("date -d '2/26/2006 9:14:37 AM' '+%s' ")
> >
> > This works, but if I instead use an NCL-concatenated variable
> > representation of the same string, say Sdatetime:
> >
> > in NCL> Sdatetime = "2/26/2006 9:14:37 AM"
> >
> > and then use systemfunc:
> >
> > in NCL> time = systemfunc("date -d " + Stimedate + " '+%s'")
> >
> > date complains that it has too many non-option arguments -- it is only
> > seeing the first part of the string that is passed to it. Putting
> > Sdatetime in single quotes doesn't work, because then NCL doesn't pass
> > the string variable's value to date.
> >
> > I'm guessing that I need to somehow put the double or single quotation
> > marks into my string before it gets passed to systemfunc, or do some
> > sort of escape sequence in the systemfunc command itself. I'm a bit
> > confused as to how to do this. Any help is appreciated.
> >
> > An example program is attached to easily replicate this issue.
> >
> > Jonathan
> >
> >
> >
> >
> >
> >
> >
> >
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
---------------------------------------------------------------------
Jonathan Vigh, Ph.D. Candidate              work phone: 970.491.8988                         
Department of Atmospheric Science           vigh_at_atmos.colostate.edu
Colorado State University    http://euler.atmos.colostate.edu/~vigh/
---------------------------------------------------------------------
~
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Mar 09 2006 - 11:11:41 MST

This archive was generated by hypermail 2.2.0 : Thu Mar 09 2006 - 17:28:09 MST