Me4President
Technical User
Hi,
Sorry for the long post, but I thought as much info as possible would help...
I did 8 weeks of fortran77 at university last year, and was always terrible. But I have been trying to use it recently at work to automate a task, trying to format the contents of an ascii text file. I am doing it on a Red Hat Linux, using tutorials found online.
I have it working - but it is very ugly - and I am sure someone could help me improve the way I am doing it
First I use awk to select the numbers I need from an exported file. This is written to a file "awk_out"
Then I use fortran to read these 2 columns of data into the format I want.
I do get a (not-too-important) error at the end about reaching end of file, but it doesn't get written to the file I make,, so I dont mind it...
I use a korn shell script to create the input file for fortran, compile, write the formatted output to a file, and then clean up a bit.
What I really want is to be able to use an alias to run the fortran program from my terminal (in any directory I want to be in). Using an input file I specify, I want an output file in the format below - ideally also specifying what string to put at the start of each line...
Any help would be greatly appreciated!
Thanks
Fortran:
Is there some way I could use counting to do 6 pairs of numbers on each line, with POLGON at the beginning?
Also the only way I could think of getting the last line in the right format was to look after each possibility individually, but it just seems a horrible way of doing it...
Sorry for the long post, but I thought as much info as possible would help...
I did 8 weeks of fortran77 at university last year, and was always terrible. But I have been trying to use it recently at work to automate a task, trying to format the contents of an ascii text file. I am doing it on a Red Hat Linux, using tutorials found online.
I have it working - but it is very ugly - and I am sure someone could help me improve the way I am doing it
First I use awk to select the numbers I need from an exported file. This is written to a file "awk_out"
Then I use fortran to read these 2 columns of data into the format I want.
I do get a (not-too-important) error at the end about reaching end of file, but it doesn't get written to the file I make,, so I dont mind it...
Code:
list in: end of file
apparent state: unit 60 named awk_out
last format: list io
lately reading sequential formatted external IO
Abort
I use a korn shell script to create the input file for fortran, compile, write the formatted output to a file, and then clean up a bit.
Code:
#!/usr/bin/ksh
echo Enter name of input file
read input
awk 'END { print NR > "awk_out" }' /$input
awk '{printf "%.0f %.0f\n", $1, $2 >> "awk_out" }' /$input
echo Enter name of output file
read output
g77 poly.f
/glb/home/nltme9/prog/a.out > $output
rm -rf awk_out
rm -rf a.out
What I really want is to be able to use an alias to run the fortran program from my terminal (in any directory I want to be in). Using an input file I specify, I want an output file in the format below - ideally also specifying what string to put at the start of each line...
Code:
POLGON 3974 1693 3877 1658 3818 1641 2461 1632 2405 1687 2347 1721
Any help would be greatly appreciated!
Thanks
Fortran:
Code:
program poly
c
c This program reads a data file of polygon
c coordinates from 123di and converts them
c for use in SIPMAP.
c 9/09
c
implicit none
integer file, n, i, j, lines, nmax, rem
parameter (nmax=9999, file=60 )
integer x(nmax), y(nmax)
c Open the data file, previously made with awk
c First line contains number of lines
open (file, FILE='awk_out', STATUS='OLD')
c Read the number of points on first line
c calculate number of lines to be used
read(file,*) n
lines = n/6
rem = n - lines*6
c write(*,*) lines
c write(*,*) rem
c Do loop over the number of lines,
c writing out 6 numbers per line in format specified @100
c note continuation using & at position 6 of new line
do 60 i= 1, lines
read(file,*) x(i),y(i),x(i+1),y(i+1),x(i+2),y(i+2),x(i+3),y(i+3)
&,x(i+4),y(i+4),x(i+5),y(i+5)
write(*,100) x(i),y(i),x(i+1),y(i+1),x(i+2),y(i+2),x(i+3),y(i+3)
&,x(i+4),y(i+4),x(i+5),y(i+5)
60 continue
c Deal with the last line...
if (rem .eq. 1) then
do 10 j=1, rem
read(file,*) x(i),y(i)
write(*,100) x(i),y(i)
10 continue
elseif (rem .eq. 2) then
do 20 j=1, rem
read(file,*) x(i),y(i),x(i+j),y(i+j)
write(*,100) x(i),y(i),x(i+j),y(i+j)
20 continue
elseif (rem .eq. 3) then
do 30 j=1, rem
read(file,*) x(i),y(i),x(i+j),y(i+j),x(i+j),y(i+j)
write(*,100) x(i),y(i),x(i+j),y(i+j),x(i+j),y(i+j)
30 continue
elseif (rem .eq. 4) then
do 40 j=1, rem
read(file,*) x(i),y(i),x(i+j),y(i+j),x(i+j),y(i+j),x(i+j),y(i+j)
write(*,100) x(i),y(i),x(i+j),y(i+j),x(i+j),y(i+j),x(i+j),y(i+j)
40 continue
elseif (rem .eq. 5) then
do 50 j=1, rem
read(file,*) x(i),y(i),x(i+j),y(i+j),x(i+j),y(i+j),x(i+j),y(i+j)
write(*,100) x(i),y(i),x(i+j),y(i+j),x(i+j),y(i+j),x(i+j),y(i+j)
50 enddo
endif
c Format for writing lines
100 format ('POLGON', 6(I6, I6))
c Close the file
close (file)
9999 stop
end
Is there some way I could use counting to do 6 pairs of numbers on each line, with POLGON at the beginning?
Also the only way I could think of getting the last line in the right format was to look after each possibility individually, but it just seems a horrible way of doing it...