Read data in more than one column [message #91695] |
Thu, 13 August 2015 08:24  |
joyrles1996
Messages: 27 Registered: August 2015
|
Junior Member |
|
|
I have datas in a file with 26 columns. In first columns there are day of year, in second there are dates and in the remaining columns there are values of temperature. I don't get read these datas starting third columns. Can you help me, please?
|
|
|
|
Re: Read data in more than one column [message #91697 is a reply to message #91696] |
Thu, 13 August 2015 09:08   |
joyrles1996
Messages: 27 Registered: August 2015
|
Junior Member |
|
|
Em quinta-feira, 13 de agosto de 2015 12:50:35 UTC-3, Paul van Delst escreveu:
> On 08/13/15 11:24, Joyrles Fernandes wrote:
>> I have datas in a file with 26 columns. In first columns there are
>> day
>> of year, in second there are dates and in the remaining columns there
>> are values of temperature. I don't get read these datas starting third
>> columns. Can you help me, please?
>
> Not enough information to really help.
>
> How about you:
> 1) Show a line or two of your input data file.
> 2) the code you are currently using to read the data.
>
> ?
file='C:\Users\Joyrles\dados.txt'
dados=read_ascii(file, data_start=1)
dados=dados.(0)
date=dados[0,*]
day=[1,*]
temp=[?,*]
I do not know how to put to read the rest of the columns missing and all lines for me to withdraw temperatures.
|
|
|
Re: Read data in more than one column [message #91710 is a reply to message #91697] |
Thu, 13 August 2015 19:42   |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Thursday, August 13, 2015 at 9:08:16 AM UTC-7, Joyrles Fernandes wrote:
> Em quinta-feira, 13 de agosto de 2015 12:50:35 UTC-3, Paul van Delst escreveu:
>> On 08/13/15 11:24, Joyrles Fernandes wrote:
>>> I have datas in a file with 26 columns. In first columns there are
>>> day
>>> of year, in second there are dates and in the remaining columns there
>>> are values of temperature. I don't get read these datas starting third
>>> columns. Can you help me, please?
>>
>> Not enough information to really help.
>>
>> How about you:
>> 1) Show a line or two of your input data file.
>> 2) the code you are currently using to read the data.
>>
>> ?
>
> file='C:\Users\Joyrles\dados.txt'
>
> dados=read_ascii(file, data_start=1)
>
> dados=dados.(0)
> date=dados[0,*]
> day=[1,*]
> temp=[?,*]
>
> I do not know how to put to read the rest of the columns missing and all lines for me to withdraw temperatures.
Still hard to say, without looking at a few lines from your file.
|
|
|
Re: Read data in more than one column [message #91717 is a reply to message #91710] |
Fri, 14 August 2015 06:58   |
joyrles1996
Messages: 27 Registered: August 2015
|
Junior Member |
|
|
Em quinta-feira, 13 de agosto de 2015 23:42:50 UTC-3, Paulo Penteado escreveu:
> On Thursday, August 13, 2015 at 9:08:16 AM UTC-7, Joyrles Fernandes wrote:
>> Em quinta-feira, 13 de agosto de 2015 12:50:35 UTC-3, Paul van Delst escreveu:
>>> On 08/13/15 11:24, Joyrles Fernandes wrote:
>>>> I have datas in a file with 26 columns. In first columns there are
>>>> day
>>>> of year, in second there are dates and in the remaining columns there
>>>> are values of temperature. I don't get read these datas starting third
>>>> columns. Can you help me, please?
>>>
>>> Not enough information to really help.
>>>
>>> How about you:
>>> 1) Show a line or two of your input data file.
>>> 2) the code you are currently using to read the data.
>>>
>>> ?
>>
>> file='C:\Users\Joyrles\dados.txt'
>>
>> dados=read_ascii(file, data_start=1)
>>
>> dados=dados.(0)
>> date=dados[0,*]
>> day=[1,*]
>> temp=[?,*]
>>
>> I do not know how to put to read the rest of the columns missing and all lines for me to withdraw temperatures.
>
> Still hard to say, without looking at a few lines from your file.
my datas are organized in columns. In first column i have days of year, with 355 lines. In second column I have dates, with 355 lines of datas and from third i have 24 columns with temperature, with 355 lines.
1 01/01/2010 13,4 22,3 ... 353
2 02/01/2010 21 321 ... 245
. . . . .
. . . . .
. . . . .
355 21/12/2010 15 124 ... 193,3
I am getting just to read the first, the second and the tirdh column, but i need to create a array with all columns starting of third, obtain a array tem[24,355], but I am starting with IDL. I am sorry for my english, I am brasilian.
|
|
|
Re: Read data in more than one column [message #91723 is a reply to message #91717] |
Fri, 14 August 2015 08:46  |
zacharyanorman
Messages: 17 Registered: July 2015
|
Junior Member |
|
|
If you have a text file where all of your data is separated by spaces and each line has the exact same number of data entries, you could try something like this code, which reads the text file and uses STRSPLIT to extract each separate element that has a space between it:
;read the file into a string array which is info
file = 'C:\path\to\file'
OPENR, lun, file, /GET_LUN
nlines = FILE_LINES(file)
info = STRARR(nlines)
READF, lun, info
FREE_LUN, lun
;initialize array of split data
split_info = strarr(n_elements(strsplit(info[0], ' ', /extract)), nlines)
;separate your data by the space that is between them
for i=0, nlines-1 do split_info[i] = strsplit(info,' ' , /extract)
|
|
|