Silverfrost Forums

Welcome to our forums

TODATE@ and TOTIME@ compile error

30 Apr 2010 9:24 #6339

I'm using the FILEINFO@ subroutine to return the size and time values. In the documentation it mentions using TOTIME@ and TODATE@ to then turn the times/dates into characters. However when i do so, I get the following errors:

Only CHARACTER variables can be assigned to CHARACTER variables, found REAL(KIND=1) C:\test\test\FreeFormat1.F95 12

Only CHARACTER variables can be assigned to CHARACTER variables, found REAL(KIND=1) C:\test\test\FreeFormat1.F95 13

Am I doing something wrong in the sample below?

WINAPP
PROGRAM Test

  CHARACTER(LEN=8)  myDate
  CHARACTER(LEN=8)  myTime
  CHARACTER(LEN=20) PATH
  INTEGER (KIND=2) MODE, DEV, RDEV, NLINK, ERROR_CODE
  INTEGER (KIND=3) SIZE, ATIME, MTIME, CTIME
  
  PATH = 'C:\\CalInstall.log'
	Call FILEINFO@(PATH, MODE, DEV, RDEV, NLINK, SIZE, ATIME, MTIME, CTIME, ERROR_CODE)
	myDate = TODATE@(ATIME)
	myTime = TOTIME@(ATIME)
END PROGRAM  Test
2 May 2010 10:43 #6340

Yes, but only a small mistake, and it is not really your mistake, it should be stated in the documentation. You also need to define the functions as character*8. and in the case of the TODATE@, you can also define it and its destination variable as LEN=10 to give the two digits of the century as well. See code below:

WINAPP 
PROGRAM Test 
  
  CHARACTER(LEN=10)  myDate, TODATE@
  CHARACTER(LEN=8)  myTime, TOTIME@
  CHARACTER(LEN=20) PATH 
  INTEGER (KIND=2) MODE, DEV, RDEV, NLINK, ERROR_CODE 
  INTEGER (KIND=3) SIZE, ATIME, MTIME, CTIME 
  
  PATH = 'CalInstall.log' 
   Call FILEINFO@(PATH, MODE, DEV, RDEV, NLINK, SIZE, ATIME, MTIME, CTIME, ERROR_CODE) 
   myDate = TODATE@(ATIME) 
   myTime = TOTIME@(ATIME) 
   print *, mydate, ' ',mytime,atime
END PROGRAM  Test 

The clue that you have to declare the function type as character is in the documentation for DATE@. This also hints that four digit years may be available in other textual date related functions.
The standard for FORTRAN is to use variables beginning a-h, o-z as 4-byte reals and i-n as integer. That is no standard start characters for character variables. You did not use the implicit-none compiler switch, so it thought the functions were real, hence the error message. Using that option would have forced you to declare the function type at the point of use. Regards Ian

3 May 2010 2:26 #6342

Thanks Ian, that was explained perfectly.

Please login to reply.