#=============================================== # TkRINT2000 #=============================================== package TkRINT2000; use Crystal::Rietan; use TkPlotModule; @ISA = qw(Rietan TkPlotModule); #公開したいサブルーチン #@EXPORT = qw(DelSpace Reduce01 MakePath RegExpQuote); use strict; use Utils; use MyTk::GraphFrameArray; use GraphData; #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module, $app) = @_; # my ($module, $app, $canvas) = @_; my $this = {}; bless $this; $this->SetApplication($app) if($app); # $this->SetCanvas($canvas) if($canvas); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } #============================================================ # 継承クラスで定義しなおす関数 #============================================================ sub CheckFileType { my ($path) = @_; my ($drive, $dir, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($path); if($ext =~ /^\.asc$/i) { my $infile = new JFile($path, "r"); return undef unless($infile); my $line = $infile->SkipTo("\\*GONIO "); $infile->Close(); return unless($line); return "RINT2000 XRD Data"; } return undef; } sub ReadASCFile { my ($this, $path) = @_; my ($drive, $dir, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($path); my $in = new JFile($path, "r"); return undef unless($in); my $line = $in->SkipTo("\\*SAMPLE "); my ($Sample) = ($line =~ /=\s*(\S+)/); $Sample = $filebody unless($Sample); Utils::DelSpace($Sample); #print "Sample: $Sample\n"; $in->rewind(); $line = $in->SkipTo("\\*START "); my ($start) = ($line =~ /=\s*(\S+)/); #print "Start: $start\n"; $in->rewind(); $line = $in->SkipTo("\\*STEP "); my ($step) = ($line =~ /=\s*(\S+)/); #print "Step: $step\n"; $in->rewind(); $line = $in->SkipTo("\\*COUNT "); my ($nData) = ($line =~ /=\s*(\S+)/); #print "nData: $nData\n"; my @Q2; my @Int; my $c = 0; while(!$in->eof()) { $line = $in->ReadLine(); last if($line =~ /\\*END/); last if($line =~ /\\*EOF/); my @a = Utils::Split("\\,\\s*", $line); for(my $i = 0 ; $i < @a ; $i++) { $Q2[$c] = $start + $c * $step; $Int[$c] = $a[$i]; $c++; last if($c >= $nData); } last if($c >= $nData); } $nData = $c; #print "nData: $nData\n"; $in->Close(); $this->SetDataArray(new GraphDataArray); my $IntData = new GraphData; $IntData->SetTitle($Sample); $IntData->{'x0'} = \@Q2; $IntData->{'y0'} = \@Int; $IntData->{'x0_Name'} = "2Theta"; $IntData->SetXCaption("2Theta"); $IntData->{'y0_Name'} = $Sample; $IntData->SetYCaption("Intensity"); $IntData->CalMinMax(); $this->{'DataArray'}->AddGraphData($IntData); return 1; } sub Read { my ($this, $filename) = @_; $this->ClearAll(); my $FileType = $this->{'FileType'} = CheckFileType($filename); return undef unless($FileType); $this->SetFileName($filename); if($FileType eq "RINT2000 XRD Data") { return $this->ReadASCFile($filename); } return undef; } 1;