Import selected lines from an Ascii file

G

Guest

I have an ascii file that has data organized in blocks.
Each block's header line has a "~" in column 1.
eg.
~Well Information Block

How can I import the data in the "Curve information block" and the "~ASCII DEPTH" or sometimes called "~A DEPTH" blocks only?

I 've included some sample data.

~Version : LASO vs 4.1 - DATA COPYRIGHT - INTERNATIONAL DATASHARE CORPORATION
VERS. 2.0 : CWLS Log ASCII Standard -VERSION 2.0
WRAP. NO : One line per depth step
~Well Information Block
#MNEM.UNIT Data Description of Mnemonic
#----.---- -------------------------- : -----------------------------
STRT.M 80.8000 : Start Depth
STOP.M 1294.6000 : End Depth
STEP.M 0.2000 : Depth Increment
NULL. -999.25 : NULL Value
COMP. : COMPANY
WELL. PCP WROSES 6-3-45-3 : WELL NAME
FLD . : FIELD NAME
LOC . : WELL LOCATION
UWI . 100060304503W500 : UNIQUE WELL ID
~Tops
#TOPS NAME DEPTH:
TOTAL DEPTH 1295.0000:
~Curve Information Block
#MNEM.UNIT API CODE Curve Description
#----.---- LG--CV-CL--M : -----------------
DEPT.M 0 1 0 0 : 1 DEPTH
GR .GAPI 0 310 1 0 : 2 GAMMA RAY
AO10.OHMM 14 125 11 0 : 3 AIT 1FT VERT, 10" DEPTH
AO20.OHMM 14 125 12 0 : 4 AIT 1FT VERT, 20" DEPTH
AO30.OHMM 14 125 13 0 : 5 AIT 1FT VERT, 30" DEPTH
AO60.OHMM 14 125 16 0 : 6 AIT 1FT VERT, 60" DEPTH
AO90.OHMM 14 125 19 0 : 7 AIT 1FT VERT, 90" DEPTH
AT10.OHMM 14 125 21 0 : 8 AIT 2FT VERT, 10" DEPTH
AT20.OHMM 14 125 22 0 : 9 AIT 2FT VERT, 20" DEPTH
AT30.OHMM 14 125 23 0 :10 AIT 2FT VERT, 30" DEPTH
AT60.OHMM 14 125 26 0 :11 AIT 2FT VERT, 60" DEPTH
AT90.OHMM 14 125 29 0 :12 AIT 2FT VERT, 90" DEPTH
CALI.MM 42 280 5 0 :13 CALIPER
CAY .MM 42 280 2 0 :14 CALIPER-2
NPHI.V/V 42 890 4 0 :15 NEUTRON POROSITY (OTHER)
DEN .K/M3 45 350 1 0 :16 BULK DENSITY
DPHI.V/V 45 890 13 0 :17 DENSITY POROSITY (OTHER)
SP .MV 7 10 1 0 :18 SPONTANEOUS POTENTIAL
CAX .MM 43 280 1 0 :19 CALIPER-1
DC .K/M3 43 356 0 0 :20 DENSITY CORRECTION
PEF . 43 358 1 0 :21 PHOTO ELECTRIC EFFECT
~Parameter Information Block
#MNEM.UNIT Data Description of Mnemonic
#----.---- -------------------------- : -----------------------------
RUN . 1 : Run Number
GL .M 0.0000 : Ground Level Elevation
DREF. KB : Depth Reference
EREF.M 0.0000 : Elevation of Depth Reference
KB .M 0.0000 : Elevation of Kelly Bushing
DF .M 0.0000 : Elevation of Derrick Floor
TDL .M 0.0000 : Total Depth Logger
TDD .M 0.0000 : Total Depth Driller
TLI .M 80.6250 : Top of Logged Interval
BLI .M 1294.7500 : Bottom of Logged Interval
# DEPTH GR AO10 AO20 AO30 AO60 AO90 AT10 AT20 AT30 AT60 AT90 CALI CAY NPHI DEN DPHI SP CAX DC PEF
~ASCII DEPTH
80.8000 44.9229 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500
81.0000 44.9229 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500
81.2000 44.9229 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500 -999.2500
 
K

keepITcool

does this give you the start you need?
it writes the lines of the blocks to columns 1 and 2 of the activesheet

once this has run you can parse those ranges with texttocolumns method



Sub ReadFromAscii()
Dim sLine$, sBlock$
Dim a&, c&

Open "c:\myascii.txt" For Input As #1

Do While Not EOF(1)
Line Input #1, sLine

If Left(sLine, 1) = "~" Then
If Left(sLine, 2) = "~C" Then
sBlock = "C"
ElseIf Left(sLine, 2) = "~A" Then
sBlock = "A"
Else
sBlock = ""
End If
Else
Select Case sBlock
Case "C"
c = c + 1
ActiveSheet.Cells(c, 1) = sLine
Case "A"
a = a + 1
ActiveSheet.Cells(a, 2) = sLine
End Select
End If
Loop
Close #1

End Sub



keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top