DVW_folder.pl

来源:互联网 发布:数据生成图表 编辑:程序博客网 时间:2024/06/06 08:45
 

#!perl
$|=1;

SET_ENVIRONMENT:{ #to set the environment defined in the environment file: this file should be put in the same folder of the script
use FindBin '$Bin'; #find the folder where the script is saved
push(@INC, "$Bin"); #put the folder of the script in the list of INC
require "ENVIRONMENT.pm";

eval { #the unnecessary environment variables are put in comments
$CYGWIN_path=$ENVIRONMENT::CYGWIN_path or die "No CYGWIN_path\n";
$DVW_path=$ENVIRONMENT::DVW_path or die "No DVW_path\n";
#$WRAP_path=$ENVIRONMENT::WRAP_path or die "No WRAP_path\n";
#@wrap_filter_ok=@ENVIRONMENT::wrap_filter_ok or die "No wrap_filter_ok\n";
#@wrap_filter_nok=@ENVIRONMENT::wrap_filter_nok or die "No wrap_filter_nok\n";
}; #end of eval

if ($@) {print "Error while setting the environment in ENVIRONMENT.pm: $@...Press ENTER to continue...";<STDIN>;exit;}
} #end of SET_ENVIRONMENT

$exit_code=0;

if ($#ARGV == 0) { #one arguments: the file
 $path=$ARGV[0];
 if ($path =~ m%([\\\/](\w+\.(\w+)))$%) { $path =~ s%$1%%;} #delete the name of the file from the path if the argument is a file
 chdir  "$path"; #the argument is the name of a folder
} else {die "Error: Wrong number of argument. A folder needs to be specified";}

@draw_files=glob "aol_*_draw.c";
print "The files found are: @draw_files\n"; #for_debug

foreach $file (@draw_files) {
print "\n","*"x 30,"\nProcessing of $file\n","*"x 30,"\n"; #for_log
 
$layer_name = $file;$layer_name =~ s/aol_(\w+)_draw.c/$1/; #retrieve the name of the layer_name
print "The name of the layer is: $layer_name\n"; #for_debug

open DRAW_C, "<$file" or die "Error while opening $file ($!)\n";
$read_line="";
  until ($read_line =~ /Command line/) {
  ++$line; #increment the number of the line
  unless (defined ($read_line = <DRAW_C>)) {
   die "Command line not found in the header (line $line)\n"; } # if the end of the file is not reached
 } #end of until : mode has been found
 if ($read_line =~ /-mode (SGL|OpenGL)/) {$mode =$1;}
 else {die "Mode not specified for $file\n";}
 print "The mode is $mode\n"; #for_debug
close DRAW_C;

$mode =~ s/SGL/batch/; #the mode is "-OpenGL" for OpenGL and "-batch" for SGL
print "\n","*"x 65,"\nDYViewer.sh $mode -symbology . . $layer_name 120\n","*"x 65,"\n";
$exit_code += system("$CYGWIN_path/sh.exe $DVW_path -$mode -symbology . . $layer_name 120");

}#end of foreach

if ($exit_code >0) {print "\nError while running Display Viewer\nPress ENTER to continue... ($exit_code)\n";<STDIN>;}