Re: I found one thing!!! [message #51298] |
Wed, 15 November 2006 06:47  |
Braedley
Messages: 57 Registered: September 2006
|
Member |
|
|
Your string array should only be of dimensions (28). You'll read each
of the 28 lines, and then strsplit them into the data array like so:
s_in=strarr(file_lines(filename))
openr, lun, /get_lun, filename
readf, lun, s_in
close, lun
free_lun, lun
length=n_elements(s_in)
temp=strsplit(s_in[0], '|', /extract, count=count)
data=intarr(length, count)
for i=0, length-1 do data[i, *]=fix(strsplit(s_in[i], '|', /extract))
This method also keeps the program more flexible. Hard coding values
is rarely a good thing.
Braedley
kim20026@gmail.com wrote:
> Sorry, everyone!!! I found these data below seem to be one line, but
> they were not!!! They were set to an array with 28 columns * 157842
> rows already...
>
> Now, the problem can be easier, but I am still a beginner. Please give
> me some comments.
>
> My basic idea was...
>
> 1. Make an array (28, 157842)
> 2. Open and read the data
> 3. Put the data into the array made in 1.
> 4. Slice the array into 3 and print to 3 different files.
>
> So I did this way, but still not working...
> --------------------
> Pro temp1
>
> ; Main working directory (location of IDL procedures and functions)
> WorkDir = 'D:\MODIS_Documents\MetData\IDLPractice'
>
> s=intarr(28, 157824L)
> Openr, lun, 'temp1.txt', /get_lun
> Readf, lun, s ; <- IDL still halts right here. (T.T)
> free_lun, lun
>
> data=fix(strsplit(s, '|', /extract))
>
> for i=0L, 157824-1 do begin
> if i mod 52608L eq 0 then begin
> close, /all
> file_no=i / 52608L + 1 ; 1, 2, 3
> openw, 1, 'out'+string(file_no, format='(I1)')+'.txt'
> ;예)out1.txt
> endif
> printf, 1, strjoin(string(data[*, i], format='(I4)'), ' ')
>
> endfor
>
> close, /all
> end
>
>
>
>
> kim20026@gmail.com wrote:
>> I requested some meteological data to a governmental institute. To
>> reduce the file size, they sent me this way...
>>
>> 90|2000|1|1|25|25|26|26|26|25|26|28|31|34|36|39|40|38|38|37| 35|33|35|37|34|34|35|29|90|2000|1|2|30|32|29|28|31|33|55|65| 74|68|72|75|71|83|85|77|69|60|51|43|41|34|34|29|90|2000|1|3| 25|20|12|9|8|5|-2|-3|14|27|31|42|51|54|48|51|37|28|15|11|6|- 12|0|-13|90|2000|1|4|-7|-5|-8|-10|-21|-21|-13|-18|-2|23|36|4 0|50|49|42|37|29|22|9|3|0|0|5|4|90|2000|1|5|1|4|12|10|15|15| 9|6|0|-1|1|3|5|4|4|6|8|8|10|9|9|13|13|17|90|2000|1|6|17|18|2 3|23|24|28|28|27|25|26|45|73|87|90|81|72|58|54|39|19|-2|-11| -17|-26|90|2000|1|7|-31|-39|-43|-55|-67|-77|-85|-86|-78|-71| -63|-63|-52|-43|-39|-41|-49|-51|-53|-54|-58|-53|-54|-57|90|2 000|1|8|-57|-52|-49|-48|-45|-39|-36|-30|-25|-18|-11|-8|0|2|1 2|7|-3|-7|-7|-7|-6|-16|-15|-17|
>> ...
>>
>> This is only one line, but contains a matrix of 28 columns * 157824L
>> rows. As you guys may know, Excel can only 65,000 rows approximately,
>> and I need to divide this into three to read this file correctly.
>>
>> I have tried like this so far, but everytime I try, I have the same
>> error message and the program stops.
>>
>>
>> ------------------------------------------
>> Pro temp1
>>
>> ; Main working directory (location of IDL procedures and functions)
>> WorkDir = 'D:\MODIS_Documents\MetData\IDLPractice'
>>
>> s=''
>> Openr, 1, 'temp1.txt'
>> Readf, 1, s
>> print, strlen(s)
>> close, 1
>>
>> data=fix(strsplit(s, '|', /extract))
>> help, data
>> data=reform(data, 28, 157824L) ; <- Execution halts right here
>> everytime!!!
>> print, data[*, 0]
>> print, data[*, 1]
>>
>> for i=0L, 157824-1 do begin
>> if i mod 52608L eq 0 then begin
>> close, /all
>> file_no=i / 52608L + 1 ; 1, 2, 3
>> openw, 1, 'out'+string(file_no, format='(I1)')+'.txt'
>> ;ex) out1.txt
>> endif
>> printf, 1, strjoin(string(data[*, i], format='(I4)'), '')
>>
>> endfor
>> close, /all
>> end
>> ------------------------------------------------------------ ------------
>>
>> Please let me know if you have any solutions (or suggestions at least.
>> It's urgent!! T.T)
|
|
|
|
I made it!!! [message #51376 is a reply to message #51298] |
Wed, 15 November 2006 17:53  |
kim20026
Messages: 54 Registered: November 2006
|
Member |
|
|
Good morning everyone.
Thank you very much for your invaluable comments and suggestions. I
finally made it!!! (^.^) but I need to say there was another major
contributor, Jonghyeok Lee, one of my new friends in Seoul.
The latest version of this code is...
---------------------------
pro temp1
file='D:\MODIS_Documents\MetData\IDLPractice\temp.txt'
n=file_lines(file)
allline=strarr(n)
openr, 1, file
readf, 1, allline
close, 1
for i=0L, n-1 do begin
if i mod 52608L eq 0 then begin
close, /all
filew='D:\MODIS_Documents\MetData\IDLPractice\temp'+string(i /
52608L +1, format='(I1)')+'.txt'
openw, 2, filew
endif
oneline=allline[i]
data=fix(strsplit(oneline, '|', /extract))
printf, 2, data, format='(28I5)'
endfor
close, /all
end
-----------------------------
If you have any other comments or suggestions, please don't hesitate.
Thanks again. Have a nice day!!!
Harry from Chuncheon, Korea
---------------------------------------------
Braedley wrote:
> Your string array should only be of dimensions (28). You'll read each
> of the 28 lines, and then strsplit them into the data array like so:
>
> s_in=strarr(file_lines(filename))
> openr, lun, /get_lun, filename
> readf, lun, s_in
> close, lun
> free_lun, lun
> length=n_elements(s_in)
> temp=strsplit(s_in[0], '|', /extract, count=count)
> data=intarr(length, count)
> for i=0, length-1 do data[i, *]=fix(strsplit(s_in[i], '|', /extract))
>
> This method also keeps the program more flexible. Hard coding values
> is rarely a good thing.
>
> Braedley
>
> kim20026@gmail.com wrote:
>> Sorry, everyone!!! I found these data below seem to be one line, but
>> they were not!!! They were set to an array with 28 columns * 157842
>> rows already...
>>
>> Now, the problem can be easier, but I am still a beginner. Please give
>> me some comments.
>>
>> My basic idea was...
>>
>> 1. Make an array (28, 157842)
>> 2. Open and read the data
>> 3. Put the data into the array made in 1.
>> 4. Slice the array into 3 and print to 3 different files.
>>
>> So I did this way, but still not working...
>> --------------------
>> Pro temp1
>>
>> ; Main working directory (location of IDL procedures and functions)
>> WorkDir = 'D:\MODIS_Documents\MetData\IDLPractice'
>>
>> s=intarr(28, 157824L)
>> Openr, lun, 'temp1.txt', /get_lun
>> Readf, lun, s ; <- IDL still halts right here. (T.T)
>> free_lun, lun
>>
>> data=fix(strsplit(s, '|', /extract))
>>
>> for i=0L, 157824-1 do begin
>> if i mod 52608L eq 0 then begin
>> close, /all
>> file_no=i / 52608L + 1 ; 1, 2, 3
>> openw, 1, 'out'+string(file_no, format='(I1)')+'.txt'
>> ;예)out1.txt
>> endif
>> printf, 1, strjoin(string(data[*, i], format='(I4)'), ' ')
>>
>> endfor
>>
>> close, /all
>> end
>>
>>
>>
>>
>> kim20026@gmail.com wrote:
>>> I requested some meteological data to a governmental institute. To
>>> reduce the file size, they sent me this way...
>>>
>>> 90|2000|1|1|25|25|26|26|26|25|26|28|31|34|36|39|40|38|38|37| 35|33|35|37|34|34|35|29|90|2000|1|2|30|32|29|28|31|33|55|65| 74|68|72|75|71|83|85|77|69|60|51|43|41|34|34|29|90|2000|1|3| 25|20|12|9|8|5|-2|-3|14|27|31|42|51|54|48|51|37|28|15|11|6|- 12|0|-13|90|2000|1|4|-7|-5|-8|-10|-21|-21|-13|-18|-2|23|36|4 0|50|49|42|37|29|22|9|3|0|0|5|4|90|2000|1|5|1|4|12|10|15|15| 9|6|0|-1|1|3|5|4|4|6|8|8|10|9|9|13|13|17|90|2000|1|6|17|18|2 3|23|24|28|28|27|25|26|45|73|87|90|81|72|58|54|39|19|-2|-11| -17|-26|90|2000|1|7|-31|-39|-43|-55|-67|-77|-85|-86|-78|-71| -63|-63|-52|-43|-39|-41|-49|-51|-53|-54|-58|-53|-54|-57|90|2 000|1|8|-57|-52|-49|-48|-45|-39|-36|-30|-25|-18|-11|-8|0|2|1 2|7|-3|-7|-7|-7|-6|-16|-15|-17|
>>> ...
>>>
>>> This is only one line, but contains a matrix of 28 columns * 157824L
>>> rows. As you guys may know, Excel can only 65,000 rows approximately,
>>> and I need to divide this into three to read this file correctly.
>>>
>>> I have tried like this so far, but everytime I try, I have the same
>>> error message and the program stops.
>>>
>>>
>>> ------------------------------------------
>>> Pro temp1
>>>
>>> ; Main working directory (location of IDL procedures and functions)
>>> WorkDir = 'D:\MODIS_Documents\MetData\IDLPractice'
>>>
>>> s=''
>>> Openr, 1, 'temp1.txt'
>>> Readf, 1, s
>>> print, strlen(s)
>>> close, 1
>>>
>>> data=fix(strsplit(s, '|', /extract))
>>> help, data
>>> data=reform(data, 28, 157824L) ; <- Execution halts right here
>>> everytime!!!
>>> print, data[*, 0]
>>> print, data[*, 1]
>>>
>>> for i=0L, 157824-1 do begin
>>> if i mod 52608L eq 0 then begin
>>> close, /all
>>> file_no=i / 52608L + 1 ; 1, 2, 3
>>> openw, 1, 'out'+string(file_no, format='(I1)')+'.txt'
>>> ;ex) out1.txt
>>> endif
>>> printf, 1, strjoin(string(data[*, i], format='(I4)'), '')
>>>
>>> endfor
>>> close, /all
>>> end
>>> ------------------------------------------------------------ ------------
>>>
>>> Please let me know if you have any solutions (or suggestions at least.
>>> It's urgent!! T.T)
|
|
|