Re: Challenge: reading ascii data
- From: "robin" <robin_v@xxxxxxxxxxx>
- Date: Fri, 09 Nov 2007 13:20:18 GMT
"David Frank" <dave_frank@xxxxxxxxxxx> wrote in message news:13j63uvh1odv138@xxxxxxxxxxxxxxxxxxxxx
"David Frank" <dave_frank@xxxxxxxxxxx> wrote in message
news:13j5uvlp26i9i79@xxxxxxxxxxxxxxxxxxxxx
I have a Fortran solution to this problem and challenge the
AWK/RUBY/PLI/ETC advocates to post their solutions that
can process the U,V records below -> internal arrays and then output UV
product records in format requested by
original (homework?) assignment.
Exception: no UV record is to be output unless both U,V, 3d indexed
records exist as positive non-zero weather
data..
I will post my Fortran code once someone posts a non-Fortran solution that
matches the UV output format shown.
As I dont really expect my challenge to be met, here is my solution using a
type variable to simplify things.
! -----------------------
program demo ! input array processing
implicit none
integer :: i, i1,i2,i3, n,ntimes
real :: u, v
character(80) :: dat
type time_uv
integer :: time
real :: u(3,3,3), v(3,3,3)
end type
type (time_uv),allocatable :: tuv(:)
open (11,file='demo.in')
ntimes = 0
do ! count time frames
read (11,'(a)',end=101) dat
if (dat(1:4) == 'time') ntimes = ntimes+1
end do
101 rewind (11)
allocate ( tuv(ntimes) )
do n = 1,ntimes
tuv(n)%u = 0 ; tuv(n)%v = 0 ! positive non-zero inputs expected
do
read (11,'(a)') dat
i = index(dat,':')
if (i > 0) exit ! assume time: xxxx minutes record
end do
read (dat(6:),*) tuv(n)%time ! get time
do
read (11,'(a)',end=102) dat
if (dat(1:4) == 'time') then
backspace(11) ; exit ! go back and process time record
end if
i = index(dat,'(') ; if (i == 0) cycle
read (dat(i+1:),*) i1,i2,i3
i = index(dat,'=')
if (dat(1:1) == 'U') then
read (dat(i+2:),*) tuv(n)%u(i1,i2,i3)
else if (dat(1:1) == 'V') then
read (dat(i+2:),*) tuv(n)%v(i1,i2,i3)
end if
end do
end do ! 1:ntimes
102 close (11)
open (22,file='demo.out')
do n = 1,ntimes ! output time frames time,u,v,uv from arrays
write (22,90) 'time: ',tuv(n)%time,' minutes'
do 1 i1 = 1,3
do 1 i2 = 1,3
do 1 i3 = 1,3
u = tuv(n)%u(i1,i2,i3)
if (u == 0) cycle ! U value not avail
write (22,91) 'U(',i1,i2,i3, u
1 end do
do 2 i1 = 1,3
do 2 i2 = 1,3
do 2 i3 = 1,3
v = tuv(n)%v(i1,i2,i3)
if (v == 0) cycle ! V value not avail
write (22,91) 'V(',i1,i2,i3, v
2 end do
do 3 i1 = 1,3
do 3 i2 = 1,3
do 3 i3 = 1,3
u = tuv(n)%u(i1,i2,i3) ; v = tuv(n)%v(i1,i2,i3)
if (u*v > 0) write (22,92) 'UV(',i1,i2,i3, u*v
3 end do
write (22,*) ! blank record between time frames
end do
90 format (a,i0.2,a)
91 format (a,2(i0,','),i0,') = ',f0.2)
92 format (a,2(i0,','),i0,') = ',f0.3)
end program
Above program outputs:
In spite of all the hype, this program just does not work.
It gets stuck in an infinite loop.
.
- References:
- Challenge: reading ascii data
- From: David Frank
- Re: Challenge: reading ascii data
- From: David Frank
- Challenge: reading ascii data
- Prev by Date: Re: Challenge: reading ascii data
- Next by Date: Re: fortran code reading ascii file.
- Previous by thread: Re: Challenge: reading ascii data
- Next by thread: Re: Challenge: reading ascii data
- Index(es):
Relevant Pages
|
Loading