There are two steps in logging an event: you first create a string that contains the message you want to write to the logfile, and you then call the LogMessage subroutine. (LogMessage will automatically prepend the correct timestamp; it's smart like that.) You will no doubt be tempted to skip creating the string containing the message, supposing that you will just pass it as a string literal in the subroutine call. If you do that each log entry will be padded out to the 80 characters with nulls, and your logfile will be a nightmare to read. Trust me. And don't assume that little feature is documented in most Fortran 90 books, either. Here's a very simple code snippet:
LogMessage = 'The quick brown fox jumped over the lazy dogs.' call log_message(LOGfile,LogMessage)
Of course, it's not for nothing that we provide the LOGon parameter, which toggles logging on and off, so perhaps we should respect the user's wishes and check it:
if ( LOGon == 1 ) then LogMessage = 'The quick brown fox jumped over the lazy dogs.' call log_message(LOGfile,LogMessage) end if
if ( LOGon == 1 .and. LOGfreq > 0 ) then LogMessage = 'This message is printed every time bestpred() is entered.' call log_message(LOGfile,LogMessage) end if
if ( LOGon == 1 .and. LOGfreq > 0 .and. mod(ncall,LOGfreq) == 0 ) then
LogMessage = 'Allocating arrays in call '//trim(char(ncall+ICHAR('0')))
call log_message(LOGfile,LogMessage)
end if
if ( LOGon == 1 .and. LOGfreq > 0 .and. mod(ncall,LOGfreq) == 0 ) then
LogMessage = 'Allocating arrays in call '//trim(char(ncall+ICHAR('0')))
call log_message(LOGfile,LogMessage)
end if
[jcole@aipl3850 bestpred_onepass]$ cat example.20080807.log # example.20080807.log created on 08/07/2008 at 10:31:41 [10:31:41]: Starting BESTPRED 2.0b9 [10:31:41]: Allocating matrices for means, SD, and covariances [10:31:41]: Allocating arrays in call 0 [10:31:41]: Converting from lbs to kg for interal calculations [10:31:41]: Calling interpolate with method W and breed 4 [10:31:41]: Calling interpolate with method W and breed 4 [10:31:41]: Calling interpolate with method W and breed 4 [10:31:41]: Calling interpolate with method W and breed 4 [10:31:43]: Calling interpolate with method W and breed 4 [10:31:43]: Calling interpolate with method W and breed 4 [10:31:43]: Calling interpolate with method W and breed 4 [10:31:43]: Calling interpolate with method W and breed 4