#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2006
    Posts
    163
    Rep Power
    26

    Concatenate integer with a character data type


    Is there any way in Fortran77 to concatenate an integer with a character data type?
    Basically, I'm trying to create filenames in a loop like:
    file01.out
    file02.out
    file03.out
    ....
    .......
    for this I need to concatenate 'file' which is a character with 01 which is an integer, and I cannot simply do file//01, since the data types are different.
    Is there a way to get around this issue in Fortran77.
    is there any function similar to sprintf in F77.
  2. #2
  3. I have a red lunch bag
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jan 2005
    Location
    The armpit of Niagara
    Posts
    3,125
    Rep Power
    339
    Please start your own thread.
    Web Design Tips - Posting and You

    If I've been helpful, and/or you're really nice, consider buying something from my Amazon.com wishlist.
    • There is no room for pride when trying to be the best at what you do.
    • Friends don't let friends use bad code.
    The club is dead.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    There is already a thread with this question ... and there is already an answer
  6. #4
  7. Making a mistake is not sin.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Location
    Finland
    Posts
    406
    Rep Power
    209
    At least with F90 you can use write and fmt. I believe it was something like:

    WRITE (chars,( // .fmt. n // )) n

    (n is integer)

    EDIT:
    Oh, sorry. I guess I was just a bit too enthusiastic to reply cause I once in my life knew the (partial) answer to something :/ Dang. Perhaps I someday will be the fastest

    http://c-ohjelmoijanajatuksia.blogspot.com/
    http://maz-programmersdiary.blogspot.com/
    Admitt you do not know - and become wise.
    Pretend to be wise - and stay stupid.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2006
    Posts
    163
    Rep Power
    26
    Originally Posted by gaanee
    Is there any way in Fortran77 to concatenate an integer with a character data type?
    Basically, I'm trying to create filenames in a loop like:
    file01.out
    file02.out
    file03.out
    ....
    .......
    for this I need to concatenate 'file' which is a character with 01 which is an integer, and I cannot simply do file//01, since the data types are different.
    Is there a way to get around this issue in Fortran77.
    is there any function similar to sprintf in F77.

    the concatanation operator "//" deosn't work since one argument is integer, so I wrote a format statement and then write it to a file then read it from the file. seems to be some extra work in opening, writing and then reading it from a file, but it works. I've to write it and then read, since it seems that if u have a format statement, then the only place u can use it is a write statement.
    does anyone know of a better way?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    I've to write it and then read, since it seems that if u have a format statement, then the only place u can use it is a write statement.
    does anyone know of a better way?
    Hello? Did you read my answer in your other post?

IMN logo majestic logo threadwatch logo seochat tools logo