×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Find a phrase in a file

Find a phrase in a file

Find a phrase in a file

(OP)
All-  So the last time I wrote a program in Fortran was over 15 years ago.  I have Chapman's book and trying to refresh my memory now.  It's coming back to me, but slowly (old age).

So my problem.  I have a file that contains a lot of information in sections and need strip out each section to another file.  The sections starts with *NAME and ends with a * or $.  Below is an example:

*NODE
  600204       2.8416665       -0.132341       0.6456926
  600205       2.8416665      -0.1343255       0.6204348
  600206       2.8416665        -0.13631        0.595177
  600207       2.8416665      -0.1618106        0.595177
  600208       2.8416665      -0.1873112        0.595177
  600209       2.8416665      -0.2128118        0.595177
  600210       2.8416665      -0.2383125        0.595177
  600211       2.8416665      -0.2638131        0.595177
  600212       2.8416665      -0.2893137        0.595177
  600213       2.8416665      -0.3148143        0.595177
  600214       2.8416665      -0.3403149        0.595177
...
...
*     !or may end with $

The file has multiple *NODE sections in different places in the file.  How do I search for *NODE in a file, take that information in between, and write it to another file?

Any suggestion will be very helpful....

Roger

RE: Find a phrase in a file

Which fortran are you using - 66, 77, 90, 95 or 2003?  Also which compiler?  We've had people programming in MSFortran 4.1 in F66.

RE: Find a phrase in a file

Why do you need to do it in FORTRAN?  

This is something that you can Macro Record in Word and wrap with a FOR loop.  The following is an EXCEL macro that finds a word in a WORD file "transmittance" and copies the value from the text file back into the Excel file

CODE

Sub LT7()
'
' Lowtran7 macro to paste Lowtran transmission results into Excel Spreadsheet
' Macro recorded 1/23/98
'

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Dim ColIndex, RowIndex, StartRow, Done, Index
    Dim FileName, SheetName
    
    Dim WordApp As Object
    Dim Trans As String
       
    Set WordApp = GetObject(, "word.application")
    
    FileName = ActiveWorkbook.Name
    SheetName = ActiveSheet.Name
    
    Sheets(SheetName).Select
    Done = False
    ColIndex = ActiveCell.Column
    RowIndex = ActiveCell.Row
    StartRow = RowIndex
    
    Cells(RowIndex, ColIndex).Select
    With WordApp.Selection.Find
        .Text = "transmittance ="
        .Replacement.Text = ""
    End With
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    For Index = 1 To 25
        WordApp.Selection.Find.ClearFormatting
        WordApp.Selection.Find.Execute
        WordApp.Selection.MoveRight unit:=wdCharacter, Count:=1
        WordApp.Selection.MoveRight unit:=wdSentence, Count:=1, Extend:=wdExtend
'        WordApp.Selection.Copy
        Trans = WordApp.Selection.Text
        WordApp.Selection.MoveDown unit:=wdLine
        
        Cells(RowIndex, ColIndex).Select
'        ActiveSheet.Paste
        ActiveCell.Formula = Trans
        
        RowIndex = RowIndex + 1
    Next
    Cells(StartRow, ColIndex).Select
End Sub

TTFN

FAQ731-376: Eng-Tips.com Forum Policies
Chinese prisoner wins Nobel Peace Prize

RE: Find a phrase in a file

(OP)
XWB-  i am using fortran 90 and I have the intel compiler.

Thanks alot...

RE: Find a phrase in a file

Declare a buffer as

CODE

character*80 buff
Read each line from the file as '(A)'

Check if buff(1:1) is '*'.  If it isn't, read (buff, ...) if you wish to read the data

If it is,

ll = len(trim(buff))
if (buff(ll:ll) .eq. '$') then  do whatever.

RE: Find a phrase in a file

the usual problem with spreadsheet calc is insufficient representation of floating point, otherwise it is great where it works

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close