comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: chi^2 minimisations & calling c
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: chi^2 minimisations & calling c [message #36676] Thu, 16 October 2003 10:50
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
danb@star.herts.ac.uk (Dan B) writes:


>> You must have spilled it wrong! :-)
>>
>
> Indied. Had to scroll down the page, doh.
>
> I am now having real trouble trying to get mpfit to work with spawn in
> the function_name though. When I ddread the model data points back I
> get told:
>
> % CLOSE: Variable is undefined: LUN.
> % Error occurred at: DDREAD 302

Please, take MPFIT out of the situation. First, get your model to
work by calling it alone, without MPFIT. When you are confident that
it works (repeatedly), then try to combine it with the fitter.
*Think* about why LUN could be undefined within DDREAD. Do you really
think it's a problem with the fitting? Probably not. It sounds more
like an I/O problem, so you need to solve that first.


>> function bla
>>
>> spawn program with a b c d e f
>>
>> x =ddread(modeldatapoints)
>> y =ddread(truedatapoints)
>>
>> end

Obviously this can't be correct since MODELDATAPOINTS and
TRUEDATAPOINTS do not exist as variables.

>> pro blabla
>>
>> p =[a,b,c,d,e,f]
>>
>> fit = mpfit(x, y, p, FUNCTION_NAME=bla)

MPFIT does not have a FUNCTION_NAME keyword.

Good luck,
Craig
Re: chi^2 minimisations & calling c [message #36677 is a reply to message #36676] Thu, 16 October 2003 10:41 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Dan B wrote:
>
>> You must have spilled it wrong! :-)
>>
>
> Indied. Had to scroll down the page, doh.
>
> I am now having real trouble trying to get mpfit to work with spawn in
> the function_name though. When I ddread the model data points back I
> get told:
>
> % CLOSE: Variable is undefined: LUN.
> % Error occurred at: DDREAD 302
>
> which I find a little confusing.

You get this error in DDREAD when the file you are trying to read does not exist. Maybe
you spilled the filename variable incorrectly, too?

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Ph: (301)763-8000 x7748
Fax:(301)763-8545
Re: chi^2 minimisations & calling c [message #36679 is a reply to message #36677] Thu, 16 October 2003 10:15 Go to previous message
danb is currently offline  danb
Messages: 4
Registered: October 2003
Junior Member
> You must have spilled it wrong! :-)
>

Indied. Had to scroll down the page, doh.

I am now having real trouble trying to get mpfit to work with spawn in
the function_name though. When I ddread the model data points back I
get told:

% CLOSE: Variable is undefined: LUN.
% Error occurred at: DDREAD 302

which I find a little confusing.

The general routine goes like:

> function bla
>
> spawn program with a b c d e f
>
> x =ddread(modeldatapoints)
> y =ddread(truedatapoints)
>
> end
>
> pro blabla
>
> p =[a,b,c,d,e,f]
>
> fit = mpfit(x, y, p, FUNCTION_NAME=bla)
>
> end

