Question

I am trying to run a model on a cluster but IDL is throwing an error when using openw because the file locations name has [] in it (this is my conclusion after some testing). What I'd like to do is feed IDL a slightly different string that includes escape characters. I believe one way to do this is with regex but I could use some help and specifically don't know much IDL.

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

How would I send:

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

The number represents the jobid on the cluster, and I don't know this until its running. /local/scratch/$PBS_JOBID.cluster.name is held in $TMPDIR which I'm getting with getenv('TMPDIR') Thanks!

Was it helpful?

Solution

Well, it's a bit awkward, but this should work:

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 is available on GitHub.

OTHER TIPS

A colleague wrote this for me:

IDL> spawn,'printenv TMPDIR | sed "s/\[/\\\[/" | sed "s/\]/\\\]/"',mytemp
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top