Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8885963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:26:29+00:00 2026-06-14T21:26:29+00:00

Is it possible change the type (or copy) a double type array into a

  • 0

Is it possible change the type (or copy) a double type array into a char?

My objective is mix accurate data with strings, and then write to .txt file.


With your tips, I reach this code:

Program logArray

Implicit None

Integer, Parameter :: wp = Selected_real_kind( 12, 70 )

Real( wp ), Dimension( 1:5 ) :: vals
Character( Len = 40 ), Dimension( 1:5 ) :: stuff

character (40) :: fileName
Integer :: i,stat


Call Random_number( vals )

write(*,*) 'Printing Values from Real array'
do i = 1, 5
    write(*,*) 'vals', i, vals(i)
end do


Write( stuff, '( "Value ", i1, " is ", f20.16 )' ) &
   ( i, vals( i ), i = 1, Size( vals ) )

fileName='log.txt'

open(2, file=fileName, status='replace', iostat=stat)
    if (stat /= 0) then
        write(*,*) fileName, ' The file  cannot be opened !'
        go to 20
    end if

    !Write( *, '( 99999( a, :, / ) )' ) stuff  
    Write( 2, '( 99999( a, :, / ) )' ) stuff 

    close(2)


    20 write(*,*) 'File Closed' 

End Program logArray

However, I still don’t get it, if I want to write on log.txt something like

“—–Title of Value 1———“

Value 1 is 0.9975595900926172
Value 2 is 0.5668247076112733

“—–Value 3 means love——-“
Value 3 is 0.9659153754961249
Value 4 is 0.7479276854714322
Value 5 is 0.3673908973747557

I’m newbie at Fortran. I used to write to files with cycles, your “magic” instruction does the things in a different way, and I don’t get it how can I manipulate in main favor.

Thank you very much for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:26:30+00:00Added an answer on June 14, 2026 at 9:26 pm

    Not quite sure what you mean, but what you probably need is an internal file – this is how you convert numeric data to/from character form in Fortran. Here’s an example:

    [luser@cromer stackoverflow]$ cat char.f90
    Program char
    
      Implicit None
    
      Integer, Parameter :: wp = Selected_real_kind( 12, 70 ) 
    
      Real( wp ), Dimension( 1:5 ) :: vals
    
      Character( Len = 40 ), Dimension( 1:5 ) :: stuff
    
      Integer :: i
    
      Call Random_number( vals )
    
      Write( stuff, '( "Value ", i1, " is ", f20.16 )' ) &
           ( i, vals( i ), i = 1, Size( vals ) )
    
      Write( *, '( 99999( a, :, / ) )' ) stuff
    
    End Program char
    [luser@cromer stackoverflow]$ nagfor -C=all -C=undefined char.f90
    NAG Fortran Compiler Release 5.3.1 pre-release(904)
    [NAG Fortran Compiler normal termination]
    [luser@cromer stackoverflow]$ ./a.out
    Value 1 is   0.5247509555250293         
    Value 2 is   0.2338414404620047         
    Value 3 is   0.8165253430643411         
    Value 4 is   0.2788076219798084         
    Value 5 is   0.9609032005446272         
    

    The line

      Write( stuff, '( "Value ", i1, " is ", f20.16 )' ) &
           ( i, vals( i ), i = 1, Size( vals ) )
    

    is the one that does the magic – It writes out vals according to the format given, but instead of writing to file it writes to the character array stuff, each element of the array acting as a record i the “file”

    I hope this makes sense. To be more specific we need more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering if its possible to change a HTML elements data type with
Is it possible to change the type of a TFS work item? For example,
Is it possible to change type of calendar in DateTimePicker (C#) ? e.g :
Is it possible to change the OUTPUT font type instead of the default one?
is it possible to change type of a attribute after it has been created.
Possible Duplicate: Change the URL in the browser without loading the new page using
Possible Duplicate: Change icon on of an App in iOS 4 in run-time Is
Possible Duplicate: change layout and template in zend dynamically according to the device(android tab,iphone,ipad)
Is it possible to change the color of View Results text in below ?
Is it possible to change C#'s built-in Vector3 struct to not use floating point

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.