How to read OMI/MLS unstructured ASCII data in R?

119 views Asked by At

I am trying to read following data in R. I could find a code written for numpy but there was not any for R.

According to the link: "After skipping the first three lines, each following 12 lines contains one row of the total 2D array. It's concatenated integers of three digits each. Reading ASCII in R needs a separator keyword, but I don't have a separator here.Any help would be really appreciated.

April 2008  OMI/MLS Tropo O3 Column (Dobson Units) X 10
Longitudes:  288 bins centered on 179.375W to 179.375E (1.25 degree steps)
Latitudes:  120 bins centered on -59.5S to 59.5N (1.00 degree steps)
 166217223211241326285354290338228257199268342304270284206277284257222239296
 260308184247224202214256242220241234247297278270237201247186238239284263212
 201204206191184186177199218199234242242205240231246269233208210227275242213
 246222272320276248166201197200188173209231199198234238231188250228285253247
 249256181180233249252211210184212242242179287233269310305315234236228135128
 117219226194243273280321323389427283352446431379385319265243288309242222346
 289306281288271267274235277306306273250235252264274260300304322305357336297
 281286324324316347308296323294256289246239197256279298275340317337289322356
 315286280281276206228225211220251255244210208232239280274268237252238226181
 209246254242274248252250240262253226223229204204228197200209245263253247260
 267313334255264206163165188220261300266266240247224208223213262248169260298
 208356315279242223222168245286303325329  lat =  -59.5
 312293362274234235237227305283172142294249334273287306283264267228238348370
 314255273250279264261285254275261254246249282223225206214199241236244254276
 224224232214225226205192175195204202183176194231285284274277284264275286265
 242253247187264238203212213181184188219214221192227209233185217255254325236
 206328342260262279277296265222275339239319292237352279311238273169141268188
 222266281238251310281268268326363389305366312251281289443469386293271355354
 342301281240278232224246244218213251291257222242233254230300323350348289258
 256264309269273251241264273292271275236245250280277292280299335323345348367
 352358346323265265254246235235266260258206221218212232255259260258246233233
 223240299281223208269260233246261257250238232236238210215210218259279291298
 304301291271240244205193221244252287306297278214235176261322276282196239296
 339340295266256241263348321274309308267  lat =  -58.5

Edited: I manipulated original data. First I have removed the first three lines using "sed '1,3d' -i file.txt" which is not that necessary. Second, I have removed the first blank column to have a consistent 3-integer separator by "sed -i 's/^ *//g' file.txt". Then, According to Andrew Gustar, I have tried read.fwf. Now, it reads data column-wise whereas I want them to be read every three data as an input. BTW, output is only one column.

data=read.fwf(fils[1],skip = 0,widths = 3,
              comment.char = "l")

It is part of the output:

head(data)
   V1
1 166
2 260
3 201
4 246
5 249
6 117

They have two integers long while it should be 3

0

There are 0 answers