Code: Select all
subroutine process_workfile (string fname, string sname)
%fn = fname
wfopen {%fn}
%sn = sname
endsub
call process_workfile ("example.wf1", "example_series")
Then I get an error message "SNAME is not defined in %sn = sname". However if I just move the position of the %sn assignment:
Code: Select all
subroutine process_workfile (string fname, string sname)
%fn = fname
%sn = sname
wfopen {%fn}
endsub
then the program runs without error. It appears therefore that subroutine parameters become inaccessible following some kinds of file operations.
The second issue is this: if I remove the %fn=fname line, and just have:
Code: Select all
subroutine process_workfile (string fname)
wfopen {fname}
endsub
then I get an error "FNAME is not a valid string or scalar name in WFOPEN {FNAME}". Removing the curly brackets doesn't help - just gives a different kind of error. So clearly parameters passed to subroutines are not treated in the same way as ordinary variables.
To prevent these kinds of problems I now always have a few lines of code at the start of any subroutine which assign the values of any passed parameters to variables (e.g. %fn in example above) and then only use those variables in the rest of the subroutine. However this seems a bit of a work-around. Is there something I'm missing or doing wrong?
Thanks