[7541] | 1 | # codeinc.awk - filter of ORCHIDEE f90 files |
---|
| 2 | # command : gawk -f codeinc.awk [-d] file.f90 |
---|
| 3 | # create a file.f90_preproc_codeinc filtered |
---|
| 4 | |
---|
| 5 | #************************************************************** |
---|
| 6 | # Author: Martial.Mancip |
---|
| 7 | # Contact: Martial.Mancip__at__ipsl.jussieu.fr |
---|
| 8 | # $Revision:: $ Revision of last commit |
---|
| 9 | # $Author:: $ Author of last commit |
---|
| 10 | # $Date:: |
---|
| 11 | # IPSL (2006) |
---|
| 12 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
| 13 | # Modification: |
---|
| 14 | # |
---|
| 15 | #************************************************************** |
---|
| 16 | #========================== |
---|
| 17 | function debugprint(str) { |
---|
| 18 | if (debug) { |
---|
| 19 | print str | "cat 1>&2" |
---|
| 20 | } |
---|
| 21 | } |
---|
| 22 | function myprint(str) { |
---|
| 23 | print str >> output_file |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | #========================== |
---|
| 28 | BEGIN { |
---|
| 29 | debugprint("traitement de " ARGV[1]) |
---|
| 30 | |
---|
| 31 | nbarg=ARGC |
---|
| 32 | if (ARGV[1] == "-d") { |
---|
| 33 | debug=1 |
---|
| 34 | file=ARGV[2] |
---|
| 35 | delete ARGV[1] |
---|
| 36 | nbarg-- |
---|
| 37 | } else { |
---|
| 38 | debug=0 |
---|
| 39 | file=ARGV[1] |
---|
| 40 | } |
---|
| 41 | output_file=file "_preproc_codeinc" |
---|
| 42 | if (debug) { |
---|
| 43 | lscommand=("ls " output_file) |
---|
| 44 | outsys=system(lscommand) |
---|
| 45 | debugprint("output of ls : " outsys) |
---|
| 46 | if ( outsys == 0 ) { |
---|
| 47 | debugprint("Already find " output_file) |
---|
| 48 | outsys=system("rm " output_file) |
---|
| 49 | debugprint("output of rm : " outsys) |
---|
| 50 | system("touch " output_file) |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | # When exit statement, 'END' rule is always executed, so defined a exit_value to manage this |
---|
| 55 | exit_value=0 |
---|
| 56 | if (nbarg != 2) { |
---|
| 57 | debugprint("Usage: codeinc.awk [-d] file.f90") |
---|
| 58 | debugprint("") |
---|
| 59 | debugprint("Args:") |
---|
| 60 | debugprint(" file.f90 = source code to be parsed") |
---|
| 61 | debugprint("") |
---|
| 62 | debugprint("Options:" ) |
---|
| 63 | debugprint(" -d = debug mode") |
---|
| 64 | debugprint("") |
---|
| 65 | exit_value=1 |
---|
| 66 | exit |
---|
| 67 | } |
---|
| 68 | codeinc=0 |
---|
| 69 | linecodeinc[1]="" |
---|
| 70 | line[1]="" |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | #========================== |
---|
| 74 | { |
---|
| 75 | debugprint($0) |
---|
| 76 | |
---|
| 77 | # Get information with MPI Program Information output on NEC |
---|
| 78 | if (match($0, " *!> @codeinc *")) |
---|
| 79 | { |
---|
| 80 | codeinc=1 |
---|
| 81 | nblines=0 |
---|
| 82 | Length=(match($0,"!>")-1) |
---|
| 83 | spaces=substr($0,1,Length) |
---|
| 84 | debugprint("Find @codeinc !" spaces Length) |
---|
| 85 | myprint(spaces "!> @code") |
---|
| 86 | next |
---|
| 87 | } |
---|
| 88 | else if ( codeinc == 1 ) |
---|
| 89 | { |
---|
| 90 | if (match($0, " *!> @endcodeinc *")) |
---|
| 91 | { |
---|
| 92 | codeinc=0 |
---|
| 93 | debugprint("Find @endcodeinc !") |
---|
| 94 | for (i=0; i<nblines; i++) { |
---|
| 95 | myprint(spaces "!> " linecodeinc[i]) |
---|
| 96 | } |
---|
| 97 | myprint(spaces "!> @endcode") |
---|
| 98 | for (i=0; i<nblines; i++) { |
---|
| 99 | myprint(line[i]) |
---|
| 100 | } |
---|
| 101 | nblines=0 |
---|
| 102 | } |
---|
| 103 | else |
---|
| 104 | { |
---|
| 105 | line[nblines]=$0 |
---|
| 106 | debugprint(nblines " | " line[nblines]) |
---|
| 107 | linecodeinc[nblines]=substr(line[nblines],Length+1) |
---|
| 108 | debugprint(linecodeinc[nblines]) |
---|
| 109 | nblines++ |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | else |
---|
| 113 | { |
---|
| 114 | myprint($0) |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | END { |
---|
| 120 | close(output_file) |
---|
| 121 | } |
---|