[cig-commits] [commit] devel: added utils/clean_listings_specfem.pl , which is used by BuildBot (c7a62e9)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Fri Jan 9 09:04:28 PST 2015
Repository : https://github.com/geodynamics/specfem3d
On branch : devel
Link : https://github.com/geodynamics/specfem3d/compare/3ad640558f4b1a557ba5ff694dac9425571ba95c...c7a62e95327698dbd3301103fb8787dfc87b1930
>---------------------------------------------------------------
commit c7a62e95327698dbd3301103fb8787dfc87b1930
Author: Dimitri Komatitsch <komatitsch at lma.cnrs-mrs.fr>
Date: Fri Jan 9 18:00:32 2015 +0100
added utils/clean_listings_specfem.pl , which is used by BuildBot
>---------------------------------------------------------------
c7a62e95327698dbd3301103fb8787dfc87b1930
utils/clean_listing_f90.pl | 57 --------------
utils/clean_listings_specfem.pl | 170 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 170 insertions(+), 57 deletions(-)
diff --git a/utils/clean_listing_f90.pl b/utils/clean_listing_f90.pl
deleted file mode 100755
index 8a5fae1..0000000
--- a/utils/clean_listing_f90.pl
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/usr/bin/perl
-
-#
-# Clean spaces, tabs and other non-standard or obsolete things in f90 files
-#
-# Author : Dimitri Komatitsch, EPS - Harvard University, January 1998
-#
-
-#
-# read and clean all f90 files in the current directory
-#
-
- @objects = `ls *.f90 *.F90 *.h *.h.in */*.f90 */*.F90 */*.h */*.h.in */*/*.f90 */*/*.F90 */*/*.h */*/*.h.in`;
-
- foreach $name (@objects) {
- chop $name;
-# change tabs to white spaces
- system("expand -2 < $name > _____tutu08_____");
- $f90name = $name;
- print STDOUT "Cleaning $f90name ...\n";
-
- open(FILE_INPUT,"<_____tutu08_____");
- open(FILEF90,">$f90name");
-
-# open the input f90 file
- while($line = <FILE_INPUT>) {
-
-# suppress trailing white spaces and carriage return
- $line =~ s/\s*$//;
-
-# use new syntax of comparison operators, ignoring case in starting pattern (useful in case of mixed case)
- $line =~ s#\.le\.#<=#ogi;
- $line =~ s#\.ge\.#>=#ogi;
- $line =~ s#\.lt\.#<#ogi;
- $line =~ s#\.gt\.#>#ogi;
- $line =~ s#\.eq\.#==#ogi;
- $line =~ s#\.ne\.#/=#ogi;
-
-# change pause statements into stop statements
-# $line =~ s#pause#stop#ogi;
-
- $line =~ s#end do#enddo#ogi;
- $line =~ s#end if#endif#ogi;
-
- $line =~ s#elseif#else if#ogi;
-
- print FILEF90 "$line\n";
-
- }
-
- close(FILE_INPUT);
- close(FILEF90);
-
- }
-
- system("rm -f _____tutu08_____");
-
diff --git a/utils/clean_listings_specfem.pl b/utils/clean_listings_specfem.pl
new file mode 100755
index 0000000..5ed2ad3
--- /dev/null
+++ b/utils/clean_listings_specfem.pl
@@ -0,0 +1,170 @@
+#!/usr/bin/perl
+
+
+################
+################ run this script from the root directory of the package
+################
+
+
+# List of source code beautifiers found by Dimitri, June 2014:
+# -----------------------------------------------------------
+
+# My own Perl script (below), which cannot hurt anyway, and which I already run manually on the three source codes a few
+# times a year:
+
+# clean_listing_specfem.pl
+
+# Basic, but replaces all tabs, removes useless white spaces, switches all comparison operators to their modern syntax
+# (changing .GE. to >= and so on), and a few other useful things.
+# It does not analyze indenting though.
+
+# For C files we could use "A-Style" instead ( http://astyle.sourceforge.net/ ) as we mentioned (I am not sure if it
+# handles CUDA in addition to C; it does NOT support Fortran for sure).
+
+# --------------------
+
+# For Fortran:
+
+# https://www.freelancer.com/projects/Python-Fortran/Fortran-source-code-beautifier-Python.html
+# Quote from that page: "NOTE: as example of beautiful Fortran code refer to http://www.cp2k.org/. By the way, as part of
+# CP2K there is Python normalizer which performs good Fortran beautification and can be used as a baseline."
+# http://www.cp2k.org
+# http://www.cp2k.org/dev:codingconventions
+
+# It contains a Python script called prettify.py, which calls another Python program called normalizeFortranFile.py.
+# We could try it (I am not sure I like their idea of converting all Fortran keywords to uppercase, but I think there is
+# a flag to turn that off).
+# Not clear if it takes care of indenting, it probably does but we should check (if not then it is probably not very
+# useful for SPECFEM because my simple Perl script below is then probably sufficient).
+
+# --------------------
+
+# http://dev.eclipse.org/mhonarc/lists/photran/msg01761.html
+# http://dev.eclipse.org/mhonarc/lists/photran/msg01767.html
+# http://www.ifremer.fr/ditigo/molagnon/fortran90/
+
+# Was nice, but written in 2001 and unsupported since then (although the language has not changed that much since then,
+# thus it may not be a problem; but Fortran2003 has a few extra keywords, and it seems this package only supports F90 but
+# not F95, which we use a lot).
+# I would tend to favor the Python program above because it is actively maintained and was written much more recently.
+# And it is used routinely by CP2K developers, CP2K being a well-known open-source project for molecular dynamics.
+
+# --------------------
+
+# http://ray.met.fsu.edu/~bret/fpret.html
+
+# Was nice, but written in 1995 and only supports Fortran77, thus cannot be used in our case.
+
+# --------------------
+
+# Conclusions:
+
+# - BuildBot could already automatically run my Perl script (on every pull request? or on the whole code, from time to
+# time, independently of pull requests?). It cannot hurt.
+
+# - see if calling prettify.py from CP2K (with upper case conversion turned off?) for our Fortran files
+# could be a good idea.
+
+
+# --------------------
+# --------------------
+# --------------------
+
+
+#
+# Clean spaces, tabs and other non-standard or obsolete things in f90 files
+#
+# Author : Dimitri Komatitsch, EPS - Harvard University, USA, January 1998
+#
+
+#
+# read and clean all f90 files in the current directory and subdirectories
+#
+
+ @objects = `ls *.f90 *.F90 *.h *.h.in *.fh */*.f90 */*.F90 */*.h */*.h.in */*.fh */*/*.f90 */*/*.F90 */*/*.h */*/*.h.in */*/*.fh */*/*/*.f90 */*/*/*.F90 */*/*/*.h */*/*/*.h.in */*/*/*.fh`;
+
+ foreach $name (@objects) {
+ chop $name;
+# change tabs to white spaces
+ system("expand -2 < $name > _____temp08_____");
+ $f90name = $name;
+ print STDOUT "Cleaning $f90name ...\n";
+
+ open(FILE_INPUT,"<_____temp08_____");
+ open(FILEF90,">$f90name");
+
+# open the input f90 file
+ while($line = <FILE_INPUT>) {
+
+# suppress trailing white spaces and carriage return
+ $line =~ s/\s*$//;
+
+# use new syntax of comparison operators, ignoring case in starting pattern (useful in case of mixed case)
+ $line =~ s#\.le\.#<=#ogi;
+ $line =~ s#\.ge\.#>=#ogi;
+ $line =~ s#\.lt\.#<#ogi;
+ $line =~ s#\.gt\.#>#ogi;
+ $line =~ s#\.eq\.#==#ogi;
+ $line =~ s#\.ne\.#/=#ogi;
+
+#
+# known problem: does the changes also in constant strings, and not only
+# in the code (which is dangerous, but really easier to program...)
+#
+# DK DK this could be dangerous if these words appear in strings or print statements
+ $line =~ s#end\s*if#endif#ogi;
+ $line =~ s#end\s*do#enddo#ogi;
+ $line =~ s#elseif#else if#ogi;
+ $line =~ s#use\s*::\s*mpi#use mpi#ogi;
+ $line =~ s#enddo_LOOP_IJK#ENDDO_LOOP_IJK#ogi;
+
+ print FILEF90 "$line\n";
+
+ }
+
+ close(FILE_INPUT);
+ close(FILEF90);
+
+ }
+
+ system("rm -f _____temp08_____");
+
+#
+# Clean spaces in C files
+#
+# Author : Dimitri Komatitsch, EPS - Harvard University, USA, January 1998
+#
+
+#
+# read and clean all C and CUDA files in the current directory
+#
+
+ @objects = `ls *.c *.cu *.h *.h.in *.fh */*.c */*.cu */*.h */*.h.in */*.fh */*/*.c */*/*.cu */*/*.h */*/*.h.in */*/*.fh */*/*/*.c */*/*/*.cu */*/*/*.h */*/*/*.h.in */*/*/*.fh`;
+
+ foreach $name (@objects) {
+ chop $name;
+# transformer les tabulations en caracteres blancs
+ system("expand -2 < $name > _____temp08_____");
+ $cname = $name;
+ print STDOUT "Cleaning $cname ...\n";
+
+ open(FILEDEPART,"<_____temp08_____");
+ open(FILEC,">$cname");
+
+# lecture proprement dite du fichier C et changements
+ while($line = <FILEDEPART>) {
+
+# suppress trailing white spaces and carriage return
+ $line =~ s/\s*$//;
+
+ print FILEC "$line\n";
+
+ }
+
+ close(FILEDEPART);
+ close(FILEC);
+
+ }
+
+ system("rm -f _____temp08_____");
+
More information about the CIG-COMMITS
mailing list