fortran derived type assignment
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 |
Re: fortran derived type assignment
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 |
All times are GMT -4. The time now is 01:05. |