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 

Data statement

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



Joined: 08 Apr 2011
Posts: 155

PostPosted: Tue Jul 05, 2011 4:26 am    Post subject: Data statement Reply with quote

I now that; The DATA statement is a non-executable statement used to initialise variables. It is particularly useful for initialising arrays. It has the form:

DATA variable_list/constant_list/ [,variable_list/constant_list/] ...

Can anyone tell em the interpretation of this;

data X/7*' '

data Y/5* 'Settings'/

Please help-
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Tue Jul 05, 2011 6:58 am    Post subject: Reply with quote

This is old Fortran syntax, but still part of the Language. Look at the following.

The first use initialises the array x so all elements have the value 0.0

The second use initialises the array y so all elements have the value 'Settings'

The third case is equivalent to the second (for variable z), but uses newer syntax.

Code:

! First
real :: x(5)
data x/5*0.0/

! Second
character(len=8) :: y(5)
data y/5*'Settings'/

! Third
character(len=8) :: z(5) = 'Settings'


The main thing to remember about DATA is it only initialises at compile time (sometimes at link time), so don't expect values to be reset when a procedure with DATA statements is called multiple times.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
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 -> General 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