Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran90 help

  1. May 6, 2007 #1
    Hey,

    I wasn't sure whether or not to put this in the homework section or not because I need to complete this code for an assignment, but I thought that someone with fortran knowledge might have a better chance of seeing it in this section.

    PROGRAM testing

    ! Variable declarations
    CHARACTER input*100 ! buffer for holding a line of data from a file
    INTEGER, PARAMETER :: DATAFILE = 30, STDIN = 5, STDOUT = 6
    INTEGER numRecords, & ! number of records for each star
    starNum, &
    flag, &
    numRepetitions
    REAL (KIND=8) :: barycentricJD, bMag, deltaBMag, backgroundB, &
    vMag, deltaVMag, backgroundV, fluxconv, mean, std, zeromean

    REAL (KIND=8), PARAMETER :: F0=0.0000000216

    ! Program Start

    ! Read information from the keyboard
    WRITE(STDOUT,*) "Enter number of stars to read in: "
    READ(STDIN,*) numRepetitions

    ! Open the .dat file
    OPEN( FILE = 'TYC_EP.dat', UNIT = DATAFILE, STATUS = 'OLD', IOSTAT = IOStat )

    DO I = 1, numRepetitions ! read in numRepetitions stars
    READ (DATAFILE, "(a)") input ! read header information for current star
    READ(input(6:10), FMT="(I5)") starNum ! extract star number from header info
    READ(input(14:16), FMT="(I3)") numRecords ! extract number of transits for current star

    WRITE (STDOUT,*) "Star number is: ", starNum
    WRITE (STDOUT, *) "Number of records is: ", numRecords

    fluxconvsum=0

    DO J = 1, numRecords
    READ (DATAFILE,"(a)") input
    READ(input(1:50), "(F10.1,1X,F6.3,1X,F5.3,1X,F6.2,1X,F6.3,1X, F5.3,1X, F6.2)") &
    barycentricJD, bMag, deltaBMag, backgroundB, &
    vMag, deltaVMag, backgroundV
    READ(input(83:84), "(I2)") flag
    fluxconv=F0*(10**(-bMag/2.5))
    fluxconvsum=fluxconvsum+fluxconv
    WRITE(STDOUT,*) barycentricJD," ", bMag, " ", deltaBMag," ",&
    backgroundB," ", vMag," ", deltaVMag," ",&
    " ", backgroundV, " ",flag, " ", fluxconv

    END DO ! End of loop for reading in each record
    mean=(fluxconvsum)/numRecords
    WRITE(STDOUT, *) "MEAN", mean, fluxconv

    END DO ! End of loop for reading in each star


    CLOSE(DATAFILE)

    END PROGRAM testing

    I'm no expert in fortran (well actually I've never done programming ever and I'm really bad at it) and this program has essentially been created by trial and error from my lecture notes and I've been lucky up until this moment. In the loop for the "reading in each record" I will get 111 individual entries for fluxconv (for the first star), but then I write fluxconv outside of the loop it only returns the very last value of fluxconv. All I want to know is why this is? If I know this then I should be able to sort it out and then proceed to zero mean the data.

    I'd appreciate any help at all
    Thanks
     
    Last edited: May 6, 2007
  2. jcsd
  3. May 8, 2007 #2
    I don't mean to be a bother, but could you put [ code ] and [ /code ] (without the spaces) around your code to make it more readable, so that whatever indenting you do isn't ignored by the forums software?
     
  4. May 9, 2007 #3
    What are you expecting, or, what is it you're hoping for? -- right now, you are using "fluxconv" as a simple variable and thus, it will only retain the last value assigned to it (the last value at the end of the J cycle for each iteration of I).
     
  5. Nov 27, 2008 #4
    How can I open, read, write multiple filenames in fortran90 using linux?
     
  6. Nov 27, 2008 #5
    this is my first fortran program and i tried to learn fortran myself i would like anyone please to comment on this program and if there is an improvement can be done
    i appreciate your help and thank you very much





    PROGRAM FIRST
    ! FINITE VOLUME METHOD FOR ONE DIMENSIONAL UNSTEADY STATE HEAT CONDUCTION
    ! EXPLICIT SCHEME
    ! EXAMPLE 8.1
    !
    ! THE ONE DIMENSIONAL TRANSIENT HEAT CONDUCTION EQUATION IS D*dT/dt=d/dx(k*dT/dx)
    ! THE INITIAL CONDITIONS ARE T=200 AT t=0
    !
    ! THE BOUNDARY CONDITIONS ARE: dT/dx=0 at x=0, t>0 and T=0 at x=L, t>0
    ! THE NUMERICAL SOLUTION WITH THE EXPLICIT METHOD IS GENERATED BY DIVIDING THE
    ! DOMAIN INTO FIVE EQUAL CONTROL VOLUMES WITH (DELTA X = 0.004 m)
    ! !
    !P*TP=W*TW+E*TE+[P-(W+E)]*TP+Su
    !
    REAL, DIMENSION (0:50,0:50):: T
    INTEGER :: j
    REAL :: E,P,W

    PRINT*, ' '
    !
    ! AS THE PLATE INITIALLY AT A UNIFORM TEMPERATURE OF 200
    ! !
    DATA T(0,1),T(0,2),T(0,3),T(0,4),T(0,5) /5*200/
    !
    PRINT*,' '
    CALL ONE(E,P,W)
    !
    PRINT*, T(0,1),T(0,2),T(0,3),T(0,4),T(0,5)
    !
    DO j=0,19
    !
    ! NODE (1) EQUATION
    T(j+1,1)=E/P*T(j,2)+(1-(E/P))*T(j,1)
    !
    ! NODE(2-4)EQUATIONS
    T(j+1,2)=W/P*T(j,1)+E/P*T(j,3)+(1-((W/P)+(E/P)))*T(j,2)
    T(j+1,3)=W/P*T(j,2)+E/P*T(j,4)+(1-((W/P)+(E/P)))*T(j,3)
    T(j+1,4)=W/P*T(j,3)+E/P*T(j,5)+(1-((W/P)+(E/P)))*T(j,4)
    !
    ! NODE (5)EQUATION
    T(j+1,5)=W/P*T(j,4)+((1-(3*W/P)))*T(j,5)
    !
    ! THE RESULTS OF 40 SECONDS
    PRINT*, T(j+1,1),T(j+1,2),T(j+1,3),T(j+1,4),T(j+1,5)
    !
    END DO
    !
    END PROGRAM FIRST

    !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    SUBROUTINE ONE(E,P,W)
    ! K : IS THE THERMAL CONDACTIVITY (W/m/K)
    ! D : IS THE MATERIAL DINSITY TIMES THE SPECIFIC HEAT (J/m3/K)
    ! DELTAX: IS THE CONTROL VOLUME WIDTH (m)
    ! DELTAT: IS THE TIME STEP (SECONDS)
    REAL :: K, D, DELTAX, DEALTAT
    REAL :: E,P,W
    !
    K=10.00
    D=10.00E6
    DELTAX=0.004
    DELTAT=(D*DELTAX**2)/(2*K)
    !
    !THE TIME STEP FOR THE EXPLICIT METHOD IS SUBJECT TO THE CONDITION : DELTAT < D*DELTAX**2/2**K
    !
    PRINT*, 'THE TIME STEP SHOULD BE LESS THAN ',DELTAT, 'SEC'
    PRINT*, ' '
    PRINT*, 'LET THE TIME STEP '
    READ*, DELTAT
    E=K/DELTAX
    P=(D*DELTAX)/DELTAT
    W=E
    END SUBROUTINE ONE
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Fortran90 help
  1. Help me in fortran90 (Replies: 7)

  2. Fortran90 help (Replies: 5)

Loading...