Subroutine or Function Summary


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Subroutine or Function Summary
# 1  
Old 08-03-2016
Subroutine or Function Summary

I have a fortran file with code declarations such as

Code:
 Subroutine  str_tnum_tu  &
   (                      &
     s, dl, tu, pos       &
   )
   !
 Class (*), Intent (InOut) :: tu(:)
 Character (Len=*), Intent (In) :: s, dl
 Character (Len=*), Intent (In), Optional :: pos

 ...

or

Code:
 Function  str_tnum_tu  &
   (                                      &
     s, dl, tu, pos               &
   )
   !
 Class (*), Intent (InOut) :: tu(:)
 Character (Len=*), Intent (In) :: s, dl
 Character (Len=*), Intent (In), Optional :: pos
 
 ...

I want to run a command ti get me the lines starting from
the word 'Subroutine' or 'Function' to the line before an empty line.
# 2  
Old 08-03-2016
Code:
awk '/^ *Subroutine/ || /^ *Function/ {p=1} !NF {p=0} p' infile

# 3  
Old 08-04-2016
Code:
sed -n '/^ *\([sS]ub\|[fF]unc\)/,/^ *$/p' file

# 4  
Old 08-05-2016
Both commands are printing the whole file, not just the subroutine or function declarations.
# 5  
Old 08-05-2016
No, they do NOT. Both tested OK with the sample given. Check your context / environment.
# 6  
Old 08-05-2016
I have tried the following and it should print

Code:
 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold

However the output is getting past the blank line after

Code:
Class (*), Intent (in) :: mold



Code:
 !$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

 !> \brief Determines if a string is numeric.
 !
 !> \par Example
 !> \code{.f} 
 !>    Character (len=8) :: s;  Logical :: isnum; 
  !> \endcode
 !
 !> \param[in] s     String.
 !> \param[in] fmt   Format descriptor.
 !> \param[in] mold  Scalar or an array of any type. 
 !
 !> \result    True if string represents a numeric value. 

 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold

 Real :: r
 Integer :: i
 Double Precision :: d

 Character (len=65) :: frmt
 Integer :: ios

# 7  
Old 08-05-2016
Code:
dos2ux < infile | awk '/^ *Subroutine/ || /^ *Function/ {p=1} !NF {p=0} p'

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to convert FORTRAN subroutine to awk function?

Hi All I am trying to convert some Fortran subroutine to awk function , those who know kindly explain how to define function in awk, and how to call function Fortran subroutine looks somewhat like this SUBROUTINE GDATE (JD, YEAR,MONTH,DAY) C C---COMPUTES THE GREGORIAN CALENDAR DATE... (5 Replies)
Discussion started by: Akshay Hegde
5 Replies

2. Shell Programming and Scripting

Passing parameters to bash script function (or subroutine)

I've found a few posts regarding passing parameters to a function or subroutine, but for some reason when I try to run a command based on part with these parameters it's not working. If I have the function echo the parameters they show correctly so I believe they are being passed right but the... (2 Replies)
Discussion started by: withanh
2 Replies

3. UNIX for Dummies Questions & Answers

Help with Subroutine

Okay I have a 1TB drive that is almost completely full with vids. I am in the process of converting them to mp4. I have two scripts right now. One is a shell script to convert them with Handbrake. The other is a script to get a sort of progress report. To make things easier to understand, I will... (0 Replies)
Discussion started by: Dalton63841
0 Replies

4. Shell Programming and Scripting

getopts not updating from subroutine.

So, I'm running a script with a couple of subroutines, one of which takes arguments using getopts. The first time i call the subroutine everything works as expected, the second time I call it none of the arguments change. Here's a small section of code that shows this behavior. #!/bin/sh... (3 Replies)
Discussion started by: dhibbit
3 Replies

5. Shell Programming and Scripting

Running more than one function from a subroutine

Hi All I am new to perl so had one question. I have one Subroutine which works as expected and below is just an example. where I ran a command and check the output. so my question is if I have more than one command then how to check the results, meaning I want to add more command and check... (2 Replies)
Discussion started by: tannu
2 Replies

6. Shell Programming and Scripting

Using Subroutine / Function in case statement

I have issue running functions under case statement #!/bin/bash single() { Commands } multiple() { Commands } until ; do echo -e " \t \t M A I N - M E N U Perforce delete script \n" (1 Reply)
Discussion started by: sriram003
1 Replies

7. Programming

Subroutine Hung

Hi friends I am Administrator for a system works with uinx OS but, many times I get messages from server console inform me about Subroutine is Hanging so what can I do to reset this Subroutine? Note: always when I got that I restart the server but I think that is not professional solution. (3 Replies)
Discussion started by: bintaleb
3 Replies

8. AIX

Using the passwdpolicy() subroutine.

Okay, so in AIX, there are various subroutines that is built in to the OS. The subroutine is I want to use is passwdpolicy(). So I want to construct a C program that will be able to pass credentials into the program and thusly into the subroutine. I'm not asking for homework, or for someone to... (0 Replies)
Discussion started by: syndex
0 Replies
Login or Register to Ask a Question