Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Fortran Programming Language

how to "rename" an array


My apologies if this question is too stupid... :-P

I am wondering if there is any command offering the array"renaming"
capability
(something like the rename command in DOS operation)

Currently I just create an empty array and then feed the original
array into the new array....
But this looks clumsy and doubles the memory usage temporarily....

I could not locate this command in visual fortran....Can anyone give a
hand?

Thanks in advance.

On Apr 14, 7:42 am, "Liang-Chun Liu" <lancy@gmail.com> wrote:

> I am wondering if there is any command offering the array"renaming"
> capability
> (something like the rename command in DOS operation)

> Currently I just create an empty array and then feed the original
> array into the new array....
> But this looks clumsy and doubles the memory usage temporarily....

I'm not entirely sure about your reference to "renaming".  Your
description makes me think of the common desire to expand the size of
an allocatable array without doing two copies.  Is that what you want?

The closest thing Fortran has to "renaming" is the MOVE_ALLOC
intrinsic of Fortran 2003.  This lets you move the "allocation" of one
array (with its data) to another, the original array now being
unallocated.  With this, expanding an array requires one copy and two
arrays allocated for a while, but it saves a second copy that would be
required without it.

Let's say you have an array A that you want to double its size while
preserving the original data.

Without MOVE_ALLOC you'd do this:

OLD_SIZE = SIZE(A)
ALLOCATE (TEMP_ARRAY(OLD_SIZE)
TEMP_ARRAY = A ! First copy
DEALLOCATE (A)
ALLOCATE (A(2*OLD_SIZE))
A(1:OLD_SIZE) = TEMP_ARRAY ! Second copy
DEALLOCATE (TEMP_ARRAY)

With MOVE_ALLOC you can do this:

ALLOCATE(TEMP_ARRAY(2*SIZE(A))
TEMP_ARRAY(1:SIZE(A)) = A
CALL MOVE_ALLOC (TEMP_ARRAY, A)
! TEMP_ARRAYis now unallocated

You say you are using "Visual Fortran" but don't provide further
details. MOVE_ALLOC is supported in Intel Visual Fortran 9.1.028 and
higher, not in Compaq or Digital Visual Fortran. For Intel Visual
Fortran, you'll currently find it described only in the Release Notes
and not the regular manuals.

Steve

Hi,

On Apr 14, 1:42 pm, "Liang-Chun Liu" <lancy@gmail.com> wrote:

> My apologies if this question is too stupid... :-P
> I am wondering if there is any command offering the array"renaming"
> capability
> (something like the rename command in DOS operation)

> Currently I just create an empty array and then feed the original
> array into the new array....
> But this looks clumsy and doubles the memory usage temporarily...

Depending what you want to do, you could use a pointer:

real, dimension(88) :: myArray
real, pointer, dimension(:) :: ptr
nullify(ptr)

myArray = initializeMyArray()
ptr => myArray
prt(5) ! accesses myArray(5)

Tobias

On 4?14?, ??8?40?, "Steve Lionel" <steve.lio@intel.com> wrote:

Thank you so much for the detailed answer.
In this post I was asking how to change the name of an array while
retain the content of it
i.e., change a=[1,2,3] to b=[1,2,3]....
but actually your answer solved my problem.

My original question is: I need to dynamically maintain my array
for example: [1,4,4]==>[1,4,4,6]==>[1,4]

in the 1st process I need to add an element
in the 2nd process I need to remove 2 elements

for now I use a temp array as you described in the "without MOVE_ALLOC
process"

I'll check out Intel fortran later for this function.

OK I may be dating myself here, but I would do...

PROGRAM MyProgram

INTEGER max
PARAMETER (max = 1000)

INTEGER A(max), B(max), C(max), me(max)

COMMON /rename/ A, B, C, me

CALL initialize(A)

CALL transforms(B)

CALL skew(me)

STOP
END

This is more like aliases, but might accomplish the same semantic as your
"rename"

"Liang-Chun Liu" <lancy@gmail.com> wrote in message

news:1176550975.002621.64910@e65g2000hsc.googlegroups.com...

On Sat, 14 Apr 2007 19:22:16 UTC, "Patrick Thrapp"

<collec@garbage.dump> wrote:
> OK I may be dating myself here, but I would do...

> PROGRAM MyProgram

> INTEGER max
> PARAMETER (max = 1000)

> INTEGER A(max), B(max), C(max), me(max)

> COMMON /rename/ A, B, C, me

So would I ... COMMON is probably deprecated these days!

--
Jim Backus running OS/2 Warp 3 & 4, Debian Linux and Win98SE
bona fide replies to j <dot> backus <the circle thingy> jita <dot>
demon <dot> co <dot> uk

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc