Package: tucan
TUCAN (Tool to Unformat, Clean, ands Analyse) is a code parser for scientific codebases. It tager languages are:Very old FORTRANRecent FORTRANPython (Under development)C/C++ (Eazrly development)What is does?Remove Coding archaismsFirst is it a code cleaner. For example, this loop in `tranfit.f' a piece of CHEMKIN package  good'old FORTRAN:(547)DO2000K=1,KK-1(548)DO2000J=K+1,KK(549)DO2000N=1,NO(550)COFD(N,J,K)=COFD(N,K,J)(551)2000CONTINUEIs translated  with the commandtucan clean tranfit.fas :(547-547)do2000k=1,kk-1(548-548)do2000j=k+1,kk(549-549)do2000n=1,no(550-550)cofd(n,j,k)=cofd(n,k,j)(551-551)end do! 2000(551-551)end do! 2000(551-551)end do! 2000The cleaned version simplify the code for further analysis passes, like computing cyclomatic complexity, extracting structures, etc...Extracting code structureOn the same filetucan struct tranfit.fprovides a nested dictionary of the code structure. Here is an exemple from a code in very recent fortran:type htable.h_tuple_t:At path ['htable', 'h_tuple_t'], name h_tuple_t, lines 47 -> 526 statements over 6 linesComplexity 1Refers to 1 callables:-classContains no inner structuresContains no annotationstype_public_abstract htable.htable_t:At path ['htable', 'htable_t'], name htable_t, lines 55 -> 6410 statements over 10 linesComplexity 1Refers to 2 callables:-pass-tContains no inner structuresContains no annotationsfunction_pure htable.interface_abstract66.htable_hash:At path ['htable', 'interface_abstract66', 'htable_hash'], name htable_hash, lines 67 -> 726 statements over 6 linesComplexity 1Refers to 2 callables:-class-htable_hashContains no inner structuresContains no annotationsinterface_abstract htable.interface_abstract66:At path ['htable', 'interface_abstract66'], name interface_abstract66, lines 66 -> 738 statements over 8 linesComplexity 1Contains no callablesContains 1 elements:-htable.interface_abstract66.htable_hashContains no annotationsThis information allows the creation and manipulation of graphs to extract the structure of the codeInterpreting IFDEFSAn other nasty example is the use of ìfdefs in C or FORTRAN:#ifdef FRONT
        WRITE(*,*) " FRONT is enabled " ! partial front subroutine
        SUBROUTINE dummy_front(a,b,c)
        WRITE(*,*) " FRONT 1"     ! partial front subroutine
#else                
        SUBROUTINE dummy_front(a,d,e)
        WRITE(*,*) " FRONT 2"       ! partial front subroutine
#endif
        END SUBROUTINE

        SUBROUTINE dummy_back(a,b,c)
#ifdef BACK
        WRITE(*,*) " FRONT is enabled " ! partial front subroutine
        WRITE(*,*) " BACK 1"    ! partial back subroutine
        END SUBROUTINE  
#else
        WRITE(*,*) " BACK 2"    ! partial back subroutine
        END SUBROUTINE  
#endifDepending on the pre-definition of variables FRONT and BACK, this code snippet can be read in four ways possible.
Here are usages:tucan ifdef-clean templates_ifdef.fyields:SUBROUTINEdummy_front(a,d,e)WRITE(*,*)" FRONT 2"! partial front subroutineEND SUBROUTINESUBROUTINEdummy_back(a,b,c)WRITE(*,*)" BACK 2"! partial back subroutineEND SUBROUTINEtucan ifdef-clean templates_ifdef.f -v FRONTyields:WRITE(*,*)" FRONT is enabled "! partial front subroutineSUBROUTINEdummy_front(a,b,c)WRITE(*,*)" FRONT 1"! partial front subroutineEND SUBROUTINESUBROUTINEdummy_back(a,b,c)WRITE(*,*)" BACK 2"! partial back subroutineEND SUBROUTINEtucan ifdef-clean templates_ifdef.f -v FRONT,BACKyields:WRITE(*,*)" FRONT is enabled "! partial front subroutineSUBROUTINEdummy_front(a,b,c)WRITE(*,*)" FRONT 1"! partial front subroutineEND SUBROUTINESUBROUTINEdummy_back(a,b,c)WRITE(*,*)" BACK is enabled "! partial front subroutineWRITE(*,*)" BACK 1"! partial back subroutineEND SUBROUTINEMore about tucanTucanis used byanubis, our open-source  tool to explore the git repository of a code, andmarauder's mapour open-source tool to show codes structures by in-depth vizualisation of callgraphs and code circular-packing .