Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > Re: derived typ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 8222 of 8656
Post > Topic >>

Re: derived type as argument

by Tim Prince <tprince@[EMAIL PROTECTED] > May 11, 2008 at 11:38 AM

GeoGarfield@[EMAIL PROTECTED]
 wrote:
> hi,
> I have been asking myself this question for a long time, and there's
> nobody around me at work who knows anything about programming, so
> there it is.
> 
> I very much like derived types. I use them all the time. In the
> derived type ptcl I have three unallocated arrays x,y and z. In the
> main I create the variable ptcles of type ptcl. I would like to pass
> ptcles as argument to a routine called gnagna that would allocate the
> arrays ptcles%x, ptcles%y, and ptcles%z.
> 
> Here is the code. When I compile it with the PGI compiler on a Cray,
> it works. I first get F F F , then T T T.
> Beyond the practical aspect, I would like to know whether I am lucky,
> or whether all F90 compilers on all machines will accept it.
> 
>
--------------------------------------------------------------------------------------------
> module opla
> type ptcl
> double precision, dimension(:), pointer :: x,y,z
> end type
> end module
> 
> !==============================
> 
> program essai
> use opla
> implicit none
> type(ptcl) ptcles
> print *,allocated(ptcles%x), allocated(ptcles%y), allocated(ptcles%z)
> call gnagna(ptcles)
> print *,allocated(ptcles%x), allocated(ptcles%y), allocated(ptcles%z)
> end program
> 
> !===============================
> 
> subroutine gnagna(ptcles)
> use opla
> implicit none
> type(ptcl) ptcles
> allocate(ptcles%x(100))
> allocate(ptcles%y(100))
> allocate(ptcles%z(100))
> end subroutine
It works with ifort and gfortran on 32-bit Windows, if I change pointer 
to allocatable.
 




 5 Posts in Topic:
derived type as argument
GeoGarfield@[EMAIL PROTEC  2008-05-11 11:20:06 
Re: derived type as argument
Tim Prince <tprince@[E  2008-05-11 11:38:02 
Re: derived type as argument
nospam@[EMAIL PROTECTED]   2008-05-11 12:18:05 
Re: derived type as argument
Ron Shepard <ron-shepa  2008-05-11 19:49:35 
Re: derived type as argument
GeoGarfield@[EMAIL PROTEC  2008-05-12 10:21:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Aug 30 8:23:48 CDT 2008.