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 7749859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:08:30+00:00 2026-06-01T11:08:30+00:00

I was trying to code this problem in fortran. The output file contains the

  • 0

I was trying to code this problem in fortran. The output file contains the result in two columns. I am having hard time to modify my code (below) to get a gnuplot-ready output file containing nt columns and nx lines. Can anybody help me? Thanks!

PROGRAM odlc
IMPLICIT NONE
INTEGER::i,it,nx,nt,k,ierr
DOUBLE PRECISION::dx,dt,c
DOUBLE PRECISION,DIMENSION(2000)::u,un
ierr=0
nx=20
nt=50
dt=0.01
c=1.0
dx=2./(nx-1.)
!initial condition
DO i = 1,nx
    IF(i*dx>=0.5 .and. i*dx<=1) THEN
    u(i) = 2    
    ELSE
    u(i)=1
    ENDIF   
ENDDO
!Finite Difference
OPEN(UNIT=200,FILE='tab2.txt',STATUS='REPLACE',ACTION='WRITE',IOSTAT=ierr)
  DO it=1,nt
    DO k=1,nx
    un(k)=u(k)
    ENDDO 
        DO i=2,nx-1
        u(i)=un(i)-c*dt/dx*(un(i)-un(i-1))
        ENDDO
            DO i=1,nx
            WRITE(200,'(I7,F10.2)')i,u(i)
            ENDDO
ENDDO
CLOSE(UNIT=200)
END
  • 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-01T11:08:31+00:00Added an answer on June 1, 2026 at 11:08 am

    I’m not 100% sure that it is exactly what you want but here you go:

    Declare

    CHARACTER(len=32)::fmt
    

    and initialize it like this

    WRITE(fmt,*)'(',nx,'F10.2)'
    

    This just creates a format string which writes a single line of nx reals.

    Then replace

    DO i=1,nx
    WRITE(200,'(I7,F10.2)')i,u(i)
    ENDDO
    

    by

        WRITE(200,fmt) (/ (u(i), i=1,nx) /)
    

    Now in your tab2.txt file, you will get nt lines and nx columns.


    After your update, here is the (slightly shortened) code that will do what you want:

    PROGRAM odlc
      IMPLICIT NONE
      INTEGER::i,it
      INTEGER,PARAMETER::nx=20,nt=50
      DOUBLE PRECISION,PARAMETER::dx=2./(nx-1.),dt=0.01,c=1.0
      DOUBLE PRECISION,DIMENSION(nt,nx)::u
      CHARACTER(len=32)::fmt
      WRITE(fmt,*)'(I3,',nt,'F5.2)'
      !initial condition                                                                                                                                                                                                                                                     
      DO i = 1,nx
         IF(i*dx>=0.5 .and. i*dx<=1) THEN
            u(1,i) = 2
         ELSE
            u(1,i)=1
         ENDIF
      ENDDO
      !Finite Difference                                                                                                                                                                                                                                                     
      DO it=2,nt
         DO i=2,nx-1
            u(it,i)=u(it-1,i)-c*dt/dx*(u(it-1,i)-u(it-1,i-1))
         ENDDO
      ENDDO
      !Write to file                                                                                                                                                                                                                                                         
      OPEN(UNIT=200,FILE='tab2.txt',STATUS='REPLACE',ACTION='WRITE')
      DO i=1,nx
         WRITE(200,fmt)REAL(i*(2./(nx-1.))),u(:,i)
      ENDDO
      CLOSE(UNIT=200)
    END PROGRAM odlc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert this test code to C# and having a problem
I'm trying to solve this problem, its not a homework question, its just code
I am trying to solve this exponentiation problem . Here is the code that
I am having an issue converting type. I was trying code like this (minimal,
I've been trying to code this page for a while, but my biggest problem
I'm trying to find a solution for this problem. This is my example code:
I am trying to solve this problem in Haskell but getting time limit exceed.
I'm trying to run this MPI Fortran code. There are several problems: 1) when
I am trying to code this algorithm. I am stuck in the part of
I am trying this code: entLoop:for(var i:*in entities) { for(var i2:*in ignoreEntities) { if(entities[i].type==ignoreEntities[i2])

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.