File: invert_pascal.pas

package info (click to toggle)
gwyddion 2.57-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 48,860 kB
  • sloc: ansic: 405,916; python: 7,867; sh: 5,241; makefile: 4,507; xml: 3,786; cpp: 2,572; pascal: 418; perl: 154; ruby: 130
file content (82 lines) | stat: -rw-r--r-- 2,297 bytes parent folder | download | duplicates (6)
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
program invert_pascal;
{$ifdef MSWINDOWS}{$apptype CONSOLE}{$endif}
uses
  Math, GwyddionDump;

(********************** ACTIONS ***********************)
(* Register: print registration infromation on standard output.
   While it doesn't work realiably under some MS Windows versions, it's good
   to always define anyway *)
function Register : boolean;
begin
    WriteLn('invert_pascal');
    WriteLn('/_Test/Value Invert (Pascal)');
    WriteLn('noninteractive with_defaults');
    Register := True;
end;

(* Run: actually do something with the data.
   The first parameter (paramstr(2)) is run mode,
   the second parameter (paramstr(3)) is the file to read, process, and write
   back. *)
function Run : boolean;
var
    dump     : tDump;
    i, size  : integer;
    min, max : double;
    filename : string;
    run_mode : string;

begin
    run_mode := paramstr(2);
    filename := paramstr(3);
    Run := False;

    (* Possible run modes of this plug-in (as printed by Register) *)
    if (run_mode <> 'noninteractive') and (run_mode <> 'with_defaults') then
        Exit;

    (* Read dump file *)
    if not ReadDump(filename, dump) then
        Exit;

    (* Find tha main data field there *)
    i := FindDataField(dump, '/0/data');
    if i < 0 then
        Exit;

    (* Process the data *)
    with dump.data[i] do begin
        (* Find range so we can properly mirror the data inside it *)
        min := 1.0E300;
        max := -1.0E300;
        size := xres*yres;
        for i := 0 to size-1 do begin
            if data[i] < min then
                min := data[i];
            if data[i] > max then
                max := data[i];
        end;
        (* Invert value inside min..max *)
        for i := 0 to size-1 do
            data[i] := (min + max) - data[i];
    end;

    (* Write back result *)
    Run := WriteDump(filename, dump);
end;

(********************** MAIN ***********************)
var
    actions : array[0..1] of tPluginAction = (
        ( name : 'register'; nargs : 0; action : Register ),
        ( name : 'run';      nargs : 2; action : Run      )
    );

begin
    (* Just call helper with list of possible actions and let it sort them
       out *)
    PluginHelper(actions);
end.

(* vim: set ts=4 sw=4 et nocin si errorformat=%f(%l\\\,%c)\ %m : *)