Hi, I'm new to this website, and also very new with FORTRAN and programming in general but I have an assignment I'm very confused about and having lots of problems with. If anyone smarter than me could help me out or give me some tips at where to go that would be greatly appreciated.
Heres basically what I have to do:
Your job is to take the list of any store's employee IDs (the data file will always be called
"empids.dat"), sort them in order from lowest to highest, and then put the newly sorted list of IDs in a
new file of the user's choice. This newly constructed file will now be compatible with the payroll system,
and will save the company a lot of man hours in these troubling times. Naturally this will justify a few
layoffs, but luckily for us there is not a company, at least to my knowledge, that would do anything
similar to this in real life.
Here is a step-by-step breakdown of what your program should do:
? OPEN up the file "empids.dat" and use READ statements along with a counter and
'ierror' to find out how many lines of data are in the file. After all, each store does have
a different number of employees in it.
? ALLOCATE an allocatable array so that it has a number of elements that is the same as
the number of lines in the input file.
? READ the values from the input file into the array.
? Sort the values from lowest to highest.
? Ask the user what s/he would like to call the output file.
? CLOSE the old file; OPEN the new one.
? WRITE the sorted values to the output file.
? CLOSE the new file, and let the user know that the values were stored to the file.
In a nutshell. This is what I've got so far, past this, I'm pretty lost:
WRITE(*,'(A)',ADVANCE="NO") "Enter the employee file name: "
READ(*,*) fname
OPEN (UNIT = 10, FILE = 'fname', STATUS = "OLD", ACTION = "READ", IOSTAT = ierror)
IF (ierror /= 0) STOP "Error opening file. Aborting."
i = 1
DO
READ(10,*,IOSTAT=ierror) nums(i)
IF (ierror /= 0) EXIT
i=i+1
END DO
ALLOCATE (list(i), STAT = ierror)
IF (ierror /= 0) STOP "Error allocating array."
Any tips would be greatly appreciated.
Heres basically what I have to do:
Your job is to take the list of any store's employee IDs (the data file will always be called
"empids.dat"), sort them in order from lowest to highest, and then put the newly sorted list of IDs in a
new file of the user's choice. This newly constructed file will now be compatible with the payroll system,
and will save the company a lot of man hours in these troubling times. Naturally this will justify a few
layoffs, but luckily for us there is not a company, at least to my knowledge, that would do anything
similar to this in real life.
Here is a step-by-step breakdown of what your program should do:
? OPEN up the file "empids.dat" and use READ statements along with a counter and
'ierror' to find out how many lines of data are in the file. After all, each store does have
a different number of employees in it.
? ALLOCATE an allocatable array so that it has a number of elements that is the same as
the number of lines in the input file.
? READ the values from the input file into the array.
? Sort the values from lowest to highest.
? Ask the user what s/he would like to call the output file.
? CLOSE the old file; OPEN the new one.
? WRITE the sorted values to the output file.
? CLOSE the new file, and let the user know that the values were stored to the file.
In a nutshell. This is what I've got so far, past this, I'm pretty lost:
WRITE(*,'(A)',ADVANCE="NO") "Enter the employee file name: "
READ(*,*) fname
OPEN (UNIT = 10, FILE = 'fname', STATUS = "OLD", ACTION = "READ", IOSTAT = ierror)
IF (ierror /= 0) STOP "Error opening file. Aborting."
i = 1
DO
READ(10,*,IOSTAT=ierror) nums(i)
IF (ierror /= 0) EXIT
i=i+1
END DO
ALLOCATE (list(i), STAT = ierror)
IF (ierror /= 0) STOP "Error allocating array."
Any tips would be greatly appreciated.