~maddevelopers/mg5amcnlo/WWW5_caching

« back to all changes in this revision

Viewing changes to users/mardelcourt/PROC_129738/PROC_129738/bin/internal/gen_jpeg-pl

  • Committer: John Doe
  • Date: 2013-03-25 20:27:02 UTC
  • Revision ID: john.doe@gmail.com-20130325202702-5sk3t1r8h33ca4p4
first clean version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
#---------------------------------------------------------------------
 
4
# Run GS to create jpeg files defined as $gs
 
5
#---------------------------------------------------------------------
 
6
system("/bin/bash -c \"rm -f matrix*.jpg\" ");
 
7
 
 
8
$imatrix = "";
 
9
if (! -e "matrix.ps") {$imatrix = 1;}
 
10
$max_jpg = 2;
 
11
if ($imatrix eq "") {$max_jpg = 5;}
 
12
# add 1 to max_jpg, to get max_jpg pages
 
13
$max_jpg += 1;
 
14
open(PAGE,"> diagrams.html") || die "Error creating diagrams.html";
 
15
print PAGE "\<HTML\> \n";
 
16
print PAGE "\<HEAD\> \n";
 
17
print PAGE "\<TITLE\>Feynman Diagrams \<\/TITLE\> \n";
 
18
print PAGE "\<\/HEAD\> \n";
 
19
print PAGE "\<BODY\> \n";
 
20
while ( -e "matrix$imatrix.ps"){
 
21
  open(IN, "< matrix$imatrix.ps") || die "No file matrix$imatrix.ps";
 
22
  open(OUT, "> matrix-1.ps") || die "Could not open file matrix-1.ps";
 
23
  while (<IN>) {
 
24
    if ($_ =~ m/^%%Page: $max_jpg $max_jpg/) {last;}
 
25
    else {print OUT $_, "\n";}
 
26
  }
 
27
  close(OUT);
 
28
  close(IN);
 
29
  system "/bin/bash -c \"nice gs  \-sDEVICE\=jpeg \-sOutputFile\=matrix$imatrix\%00d.jpg \-q \-dNOPAUSE \-dBATCH matrix-1.ps\"";
 
30
  system "rm -f matrix-1.ps";
 
31
 
 
32
# Determine how many jpg files we have
 
33
  $pages=1;
 
34
 
 
35
  while(-e "matrix$imatrix$pages.jpg"){
 
36
    $pages++;
 
37
  }#end of while
 
38
  #reduce it by one
 
39
  if ($pages > $max_jpg){
 
40
    $pages -= 1;
 
41
  }
 
42
# Find name of process
 
43
  open PROCESS, "grep Process auto_dsig$imatrix.f |" or print "Error: can't do grep\n";
 
44
  $proc = <PROCESS>;
 
45
  if ($proc =~ /Process: (.+?)(\s\w+=\d+)*$/) { $proc = $1; }
 
46
  print PAGE "<P>\<A HREF\=\"matrix$imatrix.ps\" id\=\"$imatrix\"\> Postscript Diagrams for $proc\<\/A\> \<BR\> \n";
 
47
  for($j=1;$j<$pages;$j++){
 
48
    print PAGE "\<IMG SRC=\"matrix$imatrix$j.jpg\" ALT=\"Page $j of $pages \" \> \<BR\> \n";
 
49
  }#end of for
 
50
#
 
51
#   In case I didn't include all of the diagrams as jpeg, warn user
 
52
#
 
53
  if (-e "matrix$imatrix$max_jpg.jpg" ) {
 
54
    print PAGE "<P>To save bandwidth not all diagrams were converted to jpeg.";
 
55
    print PAGE "<P> To view all diagrams click on ";
 
56
    print PAGE "\<A HREF\=\"matrix$imatrix.ps\"\> postscript. \<\/A\> \<BR\> \n";
 
57
#
 
58
#    Delete files which aren't included in diagrams.html
 
59
#
 
60
    system ("/bin/bash -c \"rm -f matrix$max_jpg.jpg\" ");
 
61
  }
 
62
#
 
63
#  Now create jpeg file for card
 
64
#
 
65
  if (! -e "../../card.jpg") {
 
66
    system ("/bin/bash -c \"head -352 matrix$imatrix.ps >& junk.ps\" ");
 
67
    open(JUNK,">> junk.ps") || die "Error opening junk.ps";  
 
68
 
 
69
    print JUNK "-30 -380 translate \n";
 
70
    print JUNK "0.7 0.7 scale \n";
 
71
    close(JUNK);
 
72
 
 
73
    system ("/bin/bash -c \"cat matrix$imatrix.ps | sed 1,352d >> junk.ps\" ");
 
74
 
 
75
    system "/bin/bash -c \"nice gs  \-sDEVICE\=jpeg \-sOutputFile\=card.jpg \-q \-dNOPAUSE \-dBATCH \-g180x150 ./junk.ps; rm -f junk.ps; cp -p card.jpg ../../card.jpg\" ";
 
76
  }
 
77
  if ($imatrix eq "") {$imatrix = 0;}
 
78
  $imatrix = $imatrix + 1;
 
79
}
 
80
 
 
81
print PAGE "\n";
 
82
print PAGE "\<\/BODY\> \n";
 
83
print PAGE "\<\/HTML\> \n";
 
84
close(PAGE);