0

IDL beginner here! Let's say I have two procedures, PRO1 and PRO2. If I receive a command line argument in PRO2, how can I give the argument value to a variable in PRO1?

I have previously tried to make an object reference ,'My', to PRO1, but I receive a syntax error on line 6.

PRO PRO2 
opts = ob_new('mg_options)
opts.addOption, 'value', 'v'
opts.parseArgs,error_message = errorMsg
My = obj_new('PRO1')
My.A=opts.get('value')
END

For reference, I attempted to follow these instructions for receiving command line arguments: http://michaelgalloy.com/2009/05/11/command-line-options-for-your-idl-program.html

user49193
  • 3
  • 5
  • Hoo, did you actually make PRO1 a real object (in a __define.pro file with an init method) rather than just a procedure? I haven't kept up with the particulars of the most recent versions of IDL, but that looks fishy to me. But also, maybe I don't understand the question, but why don't you just do what the pseudocode does in the top box? No funny object reference necessary. You just have to make sure that PRO1 is *compiled* before PRO2 executes. – Ajean Aug 11 '14 at 02:55
  • I'm curious since you deleted your pseudocode and clearly just an object is not what you are looking for - what are you trying to accomplish by "passing variables using object references"? This may be an XY problem... – Ajean Aug 11 '14 at 15:28

1 Answers1

0

I had something else here, but I think your example above is actually what you want to avoid, yes? I'm not sure how it ends up being all that different, but if you want to make your procedure an object, you'll have to define an actual object (see here) and create methods for it containing your code functionality. Here's something close-ish.

In a file called pro1__define.pro:

function pro1::Init
    self.A = 0L
    return, 1
end

pro pro1::process, in_val
    self.A = in_val
    print, self.A
end

pro pro1__define
    struct = {pro1, A:0L}
end

Then in pro2 you would do something like

arg = 2
pro1_obj = pro1()
pro1_obj->process, arg

Depending on which version of IDL you are using you may have to modify the initialization line to the obj_new() syntax.

Ajean
  • 5,528
  • 14
  • 46
  • 69