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

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed, 8 Mar 2006 22:31:59 -0700 (MST)

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
Received on Wed Mar 08 2006 - 22:31:59 MST

This archive was generated by hypermail 2.2.0 : Thu Mar 09 2006 - 08:06:41 MST