File: mem_counter

package info (click to toggle)
espresso 6.7-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 311,068 kB
  • sloc: f90: 447,429; ansic: 52,566; sh: 40,631; xml: 37,561; tcl: 20,077; lisp: 5,923; makefile: 4,503; python: 4,379; perl: 1,219; cpp: 761; fortran: 618; java: 568; awk: 128
file content (66 lines) | stat: -rwxr-xr-x 1,664 bytes parent folder | download | duplicates (3)
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
#!/bin/bash

TOOLDIR=$(dirname $0)

revert=0
case $1 in 
    ("-h" | "--help" )      echo " Add memory counter to *.f90 files. Usage:
   mem_counter [-h, --help] [-r, --revert] [DIRS]

 -h, --help           print this manual    
 -r, --revert         revert to original state
 DIRS                 list of directories to be processed
                      (also accepted: list of files to be processsed)
                      if absent, search all directories below the current one"
 exit 0;;
    ("-r" | "--revert" )  revert=1; shift;;
esac

if [[ $# == 0 ]] ; then
    fnames=$(find -type f -name "*.f90" )
else
    for dir in $@
    do
	if [[ -d $dir ]] ; then
	    fnames="$fnames $dir/*.f90"
	else
	    fnames="$fnames $dir"
	fi
    done
fi

if [[ $revert == 0 ]] ; then
    # add memory check
    for f in $fnames ; do
        # for all *.f90 files found ...
	if [[ ! -f $f.bkp ]] ; then 
           # if there is no *.f90.bkp file ...
	   python $TOOLDIR/mem_counter.py $f
           # add calls to mem_report
	   diff -q $f.new $f > /dev/null
           # check if file $f.new differs from $f
	   if [[ $? == 1 ]] ; then
	       # file is modified: save old copy in .bkp 
	       mv $f $f.bkp
	       mv $f.new $f
	   else
	       # file is not modified: leave as is
	       /bin/rm $f.new
	   fi
	fi
    done
else
    # remove memory check
    for f in $fnames ; do
	if [[ -f $f.bkp ]] ; then
           # if there is a *.f90.bkp file, restore it ...
	   mv $f.bkp $f
           # ... and delete file *.o if ptesent
	   fil=$(basename $f .f90)
	   dir=$(dirname $f)
	   obj="$dir/$fil".o
	   if [[ -f $obj ]] ; then echo /bin/rm $obj; fi
	fi
    done
fi