Re: Challenge: reading ascii data



"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.


.



Relevant Pages

  • Re: Challenge: reading ascii data
    ... can process the U,V records below -> internal arrays and then output UV product records in format requested by ... I will post my Fortran code once someone posts a non-Fortran solution that matches the UV output format shown. ... character:: dat ... output time frames time,u,v,uv from arrays ...
    (comp.lang.fortran)
  • Re: Challenge: reading ascii data
    ... can process the U,V records below -> internal arrays and then output UV ... matches the UV output format shown. ... character:: dat ... output time frames time,u,v,uv from arrays ...
    (comp.lang.fortran)
  • Re: [PATCH] cpumask 5/10 rewrite cpumask.h - single bitmap based implementation
    ... >> likewise for whatever else is copying unsigned long arrays to userspace. ... The kernel bitmaps/cpumasks are arrays ... > I presume that it is too late to change the low level format of masks ... since it seems the perfctr stuff Mikael Pettersson ...
    (Linux-Kernel)
  • Re: Why DAT failed (was: CD Quality)
    ... It turned out to be a popular professional format, ... I got a great story on DAT's failure from a high-ranking Sony exec, ... or so (when DAT started to ship), they realized to their horror that, because ... first machines to sell for maybe $500 or so, but the U.S. dollar plunged so ...
    (rec.audio.pro)
  • Re: Hi-Def football
    ... DAT was a special case. ... It was the first decent consumer format ... from standard DVDs, but it all means buying new equipment less than 10 ... hard drives are big enough to buy cheap ...
    (uk.media.tv.misc)

Loading