ALLOCATE: expand array or string dimensions(H)
⇒Home
⇒Contents
⇒more on Programming
(⇒Optional Keywords Syntax)
⇒ Example of a ALLOCATE call in "Greatest_element_of_a_list" (RosettaCode)
Bookmarks:
⇒dynamically increase string length
⇒equivalence
⇒increase array size
⇒named substrings
⇒rename part of an array
⇒reshape matrix
increase array size
to a new size of rows*columns:
bytes_allocated = ALLOCATE( name, columns [, rows])
if rows is omitted, its value is internally set to 1
ALLOCATE can be used to
reshape matrix
by retaining the value of rows*columns.
This includes the reshape of a vector to a matrix (rows present)
or of a matrix to a vector. (rows not present)
REAL
:: vec(1)
! initially 1 element only
ALLOCATE( vec, 10 )
! increase to 10 elements
ALLOCATE( vec, 2*
LEN
(vec) )
! double the current length
ALLOCATE( vec, 2, LEN(vec)/2 )
! reshape vec to a 2 column matrix
ALLOCATE( vec, LEN(vec) )
! reshape to a vector
rename part of an array
ALIAS
( vec, 11, sub_vec, 5 )
! rename vec(11...15) to sub_vec
this has the functionality of
equivalence
in Fortran
the current values of name are retained when ALLOCATE is executed
⇒ LEN(vec) to get the current length of vec
⇒ LEN_TRIM(vec) to get the length of vec when stripped of trailing zeros
dynamically increase string length
to new_length:
bytes_allocated = ALLOCATE( name, new_length )
CHARACTER
:: txt = "abc"
! initial length is 3
ALLOCATE(txt, 20)
! txt length increased to 20
ALLOCATE(txt, 2*LEN(txt) )
! txt length is doubled
named substrings
ALIAS( string, 11, sub_string, 5 )
! rename string(11:15) to sub_string
this has the functionality of
equivalence
in Fortran
the current values of name are retained when ALLOCATE is executed
⇒ LEN(string) to get the current length of string
⇒ LEN_TRIM(string) to get the length of string when stripped of trailing blanks
How your donation will be used, and how to get a HicEst key code in return
©2000-2010 Georg Petrich, HicEst Instant Prototype Computing. All rights reserved.
Impressum