replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Parameter derived types
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Parameter derived types

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
simon



Joined: 05 Jul 2006
Posts: 299

PostPosted: Fri Aug 20, 2010 2:45 pm    Post subject: Parameter derived types Reply with quote

I want to declare a derived type as a parameter, but cannot work out how to initialise it. Can anybody comment on the following, which generates a number of compilation errors? I can see that the second last line is trying to set up an array rather than the two components of the derived type, but what should the syntax be?

Code:
MODULE m1
  TYPE t1
     CHARACTER(LEN=1) :: c1
     CHARACTER(LEN=2) :: c2
  END TYPE t1
  TYPE(t1), PARAMETER :: a=(/'A','Aa'/)
END MODULE m1
Back to top
View user's profile Send private message
sparge



Joined: 11 Apr 2005
Posts: 371

PostPosted: Fri Aug 20, 2010 3:45 pm    Post subject: Reply with quote

If it's legal (I'm guessing not), logically you would write:

TYPE(t1), PARAMETER :: a=t1 ('A','Aa')

?
Back to top
View user's profile Send private message Send e-mail
simon



Joined: 05 Jul 2006
Posts: 299

PostPosted: Fri Aug 20, 2010 4:45 pm    Post subject: Reply with quote

Thanks. I'll try.
A colleague thinks that it may be a Fortran 2003 feature.
Back to top
View user's profile Send private message
sparge



Joined: 11 Apr 2005
Posts: 371

PostPosted: Fri Aug 20, 2010 5:25 pm    Post subject: Reply with quote

I got curious and tried it too. The code below works for me. Whether it ought to, and whether more realistic code would, I have no idea Smile but I have occasionally wanted to declare derived type parameters in the past, and been instinctively wary, so if it is legit I shall be incrementally happier as a result.

Andy

Code:
        program c
        use m1
        type (t1) b
        b = a
        stop
        end program c

      module m1
        type t1
           character(len=1) :: c1
           character(len=2) :: c2
        end type t1
        type(t1), parameter :: a=t1 ('a','aa')
      end module m1
Back to top
View user's profile Send private message Send e-mail
simon



Joined: 05 Jul 2006
Posts: 299

PostPosted: Fri Aug 20, 2010 8:16 pm    Post subject: Reply with quote

Great. That works. I needed an array so here's how that works:

Code:
MODULE m1
  TYPE t1
     CHARACTER(LEN=1) :: c1
     CHARACTER(LEN=2) :: c2
  END TYPE t1
  TYPE(t1), PARAMETER :: ab(2)=(/t1('A','Aa'),t1('B','Bb')/)
END MODULE m1
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group