I'm currently facing an apparently silly problem with Matlab but I just can't figure out what is wrong (or better yet, I think it is wrong, but I'm being told it should work).
I have a Matlab script, "myscript.m" which needs to use a C-programmed function, "myfunc.c" which in turn has been compiled (or "lives") inside a library, "mylib.dll". In order for "myscript.m" to access and execute "myfunc.c" there is also a "myfunc.m" Matlab script, which is being called in "myscript.m". However, "myfunc.m" is a completely empty file, except for some comments (in no particular format or pattern either). All of these files were given to me and I'm being told that as it is, Matlab should correctly execute "myfunc.c" because "myfunc.m" is acting as a wrapper.
The problem I'm having is that it is of course not working. When I execute the line in "myscript.m" that reads:
output1 = myfunc(input1, input2);
I get Matlab errors saying that I'm trying to execute a script as a function. In my mind, this is correct, because I'm sending input and requesting outputs to something that is stated to have neither, since "myfunc.m" is empty (except for the comments, which are NOT code).
I think that Matlab has no way (as it is) to know that I want to access the C code inside "mylib.dll". I also DO NOT have a header file "mylib.h" so that I can load the library in Matlab using loadlibrary.
My question is, given the current description, could this execution work at all? Is there any way to make it work, or something that I'm missing? One possibility is that this is an old wrapper format and it currently doesn't work anymore.
If anyone knows anything or has suggestions, they will be greatly appreciated. Thanks!!!
Hugo
it sounds like myfunc.c is a mex file. try compiling it in Matlab using mex command. The dll extension is maybe old version matlab.
Have you tried with loadlibrary? You need a .h file but it's easy recreate on if you know the prototype of the function.
Related
I am trying to call a do file which has loops from a program in other do file. I am getting an error.
Now, if I use do instead of include, it runs fine but I don't get to use local macros created. I used include so I can use the macros further in the program. I don't want to use global.
First do file (test.do).
forval i = 1/5 {
local val`i' = `i'
}
Second do file(call-test.do)
capture program drop test
program test
include "test.do"
di `val1'
end
test
I got error r(9611);
I using version 16.1
Response from Stata support
The -include- is designed to let you share definitions. It will not
work correctly within a program as documented in -help include-
The short answer is that -include- is usually ok to use in programs,
but not with looping commands, and if you use -include- in a program,
it probably isn't working the way you think it is.
Here's the long version of exactly what is going on:
When you use -include- in a program, your program literally includes
the -include- command in it. The program does NOT have the contents
of the include file substituted in place. That's the start of the
problem for looping commands.
In any case, when a program executes the -include- command, Stata gets
confused about whether to define a loop program on the behalf of a
looping command globally or within the program, and things go downhill
from there. Given how the code is structured, it is unlikely we could
fix -include- to behave differently, so our documentation really
should simply recommend against using -include- in programs. In
addition, at the point at which the failure occurs, Stata simply knows
that it cannot call a program that it thinks should already be in
memory, hence the 9611 return code. It has no idea at that point that
this was because it was called with -include-, unfortunately.
We could in the future introduce a true C-like "#include" for use in
programs which would simply substitute in-line the lines from whatever
was included into your program
I want to start a program using a batch-file. When I start the program manually (just double-clicking the exe-file) I have to select two file paths manually. I want to make a bat-script which starts the program and passes these two paths as arguments, so that the paths are already set when the program starts. The problem is that I don't know what the program will accept as arguments, or what order the of the arguments should be.
Is there any way of figuring out which arguments an exe-file can take?
If the exe doesn't provide a help output using ? or h as parameter and there is no doc, there is no easy way. Depending on the language the program is written in and whether you are allowed to decompile it or not, you might use tools like Reflector to decompile it and check which arguments are possible. This might help you: How do I decompile a .NET EXE into readable C# source code?
However, most software licenses prohibit decompiling even if they can't prevent it.
I'm a newbie to kernel programming, and I'm stuck on something, so I'd appreciate some help. I appologize in advance if something similar was asked before, I did not find any relevant post, and could find explanations on the web which were simple enough for someone unexperienced as myself in this field to understand.
I want to experiment with my own version of ext2.
I've got the source files from kernel.org, and made the proper changes. Nothing fancy, just to check something I had in mind.
Now I want to insert it to my linux kernel (ubuntu 2.6.31-14-generic-pae if it matters).
How can I do this?
My (obviously naive) initial thought was to simply use the makefile that comes along with it (after manually setting various flags there so it has obj-m/obj-y where needed) and compile it as a kernel module.
However I keep getting errors during compile time about redifining macros, implicit declarations of functions etc. For example
ext2.h:181:1: warning: "ext2_find_first_zero_bit" redefined
balloc.c:574: error: implicit declaration of function dquot_free_block_nodirty
Obviously this is not the way to go. I guess worst case scenario is compiling the entire kernel again (with my modified ext2 code instead of the original) so it creates the relevant library with my own ext2, and rebooting from the new image. I find it hard to believe this is the best approach.
Is it even possible for a new file system to be inserted as a kernel module?
Myabe I should put my modified ext2 code in /usr/src and somehow compile only the relevant library which contains the current ext2 code?
Anyway, I'd appreciate any help on what should I be doing.
Thank you
Do a search and replace of ext2 with my_awesome_filesystem or some such.
I am looking for an easy way to print out a specific function from within some C/C++ source code. For example, assume that test.c has several functions defined within it. I want to be able to print out the source code associated with only one of those functions.
Edit: Sorry, I should be a bit more clear about my end goal. I want the function printed to the screen so I can use wc to grab the word count of this specific function. Also, I want this be part of a command line tool-chain so it isn't an option to manually enter files and select the text.
You can run your project through doxygen. It will index all your functions (and classes, structs etc) and can make them available in multiple formats (including PDF and HTML, both easily printable).
What is your end goal with printing out a function?
Do you want to use this as such:
if (error == Foo())
{
PrintFunction(foo);
exit(1);
}
There are easier ways to output where errors are. I could maybe help more if I had a better idea of the problem you are trying to solve with this.
For a idea of how to implement such a PrintFunction():
Have a data struct that wraps around a function and contains: function line start, function line end, and maybe a pointer to the function.
Write a function that prints out a line base on number of the
source file. __FILE__ gives you the source file name.
With knowing the start and end of where the function lies in the
code, printing the function would be trivial.
This has an annoying pitfall of needing to update the line numbers of where your function lies in the file. But this could maybe be solved with a macro.
I generally use the print-region (or preferably print-region-with-faces) from within emacs. However, it is not automated, I have to select the region by hand.
Works in other languages as well.
The following due to Tom Smith in the comments:
(defun print-fn (interactive)
(save-excursion (mark-defun)
(print-region)))
If you liked this, follow the link to Tom's user-page and see if he deserves your vote...
Making this CW, so I won't benefit from people voting up Tom's good thinking. Cheers.
Edit after clarification: This doesn't seem to be pointed at the OP's actual question. Alas.
I wrote an algorithm in c that takes input of double precision numbers and returns a double. I would like to use this in libreoffice calc. I tried making a macro function using shell but it only gives back 0. How do I write the macro so it gives back the number that the c program returns. Also how do I make it so I can input the three numbers from a cell into the c program?
Thank you.
Using a shell interface does not seem workable here, because as you mentioned, it will just return 0 for success. Instead, I can think of two ways to do this.
The first is to create a Calc add-in. You can specify the number of arguments (3 in your case) in the IDL file. This would mean that there is no need for any OpenOffice Basic code -- everything can be done in C++. It is a rather clean solution. There are quite a few configuration files needed though, and it may initially be more difficult than what is described below.
The second is to dynamically load the DLL and call the function. I have had success using PyUNO with the ctypes library, but it can be done in OpenOffice Basic as well.
See also:
https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=45675
http://sheepdogguides.com/fdb/opof6dll.htm