Here is the source code of a C utility to do what you (viroxa) want; I modified an existing utility that I had for this purpose. It assumes the following input file structure:
- heading line containing PROGRAM, SUBROUTINE or <type> FUNCTION
- any number of comment lines
- line containing IMPLICIT NONE statement
The same processing could be done in Fortran, if you want to write the code.
/* Utility to echo subprogram heading and subsequent comment lines
until an 'IMPLICIT NONE' line is seen.
USAGE: comnts < abc.f90 > myheaders.txt
...
comnts < xyz.f90 >> myheaders.txt
Fortran source is read from STDIN, and must be free form.
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <clib.h>
main(){
char line[200],*ptr;
int i,printon;
printon=0;
while(fgets(line,200,stdin)){
i=0; while(line[i] != '\n')i++; // remove trailing blanks
do i--; while(line[i]==' '); line[++i]='\n'; line[++i]='\0';
i=0;
while(line[i]==' ')i++; // skip leading blanks
if(line[i] != '!'){
if(strnicmp(line+i,'subroutine',10)==0)printon=1;
else if(strnicmp(line+i,'program',7)==0)printon=1;
else if(strnicmp(line+i,'implicit none',13)==0)printon=0;
else {
ptr=strchr(line+i,'f'); if(!ptr)ptr=strchr(line+i,'F');
if(ptr && strnicmp(ptr,'function',8)==0)printon=1;
}
}
if(printon)printf(line);
}
}
You can use any C compiler, including Silverfrost SCC (the '#include <clib.h>' line is needed for only SCC).