[ncl-talk] Pass a string to ncl via csh that contains a space

Dennis Shea shea at ucar.edu
Fri Apr 1 09:06:18 MDT 2016


FYI only:
The reverse of the original question. From an NCL script, pass a string to
NCL's system procedure ...

An NCL script 'acting' like a shell script to invoke another NCL script  :-)

===

The next release of NCL: 6.4.0 has an embarassingly simple utility function
that I have used used that in someways simplifies text issues

http://www.ncl.ucar.edu/Document/Functions/Built-in/cla_sq.shtml

undef("cla_sq")
function cla_sq(sleft[1]:string, sright[1]:string)
; Simple utility used for creating Command Line Assignments (CLAs) within a
script
;
; Return a string with a single quote (sq) at the
; beginning and end which enclose *nix sensitive characters.
;
; [1]  s  = cla_sq("PATH","./FIM.G5test.nc")  => 'PATH="./FIM.G5test.nc"'
;
; [2]
; asgn1 = cla_sq(  "f", "test.nc")             ; asgn1= 'f="test.nc"'
; asgn2 = cla_sq(  "p", "(/850,500,200/)")     ; asgn2= 'p=(/850,500,200/)'
; asgn3 = cla_sq("var", "(/"T","Q"/)"          ; asgn3= 'var=(/"T","Q"/)'
; cmd   = "ncl year=2015 "+asgn1+" "+asgn2+" "+asgn3+" foo.ncl"
; system(cmd)
;---
local sq
begin
   sq    = str_get_sq()      ; single quote character
   return(sq+ sleft +"="+sright +sq)
end

Maybe it will be useful.

D


On Fri, Apr 1, 2016 at 2:12 AM, Karl-Hermann Wieners <
karl-hermann.wieners at mpimet.mpg.de> wrote:

> Hi Annie,
>
> On 03/22/2016 09:37 PM, Annie Seagram wrote:
> > However, in a csh script how does one pass the title as a variable? It
> > seems to crash when there are spaces. e.g.
> >
> > This fails:
> >
> > #!/bin/csh -f
> >
> > set title = “This is a title”
> >
> > ncl year=2014 month=5 title= \"{$title}\" myscript.ncl
> >
> > The error:
> >
> > Missing }.
>
> There are two answers to this:
>
> (1) Use double quotes instead of curlies:
>
> #!/bin/csh -f
> set title = "This is a title"
> ncl year=2014 month=5 title=\""$title"\" myscript.ncl
>
> (2) If you need this often, you may want to try a wrapper script for
> ncl, called nclsh, (see gzipped attachment) which - if put in PATH - may
> be called like ncl, but passes any command line options as NCL args,
> creating quotes internally:
>
> #!/bin/csh -f
>
> set title = "This is a title"
> nclsh --year=2014 --month=5 --title="$title" myscript.ncl
>
> More information may be found at
> https://code.zmaw.de/projects/nclsh/news/
>
> Best,
> Karl
>
> --
> Karl-Hermann Wieners
> Max-Planck-Institut für Meteorologie
> Bundesstraße 53
> 20146 Hamburg
> Germany
> phone: +49 40 41173 161
> email: karl-hermann.wieners at mpimet.mpg.de
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160401/04a847b9/attachment.html 


More information about the ncl-talk mailing list