allocate / deallocate question
From: Les (l.neilson_at_ace_programmer_cad.co.uk)
Date: 07/23/04
- Next message: Arindam Chakraborty: "Help :Writing potable unformated files in fortran"
- Previous message: TimC: "Re: FORMAT in F77"
- Next in thread: *** Hendrickson: "Re: allocate / deallocate question"
- Reply: *** Hendrickson: "Re: allocate / deallocate question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 23 Jul 2004 09:48:27 +0100
I am working on part of a large CAD project making some data arrays dynamic
instead of static.
I copy the data to a temporary array, allocate the data array with its new
size, and copy the data back again. If the allocation of the newsize fails
then I wanted to re-allocate at the oldsize, and copy back the data.
In my destructive testing the "allocate(X3D(newsize),stat=iEr) " fails, but
then so does the attempt to re-allocate X3D at the oldsize.
I am trying to do a "graceful exit" but would like to recover the data that
was originally in X3D array.
Any helpful suggestions / workarounds/ corrections would be gratefully
received.
Thanks
Les
CVF 6.1A on Windows XP
Code snippet below
! Allocate temporary array
allocate(R8Temp(oldsize),stat=iEr)
if(iEr == 0) then
! Store current data in temporary array
R8Temp(1:oldsize)=X3D(1:oldsize)
! deallocate array of current data
deallocate(X3D,stat=iEr)
! ok now allocate new x3d array of newsize
if(iEr == 0) then
allocate(X3D(newsize),stat=iEr)
! if ok then copy data from temporary to new x3d array
if(iEr == 0) then
X3D(1:oldsize)=R8Temp(1:oldsize)
else
! failed. re-allocate x3d at oldsize and restore the data
allocate(X3D(oldsize),stat=iEr)
if(iEr == 0) then
X3D(1:oldsize)=R8Temp(1:oldsize)
endif
endif
endif
endif
- Next message: Arindam Chakraborty: "Help :Writing potable unformated files in fortran"
- Previous message: TimC: "Re: FORMAT in F77"
- Next in thread: *** Hendrickson: "Re: allocate / deallocate question"
- Reply: *** Hendrickson: "Re: allocate / deallocate question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]