From j.l.schonfelder@liverpool.ac.uk  Fri Jul  4 17:58:24 1997
Received: from pcmail.liv.ac.uk (pp@pcmail.liv.ac.uk [138.253.252.13]) by dkuug.dk (8.6.12/8.6.12) with SMTP id RAA17463 for <SC22WG5@dkuug.dk>; Fri, 4 Jul 1997 17:58:23 +0200
Received: from jlspcnt.liv.ac.uk [138.253.102.118] 
	by pcmail.liv.ac.uk with smtp (Exim 1.61 #3)
	id 0wkAkW-00076i-00; Fri, 4 Jul 1997 16:58:20 +0100
From: Lawrie Schonfelder <j.l.schonfelder@liverpool.ac.uk>
Sender: J.L.Schonfelder@liverpool.ac.uk
Reply-To: j.l.schonfelder@liverpool.ac.uk
To: SC22/WG5 members <SC22WG5@dkuug.dk>
Subject: ELEMENTAL assignment in F95 Varying Strings
Message-ID: <SIMEON.9707041618.K@jlspcnt.liverpool.ac.uk>
Date: Fri, 4 Jul 1997 16:58:18 +0100 (British Summer Time)
Priority: NORMAL
X-Mailer: Simeon for Win32 Version 4.1.1 Build (17)
X-Authentication: IMSP
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII

In order to deal with the IMO unnecessary restriction on elementary 
procedures imposed on F95 I have to do something like this for 
string to string assignment. 
!----- ASSIGNMENT Procedures -------------------------------------------------!
 ELEMENTAL SUBROUTINE s_ass_s(var,expr) 
  type(VARYING_STRING),INTENT(OUT) :: var 
  type(VARYING_STRING),INTENT(IN)  :: expr 
  !  assign a string value to a string variable overriding default assignement 
  !  reallocates string variable to size of string value and copies characters 
  CHARACTER,ALLOCATABLE :: tmpexpr(:)
  ALLOCATE(tmpexpr(1:SIZE(expr%chars)))
  tmpexpr = expr%chars
  IF(ASSOCIATED(var%chars))DEALLOCATE(var%chars)
  ALLOCATE(var%chars(1:SIZE(tmpexpr)))
  var%chars = tmpexpr 
 ENDSUBROUTINE s_ass_s 
The temp is necessary to deal with this sort of situation
stra = stra
Without it the deallocation destroys the value of the expression before 
allocating the space to contain the new copy. This is a very heavy handed 
solution to a rather small problem. 
I have to think some more about the whole structure of the module. I think it 
may be the case that it is only when there is total overlap of var and expr 
that the problem arrises. I think in all other cases where there would be 
what looks like a partial overlap, e.g.
stra=stra//strb
the actual expr value is held in some temporary space already and there is no 
real overlap. If I can convince myself that this is the case then the code 
could become
 ELEMENTAL SUBROUTINE s_ass_s(var,expr) 
  type(VARYING_STRING),INTENT(OUT) :: var 
  type(VARYING_STRING),INTENT(IN)  :: expr 
  !  assign a string value to a string variable overriding default assignement 
  !  reallocates string variable to size of string value and copies characters 
  IF(ASSOCIATED(var%chars,expr%chars))THEN
    RETURN ! identity assignment do nothing
  ELSEIF(ASSOCIATED(var%chars))THEN
    DEALLOCATE(var%chars)
    ALLOCATE(var%chars(1:SIZE(expr%chars)))
    var%chars = expr%chars
  ENDIF 
 ENDSUBROUTINE s_ass_s 
--
Lawrie Schonfelder
Director, Computing Services Dept.
The University of Liverpool, UK, L69 7ZF
Phone: 44(151)794 3716, Fax: 44(151)794 3759




