-
Notifications
You must be signed in to change notification settings - Fork 0
/
Convert31to32.m
62 lines (42 loc) · 1.21 KB
/
Convert31to32.m
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
(*
Convert31to32.m
renames the ShapeData files of FeynArts 3.1
for the new naming scheme of FeynArts 3.2
last modified 1 Jul 03 th
*)
Needs["FeynArts`"]
shapeDir = ToFileName[Directory[], "ShapeData"]
If[ FileType[shapeDir] =!= Directory,
Print["No directory ", shapeDir, " found"];
Abort[]
]
backupDir = ToFileName[Directory[], "ShapeData-3.1"]
If[ FileType[backupDir] === Directory,
Print["Conversion already performed (", backupDir, " exists)."];
Abort[]
]
RenameFile[shapeDir, backupDir]
MkDir[dir_String] := dir /; FileType[dir] === Directory
MkDir[dir_String] := Check[CreateDirectory[dir], Abort[]]
MkDir[dirs__String] := Fold[MkDir[ToFileName[##]]&, {}, {dirs}]
newName[s_String] :=
Block[ {c, p, int = "0", out = "0", in = "0"},
c = Characters[StringReplace[s, ".m" -> ""]];
p = Position[c, "+"];
If[ p =!= {},
p = p[[1, 1]];
in = str[Drop[c, p]];
c = Take[c, p - 1];
];
p = Position[c, "-"];
If[ p =!= {},
p = p[[1, 1]];
out = str[Drop[c, p]];
c = Take[c, p - 1];
];
int = str[c] <> ".m";
CopyFile[s, ToFileName[MkDir[shapeDir, in, out], int]]
]
str[c_] := StringJoin[Partition[c, 2]//Reverse] /. "" -> "0"
SetDirectory[backupDir]
newName/@ FileNames[]