Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Retrieving Specific Data From a .txt file - PVWAVE
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Erini Lambrides  
View profile  
 More options Apr 25 2012, 2:09 pm
Newsgroups: comp.lang.idl-pvwave
From: Erini Lambrides <elamb...@u.rochester.edu>
Date: Wed, 25 Apr 2012 11:09:51 -0700 (PDT)
Local: Wed, Apr 25 2012 2:09 pm
Subject: Retrieving Specific Data From a .txt file - PVWAVE
Hello Folks,

   I haven't used pv-wave for very long, so bear with me if the answer
to my questions seem obvious. In a procedure I am writing, I want to
be able to extra certain data from a .txt file and store that data
into specific variables that I have already in my procedure. The data
within the .txt files are produced through pv-wave so it will always
be the same formatting - so Step1: find the file ( I know how to do
this)
                     Step2: user inputs a number (in my case this is
called the shot number)
                     Step3: check if that number is there
                     Step4:retrieve the data (i would only need the
lines below that shot and above the next shot)
                     Step5:split up the data into specific variables
(I can manage that)
The format of the .txt file looks something like this
shot 12345
h12 54 69 72
h13 47 85 92
.
.
.
shot 12346

Any ideas at all? Sorry if this is all sounds convoluted.

Thanks for any help!
-erini


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Helder  
View profile  
 More options Apr 25 2012, 4:03 pm
Newsgroups: comp.lang.idl-pvwave
From: Helder <hel...@marchetto.de>
Date: Wed, 25 Apr 2012 13:03:49 -0700 (PDT)
Local: Wed, Apr 25 2012 4:03 pm
Subject: Re: Retrieving Specific Data From a .txt file - PVWAVE
Hi,
I don't know about pv-wave, but below is the IDL code I would use and I'm not an expert... I just try to make things work. Please notice:
- that the is no control that the inserted number is in fact a number. In case it is not, it will either complain or go through the procedure without getting any hit.
- if you're trying to get the last shot number and the file ends on the last line (or on the line just after), the last input line will not be found. Add to your file a line with something like "end" to be on the safe side
- if the number of lines for each shot is high, then the code line MyInputData = [MyInputData,Str] will become very inefficient. If you know how many lines you will expect it is best to make the array beforehand, otherwise you might have to loop through and count the lines...

Hope it helps.

Cheers, Helder

PRO ReadShots

ShotNr = 0
READ, PROMPT='Enter Shot Number: ', ShotNr
ShotNr = LONG(ShotNr)

OPENR, LunShots, 'F:\YourDirectory\Shots.txt', /GET_LUN
Str = ''
MyInputData = ''
WHILE ~EOF(LunShots) DO BEGIN
   READF, LunShots, Str
   Pos = STRPOS(STRUPCASE(Str), 'SHOT')
   IF Pos GE 0 THEN BEGIN
      SplitStr = STRSPLIT(Str, /EXTRACT)
      IF LONG(SplitStr[1]) EQ ShotNr THEN BEGIN
         READF, LunShots, Str
         Pos = STRPOS(STRUPCASE(Str), 'SHOT')
         WHILE Pos EQ -1 && ~EOF(LunShots) DO BEGIN
           MyInputData = [MyInputData,Str]
           READF, LunShots, Str
           Pos = STRPOS(STRUPCASE(Str), 'SHOT')
         ENDWHILE
         GOTO, ExitFileSearchLoop
      ENDIF
   ENDIF
ENDWHILE

ExitFileSearchLoop:CLOSE, LunShots
FREE_LUN, LunShots
nFound = N_ELEMENTS(MyInputData)
IF (nFound GT 1) THEN BEGIN
   Header    = STRARR(nFound-1)
   FirstNum  = LONARR(nFound-1)
   SecondNum = LONARR(nFound-1)
   ThirdNum  = LONARR(nFound-1)
   FOR I=1,nFound-1 DO BEGIN
       Res = STRSPLIT(MyInputData[I],/EXTRACT)
       Header[I-1]    = Res[0]
       FirstNum[I-1]  = Res[1]
       SecondNum[I-1] = Res[2]
       ThirdNum[I-1]  = Res[2]
   ENDFOR
   PRINT, Header
   PRINT, FirstNum
   PRINT, SecondNum
   PRINT, ThirdNum
ENDIF
END


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »