How would you define the following array a=(/
1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
appears N times where N is known.
|
|
0
|
|
|
|
Reply
|
makis (6)
|
9/13/2010 10:13:50 AM |
|
Hi Michael,
Michael wrote:
> How would you define the following array a=(/
> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
> appears N times where N is known.
I would type it out. You might be able to play silly burgers with
reshape (haven't thought how), but given the standard only allows up to
7 dimensional arrays N better be 0, 1 or 2, so typing it out would be
both not very long and clearer.
But what are you trying to do? I strongly suspect something to do with
derived types might be better, but given this info I can't guess what,
Ian
|
|
0
|
|
|
|
Reply
|
Ian
|
9/13/2010 10:37:02 AM
|
|
On 13/09/2010 8:13 PM, Michael wrote:
> How would you define the following array a=(/
> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
> appears N times where N is known.
program Oi_Terence_try_and_do_this_shorter_in_f77
implicit none
integer, parameter :: ru(3) = [1, 2, 13] ! the repeating unit
integer, allocatable :: a(:)
integer :: i, n
write (*,"('Enter n:')")
read (*,*) n
a = [(ru, i = 1, n)] ! F2003 allocate on assignment.
write (*, *) a ! Replace with user defined operation on a...
end
|
|
0
|
|
|
|
Reply
|
Ian
|
9/13/2010 10:44:04 AM
|
|
Ian Bush wrote:
>
> Hi Michael,
>
> Michael wrote:
>> How would you define the following array a=(/
>> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
>> appears N times where N is known.
>
> I would type it out. You might be able to play silly burgers with
> reshape (haven't thought how), but given the standard only allows up to
> 7 dimensional arrays N better be 0, 1 or 2, so typing it out would be
> both not very long and clearer.
>
> But what are you trying to do? I strongly suspect something to do with
> derived types might be better, but given this info I can't guess what,
>
What a load of rubbish - Ignore this, I obviously can't read,
Ian
|
|
0
|
|
|
|
Reply
|
Ian
|
9/13/2010 11:01:59 AM
|
|
Michael wrote:
> How would you define the following array a=(/
> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
> appears N times where N is known.
Do you mean (/ (1,2,13,i=1,N) /) ?
|
|
0
|
|
|
|
Reply
|
Michel
|
9/13/2010 12:31:15 PM
|
|
Putting Michel's solution in a working program:
program blah
implicit none
integer, parameter :: N = 5
integer, parameter :: NR = 3
integer, parameter :: R(NR) = (/1,2,13/)
integer :: i
integer :: arr(N*NR) = (/ (R,i=1,N) /)
write(*,'(10i5)') arr
end program blah
lnx: gfortran blah.f90
lnx: a.out
1 2 13 1 2 13 1 2 13 1
2 13 1 2 13
cheers,
paulv
Michel Olagnon wrote:
> Michael wrote:
>> How would you define the following array a=(/
>> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
>> appears N times where N is known.
>
> Do you mean (/ (1,2,13,i=1,N) /) ?
>
|
|
0
|
|
|
|
Reply
|
Paul
|
9/13/2010 7:20:38 PM
|
|
"Michel Olagnon" <molagnon@ifremer-a-oter.fr> wrote in message
news:4C8E1993.3060508@ifremer-a-oter.fr...
> Michael wrote:
>> How would you define the following array a=(/
>> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
>> appears N times where N is known.
> Do you mean (/ (1,2,13,i=1,N) /) ?
I was considering the possibility that N might not be integral.
Solution:
a = reshape((/integer::/),shape(a),pad=(/1,2,13/))
--
write(*,*) transfer(0.64682312090346863D-153,(/'X'/));end
|
|
0
|
|
|
|
Reply
|
James
|
9/13/2010 9:32:06 PM
|
|
On Sep 13, 11:32=A0pm, "James Van Buskirk" <not_va...@comcast.net>
wrote:
> "Michel Olagnon" <molag...@ifremer-a-oter.fr> wrote in message
>
> news:4C8E1993.3060508@ifremer-a-oter.fr...
>
> > Michael wrote:
> >> How would you define the following array a=3D(/
> >> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
> >> appears N times where N is known.
> > Do you mean (/ (1,2,13,i=3D1,N) /) ?
>
> I was considering the possibility that N might not be integral.
> Solution:
>
> a =3D reshape((/integer::/),shape(a),pad=3D(/1,2,13/))
>
> --
> write(*,*) transfer(0.64682312090346863D-153,(/'X'/));end
This does it too:
integer, parameter :: NUM =3D 3
integer :: n =3D NUM
integer, dimension (NUM*3) :: m
integer, dimension(3) :: source =3D [1, 2, 13]
!
m =3D reshape (spread (source, 2, n), [n * size (source, 1)])
!
print *, m
end
It's all a matter of taste and inclination :-)
Paul Thomas
|
|
0
|
|
|
|
Reply
|
Paul
|
9/15/2010 7:38:15 AM
|
|
|
7 Replies
213 Views
(page loaded in 0.096 seconds)
Similiar Articles: Maximum dimension array - comp.lang.fortranI would define an array y(1:800e6) but it doesn't seem possible... ... Array of something - comp.lang.java.helpArray | Define Array at Dictionary.com A one-dimensional array is also known as a "vector". A reference to an array element is written something like A[i,j,k] where A is ... Porting guide - Assembler to C - comp.lang.asm.x86DATALIST DW SIZE_DATA DW 0 DW 1 DW 2 DW 3 DW 0FFFFH ;TERMINATOR SIZE_DATA EQU $-(DATALIST+2) This is a WORD array definition. Neatest way to get the end pointer? - comp.lang.cFor instance, > today, the code might be: [snip] So use a macro that gives you the length of an array object, regardless of how it's declared, such as: #define ARRAY ... Find the median value of an array. - comp.lang.fortranHello, Given an array with 10,000 real values, I want to find the median. ... Function D_valmed (XDONT) Result (res_med) I thought that function definitions always ... use macro to import multiple excel files? - comp.soft-sys.sas ...how can i use macro to import multiple excel files? I cannot define array inside the macro, so I use data _NULL_, but it doesn't work. Also I try to... Hierarchical data structure from a multi-dimensional array - comp ...And define ..... or a (multi-dimensional) array ... you have a hierarchical record structure with a fixed number of elements in the array ... define ... array data. how to define the input variable for different functions with same ...function declaration: array output variables - comp.soft-sys ... how to define the input variable for different functions with same ..... function to evalue, string array ... Local array variables in functions - comp.lang.awkArray parameters passed ... to an empty array.[*] > Is that generally guaranteed with other awks as well? (POSIX?) "The number of parameters in the function definition need ... Find the position of max/min value in an unsorted array - comp ...thanks, good to know On Thu, 21 Jan 2010 20:19:46 -0800, Tom Abernathy <tom.abernathy@GMAIL.COM> wrote: >By definition with an unsorted array you are going to need ... array - definition of array by the Free Online Dictionary ...ar·ray (-r) tr.v. ar·rayed, ar·ray·ing, ar·rays. 1. To set out for display or use; place in an orderly arrangement: arrayed the whole regiment on the parade ground. Array - Definition and More from the Free Merriam-Webster DictionaryDefinition of ARRAY. transitive verb. 1: to dress or decorate especially in splendid or impressive attire : adorn <he had already arrayed himself in his best clothes ... 7/6/2012 6:33:41 AM
|