Re: initializing an array of user-defined data types
- From: Paul van Delst <Paul.vanDelst@xxxxxxxx>
- Date: Wed, 28 Nov 2007 15:21:03 -0500
Bart Vandewoestyne wrote:
I have a rank 2 array of a user-defined type as follows:
type(piece), dimension(:,:), allocatable, private :: board
After allocating it, I want to initialize it so that after
initialization, I can check whether board(i,j) contains a piece
or not.
I've tried things like
board = NULL
... assign some pieces to board positions and leave others empty ...
if (board(i,j) == NULL) then
... do something ...
end if
but that doesn't seem to work.
What is the proper way to do this?
What about this sort of thing:
type :: piece
integer :: i = -1
real :: x = -999.99
end type piece
...
type(piece), dimension(:,:), allocatable :: board
...
allocate(board(10,10))
...
if ( board(i,j) == piece(-1,-999.99) ) then
board(i,j) = piece(i,real(j))
... do something else ...
end if
??
Maybe you could even do
type(piece), parameter :: mynull = piece(-1,-999.99)
....
if ( board(i,j) == mynull ) then
... do something ...
end if
but I've never tried that and have no idea if it's allowed syntax. Easy to test, though.
cheers,
paulv
.
- Follow-Ups:
- Re: initializing an array of user-defined data types
- From: Dan Nagle
- Re: initializing an array of user-defined data types
- References:
- initializing an array of user-defined data types
- From: Bart Vandewoestyne
- initializing an array of user-defined data types
- Prev by Date: Re: Fortran Error Reporting Requirements (Was: GFORTRAN PROBLEM WITH SAVE STATEMENT)
- Next by Date: Re: initializing an array of user-defined data types
- Previous by thread: Re: initializing an array of user-defined data types
- Next by thread: Re: initializing an array of user-defined data types
- Index(es):
Relevant Pages
|