12.07.2015 Views

LF95 Linux User's Guide - Lahey Computer Systems

LF95 Linux User's Guide - Lahey Computer Systems

LF95 Linux User's Guide - Lahey Computer Systems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Passing Character DataIn addition, C requires a NULL terminator (i.e., CHAR(0), a byte whose value is zero) at theend of a character string in order to process it. LF64 does not supply this; hence it must beappended to a character literal or character variable before it is passed to C. Furthermore,Fortran pads the end of the string with blanks to fill its entire declared length. If this paddingis not desired then it must be removed by applying the TRIM() intrinsic and appending aNULL before the string is passed to C.Example: Passing Character Variables and Character Constants from Fortran to CThe following Fortran programprogram strtestcharacter*20 mystrmystr = 'abcde'call sub(mystr)call sub('abcde'//char(0))call sub2(carg(trim(mystr)//char(0)))call sub2(val(offset(mystr)))call sub2(carg('abcde'//char(0)))endand the following C subroutinevoid sub_(str1,i)char *str1;long int i;{printf("hidden length = %i\n",i);printf("%sHi!\n",str1);}void sub2_(str1)char *str1;{printf("%sEnd.\n",str1);}produce the following output:hidden length = 20abcdehidden length = 6abcdeHi!abcdeEnd.abcdeabcdeEnd.Hi!End.Example: Passing String Variables from C to FortranThe following Fortran function has assumed-length character dummy arguments and returnsan assumed-length character result:<strong>Lahey</strong>/Fujitsu <strong>Linux</strong>64 Fortran User’s <strong>Guide</strong> 61

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!