<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to declare a character function in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-declare-a-character-function/m-p/789794#M32003</link>
    <description>I have written a small function called STRIM, very like TRIM, except that it also strips off traling null characters. In the function itself I have declared it as:&lt;BR /&gt;&lt;BR /&gt;character*(*) function strim(string)&lt;BR /&gt;&lt;BR /&gt;But how do I declare it in the calling routine? It works if I declare it as:&lt;BR /&gt;&lt;BR /&gt;character*N strim&lt;BR /&gt;&lt;BR /&gt;where N can be any integer, but of course I don't usually know what N is.&lt;BR /&gt;&lt;BR /&gt;Is this the wrong approach? Any suggestions?&lt;BR /&gt;&lt;BR /&gt;Many thanks&lt;BR /&gt;Mike</description>
    <pubDate>Thu, 04 Sep 2003 10:40:00 GMT</pubDate>
    <dc:creator>michael_green</dc:creator>
    <dc:date>2003-09-04T10:40:00Z</dc:date>
    <item>
      <title>How to declare a character function</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-declare-a-character-function/m-p/789794#M32003</link>
      <description>I have written a small function called STRIM, very like TRIM, except that it also strips off traling null characters. In the function itself I have declared it as:&lt;BR /&gt;&lt;BR /&gt;character*(*) function strim(string)&lt;BR /&gt;&lt;BR /&gt;But how do I declare it in the calling routine? It works if I declare it as:&lt;BR /&gt;&lt;BR /&gt;character*N strim&lt;BR /&gt;&lt;BR /&gt;where N can be any integer, but of course I don't usually know what N is.&lt;BR /&gt;&lt;BR /&gt;Is this the wrong approach? Any suggestions?&lt;BR /&gt;&lt;BR /&gt;Many thanks&lt;BR /&gt;Mike</description>
      <pubDate>Thu, 04 Sep 2003 10:40:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-declare-a-character-function/m-p/789794#M32003</guid>
      <dc:creator>michael_green</dc:creator>
      <dc:date>2003-09-04T10:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to declare a character function</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-declare-a-character-function/m-p/789795#M32004</link>
      <description>Why not just return the length of the new string?&lt;BR /&gt;E.g&lt;BR /&gt;print *, string(1:len_strim(string))</description>
      <pubDate>Thu, 04 Sep 2003 20:47:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-declare-a-character-function/m-p/789795#M32004</guid>
      <dc:creator>alfredwodell</dc:creator>
      <dc:date>2003-09-04T20:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to declare a character function</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-declare-a-character-function/m-p/789796#M32005</link>
      <description>TRIM is rather unusual - there is no good way to "write your own" function that does what it does.  Alfred's suggestion is a good one.&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 04 Sep 2003 21:08:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-declare-a-character-function/m-p/789796#M32005</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2003-09-04T21:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to declare a character function</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-declare-a-character-function/m-p/789797#M32006</link>
      <description>As the original poster discovered yourself, CHARACTER(*) functions do not do what one might think -- actually, they're a quirk in F9x and considered obsolete.&lt;BR /&gt;&lt;BR /&gt;However, there &lt;B&gt;is&lt;/B&gt; a way to do the similar as TRIM: in Fortran-95, length-specification-statements can be result of user-written PURE functions. Of course, entire thing needs an explicit interface, so it's best to place entire thing in a module:&lt;BR /&gt;&lt;PRE&gt;
MODULE Strings
!===========
CONTAINS
!===========
FUNCTION CTRIM(sStr)

CHARACTER*(*),INTENT(IN):: sStr
CHARACTER(LEN=CLEN(sStr)):: CTRIM

CTRIM = sStr

END FUNCTION CTRIM
!===========
PURE INTEGER FUNCTION CLEN(szString)

CHARACTER(*),INTENT(IN):: szString

CLEN = INDEX(szString,CHAR(0)) - 1
IF (CLEN==0) CLEN = LEN_TRIM(szString)

END FUNCTION CLEN
!===========
END MODULE Strings&lt;/PRE&gt;Jugoslav&lt;BR /&gt;&lt;BR /&gt;P.S. Actually, this is a field which caused many compilers to cough, especially when sizing expression is complex. This case is rather simple; CVF is hopefully mature enough to handle even more complex cases.</description>
      <pubDate>Fri, 05 Sep 2003 14:51:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-declare-a-character-function/m-p/789797#M32006</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2003-09-05T14:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to declare a character function</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-declare-a-character-function/m-p/789798#M32007</link>
      <description>Even sleazier:&lt;BR /&gt;&lt;BR /&gt;Function fullTrim(Input)&lt;BR /&gt;implicit none&lt;BR /&gt;    Character(*),intent(in):: Input&lt;BR /&gt;    integer(1) i&lt;BR /&gt;    Character(Len_trim(Input)-verify(Input,' ')+1):: FullTrim&lt;BR /&gt;        i=verify(Input,' ')&lt;BR /&gt;        fullTrim=Input(i:)&lt;BR /&gt;end Function fullTrim&lt;BR /&gt;</description>
      <pubDate>Sat, 06 Sep 2003 03:06:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-declare-a-character-function/m-p/789798#M32007</guid>
      <dc:creator>rahzan</dc:creator>
      <dc:date>2003-09-06T03:06:36Z</dc:date>
    </item>
  </channel>
</rss>

