0

我正在尝试在集群上运行模型,但 IDL 在使用 openw 时抛出错误,因为文件位置名称中有 [] (这是我经过一些测试后得出的结论)。我想做的是向 IDL 提供一个稍微不同的字符串,其中包含转义字符。我相信做到这一点的一种方法是使用正则表达式,但我可以使用一些帮助,特别是对 IDL 了解不多。

temp_dir='/local/scratch/1940320[2000].cluster.name/temp/area'
openw,12,temp_dir+'file.dat'

我将如何发送:

temp_dir2='/local/scratch/1940320\[2000\].cluster.name/temp/area'
openw,12,temp_dir2+'file.dat'

数字代表集群上的jobid,直到它运行我才知道。/local/scratch/$PBS_JOBID.cluster.name 保存在 $TMPDIR 中,getenv('TMPDIR') 谢谢!

4

2 回答 2

0

好吧,这有点尴尬,但这应该可行:

IDL> temp_dir = '/local/scratch/1940320[2000].cluster.name/temp/area'
IDL> temp_dir = mg_streplace(temp_dir, '(\[|\])', '\\$1', /global)
IDL> print, temp_dir
/local/scratch/1940320\\[2000\\].cluster.name/temp/area
IDL> temp_dir = mg_streplace(temp_dir, '\\\\', '\', /global)
IDL> print, temp_dir
/local/scratch/1940320\[2000\].cluster.name/temp/area

MG_STREPLACE可在GitHub上找到。

于 2013-05-15T21:32:39.180 回答
0

一位同事为我写了这个:

IDL> spawn,'printenv TMPDIR | sed "s/\[/\\\[/" | sed "s/\]/\\\]/"',mytemp
于 2013-05-15T22:20:46.780 回答