请问这段代码是什么意思,代码比较长,不好意思。
sub gen_wrfnl {
my ($nlfile, $startdate, $interval_sec,
$forecast_len, $domain_id, %originhash) = @_;
my ($startyear, $startmonth, $startday, $starthour,
$enddate, $endyear, $endmonth, $endday, $endhour);
if ($startdate =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)$/){
$startyear = $1;
$startmonth = $2;
$startday = $3;
$starthour = $4;
}
if($domain_id < 2) {
$enddate = &compute_time($startdate, $forecast_len);
}else{
$enddate = $startdate;
}
if ($enddate =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)$/){
$endyear = $1;
$endmonth = $2;
$endday = $3;
$endhour = $4;
}
my ($key, $value, %namehash);
if ( $domain_id > 1) {
foreach $key ( keys %originhash ) {
if ( defined ${$originhash{$key}}[$domain_id-1] ) {
${$namehash{$key}}[0] = ${$originhash{$key}}[$domain_id-1];
}else{
${$namehash{$key}}[0] = ${$originhash{$key}}[0];
${$namehash{$key}}[0] = 1 if($key eq 'NUM_DOMAINS');
}
}
}elsif( $domain_id == 1 ) {
foreach $key ( keys %originhash ) {
@{$namehash{$key}} = @{$originhash{$key}};
${$namehash{$key}}[0] = 1 if($key eq 'NUM_DOMAINS');
}
}else{
%namehash = %originhash;
}
open(NL, "< $nlfile");
my @nl_lines = <NL>;
close(NL);
open(NL, "> $nlfile");
foreach (@nl_lines) {
if(/^\s*(\S+)(\s*)=/) {
my $name = $1; $name =~ tr/a-z/A-Z/;
if(defined ${$namehash{$name}}[0]) {
my $value = join ',', @{$namehash{$name}};
$_ = " $1$2= $value\n";
}
}
if(/^\s*(start_year)(\s*)=/i) {
$value = "$startyear, " x ${$namehash{NUM_DOMAINS}}[0];
$_ = " $1$2= $value\n"; }
if(/^\s*(start_month)(\s*)=/i) {
$value = "$startmonth, " x ${$namehash{NUM_DOMAINS}}[0];
$_ = " $1$2= $value\n"; }
if(/^\s*(start_day)(\s*)=/i) {
$value = "$startday, " x ${$namehash{NUM_DOMAINS}}[0];
$_ = " $1$2= $value\n"; }
if(/^\s*(start_hour)(\s*)=/i) {
$value = "$starthour, " x ${$namehash{NUM_DOMAINS}}[0];
$_ = " $1$2= $value\n"; }
if(/^\s*(end_year)(\s*)=/i) {
$value = "$endyear, " x ${$namehash{NUM_DOMAINS}}[0];
$_ = " $1$2= $value\n"; }
if(/^\s*(end_month)(\s*)=/i) {
$value = "$endmonth, " x ${$namehash{NUM_DOMAINS}}[0];
$_ = " $1$2= $value\n"; }
if(/^\s*(end_day)(\s*)=/i) {
$value = "$endday, " x ${$namehash{NUM_DOMAINS}}[0];
$_ = " $1$2= $value\n"; }
if(/^\s*(end_hour)(\s*)=/i) {
$value = "$endhour, " x ${$namehash{NUM_DOMAINS}}[0];
$_ = " $1$2= $value\n"; }
if(/^\s*(interval_seconds)(\s*)=/i) { $_ = " $1$2= $interval_sec,\n"; }
if(/^\s*(run_hours)(\s*)=/i) { $_ = " $1$2= $forecast_len,\n"; }
if(/^\s*(max_dom)(\s*)=/i) { $_ = " $1$2= ${$namehash{NUM_DOMAINS}}[0],\n"; }
if(/^\s*(parent_id)(\s*)=/i) {
$value = join ",", @{$originhash{PARENT_ID}};
$_ = " $1$2= $value\n"; }
if(/^\s*(i_parent_start)(\s*)=/i) {
$value = join ",", @{$originhash{DOMAIN_ORIGIN_LLI}};
$_ = " $1$2= $value\n"; }
if(/^\s*(j_parent_start)(\s*)=/i) {
$value = join ",", @{$originhash{DOMAIN_ORIGIN_LLJ}};
$_ = " $1$2= $value\n"; }
# if(parent_grid_ratio)
# if(parent_time_step_ratio)
print NL;
}
close(NL);
}
别人写的程序
上面是子程序好像
下面是引用
my (@ini_bdy_files, $id);
for($id=${$namehash{NUM_DOMAINS}}[0]; $id > 0 ; $id--) {
&wrf_operation_utils::gen_wrfnl($nlfile, $startdate, $interval_sec,
$FORECAST_LENGTH, $id, %namehash);
$id = '0'.$id if ( $id < 10 );
system("cp $nlfile d$id");
system("rm -f $WRF_ROOT/run/rsl.* $WRF_ROOT/run/wrf_real_input*");
opendir(WRFSI_OUT, $wrfsi_out_path);
@ini_bdy_files = grep /wrf_real_input_em.d$id/, readdir WRFSI_OUT;
closedir(WRFSI_OUT);
foreach (@ini_bdy_files) {
# print "\t\tlink $WRF_ROOT/run/$_
# to $moad_dataroot/siprd/$_\n";
my $flnm = $_; $flnm =~ s/d$id/d01/;
symlink "$wrfsi_out_path/$_", "$WRF_ROOT/run/$flnm";
}
if ( $id == 1 ) {
print "Create initial and boundary files for domain #01...\n";
system("$mpicommand $mpioptions $realexe") == 0 || die "system call '$realexe' failed: $?";
}else{
print "Create initial file for domain #$id...\n";
system("$mpicommand $mpioptions $realexe") == 0 || die "system call '$realexe' failed: $?";
rename "wrfinput_d01", "wrfinput_d$id";
}
}
问题是在写的文件中 没有按照 NUM_DOMAIN 〉1 循环