Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > bivariate interpolation

Reply
Thread Tools

bivariate interpolation

 
 
Charles Banas
Guest
Posts: n/a
 
      11-04-2003
CBFalconer <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Charles Banas wrote:
> >
> > I'm not sure if this is the right place to ask about this, but
> > I've seen several posts in the past regarding Akima's Bivariate
> > Interpolations routines, and i'm wondering if someone can give
> > me some ideas or PD code I can put to use right away.
> >

> ... snip ...
> >
> > Unfortunately, due to the nature of the code, I've been forced
> > to rewrite the code form its original Fortran V to much cleaner
> > C. (Actually, I've been using ISO C++, but that's beside the
> > point.) My problem is this: Akima's routine is extremely
> > cryptic and uncommented, impossible to compile with the tools I
> > have available (mostly stemming from the complexity of the
> > EQUIVALENCE statements he used), and so, is very hard to
> > rewrite into C.
> >

> ... snip ...
> >
> > I'd appreciate anything anyone has to say.

>
> This is neither fish nor fowl. It is not as far off-topic as it
> first appears, because the fundamental question is how to
> translate bad Fortran into C. Is is not really an algorithmic
> question, which would belong on comp.programming.
>

I'm *really* glad you think so. That was my biggest concern about
posting.

> Given that you are translating shaky concepts I think you should
> use a language with very strong typing, either Pascal or Ada.
> Don't worry about efficiency, just get the algorithms right.


Which is why I posted here. I'm using ISO C++ because of two main
facts: 1. it's rather strongly typed, and 2. I'm familiar/comfortable
with it.
 
Reply With Quote
 
 
 
 
Charles Banas
Guest
Posts: n/a
 
      11-04-2003
"Julian V. Noble" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Charles Banas wrote:
> >

<snip my own drivel>
>
> Let me take a swing at this for you. First of all, Fortran stores
> 2-dimensional arrays by columns, not by rows. This is a frequent
> problem when trying to call a compiled Fortran routine from C or
> other language that stores row-wise.
>

You just pinpointed my main point of confusion. I know this, yet I
have a good deal of trouble understanding.

> The point of EQUIVALENCE in Fortran was to tell the compiler to
> put two arrays (or chunks of arrays) in the same memory locations:
> thus you might have
>
> REAL MAT(10,10)
> REAL A(100)
> EQUIVALENCE M(1,1), A(1)
>

Ready for a scare? Akima's EQUIVALENCE statements are 13 cards long.
Like this:

DIMENSION ZA(5,2), ....
EQUIVALENCE ( Z3A1, ZA(1) ), ( Z3A2, ZA(2) ), ( Z3A3, ZA(3) ),
& ( Z3A4, ZA(4) ), ( Z3A5, ZA(5) ), ( Z4A1, ZA(6) ),
etc.

EQUIVALENCES like this are confounding to me.

> Old Fortran did not have dynamically dimensioned arrays. That is,
> you could not tell it how much space to allocate at run time. I
> think more modern versions let you do it.
>
>
> Finally, as far as I know, bivariate interpolation is no harder than
> univariate interpolation (at least in concept). Let's say you have
> a table of 121 points, 11 in the x-direction and 11 in the y-direction.
>

<snip useful information>

You wouldn't know that by looking at Akima's code. It's literally 20
pages of quite confusing algorithmic code. I haven't had time to
analyze it.

