毎年何かを分析するために毎日のデータを抽出しようとしています。
そこで、フォルダとファイルを検索するコードを作成しました。
その後、途中で同じ名前を持ついくつかのファイルでカーテン ラインを抽出したいと考えています。
仕事を終えて気が付くと情報はあと1日しか残っていない
日次データはこのようにグリッド形式です。
ncols 751
nrows 601
xllcorner 124.5
yllcorner 33.
cellsize 0.01
nodata_value -99
-99.0 -99.0 -99.0 -99.0 -99.0
私のコードでこのような結果を得たいです。
1.txt (2011)
10 10 10 10 10 4 4 3 2
5 4 3 2 10 4 4 3 2
1 1 10 10 10 10 10 10
2.txt (2012)
3 4 2 10 10 4 4 3 2
5 4 3 2 10 4 4 3 2
1 1 10 10 10 10 10 10
use 5.010;
use warnings;
if( $#ARGV < 0 )
{ die "need folder.\n"; }
$dirName = shift(@ARGV);
local($i);
#rutine
&readSubDir($dirName);
sub readSubDir
{
if(!opendir(dirHandle, $_[0]))
{
print "$_[0] Failed opening.\n";
return 0;
}
local(@files) = readdir(dirHandle);
local($i);
local($newFile);
local(@dironly);
local(@fileonly);
for($i = 0; $i <= $#files; $i++)
{
$newFile = $_[0]."\\".$files[$i];
if(-d $newFile)
{
push(@dironly, $files[$i]);
}
elsif(-f $newFile)
{
push(@fileonly, $files[$i]);
}
else
{}
}
@files = @dironly;
push(@files, @fileonly);
closedir dirHandle;
my $cnt = 1;
my $b = 2011;
for($i =0; $i <= $#files; $i++){
$newFile = $_[0]."\\".$files[$i];
if(-f $newFile){
open(fileHandle, $newFile)|| die "Cannot open 개체 \n";
my($dir, $file, $ext) = ($newFile =~ m|^(.*\\)(.*)(\..*)$| );
if (substr($file,17,4) eq $b){
while(<fileHandle>){
if($. == 7){
my $filename = $cnt.'.txt';
open OUT, ">$filename" or die "Failed to create $filename";
print OUT $_;
}
}
close(fileHandle);
}
elsif (substr($file,17,4) eq $b+1){
$b++;
$cnt++;
while(<fileHandle>){
if($. == 7){
my $filename = $cnt.'.txt';
open OUT, ">$filename" or die "Failed to create $filename";
print OUT $_;
}
}
close(fileHandle);
}
}
close(OUT);
}
}