| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hey everyone, I have a code that calls a batch file to assign variables that I want the main level program to have. The names of the variables and the number may change randomly, and not by me, so I didn't want to use a procedure where I would have to change it every time an alteration was made in the save file. Now, I need to execute a batch file whose name is passed by another program. I've used call_method, call_procedure, and call_function, but I see nothing like call_batch. My current fix is the following: spawn, 'cp ' + in_name+' temp_name.pro' @temp_name.pro This doesn't seem very clean, but it makes all of the variables available to the main level. Any brighter ideas? -Trae |
|
#2
| |||
| |||
| On Sep 2, 9:41*am, Trae <traewin...@gmail.com> wrote: > Hey everyone, > > I have a code that calls a batch file to assign variables that I want > the main level program to have. The names of the variables and the > number may change randomly, and not by me, so I didn't want to use a > procedure where I would have to change it every time an alteration was > made in the save file. > > Now, I need to execute a batch file whose name is passed by another > program. *I've used call_method, call_procedure, and call_function, > but I see nothing like call_batch. > > My current fix is the following: > > spawn, 'cp ' + in_name+' temp_name.pro' > > @temp_name.pro > > This doesn't seem very clean, but it makes all of the variables > available to the main level. > > Any brighter ideas? I thought EXECUTE would be the answer, but it appears that it can't call a batch file: IDL> @test 5 IDL> print, execute('@test') @test ^ % Illegal character in program text. 0 Mike -- www.michaelgalloy.com Tech-X Corporation Software Developer II |
|
#3
| |||
| |||
| Good suggestion. I just tried it too and was about to post my null result. I think the person that started writing this code is making life more difficult than it has to be. The best way to go about this, I think, is to write a procedure that reads the input file and returns an undefined structure. You can then check for tags on the structure, which gives you the necessary flexibility. One of the problems is that the original input file must be human readable text. So no .sav files. Still, if anyone has a way to dynamically call a batch file with a name that is passed as a variable, I would love to hear about it. Cheers, -Trae On Sep 2, 11:54 am, "mgal...@gmail.com" <mgal...@gmail.com> wrote: > On Sep 2, 9:41 am, Trae <traewin...@gmail.com> wrote: > > > > > Hey everyone, > > > I have a code that calls a batch file to assign variables that I want > > the main level program to have. The names of the variables and the > > number may change randomly, and not by me, so I didn't want to use a > > procedure where I would have to change it every time an alteration was > > made in the save file. > > > Now, I need to execute a batch file whose name is passed by another > > program. I've used call_method, call_procedure, and call_function, > > but I see nothing like call_batch. > > > My current fix is the following: > > > spawn, 'cp ' + in_name+' temp_name.pro' > > > @temp_name.pro > > > This doesn't seem very clean, but it makes all of the variables > > available to the main level. > > > Any brighter ideas? > > I thought EXECUTE would be the answer, but it appears that it can't > call a batch file: > > IDL> @test > 5 > IDL> print, execute('@test') > > @test > ^ > % Illegal character in program text. > 0 > > Mike > --www.michaelgalloy.com > Tech-X Corporation > Software Developer II |
|
#4
| |||
| |||
| I guess it would be cleaner to put all variables in a structure with a fixed name and just refer to the structure, but I understand this would require rewriting the code, so this is not a good idea now;-) Ciao, Paolo Trae wrote: > Hey everyone, > > I have a code that calls a batch file to assign variables that I want > the main level program to have. The names of the variables and the > number may change randomly, and not by me, so I didn't want to use a > procedure where I would have to change it every time an alteration was > made in the save file. > > Now, I need to execute a batch file whose name is passed by another > program. I've used call_method, call_procedure, and call_function, > but I see nothing like call_batch. > > My current fix is the following: > > spawn, 'cp ' + in_name+' temp_name.pro' > > @temp_name.pro > > > This doesn't seem very clean, but it makes all of the variables > available to the main level. > > Any brighter ideas? > > -Trae |
|
#5
| |||
| |||
| Trae, I'm thinking how one accomplishes this in C, seems to me that this is an include file. Is there anything that thinking of it that way makes clearer or different? Maybe even as weird as restore and save? One cleaner and better solution to the call_batch thing is to use file_copy instead of spawn 'cp '. You take a huge time hit on spawn since it executes your .cshrc file each time and with solarsoft in your .cshrc that takes a while. I learned this the hard way doing some sqlite work from idl. Cheers, Brian -------------------------------------------------------------------------- Brian Larsen Boston University Center for Space Physics http://people.bu.edu/balarsen/Home/IDL |
|
#6
| |||
| |||
| On Sep 2, 12:14 pm, Brian Larsen <balar...@gmail.com> wrote: > Trae, > > I'm thinking how one accomplishes this in C, seems to me that this is > an include file. Is there anything that thinking of it that way makes > clearer or different? Maybe even as weird as restore and save? Got it!!! Even though EXECUTE looks like a function, any variables defined in the string are inherited by the next level up. So the easy thing to do is 1. Open the passed file using OPENR 2. Read the contents of the batch file into a string variable. 3. Use EXECUTE to, well, execute the string variable. So this is the exact same as @batch_name, but this way I don't need to know the batch file name a priori, at the expense of a few lines of code. YAY! -Trae PS Brian I will use the file_copy trick in future. Good tip! > > One cleaner and better solution to the call_batch thing is to use > file_copy instead of spawn 'cp '. You take a huge time hit on spawn > since it executes your .cshrc file each time and with solarsoft in > your .cshrc that takes a while. I learned this the hard way doing > some sqlite work from idl. > > Cheers, > > Brian > > -------------------------------------------------------------------------- > Brian Larsen > Boston University > Center for Space Physicshttp://people.bu.edu/balarsen/Home/IDL |
|
#7
| |||
| |||
| Just in case another poor soul needs this and searches the group, here are the lines of code that made it work. NB: EXECUTE only accepts scalars as an input. Bogus. First define a batch file named batch_test.pro with the commands a=5 b=6 c=sin(!dpi/4.) Now here are the commands to read and execute it. file='batch_test.pro' openr, lun, file, /GET_LUN var_arr='' ;while not eof do begin WHILE ~ EOF(lun) DO BEGIN line='' READF,lun , line var_arr=[var_arr,line] ENDWHILE FREE_LUN, lun var_arr=var_arr[1:*] for i=0ul,n_elements( var_arr) -1ul do result=execute(var_arr[i]) END So you can define the variable 'file' anyway you want and it can have as many or as few commands as you need. Thanks for the help everyone! I'm off to be quite pleased with myself for awhile! ![]() Cheers, -Trae |
|
#8
| |||
| |||
| Does it work with multiline statements such as for i=0,10 do begin &$ print,i &$ endfor which are legal for batch files? Ciao, Paolo Trae wrote: > Just in case another poor soul needs this and searches the group, here > are the lines of code that made it work. NB: EXECUTE only accepts > scalars as an input. Bogus. > > First define a batch file named batch_test.pro with the commands > > a=5 > b=6 > c=sin(!dpi/4.) > > > Now here are the commands to read and execute it. > > > file='batch_test.pro' > > > > > openr, lun, file, /GET_LUN > var_arr='' > ;while not eof do begin > > WHILE ~ EOF(lun) DO BEGIN > line='' > READF,lun , line > var_arr=[var_arr,line] > ENDWHILE > FREE_LUN, lun > var_arr=var_arr[1:*] > > for i=0ul,n_elements( var_arr) -1ul do result=execute(var_arr[i]) > > END > > > So you can define the variable 'file' anyway you want and it can have > as many or as few commands as you need. > > Thanks for the help everyone! > > I'm off to be quite pleased with myself for awhile! ![]() > > Cheers, > -Trae |
|
#9
| |||
| |||
| No. It fact, it can lead to segmentation faults. You could easily test the string for '$' and then combine lines as needed. However, for this application, a series of variables are being defined. It is easier to keep 1 line per command than try to make anything to tricky. Of course, if you have time to play you can make this procedure as general as you want. -Trae On Sep 2, 12:57 pm, pgri...@gmail.com wrote: > Does it work with multiline statements such as > > for i=0,10 do begin &$ > print,i &$ > endfor > > which are legal for batch files? > > Ciao, > Paolo > > Trae wrote: > > Just in case another poor soul needs this and searches the group, here > > are the lines of code that made it work. NB: EXECUTE only accepts > > scalars as an input. Bogus. > > > First define a batch file named batch_test.pro with the commands > > > a=5 > > b=6 > > c=sin(!dpi/4.) > > > Now here are the commands to read and execute it. > > > file='batch_test.pro' > > > openr, lun, file, /GET_LUN > > var_arr='' > > ;while not eof do begin > > > WHILE ~ EOF(lun) DO BEGIN > > line='' > > READF,lun , line > > var_arr=[var_arr,line] > > ENDWHILE > > FREE_LUN, lun > > var_arr=var_arr[1:*] > > > for i=0ul,n_elements( var_arr) -1ul do result=execute(var_arr[i]) > > > END > > > So you can define the variable 'file' anyway you want and it can have > > as many or as few commands as you need. > > > Thanks for the help everyone! > > > I'm off to be quite pleased with myself for awhile! ![]() > > > Cheers, > > -Trae |
|
#10
| |||
| |||
| it might be shorter / faster to create a dummy batch file, in its own file, that calls the real batch file. In your code, you always call the same batch file, and the only thing you have to do is to write the batch file name (the one defining your variables) in that pro file. 1 write statement and your are good! something like: openW, lun, 'myDummyBatchFile.pro', /get_lun printF,lun, '@' + myGoodBatchFile_fileName close,lun then in your code @myDummyBatchFile Jean |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.