[Thread Prev][Thread Next][Index]

Urgent help needed about adding new operations using matlab



Hi Jonathan
I've spent several days on this problem and am still stuck there.
What I want to do is to use a matlab routine to make plot, and then return the picture. My approach is like this. I added the operation in las.xml file and a corresponding function in my custom/custom.pl. In the function, I forked a child process which execs a perl program with the output file name from LAS as parameter. Then the child process will create a LAS CLC session for matlab and create the picture I need. In the meantime the parent process will wait for it to die,then return. After that LAS will return the picture and the html file to the user. The code is below.

sub MooringPlotMatrix { # this is the new operation I add in custom/custom.pl file
my $self = shift;

my $output_file=$self->{output_file};
my $program_pid = fork;
if ($program_pid == 0) {
my $mycmd="/home/local/las/server/test.pl ".$output_file;
exec($mycmd);
exit(0);
}
# Here should be some statements the parent process waits for the child to die.
# I haven't written the statements yet.
}
What I want to do is to call "/home/local/las/server/test.pl " to create a picture file with the same name as the output file. The file "/home/local/las/server/test.pl " basically just creates a CLC object of a matlab
session, and creates a file upon the input parameter, i.e., the file name.
I'm attaching the test.pl and the corresponding matlab code here.
The problem is that $output_file seems not passed into test.pl. No picture was created under server/output
as supposed.If I fix the filename in function sub MooringPlotMatrix like below
my $mycmd="/home/local/las/server/test.pl plot1", then it's fine, I can see plot1.png file is created
successfully under server/output.
Other than this, I used to create a CLC session of matlab directly in sub MooringPlotMatrix (the new operation I add) without forking a child process to create CLC, but it didn't generate the picture. I guess it might be relevant with the fact that it creates a child process for matlab, and it already created a child process for ferret, in sub preExecute( ), therefore it gets messy.
I did all the tests using netscape 7.0 on a RedHat Linux 7.3. Matlab version is 6.5.
Could anybody give me suggestions how to combine matlab and LAS? You information will be highly appreciated.
Cheers, Ding




#!/usr/bin/perl 
use English;

use lib '.';
use CLC;

use Config;
use lib ('/home/local/las/xml/perl','/home/local/las', '/home/local/las/xml/perl/install/lib/' . $Config{version},
         '/home/local/las/xml/perl/install/lib/site_perl/' . $Config{version},
         '/home/local/las/xml/perl/install/lib/perl5/' . $Config{version},
         '/home/local/las/xml/perl/install/lib/perl5/site_perl/' . $Config{version});
use CGI qw(:standard); # Include standard HTML and CGI functions
use CGI::Carp qw(fatalsToBrowser); # Send error messages to browser
use LAS;
use LAS::Server;
#

# Use unbuffered output.
# Open a file for debugging output.
# Redirect stderr to stdout so we can see err msgs on the web.

$target_file=shift;

$OUTPUT_AUTOFLUSH = 1;
$debug_file="clc.debug";
#open(DBGFILE, ">$debug_file") || 
  #&mydie("Can't open $debug_file\n<P>\nAre the permissions set properly?");
#open (STDERR, ">&STDOUT") || &mydie("Can't dup stdout ($OS_ERROR)\n");
open(DBGFILE, ">$debug_file");
open (STDERR, ">&STDOUT");
print DBGFILE "\n";




	$matlab= new CLC("/home/local/las/server/matlab.sh", ">> ", \*DBGFILE);

$matlab->start("");
$matlab->wait_for_prompt;

$matlab->send_command("addpath /home/users/chi/public_html/las_mooring/");
$matlab->wait_for_prompt;

$matlab->send_command("myplot(\'$target_file\')");
$matlab->wait_for_prompt;

$matlab->send_command("quit");
$matlab->error_check("error on quit");

$matlab->close;

function myplot(filename) 
mb1=netcdf('/usr/local/ferret/go/mb1.nc');
air_temp=mb1{'Air_Temperature'}(:);
wind_speed=mb1{'Wind_Speed'}(:);
wind_direction=mb1{'Wind_Direction'}(:);
x=[ air_temp,wind_speed,wind_direction];
x(find(x==-99999))=nan;
plotmatrix(x);
eval(['print -dpng /home/local/las/server/output/' filename])

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP
Contact Us | Privacy Policy | Disclaimer | Accessibility Statement