Example * .las file:
β¦ β¦ β¦ #MNEM .UNIT API CODE :DESCRIPTION #---- ------ -------------- ----------------------------- DEPT .ft : Station Depth INCL .deg : Hole inclination AZIM .deg : Measured Azimuth #------------------------------------------------------------- # DEPT INCL AZIM ~ASCII 0.00 0.00 0.00 36.00 0.33 123.98 126.00 0.17 183.28 218.00 0.19 202.04 308.00 0.24 191.24 398.00 0.21 198.60 495.00 0.02 179.55 β¦ β¦ β¦
The goal when reading a file is to ignore the file heading and copy only the data that appeared after the line (~ASCII) , in addition, each column heading Thus, we copy the entire file and search it one by one until we reach the line (~ ASCII), then copy the line in front of it (header) and everything that appears after it (data), and we delete the line (~ ASCII).
Note that we remove the character (#) from the title bar.
The last step is to convert the data to a table and then write it as a csv file.
Full code:
#remove all variables (cleanup) rm(list=ls(all=TRUE)) gc() MWD_filePath="MWD_file.las"; conn=file(MWD_filePath,open="r") Ascii_txt=readLines(conn); mwd_txt = 0; for (i in 1:length(Ascii_txt)){ if(Ascii_txt[i] == "~ASCII"){ mwd_txt <- Ascii_txt[(i-1):length(Ascii_txt)] # remove (#) from the header line substr(mwd_txt[1], 1, 2) <- " "; # remove "~ASCII" line mwd_txt <- mwd_txt[-2] break; } } close(conn) #mwd_txt; mwd <- read.table(header = TRUE, text=mwd_txt); #head(mwd) #write the mwd data to file ... in CSV format mwd_csv_file <- paste(MWD_filePath, ".csv", sep=""); write.csv(mwd, file = mwd_csv_file);
Salem gharbi
source share