Petrologie und Geodynamik

reli.pl Perl Script

reli.pl text/x-perl, 1 KB

Dateiinhalt

#!/usr/bin/perl -w
use strict;
use File::Find;

$ARGV[0] = ('.') unless @ARGV;
# this command avoids leading spaces in the output lines... found in the web
$" = "";
my $energy = '0';
my $int = '0';
open (FILE, "$ARGV[0]") || die "Fehler\n";
my @lines = <FILE>;
my $count = 0;
    #
    # notice that $line does not contain some copy of a line of @lines
    # but is pointing to the actual value.
    #

foreach my $line (@lines)
    { 
# parse lines and get data for the 2 input fields
  ($energy, $int) = split(' ', $line); 
  
 	if (($energy > 2.258) && ($energy < 2.2433))
		{ $line = ''; }
 	elsif (($energy > 2.2911) && ($energy < 2.3830))
		{ $line = ''; }
 	elsif (($energy > 2.3992) && ($energy < 2.4627))
		{ $line = ''; }
 	elsif (($energy > 2.4920) && ($energy < 2.5437))
		{ $line = ''; }
	elsif ($energy > 2.5655)
		{ $line = ''; }
	
	else {	
	$count++;
	# calculate wavelength in Å from energy
	my $angstrom = 12396/$energy/1000;
	
	# calculate l in mm from d=4.371Å (PET), R=140mm in Å from energy
	my $l = 12.396 * 140.0/$energy/4.371;
	# assemble output line
	$line = $energy."\t".$int."\t".$angstrom."\t". $l."\n";
	}
    }
    
if (! -e './res') {
 mkdir('./res') or die "Can't create ./res:$!\n";
}
open OUTFILE, ">./res/fitspectrum.txt";    
print OUTFILE "@lines";
close OUTFILE;
close FILE;
print ($count . "\n");