#!/usr/bin/perl -w { $version = "makematlab.pl version 2.3 15 May 2012"; # 15 May 12. WJS # Most recent matlab build uses linker switch -rpath , which # puts the runtime lib defns into the executable image at link time. # This obviates the need to set LD_LIBRARY_PATH in here. I forget # what happens if LD_LIBRARY_PATH is specified anyway; ie, I don't # know which specification takes effect # [begin v 2.3] # 5 Sep 09. WJS # Allow for created matlab file along with non-empty err file # Allow user to specify makemat's -maxwidth= switch # [begin v 2.2] # 9 May 08. WJS # New test to distinguish direct from indirect access # [begin v 2.1a] # 22 May 07. WJS # Allow "direct" access; ie, no forms. For first cut, send same # html to stdout for direct and indirect cases. At some point might # change this. In particular, in addition to getting rid of html, # might want to format for machine use; eg, start off with a line # saying SUCCESS or FAILURE, followed by either the URL of the .mat # file or the error info. # [begin v 2.1] # 27 Aug 05. WJS # Better checks on env var setup # 23 Aug 05. WJS # Transfer object spec via hidden form variable rather than # QUERY_STRING or PATH_INFO # Check accessibility of makemat image # Add explicit exit after processing form # 19 Aug 05. WJS # Display list of variables considered alpha in case user wants # to change these (most likely because 1st record happens to contain # an 'nd') # 3 Aug 05. WJS # Give up on fancy matlab locations # Use wjs_web_perl_utilities.pl; hence make error msgs, etc, a bit # more similar to other OO routines I've fiddled with # [begin v 2.0] # Mar 12, 2005. WJS # Bug fix: need URL of download file in href, not download file name # Change perl location #??????, 2004 # No need for template w/new opt-build-env.pl. Get lib locs # from there (variant of "alternative" in 5 May comment) # Jun 23, 2004. WJS # Name temp file after the object instead of "makemat" # Indicate that one should download w/shift-click instead of click # (until/unless Bob defines .mat file type on server) # May 5, 2004. WJS # cgi-lib.pl's PrintHeader seems to work, replacing system echo's # Thought orig problem might have to do w/flushing STDOUT, but # could not easily reproduce orig problem... # Do some error handling. # Library path stuff # Setup in here in anticipation of user being able to select # matlab 5 or 6. # Take a cut at dealing w/a path that already includes a matlab lib defn # Create template version of this file so we can get lib locs # from opt-build-env at server build time. (Alternative is # to have optbin/build-opt-env.pl propagate the value at run # time. I could be persuaded the other way...) # Present the download as a link instead of sending output to stdout # April 1, 2004. WJS/RCG # System echo works but print STDOUT does not, but this # matches what K. Krueger says he has observed. # Outputting directly from makemat did not work, but outputting # to a temporary file and then catting the results did work. # Mar. 23, 2004: Make into a Perl script rcg/wjs # Jan. 10, 2000: replace if test expression to make valid rcg require ("cgi-lib.pl"); require "wjs_web_perl_utilities.pl"; # Set up environment. Assume .pl routine is in our directory $build_opt_env = "./build-opt-env.pl"; &check_r_access($build_opt_env); require $build_opt_env; # Define form action routine and hidden html var name for that routine. $form_action = "form_action"; $form_action_routine = $ENV{"SCRIPT_NAME"} ? $ENV{"SCRIPT_NAME"} : "/jg/makematlab.pl"; # Check that build-opt-env set up things as expected defined ($ENV{'OPTHOME'}) || &quit ("Internal problem. ", "Did not get defined env var 'OPTHOME' from $build_opt_env"); $bindir = &abs_filespec($ENV{"OPTHOME"},"Env var OPTHOME") . "/bin"; # html form variable names $alpha_list_form_var_name = "list_of_alpha_variables"; $object_form_var_name = "object_spec"; $varwidth_form_var_name = "varwidths"; &ReadParse(*form_info); # See if we are being called for human interface or direct-to-machine # interface. First stab at this: assume if args come from QUERY_STRING, # it's direct. Take a 2nd stab: QUERY_STRING is defined if there are # sel/projs $object = &get_form_var($object_form_var_name,'OPT','NOCHECK'); $direct_action = ($object ne "") && ($ENV{"REQUEST_METHOD"} eq "GET"); if ($direct_action) { &process_form($object); } else { # Main purpose of putting form action routine on form as a hidden # variable is to distinguish between use of this program in the # "put the form up" and "process the form results" modes. The # consistency check is just on general principles - anyone who de- # liberately mis-routes things here can change the hidden value as well. # Can probably do this better w/the combo of ENV{'REQUEST_METHOD'} # and a required variable like $object_form_var_name, or maybe w/ # the return value from ReadParse... some other time. if ( $after_submit = (defined $form_info{$form_action}) ) { ($form_info{$form_action} eq $form_action_routine) || &quit ("Submit action routine should be same as form value" , "Action = $form_action_routine; " . "Form value = $form_info{$form_action}" ); } if ($after_submit) { &process_form($object); } else { &print_form; } } exit; } sub print_form { &printheader(); print "\n"; $title = 'Matlab alpha variable selection page'; print "