PDA

View Full Version : Question about .run and pv-wave script



ash
12-08-2008, 02:19 PM
Hi everybody,
I am writing a pv-wave script in which I am trying to do a .run on a file and the file's name is in a variable.

For example I have a variable called my_file = 'my_file_2.pro'
and I want to do the .run based on the variable my_file , so it will result in doing
.run my_file_2.pro

Can someone please tell me how to do it or is there a better way to do it.

Thanks
Ash

rwagner
12-08-2008, 05:07 PM
Hi Ash,
You can't run executive commands like .run in a PV-WAVE script. You can, however, run them in batch mode. So if you have a file named ash.txt containing a bunch of .run commands you can type:

@ash.txt


-Ryan

ash
12-09-2008, 08:19 AM
Hi Ryan,

Thanks for the reply, I kind of figured a way to do it, basically create a new script file with the .run and the file variable in it and then execute the script file.

Here is what I did:


file_to_run = 'my_file_2.pro'
script_file = 'script_file.txt'
OPENW, unit, script_file, /Get_lun
PRINTF, unit, '.run ' + file_to_run
CLOSE, unit
FREE_LUN, unit
@script_file.txt

I was hoping there's a better way to do it.

Thanks
Ash

donb
12-09-2008, 10:09 AM
Hi Ash,

This might help, and is a way to find all the .pro files in a folder/directory and compile them all:


fnames=FINDFILE("*.pro")
FOR ii = 0L, N_ELEMENTS(fnames)-1 DO BEGIN $
.RUN fnames(ii)


This only works at the $MAIN$ level, as Ryan mentioned previously (reference to batch mode).

One other shortcut to the code you have working today - you can eliminate the CLOSE command. FREE_LUN closes a LUN if it's not already closed.

Hope this helps,

Don B.

ash
12-09-2008, 01:14 PM
fnames=FINDFILE("*.pro")
FOR ii = 0L, N_ELEMENTS(fnames)-1 DO BEGIN $
.RUN fnames(ii)


This only works at the $MAIN$ level, as Ryan mentioned previously (reference to batch mode).

I tried the above code at the $MAIN$ level in the PV-Wave console and it throws an unknown interpreter directive error and Syntax error as below


WAVE> info, /trace
% At $MAIN$ .
WAVE> fnames=FINDFILE("*.pro")
WAVE> FOR ii = 0L, N_ELEMENTS(fnames)-1 DO BEGIN $
- .RUN fnames(ii)

.RUN fnames(ii)
^
% Unknown interpreter directive: .RUN.

.RUN fnames(ii)
^
% Syntax error.
WAVE>

Thanks again,
Ash

donb
12-10-2008, 08:25 PM
Hi Ash,

Well, this is certainly embassing and a tremendous lesson for all of my future posts! I typed the code - it seemed straight forward and easy enough. What I didn't do was run the code to see if it worked :eek: Sad to say, I get the same results as you......

So Ash, and to all who read this thread, my humble apologies!

You and Ryan do have a working solution - create a text file that contains all the .RUN commands as a batch file, and then execute the file with the @ sign.

I'll ponder this a bit more, and if anything else comes to mind I'll post it (after testing the code first!).

Best Regards,

Don B.

ash
12-15-2008, 03:13 PM
Hi everyone,
Is it possible to pass variables to pv-wave script similar to passing variables to batch script?
something like this:

@ash.txt, var1, var2

Thanks
Ash

donb
12-17-2008, 12:21 PM
Hi Ash,

The answer is yes - you can pass parameters into routines (procedures or functions) in the same manner. They can be passed as positional parameters or as keywords.

For instance, if you have a procedure mypro, the procedure definition inside mypro.pro is:


PRO mypro, p1, p2, kw1=kw1, kw2=kw2

And to call it from the command line or from within any other PV-WAVE routine, you call it like any other command:


mypro, this, that, kw1=someval, kw2=otherval

It is up to mypro.pro to do all the error checking (# of params passed, correct data types passed, etc.).

You can find many more details by looking in the online docs in the Programmers Guide, Chapter 9, Writing Procedures and Functions, starting on page 241.

Cheers, Don B.

hcrisp
12-17-2008, 01:20 PM
Don,

So can you pass arguments or keywords to a "command file" using the "at" sign (@)?


WAVE> a = 'argument1'
WAVE> b = 'argument2'
WAVE> @mycommandfile.txt, a, b ; <-- does this work?
WAVE> ; etc

donb
12-17-2008, 02:48 PM
No, that doesn't work. Batch files or command files contain a series of commands, as if you were typing at the PV-WAVE prompt. So, any param/variables already defined at the $MAIN$ level are accessible to the commands executed from within the batch file.

Suppose you define these variables:


WAVE> a = 'argument1'
WAVE> b = 'argument2'

and you have a batch file (mycommandfile.txt) that looks like:


print, a
print, b

When you execute the batch file, you get:


WAVE> @mycommandfile.txt
argument1
argument2
WAVE>

Make sense?