Creating subset of compilation errors

I am compiling a fortran program using gfortran and the result looks as below

I want to write a bash or awk script that will scan the information and output
only problems within a range of line numbers

Example: If I specify the file createmodl.f08, start line 1000 and end line 1100, I will only get the lines in the mentioned range. So only errors
between createmodl.f08:1000 and createmodl.f08:1100 are displayed.

createmodl.f08:585.9:

allocate(posn_outerRect(4))
         1
Error: Allocate-object at (1) is not a nonprocedure pointer or an allocatable variable
createmodl.f08:586.9:

allocate(posn_innerRect(4))
         1
Error: Allocate-object at (1) is not a nonprocedure pointer or an allocatable variable
createmodl.f08:594:

pTopLft = posn_outerRect(1:2)
1
Error: Unclassifiable statement at (1)
createmodl.f08:595:

pBtmRht = posn_outerRect(3:4)
1
Error: Unclassifiable statement at (1)
createmodl.f08:599:

pTopLft = posn_innerRect(1:2)
1
Error: Unclassifiable statement at (1)
createmodl.f08:600:

pBtmRht = posn_innerRect(3:4)
1
Error: Unclassifiable statement at (1)
createmodl.f08:779.46:

    apodw(ix1,ix2) = win_x1(ix1) * win_x2(ix2)
                                              1
Error: Unexpected STATEMENT FUNCTION statement at (1)
createmodl.f08:1001.9:

allocate(val(6))
         1
Error: Allocate-object at (1) is not a nonprocedure pointer or an allocatable variable
createmodl.f08:1008.16:

      read(s, *) (val(k), k = 1, 6)
                1
Error: Expected variable in READ statement at (1)
createmodl.f08:1015.14:

deallocate(val)
              1
Error: 'val' at (1) is not a variable
createmodl.f08:1078.35:

end subroutine compute_bkgrdModl_1d
                                   1
Error: Expected label 'compute_bkgnd_modl_1d' for END SUBROUTINE statement at (1)
createmodl.f08:1101:

subroutine compute_bkgrd_modl_2d(nx, nz, z, bkgrd_m2d)
1
Error: Unclassifiable statement at (1)
createmodl.f08:1102.13:

implicit none
             1
Error: Unexpected IMPLICIT NONE statement at (1)
createmodl.f08:1106.25:

integer, intent(in) :: nx
                         1
Error: Unexpected data declaration statement at (1)
createmodl.f08:1107.25:

integer, intent(in) :: nz
                         1
Error: Symbol 'nz' at (1) already has basic type of INTEGER
createmodl.f08:1108.36:

real, dimension(nz), intent(in) :: z
                                    1
Error: Symbol 'z' at (1) already has basic type of REAL
createmodl.f08:1109.49:

real, dimension(nx, nz), intent(out) :: bkgrd_m2d
                                                 1
Error: Unexpected data declaration statement at (1)
createmodl.f08:1113.42:

real, dimension(:), allocatable :: bgrdm1d
                                          1
Error: Unexpected data declaration statement at (1)
createmodl.f08:1116.13:

integer :: ix
             1
Error: Unexpected data declaration statement at (1)
createmodl.f08:1117.13:

integer :: iz
             1
Error: Unexpected data declaration statement at (1)
createmodl.f08:1121.9:

allocate(bgrdm1d(nz))
         1
Error: Allocate-object at (1) is not a nonprocedure pointer or an allocatable variable
createmodl.f08:1126.36:

      bgrdm2d(ix,iz) = bkgrd_m1d(iz)
                                    1
Error: Unexpected STATEMENT FUNCTION statement at (1)
createmodl.f08:1130.19:

deallocate(bgrd_m1d)
                   1
Error: Allocate-object at (1) is not a nonprocedure pointer or an allocatable variable
createmodl.f08:1132.36:

end subroutine compute_bkgrd_modl_2d
                                    1
Error: Expected label 'compute_bkgnd_modl_1d' for END SUBROUTINE statement at (1)
createmodl.f08:1161:

subroutine compute_prtb_modl_2d(nx, nz, prtbm, pc, z, iPrtb, sTaprs, nTaprs)
1
Error: Unclassifiable statement at (1)
Fatal Error: Error count reached limit of 25.

---------- Post updated 11-05-12 at 06:46 AM ---------- Previous update was 11-04-12 at 08:28 AM ----------

I have created a small awk script

#!/bin/awk

/createmodl.f08:1000/ {doPrint=1} 
{if (doPrint==1) print} 
/createmodl.f08:1100/ {doPrint=0}

However this will only work if there is an exact match of createmodl.f08:1000 and createmodl.f08:1100

Try something like this.

awk -F ":" '
$1 == "createmodl.f08" && $2 > 1000{s=1}
$1 == "createmodl.f08" && $2 > 1100{s=""}
{if(s && $0 ~ /Error/){print }}
' file

The problem is that this only matches Error, whereas I want every line in between

createmodl.f08:1000 and createmodl.f08:1100

then remove error from awk..:slight_smile:

awk -F ":" '
$1 == "createmodl.f08" && $2 > 1000{s=1}
$1 == "createmodl.f08" && $2 > 1100{s=""}
{if(s){print }}
' file
1 Like

This might do what you want:

 awk -F: '/createmodl.f08/ {P= $2>=1000 && $2<=1100} P' file

I want to use the script as follows

awk -v fn=createmodl.f08 -v ls=1000 -v le=1100 -f compck.awk cmplnk.smry 
#!/bin/awk

#    compcheck.awk - Checks errors when compiling and linking
#
#! @synopsis
#    awk -v fn=STRING -v ls=NUM -v le=NUM -f compcheck.awk FILE
#
#! @param[in] fn  Name of file to check for compilation errors
#! @param[in] ls  Beginning of line to include information
#! @param[in] le  End of line to include information
#
#! @examples
#    awk -v fn=createmodl.f08 -v ls=1000 -v le=1100 -f compck.awk cmplnk.smry

BEGIN {
  FS = ":"
}

$1 == fn && $2 >= ls { s = 1 }
$1 == fn && $2 >= le { s = "" }
{ if (s) { print } }

---------- Post updated at 07:54 AM ---------- Previous update was at 07:47 AM ----------

How does this work exactly?

So whats the problem....:slight_smile:

$ cat file
createmodl.f08:800.36:
createmodl.f08:900.36:
createmodl.f08:1030.36:
createmodl.f08:1050.36:
Error
Error
ErrorError
Error
Error
Error
createmodl.f08:1090.36:
createmodl.f08:1132.36:
Errordfsdf
$ cat awk.awk
BEGIN {
  FS = ":"
}
$1 == fn && $2 >= ls { s = 1 }
$1 == fn && $2 >= le { s = "" }
{ if (s) { print } }
$ awk -v fn=createmodl.f08 -v ls=1000 -v le=1100 -f awk.awk file
createmodl.f08:1030.36:
createmodl.f08:1050.36:
Error
Error
ErrorError
Error
Error
Error
createmodl.f08:1090.36:

It checks for the existence of createmodl in a line, then, if $2 is greater than or equal 1000 AND less than or equal 1100, it sets the logical variable P to 1, to 0 in all other cases. While P = 1, i.e. $2 between 1000 and 1100, every line is printed.
To build your desired script, use as follows:

awk -v fn=createmodl.f08 -v ls=1000 -v le=1100 'match($0,fn) {P= $2>=ls && $2<=le} P' FS=":" cmplnk.smry

Nothing wrong