I suspect there is a really obvious reason why this kind of thing will
never work. : (
Re: chi^2 minimisations & calling c [message #36685 is a reply to message #36679] Thu, 16 October 2003 07:44 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Dan B writes:

> i do like the way that there is no mention of "spawn" in the help
> files, but it runs it quite happily.

You must have spilled it wrong! :-)

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: chi^2 minimisations & calling c [message #36686 is a reply to message #36685] Thu, 16 October 2003 07:16 Go to previous message
danb is currently offline  danb
Messages: 4
Registered: October 2003
Junior Member
Rick, you are a genius : )

That works a treat! Just what I needed, thanks.

i do like the way that there is no mention of "spawn" in the help
files, but it runs it quite happily.
Re: chi^2 minimisations & calling c [message #36689 is a reply to message #36686] Wed, 15 October 2003 10:52 Go to previous message
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
"Dan B" wrote ...

> If I was running the c program from the command line I would pass the
> parameters to it there e.g.
>
>> ./program x y z a b c
>>
>
> forgive my ignorance but is this an example of argc-argv calling
> convention?


It appears you have an executable that may or may not call a shared library?
If you do have a shared object file (.so, .dll) , is there a specific reason
you want to directly call it's functions? Or are you possibly confusing
CALL_EXTERNAL which calls functions in external libraries with SPAWN which
executes external programs?


Since you have a command line executable you might think about using SPAWN.
Something like:

x=0.
y=0.
z=0.
a=1
b=2
c='outfile.dat'

SPAWN, '/path/to/program ' + STRTRIM(x,2) + ' ' + STRTRIM(y,2) +
STRTRIM(z,2) + ' ' + STRTRIM(a,2) + ' ' + STRTRIM(b,2) + c


-Rick
Re: chi^2 minimisations & calling c [message #36691 is a reply to message #36689] Wed, 15 October 2003 04:09 Go to previous message
Richard French is currently offline  Richard French
Messages: 173
Registered: December 2000
Senior Member
>
> Just for the record (if any of you need a quick bit of cash :D )
> www.amazon.com/exec/obidos/tg/stores/offering/list/-/0967127 025/all/ref=dp_bb_
> a/102-6427530-6849768

That is amazing: $193.99 as the price for a used copy of a book that is
still in print and available for $30! I've sent an inquiry to the seller to
see if they can account for the high price, and if they can justify the 'Low
Price' designation on the Amazon web-page for this offering. Caveat emptor!

Dick French
Re: chi^2 minimisations & calling c [message #36692 is a reply to message #36691] Wed, 15 October 2003 02:52 Go to previous message
danb is currently offline  danb
Messages: 4
Registered: October 2003
Junior Member
Thanks for the comments guys. I will be using an already written chi^2
code like cti_test or linfit, whichever is more appropriate.

If I was running the c program from the command line I would pass the
parameters to it there e.g.

> ./program x y z a b c
>

forgive my ignorance but is this an example of argc-argv calling
convention?

Just for the record (if any of you need a quick bit of cash :D )
www.amazon.com/exec/obidos/tg/stores/offering/list/-/0967127 025/all/ref=dp_bb_a/102-6427530-6849768
Re: chi^2 minimisations & calling c [message #36697 is a reply to message #36692] Tue, 14 October 2003 14:46 Go to previous message
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
"Rick Towler" wrote...
>
> As much as I think that every serious IDL programmer (all 7 of us) should
> master the dlm, I don't think you would need to go thru the trouble unless
> you view this as a fun exercise. CALL_EXTERNAL should work with minimal
> effort but it does assume that your functions use the argc-argv calling
> convention and this might be where you are getting hung up.

A kind person from RSI informed me that the AUTO_GLUE keyword can work
wonders if your function doesn't follow the argc-argv calling convention.
Given the function prototype of your chi^2 routine it should be easy to use
CALL_EXTERNAL with the AUTO_GLUE keyword.

AUTO_GLUE relies on MAKE_DLL so you'll need to make sure your !MAKE_DLL
system variable is set up correctly.

-Rick
Re: chi^2 minimisations & calling c [message #36700 is a reply to message #36697] Tue, 14 October 2003 10:21 Go to previous message
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
"Dan B" wrote...

> Before I go and get Ronn Klings book on calling c from IDL am
> I going to be able to code a chi^2 minimisation routine?

Yes. If you can code it, it will come.

> The c program is already written and needs 6 parameters passed
> to it. It then does its thing and outputs a formatted ascii
> file (the model based on the parameters :D ).

<snip>

> I'm pretty sure that this is going to be possible, and that Ronn's
> book is going to be of some help (p.s. I've seen copies going for $180
> on amazon :eek:) I just want to be sure.

Wow! $180! I'll sell you mine for $100, complete with margin notes and
latte stains. Or, you could go to his website and spend $40.
www.kilvarock.com

As much as I think that every serious IDL programmer (all 7 of us) should
master the dlm, I don't think you would need to go thru the trouble unless
you view this as a fun exercise. CALL_EXTERNAL should work with minimal
effort but it does assume that your functions use the argc-argv calling
convention and this might be where you are getting hung up.

> oh, and I don't suppose anyone is going to be cheeky enough to give me
> a helping head start? :D I've mucked around with call_external, but
> it all goes horribly wrong, as, quite frankly, I don't understand the
> help files.

If you need to go the dlm route because you can't or don't want to make your
function work with CALL_EXTERNAL all you really need to do is wrap your
function inside the dlm. I wish I could point you to a proper example in
the IDL distribution which would illustrate the passing of different data
types back and forth but RSI's effort in this area is really pitiful.
Ronn's book is the way to go.

Good luck!


-Rick
Re: chi^2 minimisations & calling c [message #36701 is a reply to message #36700] Tue, 14 October 2003 09:52 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
danb@star.herts.ac.uk (Dan B) writes:
> Hi peeps.
>
> Before I go and get Ronn Klings book on calling c from IDL am I going
> to be able
> to code a chi^2 minimisation routine?

We can't speak for your abilities to code a minimization routine.
It's certainly possible, and IDL doesn't forbid it.

Strange, but I find that I have zero sympathy for people using DLMs
and CALL_EXTERNAL. Especially in a case like this, where good chi^2
minimization routines exist in IDL already, why reinvent the wheel?
Debugging the internal interface to IDL will take a lot of time.

Craig

P.S. For example MPFIT,
http://cow.physics.wisc.edu/~craigm/idl/idl.html

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Problems with 3D-Plot
Next Topic: How to get actual widget size?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:36:55 PDT 2025

Total time taken to generate the page: 0.00673 seconds