Silverfrost Forums

Welcome to our forums

Strange padding of file names.

1 Jun 2021 9:49 #27889

I have a file-name variable 77 characters long ('fn') which gets partially filled in, in the program (say, 'LS_rocket01.dat'). Whether I open the file using file=trim(fn) or file=fn, and whether I pad the rest of the variable with nulls, blanks, or just leave it alone, the compiler always puts down the file name with a large number of trailing Euro symbols, and it appears that way in the Windows folder. Is there a way around this problem?

My code follows.

! makeFileName creates a file name from the title entered by the user.
subroutine makeFileName(fn)
    implicit      none

    character(len = 77), intent(inout) :: fn

    character(len = 70) :: fileName     ! File name.
    character(len = 77) :: wholeFN      ! Longer file name.
    integer             :: FNlength     ! Length of fileName.

    write (*, 10)
10  format('Please enter a file name:')
    read  (*, *) fileName
    fnLength = len_trim(fileName)

    wholeFN(1:3) = 'LS_'
    wholeFN(4:fnLength+3) = trim(fileName)
    wholeFN(fnLength+4:fnLength+7) = '.dat'

    fn(1:fnLength+7) = wholeFN
end subroutine makeFileName



! saveRocketParameters saves user-entered rocket characteristics as a
! disk file.
subroutine saveRocketParameters
    use           launchSimGlobals
    implicit      none

    character(len = 1)  :: reply        ! User's yes or no.
    character(len = 77) :: fn           ! Whole file name.

    write (*, 10);  read (*, *) reply
10  format(/'Do you want to save all this as a file [Y/N]?  ', $)

    if ((reply .eq. 'Y') .or. (reply .eq. 'y')) then
      call makeFileName(fn)

      open  (unit=9, file=fn)
      write (9, 30) M0;  write (9, 30) R
      write (9, 30) q;   write (9, 30) gamma
      write (9, 30) mu;  write (9, 30) Pc
      write (9, 30) Tc;  write (9, 30) alpha
      write (9, 30) Ac
      close (unit=9)
30    format(es15.7)
    end if

    write (*, *)
end subroutine saveRocketParameters

[/code]

2 Jun 2021 2:28 #27890

The error is in your program. After the statement

wholeFN(fnLength+4:fnLength+7)

has been executed, the rest of wholeFN, i.e., wholeFN(fnLength+8:77), is still undefined. Those memory locations happened to contain the character €.

One solution: after reading fileName, add the prefix and suffix using:

fn = 'LS_'  // trim(filename) // '.dat'
3 Jun 2021 7:37 #27894

I'll try that! Thanks!

Please login to reply.