Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find a phrase in a file

Status
Not open for further replies.

iroger

Mechanical
Feb 20, 2011
2
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
 
Replies continue below

Recommended for you

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.
 
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
Chinese prisoner wins Nobel Peace Prize
 
XWB- i am using fortran 90 and I have the intel compiler.

Thanks alot...
 
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.
 
the usual problem with spreadsheet calc is insufficient representation of floating point, otherwise it is great where it works
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor