File: invert_narray.rb

package info (click to toggle)
gwyddion 2.67-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 54,152 kB
  • sloc: ansic: 412,023; python: 7,885; sh: 5,492; makefile: 4,957; xml: 3,954; cpp: 2,107; pascal: 418; perl: 154; ruby: 130
file content (37 lines) | stat: -rwxr-xr-x 774 bytes parent folder | download | duplicates (9)
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
#!/usr/bin/env ruby

# A very simple Gwyddion plug-in example in Ruby.

# Written by Nenad Ocelic <ocelic _at_ biochem.mpg.de>.
# Public domain.

begin
	require "narray"
rescue LoadError
	exit 1
end
$:.push(ENV['GWYPLUGINLIB'] + '/ruby')
require "gwyddion/dump"
include Gwyddion

# Plug-in information.
RUN_MODES= 'noninteractive', 'with_defaults'
PLUGIN_INFO= [ "invert_narray", "/_Test/Value Invert (Ruby+NArray)"]

def register(args)
	puts PLUGIN_INFO, RUN_MODES.join(' ')
end 

def run( args)
	run_mode= args.shift
	RUN_MODES.member? run_mode or raise "Invalid run mode"
	
	dump= DumpNArray.new args.shift
	a= dump[ '/0/data']
	mirror= a.min + a.max
	dump[ '/0/data']= mirror - a 
	dump.write # filename optional unless changed
end 

fn= ARGV.shift
send fn.intern, ARGV