File: LNLS.pm

package info (click to toggle)
libdemeter-perl 0.9.27%2Bds6-9
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 74,028 kB
  • sloc: perl: 73,233; python: 2,196; makefile: 1,999; ansic: 1,368; lisp: 454; sh: 74
file content (140 lines) | stat: -rw-r--r-- 3,083 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package Demeter::Plugins::LNLS;  # -*- cperl -*-

use Moose;
extends 'Demeter::Plugins::FileType';

has '+is_binary'   => (default => 0);
has '+description' => (default => "XAS beamlines at the LNLS");
has '+version'     => (default => 0.1);
has 'is_transmission' => (is => 'rw', isa => 'Bool', default => 0);
has 'is_datetime'    => (is => 'rw', isa => 'Bool', default => 0);

use Carp;
use Scalar::Util qw(looks_like_number);


sub is {
  my ($self) = @_;
  open D, $self->file or $self->Croak("could not open " . $self->file . " as data (LNLS)");
  my $first = <D>;
  $self->is_datetime(1) if ($first =~ m{"Data"	"Hora"});
  while (<D>) {
    $self->is_datetime(1) if ($_ =~ m{\d\d/\d\d/\d\d\t\d\d:\d\d:\d\d});	#06/07/12	15:26:20
  };
  close D;
  return $self->is_datetime;
};



sub fix {
  my ($self) = @_;
  my $file = $self->file;

  my $new = File::Spec->catfile($self->stash_folder, $self->filename);
  ($new = File::Spec->catfile($self->stash_folder, "toss")) if (length($new) > 127);
  open D, $file or die "could not open $file as data (fix in LNLS)\n";
  open N, ">".$new or die "could not write to $new (fix in LNLS)\n";

  while (<D>) {
    if (/^"Data"\s*"Hora"/) {
      if (/"Fluorescencia"/) {
	$self->is_transmission(0);
      } else {
	$self->is_transmission(1);
      }
      my @list = split(" ", $_);
      print N "# ", join("  ", @list[2..$#list]), "\n";
	  #    $self->is_transmission(0);
    } else {
      chomp;
      my @line = split(" ", $_);
      shift @line; shift @line;
      foreach (@line) {
	if (isfloat($_)) { 
	  printf N "\t%.4f", $_;
	}
	else {
	  print N "\t",$_;
	};
      };
      print N "\n";
    };
  };
  close D;
  close N;
  $self->fixed($new);
  return $new;
};

sub suggest {
  my ($self, $which) = @_;
  $which ||= 'fluorescence';
  $which = 'transmission' if $self->is_transmission;
  if ($which eq 'transmission') {
    return (energy      => '$1',
	    numerator   => '$2',
	    denominator => '$3', 
	    ln          =>  1,);
  } else {
    return (energy      => '$1',
	    numerator   => '$5',
	    denominator => '$2',
	    ln          =>  0,);
  };
};


sub isfloat{

	my $val = shift;
    return $val =~ m/^\d+.\d+$/;
};



__PACKAGE__->meta->make_immutable;
1;
__END__

=head1 NAME

Demeter::Plugin::LNLS - Import data from the XAS beamlines at LNLS

=head1 VERSION

This documentation refers to Demeter version 0.9.26.

=head1 SYNOPSIS

This plugin makes an LNLS file readable by Athena by stripping the
first two columns from the data file.

=head1 Methods

=over 4

=item C<is>

Recognize the LNLS file by the first line, which contains the words
"Data" and "Hora" and by subsequent lines, which have dates and times
rather than nice, sensible numbers in the first two columns.

=item C<fix>

Strip the first two columns from the LNLS data file.

=back

=head1 ACKNOWLEDGMENTS

This module was written by Eric Breynaert and touched up by Bruce.

=head1 BUGS AND LIMITATIONS


=head1 AUTHOR

  Bruce Ravel, L<http://bruceravel.github.io/home>
  http://bruceravel.github.io/demeter
  Athena copyright (c) 2001-2019