> It is possible to use higher-order interpolation schemes--see Abramowitz
> & Stegun (available as a Dover PB --you should own it, it's very useful).
>

Could you point me to a location I can acquire it? It does sound as
if it would be useful for other projects as well.

> I never heard of Akima or his bivariate interpolation. But it must be some-
> thing like the above.
>

I haven't been able to find much information, but it appears that
Akima used a triangle-based algorithm for the interpolation. It
doesn't look one bit like any interpolation I've seen or done before.

> Have a look at the lecture notes available at the site
>
> http://www.phys.virginia.edu/classes/551.jvn.fall01/
>
> if you need further interpolation ideas.
>

I will file this away for future reference. Thank you for the info.

>
> --
> Julian V. Noble
> Professor Emeritus of Physics
> http://www.velocityreviews.com/forums/(E-Mail Removed)
> ^^^^^^^^^^^^^^^^^^
> http://galileo.phys.virginia.edu/~jvn/
>
> "Science knows only one commandment: contribute to science."
> -- Bertolt Brecht, "Galileo".


-- Charles Banas
 
Reply With Quote
 
 
 
 
Charles Banas
Guest
Posts: n/a
 
      11-04-2003
"Malcolm" <(E-Mail Removed)> wrote in message news:<bo6lk4$312$(E-Mail Removed)>...
> "Charles Banas" <(E-Mail Removed)> wrote in message
> >
> > I'm not sure if this is the right place to ask about this

> Try comp.programming, however your post does take a C language turn.


That's why I'm here and not at c.p.

> >
> > Akima's routine is extremely cryptic and uncommented, impossible to
> > compile with the tools I have available (mostly stemming from the
> > complexity of the EQUIVALENCE statements he
> > used), and so, is very hard to rewrite into C.
> >

> I don't know much Fortran. One problem you may have is that in C 2d arrays
> are of fixed dimensions. This can be fixed by using malloc and accessing by
> array[y * width + x];
>

Sorry, I'm having a little trouble following this. I'm not quite sure
what you mean.

> Another problem is that C is call by value. This can be fixed by liberal use
> of pointers, though it will make the code very hard to read.
>

Which is one of the reasons for my rewrite. I'd rather /not/ have to
muck things up with references and pointers. I have a hard enough
time following the thread about casting malloc() calls. (Fun
read, BTW. Almost a flame war, but not quite.

> The thing to do is to use these techniques to write Fortran-like C. It will
> be horrible but it should compile (BTW did you test the routine spat out by
> your Fortran-to-C converter?).
> Then rewrite it as more idiomatic C, keeping a working version for test
> purposes.


I will try the f2c routine as I progress and use it for referencial
behavior. It's just butt-ugly.

As I mentioned, I have been doing this in ISO C++, mostly for the type
checking. But after reading the malloc() casting arguments, what
c.l.c considers "Idomatic C" honestly scares me. Such Holy Wars over
casting. Wow.

However, there is one thing I think I should have mentioned. I'm
considering using sed script to remove all the EQUIVALENCEs. I
wonder, is that safe to do, or am I playing with fire now (since my
sed knowledge is limited)?

-- Charles Banas
 
Reply With Quote
 
Alan Balmer
Guest
Posts: n/a
 
      11-04-2003
On 4 Nov 2003 13:27:38 -0800, (E-Mail Removed) (Charles
Banas) wrote:

>Which is why I posted here. I'm using ISO C++ because of two main
>facts: 1. it's rather strongly typed, and 2. I'm familiar/comfortable
>with it.


After seeing this several times, I went back to your original post,
and found: "(Actually, I've been using ISO C++, but that's beside the
point.)"

Perhaps you should consider that it might *not* be beside the point. C
and C++ are different languages, and their practitioners often have
different approaches to problems. In any case, it wouldn't hurt to
discuss this in comp.lang.c++.

I'm peculiar in that I rather enjoy deciphering and cleaning up other
people's code, and I have some pretty good tools for doing it, so if I
had your problem, I'd probably take a shot at making the f2c output
palatable.

--
Al Balmer
Balmer Consulting
(E-Mail Removed)
 
Reply With Quote
 
Charles Banas
Guest
Posts: n/a
 
      11-05-2003
Alan Balmer <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
> On 4 Nov 2003 13:27:38 -0800, (E-Mail Removed) (Charles
> Banas) wrote:
>
> >Which is why I posted here. I'm using ISO C++ because of two main
> >facts: 1. it's rather strongly typed, and 2. I'm familiar/comfortable
> >with it.

>
> After seeing this several times, I went back to your original post,
> and found: "(Actually, I've been using ISO C++, but that's beside the
> point.)"
>
> Perhaps you should consider that it might *not* be beside the point. C
> and C++ are different languages, and their practitioners often have
> different approaches to problems. In any case, it wouldn't hurt to
> discuss this in comp.lang.c++.
>

I posted here because I felt a C discussion would be more relevant
than one in C++. In any case, you may be right.

> I'm peculiar in that I rather enjoy deciphering and cleaning up other
> people's code, and I have some pretty good tools for doing it, so if I
> had your problem, I'd probably take a shot at making the f2c output
> palatable.


Which is something I just may do. I'm sure you're well aware of how
ugly f2c's output is, though.

Thank you.

-- Charles Banas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linear interpolation in vhdl df84077@gmail.com VHDL 8 10-07-2011 08:38 AM
2D - bivariate random number generatin John Java 10 06-15-2006 10:22 AM
How to stop interpolation of Escape character in variable? \Rob\ ASP .Net 8 02-24-2006 08:52 AM
Opening files with interpolation Mat W Perl 3 05-21-2004 08:40 AM
Your votes please ( drawImage bad interpolation bug id 4950176) Michele Puccini Java 0 11-09-2003 11:06 AM



Advertisments