forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Strange padding of file names.

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
bplevenson



Joined: 02 Nov 2006
Posts: 21

PostPosted: Tue Jun 01, 2021 10:49 pm    Post subject: Strange padding of file names. Reply with quote

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.



Code:
! 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]
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1580

PostPosted: Wed Jun 02, 2021 3:28 am    Post subject: Reply with quote

The error is in your program. After the statement
Code:
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:
Code:
fn = 'LS_'  // trim(filename) // '.dat'
Back to top
View user's profile Send private message
bplevenson



Joined: 02 Nov 2006
Posts: 21

PostPosted: Thu Jun 03, 2021 8:37 pm    Post subject: Strange padding of file names. Reply with quote

I'll try that! Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group