1

I was wondering if there is a way to change the values of variables inside of a compiled IDL .pro file using a bunch of .txt files that contain the values.

For example I have 3 .txt files with 2 lines in each file. Lets just call them:

 1. C:\input1.txt
 2. C:\input2.txt
 3. C:\input3.txt

Where the contents are something like:

hello
world

And the .pro I have looks like this:

pro tst1
common vars, a, b
infile = 'C:\input1.txt'
a =''
b =''
openr,lun, infile, /get_lun
readf,lun,a
readf,lun,b
end

pro tst2
common vars, a, b
tst1
print,a, b
end

What I want to do is change the infile variable for each iteration until all 3 input.txt files have been read.

Unfortunately, I do need to have the common blocks and the infile in the first pro. I am trying to automate a big nasty .pro I got (like my simple example) and its driving me a bit bonkers.

Joe
  • 2,547
  • 1
  • 18
  • 27
nori
  • 59
  • 1
  • 2
  • 6

1 Answers1

1

Something like:

pro tst1, infile
  common vars, a, b

  a = ''
  b = ''
  openr, lun, infile, /get_lun
  readf, lun, a
  readf, lun, b
  free_lun, lun
end

pro tst2
  common vars, a, b
  for i = 1, 3 do begin
    tst1, string(i, format='(%"C:\infile%d.txt")')
    print,a, b
  endfor
end
mgalloy
  • 2,356
  • 1
  • 12
  • 10