- #1
big man
- 254
- 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 starCLOSE(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
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 starCLOSE(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: