|
From: relaxmike on 17 Jun 2008 10:39 And what if fortran strings were dynamic ? Notice that fortran 2003 introduced the "character, allocatable" statement. Another possibility would be to make use of the m_vstring module of the flibs project. Suppose that the algorithm is separated into two parts : 1. the strings are added to a dynamic buffer, 2. the string string is written, depending on the modus : - if dll mode, send the string, - if stand alone mode, write the string to file. This is a sketch (i did not test it) for the buffering algorithm. The client code would be the following. use bufferstring use m_fileunit, only : fileunit_getfreeunit call buffer_startup () call buffer_append ( "My 1st line." ) call buffer_append ( "My 2nd line." ) select case (modus) case ( dll ) call sendstring ( buffer ) case ( standalone ) lunit = fileunit_getfreeunit () open ( lunit , file="myfile.log" ) call buffer_write ( lunit ) close ( lunit ) call buffer_shutdown () The buffering module would be like the following, with a static dynamic buffer string and static methods to fill the buffer. module bufferstring use m_vstring type(t_vstring), save :: buffer contains subroutine buffer_startup() call vstring_new ( buffer ) end subroutine buffer_startup subroutine buffer_shutdown () call vstring_free ( buffer ) end subroutine buffer_shutdown subroutine buffer_append ( string ) character(len=*) :: string call vstring_append ( buffer , string ) end subroutine buffer_append subroutine buffer_write ( lunit ) integer, intent (in) :: lunit call buffer_writeinternal ( lunit , buffer ) contains subroutine buffer_writeinternal ( lunit , buffer ) integer, intent (in) :: lunit type(t_vstring), intent(in) :: buffer character(len=vstring_length(buffer)) :: charstring call vstring_cast ( buffer , charstring ) write ( lunit , "(A)") charstring end subroutine buffer_writeinternal end subroutine buffer_write end module bufferstring We could even use "call buffer_append ( VSTRING_NEWLINE )" so that newlines characters are inserted between 2 appends. Michaƫl
From: Terence on 18 Jun 2008 20:11 The write statements will refer to a file number. This file number can be opened in one mode as a real named file on a hard disk. In the non-write mode, the file assigned should be the /NULL file. So you choose which OPEN statement will be used, in a CASE construct.
|
Pages: 1 Prev: User types + interface in the same module Next: Global array operations: a performance hit? |