forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Write Code to Text File

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Plato
View previous topic :: View next topic  
Author Message
viroxa



Joined: 28 Jul 2017
Posts: 69

PostPosted: Tue Aug 29, 2017 4:25 pm    Post subject: Write Code to Text File Reply with quote

Hello, everyone,

is there a way to automatically write the whole code of a project (or slices of it) to a text file?

Specifix example:
Each SUBROUTINE/FUNCTION has several commented lines at the top, containing information (what it does, when it was last changed, etc.).

Now it would be great, if I could have Plato or FTN95 extract these lines automatically from the whole project.

Thanks!
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 732

PostPosted: Thu Aug 31, 2017 1:00 am    Post subject: Reply with quote

You have made two conflicting requests. It seems to me that what you really want is just the subprogram declarations and adjacent comment lines, rather than "the whole code".

Do you want to extract just the comment lines from your source files? Do you want the context of these comment lines preserved (i.e., which subroutine/function does each comment line pertain to)? Do these comment lines precede the subprogram line, or do they follow them?

There are third party utilities to help with such work, but the task is by no means simple. If your source code was not structured so as to work with one of these utilities, that utility may not work properly.
Back to top
View user's profile Send private message
viroxa



Joined: 28 Jul 2017
Posts: 69

PostPosted: Thu Aug 31, 2017 7:36 am    Post subject: Reply with quote

You're right. Basically I only want to extract the lines between the subprogram declaration and IMPLICIT NONE.

But if there was a way to get the whole code (which I imagine to be easier) I could read the required lines from the output file.

I could just copy all the code to a text file manually, but that would take a while.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 732

PostPosted: Thu Aug 31, 2017 9:36 am    Post subject: Reply with quote

Why do you need to create duplicate copies of your source files? The source files are text files and are present in one or more sub-directories of your project, wherever those files were created.
Back to top
View user's profile Send private message
viroxa



Joined: 28 Jul 2017
Posts: 69

PostPosted: Thu Aug 31, 2017 10:07 am    Post subject: Reply with quote

Every SUBROUTINE/FUNCTION contains this header:

Code:
   SUBROUTINE form_freedom_array(fnodn,nequa)
!-------------------------------------------------------------------------
!       Title:      form_freedom_array
!
!       Type:         SUBROUTINE
!
!       Purpose:      Assemble array containing global DOFs and get number
!          of equations in problem.
!
!       Comments:    -
!
!       Licensing:      -
!
!       Originally modified:        21 August 2017
!       Original Author:             HX
!
!       Last modified:          29 August 2017
!       Modified by:             HX
!
!       Parameters:
!      I/O INTEGER fnodn:   Array containing properties of fixed nodes
!         Dimensions: (ndofn,nnodn)
!      O INTEGER nequa:   Number of equations in FE-problem
!
       IMPLICIT NONE


What I now want is to collect all these headers in my project in ONE text file, which I can then use as a reference for myself to have an overview of what I have already available and what I have to start from scratch.
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 1651
Location: Yateley, Hants, UK

PostPosted: Thu Aug 31, 2017 1:51 pm    Post subject: Reply with quote

My advice to you is to do it with a word processor, as by the time you have a program working faultlessly, you could have done the job several times over by hand! Copy your source files to a different file, and block delete the code you don't want is probably less error prone than cutting and pasting the parts you need. Finding the line numbers for each SUBROUTINE or FUNCTION statement will help you get to them in future.

I have such headers in my own programs, although usually a lot shorter, and I program in what appears to be your style: card image layout (mostly), capitals for code, lower or mixed case for comments. Your 'title' and 'type' appear to me to unnecessarily duplicate the subprogram declaration, and your 'parameters' section makes it worth putting in INTENT statements (if you haven't already got them) as they do help the compiler find a class of common programming errors.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 732

PostPosted: Thu Aug 31, 2017 2:54 pm    Post subject: Reply with quote

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:

1. heading line containing PROGRAM, SUBROUTINE or <type> FUNCTION
2. any number of comment lines
3. line containing IMPLICIT NONE statement

The same processing could be done in Fortran, if you want to write the code.
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).
Back to top
View user's profile Send private message
viroxa



Joined: 28 Jul 2017
Posts: 69

PostPosted: Sat Sep 02, 2017 11:09 pm    Post subject: Reply with quote

Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Plato All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group