READ ARRAY and extract the values [message #93129] |
Fri, 29 April 2016 14:49  |
Tanvir Hussain
Messages: 2 Registered: August 2013
|
Junior Member |
|
|
Hi All
I have a data which is organized in the following way
obj1 12.5
obj1 14.5
obj1 15.4
obj1 14.0
obj1 12.5
obj1 14.5
obj1 15.4
obj1 14.0
obj1 12.5
obj1 14.5
obj1 15.4
obj1 14.0
obj2 12.5
obj2 14.5
obj2 15.4
obj2 14.0
obj2 12.5
obj2 14.5
obj2 15.4
obj2 14.0
obj2 12.5
obj2 14.5
obj2 15.4
obj2 14.0
I want to extract all the values associated with obj1 and write them in a separate array. In a similar way for the obj2. Please help.
Thanks
Tanvir
|
|
|
Re: READ ARRAY and extract the values [message #93130 is a reply to message #93129] |
Sat, 30 April 2016 23:56   |
Sapna Mishra
Messages: 66 Registered: December 2015
|
Member |
|
|
readcol,"data.dat",obj,value
for i=0; n_elements(obj)-1 begin
if obj(i)='obj1'
forprint,obj(i),value(i),text='obj1.dat',F='(A,1x,F)'
else
forprint,obj(i),value(i),text='obj2.dat',F='(A,1x,F)'
endfor
Then you can store the value of files obj1.dat and obj2.dat in different array using readcol or openwr.
This may be the easiest way, else there might be so many other ways which others can help....
Thanks
|
|
|
Re: READ ARRAY and extract the values [message #93131 is a reply to message #93129] |
Sat, 30 April 2016 23:59   |
Sapna Mishra
Messages: 66 Registered: December 2015
|
Member |
|
|
On Saturday, April 30, 2016 at 3:19:59 AM UTC+5:30, Tanvir Hussain wrote:
> Hi All
>
> I have a data which is organized in the following way
>
> obj1 12.5
> obj1 14.5
> obj1 15.4
> obj1 14.0
> obj1 12.5
> obj1 14.5
> obj1 15.4
> obj1 14.0
> obj1 12.5
> obj1 14.5
> obj1 15.4
> obj1 14.0
> obj2 12.5
> obj2 14.5
> obj2 15.4
> obj2 14.0
> obj2 12.5
> obj2 14.5
> obj2 15.4
> obj2 14.0
> obj2 12.5
> obj2 14.5
> obj2 15.4
> obj2 14.0
>
> I want to extract all the values associated with obj1 and write them in a separate array. In a similar way for the obj2. Please help.
>
> Thanks
> Tanvir
readcol,"data.dat",obj,value
for i=0; n_elements(obj)-1 do begin
if obj(i)='obj1' then
forprint,obj(i),value(i),text='obj1.dat',F='(A,1x,F)'
else
forprint,obj(i),value(i),text='obj2.dat',F='(A,1x,F)'
endfor
Then you can store the value of files obj1.dat and obj2.dat in different array using readcol or openwr.
This may be the easiest way, else there might be so many other ways which others can help....
Thanks
|
|
|
Re: READ ARRAY and extract the values [message #93132 is a reply to message #93129] |
Sun, 01 May 2016 00:08   |
Sapna Mishra
Messages: 66 Registered: December 2015
|
Member |
|
|
On Saturday, April 30, 2016 at 3:19:59 AM UTC+5:30, Tanvir Hussain wrote:
> Hi All
>
> I have a data which is organized in the following way
>
> obj1 12.5
> obj1 14.5
> obj1 15.4
> obj1 14.0
> obj1 12.5
> obj1 14.5
> obj1 15.4
> obj1 14.0
> obj1 12.5
> obj1 14.5
> obj1 15.4
> obj1 14.0
> obj2 12.5
> obj2 14.5
> obj2 15.4
> obj2 14.0
> obj2 12.5
> obj2 14.5
> obj2 15.4
> obj2 14.0
> obj2 12.5
> obj2 14.5
> obj2 15.4
> obj2 14.0
>
> I want to extract all the values associated with obj1 and write them in a separate array. In a similar way for the obj2.
readcol,"data.dat",F='(A,1x,F)',obj,value
for i=0; n_elements(obj)-1 do begin
if obj(i)='obj1' then
forprint,obj(i),value(i),text='obj1.dat',F='(A,1x,F)'
else
forprint,obj(i),value(i),text='obj2.dat',F='(A,1x,F)'
endfor
Then you can store the values of files obj1.dat and obj2.dat in different arrays using readcol or openwr.
This may be the easiest way, else there might be so many other ways which others can help....
Regards,
|
|
|
Re: READ ARRAY and extract the values [message #93133 is a reply to message #93129] |
Sun, 01 May 2016 00:10  |
Sapna Mishra
Messages: 66 Registered: December 2015
|
Member |
|
|
On Saturday, April 30, 2016 at 3:19:59 AM UTC+5:30, Tanvir Hussain wrote:
> Hi All
>
> I have a data which is organized in the following way
>
> obj1 12.5
> obj1 14.5
> obj1 15.4
> obj1 14.0
> obj1 12.5
> obj1 14.5
> obj1 15.4
> obj1 14.0
> obj1 12.5
> obj1 14.5
> obj1 15.4
> obj1 14.0
> obj2 12.5
> obj2 14.5
> obj2 15.4
> obj2 14.0
> obj2 12.5
> obj2 14.5
> obj2 15.4
> obj2 14.0
> obj2 12.5
> obj2 14.5
> obj2 15.4
> obj2 14.0
>
> I want to extract all the values associated with obj1 and write them in a separate array. In a similar way for the obj2.
readcol,"data.dat",F='(A,1x,F)',obj,value
for i=0; n_elements(obj)-1 do begin
if obj(i)='obj1' then
forprint,obj(i),value(i),text='obj1.dat',F='(A,1x,F)'
else
forprint,obj(i),value(i),text='obj2.dat',F='(A,1x,F)'
endfor
Then you can store the values of files obj1.dat and obj2.dat in different arrays using readcol or openwr.
This may be the easiest way, else there might be so many other ways which others can help....
Regards,
|
|
|