Showing newest posts with label c. Show older posts
Showing newest posts with label c. Show older posts

20091207

A subtle source of linker errors under XCode



If one source file is sourcecode.c.objc and another is sourcecode.cpp.objcpp, you will have problems if you try to call function defined in one file from the other. The resolve this either make them the same source type, or follow this guide.



This drove me nutty because the template I was working off has code set to sourcecode.cpp.objcpp, but XCode adds new classes as sourcecode.c.objc! To check the file type, use "Get Info" in the source file's context menu.



Cheers,

Steve

20080716

unoffical libfg repository

I have set up an unofficial git respository for libfg patches and new swig generated python interface, as Gavin Baker (the author) appears to be busy with other things. This is a maintance only repository as far as libfg goes - I don't plan on adding any more features (since all the ones I need are there already). I will however work to produce a more pythonic interface to libfg, as the swig generated interface is a straight port of C api into Python.



Currently the repository contains the following fixes and enhancements:



  • RGB565 and RGB555 patch by Adalbert Prokop

  • fg_new_compatible_frame patch by echoline

  • mmap fix by me

  • swig generated Python interface by me



If you have a patch against libfg, please post it at the libfg project's page first, and then to me if Gavin does not respond. I do not intend to take over development of libfg, and it is my hope Gavin will in the future make this obselete/redundant.




Cheers,

Steve

20070414

Writing fitting functions for lmfit

lmfit expects
fitting functions with prototypes in the form:




double
function_name(double, double *);





For example:




double
sin_fit(double t, double * p)


{


return p[0] + p[1] * sin ( 2 * M_PI * ( p[2] * t + p[3]));


}





Note that while "font:12px Courier, mono;">lm_minimize takes a
pointer to an array of parameters, it may not always pass
that pointer to the fitting function. Because of this
passing fixed parameters to the fitting function using the
3rd argument will yield incorrect results. For example, the
following code is wrong:




double
wrong_fit(double t, double *p)


{


return p[0]*p[0] + p[1];


}




....




double p[2];




p[0] = 1;


p[1] = magic_number;




...




lm_minimize(..., 1, p, ..., ..., ...., ...);




Here the fitting function "font:12px Courier, mono;">wrong_fit relies on a
fixed parameter "font:12px Courier, mono;">p[1] which it expects to
contain the value "font:12px Courier, mono;">magic_number. However it
will be passed such a "font:12px Courier, mono;">p that only "font:12px Courier, mono;">p[0] has a valid value
and p[1] is
undefined. This will lead to incorrect operation.




To work around this, you can use global variables, as
follows:




double magic =
magic_number;




...




double right_fit(double t, double * p)


{


return p[0]*p[0] + magic;


}




....




double p = 1;




...




lm_minimize(..., 1, &p, ..., ..., ..., ...);





Cheers,

Steve