Index: src/fortranscanner.l
===================================================================
--- src/fortranscanner.l	(revision 617)
+++ src/fortranscanner.l	(working copy)
@@ -177,6 +177,7 @@
 static int getAmpersandAtTheEnd(const char *buf, int length);
 static void pushBuffer(QCString &buffer);
 static void popBuffer();
+static void extractPrefix(QCString& text);
 
 //-----------------------------------------------------------------------------
 #undef	YY_INPUT
@@ -639,23 +640,7 @@
 		                           // TYPE_SPEC is for old function style function result
                                            result= yytext;
                                            result= result.stripWhiteSpace();
-                                           int prefixIndex = 0;
-                                           int curIndex = 0;
-                                           bool cont = TRUE;
-                                           const char* pre[] = {"RECURSIVE","PURE","ELEMENTAL"};
-                                           while(cont)
-                                           {
-                                             cont = FALSE;
-                                             for(unsigned int i=0; i<3; i++)
-                                             {
-                                               if((prefixIndex=result.find(pre[i], curIndex, FALSE))==0)
-                                               {
-                                                 result.remove(0,strlen(pre[i]));
-                                                 result.stripWhiteSpace();
-                                                 cont = TRUE;
-                                               }
-                                             }
-                                           }
+                                           extractPrefix(result);
                                            //fprintf(stderr, "===%s\n", (const char*)result);
   					   current->type = result;
                                            yy_push_state(SubprogPrefix);
@@ -667,9 +652,12 @@
                                          BEGIN(Subprog);
                                        }
 
-<Start,ModuleBody,SubprogBody,InterfaceBody,ModuleBodyContains,SubprogBodyContains>^{BS}{SUBPROG}{BS_} {
+<Start,ModuleBody,SubprogBody,InterfaceBody,ModuleBodyContains,SubprogBodyContains>^{BS}({PREFIX}{BS_})?{SUBPROG}{BS_} {
                                          // Fortran subroutine or function found
-                                         addSubprogram(yytext);
+                                         result= yytext;
+                                         result= result.stripWhiteSpace();
+                                         extractPrefix(result);
+                                         addSubprogram(result);
                                          yy_push_state(Subprog);
                                        }
 
@@ -796,6 +784,27 @@
 %%
 //----------------------------------------------------------------------------
 
+static void extractPrefix(QCString &text) {
+  int prefixIndex = 0;
+  int curIndex = 0;
+  bool cont = TRUE;
+  const char* pre[] = {"RECURSIVE","PURE","ELEMENTAL"};
+  while(cont)
+  {
+    cont = FALSE;
+    for(unsigned int i=0; i<3; i++)
+    {
+      if((prefixIndex=text.find(pre[i], curIndex, FALSE))==0)
+      {
+        text.remove(0,strlen(pre[i]));
+        text.stripWhiteSpace();
+        cont = TRUE;
+      }
+    }
+  }
+}
+
+
 static int getAmpersandAtTheEnd(const char *buf, int length)
 {
   // Avoid ampersands in string and comments
