[ncl-talk] ncl systemfunc
Rick Brownrigg
brownrig at ucar.edu
Fri Feb 10 14:05:40 MST 2017
Hi Matthias,
I think maybe we have explaination. The so-called "brace-expansion"
appears to be a bash thing. I speculate your shell in your terminal window
is indeed bash. However, by default, NCL under the covers invokes
"/bin/sh" during the systemfunc() call. On many Linux systems, /bin/sh is
simply a symlink to bash (that's the case on my system and why things work
for me). However, apparently on Ubuntu systems, /bin/sh is a symlink to a
shell called "dash" (I'd never heard of it), and dash is the one that does
not understand brace-expansion -- you can try it yourself by invoking
"dash" on the command-line and then trying a command that involves
brace-expansion. More on this here:
http://askubuntu.com/questions/87853/what-is-default-shell-for-terminal
So a solution in your case would be something like this:
files = systemfunc("bash -c 'ls /DIRECTORY/*{.nc,.hdf,.pdf}'")
In particular note the "-c" switch to bash, and that the command you want
bash to execute is surrounded by single-quotes.
Hope that helps...
Rick
On Fri, Feb 10, 2017 at 12:54 PM, Matthias Demuzere <
Matthias.Demuzere at ugent.be> wrote:
> Hi Rick,
>
> Yes... I tested this for a single string without curly brackets (eg. *.nc)
> and that works fine ...
> Does this indicate there is somehow a system dependency, even though the
> curly brackets do work directly in the terminal? Quite puzzling, no?
>
> Matthias
>
> On 10 Feb 2017 18:30, Rick Brownrigg <brownrig at ucar.edu> wrote:
>
> Hi Matthias,
>
> That is very odd -- it works for me, both at bash command line and using
> systemfunc() from within NCL. Can you get systemfunc to return files from
> a directory without using "{}" notation, .i.e, "ls *" for example? Or
> simply "ls foo" where the file foo is known to exist in the current
> directory?
>
> Rick
>
> On Fri, Feb 10, 2017 at 10:15 AM, Matthias Demuzere <
> matthias.demuzere at ugent.be> wrote:
>
> Dear all,
>
> I am currently testing the CVDP (http://www.cesm.ucar.edu/work
> ing_groups/CVC/cvdp/) which is written in ncl.
> Currently the software does not run because it can't find the proper
> datasets.
>
> Finding the data is driven by the *systemfunc* command using curly
> brackets (multiple options).
> For example, within ncl, I want to list all files that have one of the
> following extension: .nc, .hdf, .pdf.
>
> This I do with:
> myFiles = systemfunc("ls /DIRECTORY/*{.nc,.hdf,.pdf}")
>
> If I fo this in ncl, I get an error: ls: cannot access
> '/DIRECTORY/*{.nc,.hdf,.pdf}': No such file or directory
>
> Yet, when pasting ls /DIRECTORY/*{.nc,.hdf,.pdf} directly in my system
> (ubuntu 16.04, 64bit) terminal, I do get a list of the finals with this
> extension. So the expected result.
>
> I have tested this in ncl-6.3.0 and 6.2.1, but I have the same problem in
> both.
> Did anyone else notice this before? Any idea on how to fix this?
>
> Thanks!
>
> Regards,
> Matthias
>
>
> --
> Post-doctoral Research Fellow
> _____________________________
>
> UGent [Home]
> Department of Forest and Water Management
> Laboratory for Hydrology and Water Management
> Coupure links 653, B-9000 Ghent, Belgium
> Email: Matthias.demuzere at UGent.be
> Web: http://www.ugent.be/bw/dfwm/en/research/LHWM/staff/matthias
>
> KU Leuven [Affiliated]
> Department of Earth & Environmental Sciences
> Division of Geography and Tourism / Regional climate studies
> Celestijnenlaan 200E, B-3001 Heverlee (Leuven), Belgium
> Email: matthias.demuzere at kuleuven.be
> Web: https://ees.kuleuven.be/geography/rcs
>
>
> _______________________________________________
> 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/20170210/b3e7ac63/attachment.html
More information about the ncl-talk
mailing list