CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

fortran derived type assignment

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 10, 2008, 07:28
Default fortran derived type assignment
  #1
Paolo Lampitella
Guest
 
Posts: n/a
Hi, probably this is not the best place for such a question but i think that most of you have the right knowledge of fortran (better than me of course) to help me.

I'm writing a genetic algorithm code which makes use of external modules. The code is like the following (i put between quotes "" the not important stuff):

PROGRAM example

USE external_module

IMPLICIT NONE

INTEGER(KIND=my_int_kind) :: "integer stuff"

REAL(KIND=my_real_kind) :: "real stuff"

TYPE(my_der_type) :: type_one,type_two

"Allocation of some components of type_one which have the pointer attribute to have variable dimension"

CALL initialize_type(type_one)

CALL show_me(type_one)

type_two=type_one

CALL modify_type(type_two)

CALL show_me(type_one)

END PROGRAM example

What actually happens is that after having modified type_two, type_one also is modified. I know that there could be thousands reasons for this (some of them have already been checked) but, what i would know is that if, from what i wrote of my code, there is something wrong which i'm doing with the derived types and that determines the wrong modification. I'm using Compaq Visual Fortran 6.0.

Thanks
  Reply With Quote

Old   September 12, 2008, 05:53
Default Re: fortran derived type assignment
  #2
Paolo Lampitella
Guest
 
Posts: n/a
Even if anyone has the answer for my question, maybe some of you could be interested in it (which i found in a manual). Also because i have another question.

The assignment:

type_two=type_one

when the derived type has an allocatable array of pointers as a component, is actually equivalent to

type_two=>type_one

so it is equivalent to a target assignment and this is why type_one was changing with type_two.

Now, the question is:

Because i'm going to modify my whole program to handle this, do you know if assigning my derived type component by component (instead of a single =) is going to produce the same result or what i need for it?

Thanks
  Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
second order schemes marine OpenFOAM 67 April 11, 2022 19:19
boundary conditions for simpleFoam calculation foam_noob OpenFOAM Running, Solving & CFD 8 July 1, 2015 09:07
Need help with boundary conditions: open to atmosphere Wolle OpenFOAM 2 April 11, 2011 08:32
Pressure instability with rhoSimpleFoam daniel_mills OpenFOAM Running, Solving & CFD 44 February 17, 2011 18:08
Problem with compile the setParabolicInlet ivanyao OpenFOAM Running, Solving & CFD 6 September 5, 2008 21:50


All times are GMT -4. The time now is 06:54.