#!/bin/sh

## Basic statitics on code / comments lines in NEMO sources per release

printf "%40s %7s %7s(ratio) %7s\n\n" '' code comm total

for release_srcs in "release-3.4/NEMOGCM/NEMO/*" "release-3.6/NEMOGCM/NEMO/*" "release-4.0/src/*"; do

    total_code=0; total_comm=0; total_line=0

    for dir in $release_srcs; do
        printf "%-40s " $dir
        nb_code_lines=$( find $dir -name *.[fFh]90 -exec grep '^ *[^!]' {} \; | wc -l )
        nb_comm_lines=$( find $dir -name *.[fFh]90 -exec grep '^ *!'    {} \; | wc -l )
        ratio=$( echo "scale = 3; ( $nb_comm_lines / ( $nb_code_lines + $nb_comm_lines ) ) * 100 " | bc | tr . , )
        printf "%7d %7d(%4.1f%%) %7d\n" $nb_code_lines $nb_comm_lines $ratio $(( nb_code_lines + nb_comm_lines ))
        total_code=$(( total_code + nb_code_lines                 ))
        total_comm=$(( total_comm                 + nb_comm_lines ))
        total_line=$(( total_line + nb_code_lines + nb_comm_lines ))
    done

    ratio=$( echo "scale = 3; ( $total_comm / $total_line ) * 100 " | bc | tr . , )
    printf "%40s %7d %7d(%4.1f%%) %7d\n\n" total $total_code $total_comm $ratio $total_line

done

exit 0
