I have an ncl script which I modify inside a perl script, each time I run the Perl script and then call the same ncl script within the perl script. What I have noticed is that each time I run the perl script, the lines in the ncl script are progressively rewritten to the right. I wonder how far they will go to the right and if the ncl script will still work if the move very far to the right. I am wondering if it is possible to specify the column from which to start writing. I have no idea if there is a solution to this, apart from manually boving the lines back. Below are the changes I make to the script.
open($NCLSCRPT, " < /home/zmumba/DA/TMINTMAX/Scripts/10_PlotT2mMinMax.ncl") || die "open $NCLSCRPT: failed $! ($^E)";
@scrptlines=<$NCLSCRPT>;
foreach $scrptlines (@scrptlines) {
if ($scrptlines =~ /(^|\s+)a = addfile/) {
$scrptlines =~ s/\w+\.nc/Tmin.nc/g;
}
if ($scrptlines =~ /wks = gsn_open_wks/) {
$scrptlines =~ s/\w+_\d{2}/Tmin_$day/g;
}
$scrptlines =~ s/\w+ Temperature/Minimum Temperature/g;
if ($scrptlines =~ /Valid on/) {
$scrptlines =~ s/$valdate/${day}\/${month}\/${year}/g;
}
if ($scrptlines =~ /From 00z on/) {
$scrptlines =~ s/$wrffcr/T\+00H/g;
$scrptlines =~ s/$valdate/${day}\/${month}\/${year}/g;
}
}
close $NCLSCRPT;
open($NCLSCRPT, " > /home/zmumba/DA/TMINTMAX/Scripts/10_PlotT2mMinMax.ncl") || die "open $NCLSCRPT: failed $! ($^E)";
print $NCLSCRPT "@scrptlines\n";
close $NCLSCRPT;
To do justice, i am adding a part of the text file I am processing as per request from @Håkon Hægland. Otherwise the problem has been resolved.
begin
;Open input file.
;************************
DATADir = "./"
a = addfile(DATADir+"Tmax.nc","r")
T = wrf_user_getvar(a,"T2",0)
T = T-273.15
wrf_smooth_2d( T, 3 ) ; smooth T
;printVarSummary(T)
;exit
lat2d = a->XLAT(:,:)
lon2d = a->XLONG(:,:)
lat = lat2d(:,0) ; create classic 1D coordinate arrays
lon = lon2d(0,:)
lat@units= "degrees_north"
lon@units= "degrees_east"
lat!0 = "lat"
lon!0 = "lon"
lat&lat = lat
$day
-- if it has a space (or a few) at its beginning (which it shouldn't anyway), and if$validate
(which it replaces) comes at the beginning of its line. But that wouldn't be on all lines...