This July 15th I'll have been doing this a year. I really hope I have something other than a better grasp of pointers to show for it!
That's cynical of me. I'm doing things now that a year ago I'd have considered to be black voodoo magic, like linking to libraries, playing sounds, downloading and compiling other people's programs, taking pictures with a webcam, and so on.
I'm 28 (oops, 29 now) and I want to be C literate by the time I'm 30. That's two (one) years to become competent at something I've been wanting to do nearly my whole life. No pressure.
Thursday, March 31, 2011
the GTK wagon
I pulled out my GTK book to see if it had any Cairo info but it really doesn't have much more than a brief 1 page mention of it.
The two chapters of that book that I got through were very enlightening, and I stopped because the rest of it seemed like just adding on specialty widgets to what I had already learned and that seemed like more gruntwork. Gruntwork isn't motivating.
Now that I have a goal I think I should get through the next chapter.
The biggest GTK mystery to me is passing data to callback functions. If I have a callback function to run whenever I press a button I have to pass the window handle, the button handle, and ONE pointer to misc data of my choosing. The general consensus is that I should be packing all of my variables into structures and then passing a pointer to the structure. This seems wrong in some way. I've spent time learning how to pass data to functions and now you're telling me that if I use GTK I have to wrap all of my variables in a structure? Maybe I'm missing something. This makes shoehorning a GTK interface into existing programs impossible because it would require an entire rewrite if your necessary functions.
Well, now that I think about it this might not be true.
Press button, THEN pack variables into structure, pass structure to callback, unpack variables and then pass to more interesting function?
-sigh-
Yea I think I need to get another chapter of this book under my belt before tackling anything else. Gotta walk before you can run, right?
The two chapters of that book that I got through were very enlightening, and I stopped because the rest of it seemed like just adding on specialty widgets to what I had already learned and that seemed like more gruntwork. Gruntwork isn't motivating.
Now that I have a goal I think I should get through the next chapter.
The biggest GTK mystery to me is passing data to callback functions. If I have a callback function to run whenever I press a button I have to pass the window handle, the button handle, and ONE pointer to misc data of my choosing. The general consensus is that I should be packing all of my variables into structures and then passing a pointer to the structure. This seems wrong in some way. I've spent time learning how to pass data to functions and now you're telling me that if I use GTK I have to wrap all of my variables in a structure? Maybe I'm missing something. This makes shoehorning a GTK interface into existing programs impossible because it would require an entire rewrite if your necessary functions.
Well, now that I think about it this might not be true.
Press button, THEN pack variables into structure, pass structure to callback, unpack variables and then pass to more interesting function?
-sigh-
Yea I think I need to get another chapter of this book under my belt before tackling anything else. Gotta walk before you can run, right?
Wednesday, March 30, 2011
Starting the Wumpus
I suppose I could make a Wumpus clone using GTK and Cairo.
Ok, project for this weekend (assuming I get to coding between my cousin's wedding and the usual weekend chores):
1) Initialize a Cairo window and put something there. A line, circle, box, anything.
2) Figure out how to load in an image and repeat that image (like tiles)
3) Create an array (2d if I'm feeling sassy) with values 0, 1, or 2 where each number means a different thing - lets say color of a box. Read the array and create a tile accordingly in the Cairo window.
4) See if I can get the dev/runtime dev stuff on OS X so I don't have to use the Ubuntu boot in VirtualBox.
Ok, project for this weekend (assuming I get to coding between my cousin's wedding and the usual weekend chores):
1) Initialize a Cairo window and put something there. A line, circle, box, anything.
2) Figure out how to load in an image and repeat that image (like tiles)
3) Create an array (2d if I'm feeling sassy) with values 0, 1, or 2 where each number means a different thing - lets say color of a box. Read the array and create a tile accordingly in the Cairo window.
4) See if I can get the dev/runtime dev stuff on OS X so I don't have to use the Ubuntu boot in VirtualBox.
Hunt the Wumpus
I don't remember the first time I was exposed to a computer. It was either when my dad brought home a 286 when I was four or five, or sometime earlier with my uncle's TI-99. If an original Atari 2600 counts then it was that. That thing is still somewhere in the attic....
The TI-99 was awe inducing. It didn't do much but boot into TI-BASIC and run programs off of cartridges. All the programs my uncle had were games. Some were in BASIC and some were on those cartridges. There was a racing game, some tanks game, Parsec, and Hunt the Wumpus.
http://www.stageselect.com/News/NewsViewer.aspx?newsid=593
Ah, the Wumpus. Bane of my existence whenever I went to my grandmother's house and was allowed to play.
I did some searching today and learned that Hunt the Wumpus started as a text based game. The version on the TI-99 had graphics. You just move from room to room trying to find clues about where the Wumpus had been while avoiding rooms that had pits or bats that would pick you up and put you in a random spot.
I'm at a crossroad right now. I've gotten as far as I really want to with my file reader program. I didn't get the experience allocating memory that I wanted, but that can wait until a rainy afternoon. It's a matter of feeling up to rewriting the program again. My latest quick and dirty project for work was a furious few hours of coding with a mixture of my own code and the work programmer's example code that ended with success and a knowledge of how to utilize libraries in the Windows SDK. I think what comes next should be a simple game, like Hunt the Wumpus. It could even be just text.
The TI-99 was awe inducing. It didn't do much but boot into TI-BASIC and run programs off of cartridges. All the programs my uncle had were games. Some were in BASIC and some were on those cartridges. There was a racing game, some tanks game, Parsec, and Hunt the Wumpus.
http://www.stageselect.com/News/NewsViewer.aspx?newsid=593
Ah, the Wumpus. Bane of my existence whenever I went to my grandmother's house and was allowed to play.
I did some searching today and learned that Hunt the Wumpus started as a text based game. The version on the TI-99 had graphics. You just move from room to room trying to find clues about where the Wumpus had been while avoiding rooms that had pits or bats that would pick you up and put you in a random spot.
I'm at a crossroad right now. I've gotten as far as I really want to with my file reader program. I didn't get the experience allocating memory that I wanted, but that can wait until a rainy afternoon. It's a matter of feeling up to rewriting the program again. My latest quick and dirty project for work was a furious few hours of coding with a mixture of my own code and the work programmer's example code that ended with success and a knowledge of how to utilize libraries in the Windows SDK. I think what comes next should be a simple game, like Hunt the Wumpus. It could even be just text.
success, sorta
The program for work functioned, but not better than the Matlab version. I'm certain that the function I used to play the sound is reloading the .wave every time. The other issue is that I'm trying to play a very short click and I had to make the .wav file at least a few hundred microseconds long for anything to come out of the speakers.
So the win here is that my new programming knowledge (specifically reading API docs better and linking to libraries) came in handy.
So the win here is that my new programming knowledge (specifically reading API docs better and linking to libraries) came in handy.
Tuesday, March 29, 2011
Sound 2
I've looked into SDL and CSound (thanks, Matt) but I think I'll just DL the Windows SDK and try to use the PlaySound() function. I need a .lib file that doesn't come with Windows.
I'm genuinely surprised that playing sound is this hard. Yes, I know it's tough to manage bit depth, voltage range, sampling rate, etc, but I'd have figured there would be "one way" to just get a sound out with minimal difficulty. Maybe Linux/OSX is simpler, but I need to stay in Windows-land for this project.
EDIT: I have had some success.
PlaySound("C:\\Program Files (x86)\\Steam\\resource\\warning.wav", NULL, SND_FILENAME);
I had to download the Windows SDK to link the file WinMM.lib (which must have the PlaySound implementation in it).
Ok, good. Now what? I have no idea if this will be fast enough to do what I need it to do. I'll have to generate a very tiny impulse - like a square wave 100 uS wide. Ok. Crap, I hate making such progress this late at night. It's past 10PM already and I'm trying to go to bed at a reasonable time so that I can get up early and go for a run. Healthy body healthy mind, right?
EDIT 2: I will write up a quick how-to on this topic. It's like three lines of code but NOBODY ON THE FREAKING INTERNET has written how to do what I just did succinctly and accurately.
I'm genuinely surprised that playing sound is this hard. Yes, I know it's tough to manage bit depth, voltage range, sampling rate, etc, but I'd have figured there would be "one way" to just get a sound out with minimal difficulty. Maybe Linux/OSX is simpler, but I need to stay in Windows-land for this project.
EDIT: I have had some success.
PlaySound("C:\\Program Files (x86)\\Steam\\resource\\warning.wav", NULL, SND_FILENAME);
I had to download the Windows SDK to link the file WinMM.lib (which must have the PlaySound implementation in it).
Ok, good. Now what? I have no idea if this will be fast enough to do what I need it to do. I'll have to generate a very tiny impulse - like a square wave 100 uS wide. Ok. Crap, I hate making such progress this late at night. It's past 10PM already and I'm trying to go to bed at a reasonable time so that I can get up early and go for a run. Healthy body healthy mind, right?
EDIT 2: I will write up a quick how-to on this topic. It's like three lines of code but NOBODY ON THE FREAKING INTERNET has written how to do what I just did succinctly and accurately.
ideas
I keep getting good ideas for video games.
These days I don't play so much. It used to be a hobby I sank serious time into - not just playing but also learning the ins and outs of. Late high school and early 2000s I learned how to make maps for several games (Quake, Half-Life) but I don't do that anymore.
I bought a bunch of games last year that I never played (damn you Christmas Steam sales) and whenever I do play I feel like I'm chasing the feeling I used to get when I was younger. I played maybe 10 hours into Mass Effect 2 over the winter but haven't played again since December (it says when I last played, conveniently).
I played Star Wars: Galaxies to chase the feeling I had with Ultima Online. I played Bad Company 2 to chase the feeling I had with Desert Combat. I played Dragon Age: Origins to chase the feeling I had with Baldur's Gate. Team Fortress 2 to chase Team Fortress.
Oblivion, Fallout 3, and Portal were fantastic. I played those to play them - not to chase anything. I stopped playing Mass Effect 2 because it turned into a grind to play through all the companion NPCs special missions. I am very much looking forward to Portal 2.
Anyways, sometimes I get ideas for games that I'd play. I hope someday I can get to a point where I can actually make them. I'll throw down an idea I had a while back.
1) I really like the idea of asynchronous gameplay. You make your move and send it off and wait for your opponent to make his in response (Scrabble, Words With Friends, checkers, chess, etc). I'd like to apply that concept to a light strategy game - or rather a "real time strategy" that's not real time.
You have five units: two offensive, two defensive, and one "boss" unit that protects the flag (or whatever). So does your opponent. The field is something like a soccer field with the flag your offensive units need to capture in the goal area (or something like that). You can only (at first) see your units. All characters are autonomous and you have to define some basic behaviors.
You set the defensive (two defense and the boss) in positions and define behaviors like patrol pathways and aggressiveness, weapons, and whatnot. Your offensive units you give general directions to go and maybe sacrifice not having weapons for speed. The offensive units are going to "home into" the flag once they get to a certain distance (if they get there, anyways).
So, you and your opponents set units up and then when both are finished (which can be at different times) the system says "ok you're both done setting up so run the simulation" and the game plays out with the offensive units on both teams running across the field to get the flag and encountering the defenses set up. Maybe both teams get the flag, maybe not. The point is you see the results and then can adjust your setup (and save/recall setups) and keep playing. The action of the play can be seen in "real time" since each player will have a view of the whole field (maybe?) when the game is ready to be played and the total time of the play would probably be 15-20 seconds (?).
It would make a good browser or mobile game.
These days I don't play so much. It used to be a hobby I sank serious time into - not just playing but also learning the ins and outs of. Late high school and early 2000s I learned how to make maps for several games (Quake, Half-Life) but I don't do that anymore.
I bought a bunch of games last year that I never played (damn you Christmas Steam sales) and whenever I do play I feel like I'm chasing the feeling I used to get when I was younger. I played maybe 10 hours into Mass Effect 2 over the winter but haven't played again since December (it says when I last played, conveniently).
I played Star Wars: Galaxies to chase the feeling I had with Ultima Online. I played Bad Company 2 to chase the feeling I had with Desert Combat. I played Dragon Age: Origins to chase the feeling I had with Baldur's Gate. Team Fortress 2 to chase Team Fortress.
Oblivion, Fallout 3, and Portal were fantastic. I played those to play them - not to chase anything. I stopped playing Mass Effect 2 because it turned into a grind to play through all the companion NPCs special missions. I am very much looking forward to Portal 2.
Anyways, sometimes I get ideas for games that I'd play. I hope someday I can get to a point where I can actually make them. I'll throw down an idea I had a while back.
1) I really like the idea of asynchronous gameplay. You make your move and send it off and wait for your opponent to make his in response (Scrabble, Words With Friends, checkers, chess, etc). I'd like to apply that concept to a light strategy game - or rather a "real time strategy" that's not real time.
You have five units: two offensive, two defensive, and one "boss" unit that protects the flag (or whatever). So does your opponent. The field is something like a soccer field with the flag your offensive units need to capture in the goal area (or something like that). You can only (at first) see your units. All characters are autonomous and you have to define some basic behaviors.
You set the defensive (two defense and the boss) in positions and define behaviors like patrol pathways and aggressiveness, weapons, and whatnot. Your offensive units you give general directions to go and maybe sacrifice not having weapons for speed. The offensive units are going to "home into" the flag once they get to a certain distance (if they get there, anyways).
So, you and your opponents set units up and then when both are finished (which can be at different times) the system says "ok you're both done setting up so run the simulation" and the game plays out with the offensive units on both teams running across the field to get the flag and encountering the defenses set up. Maybe both teams get the flag, maybe not. The point is you see the results and then can adjust your setup (and save/recall setups) and keep playing. The action of the play can be seen in "real time" since each player will have a view of the whole field (maybe?) when the game is ready to be played and the total time of the play would probably be 15-20 seconds (?).
It would make a good browser or mobile game.
sound
I did something in Matlab that I really want to try in C. Basically it's just a "if condition is true play a click on the speaker". Matlab has a sound command that's reasonably fast and you just pass it an array to perform D/A on. x = [0 1 0] is good enough for a click sound. The default sampling rate is ~8 kHz or something but bumping it up to 30 kHz is fine and improves the accuracy.
I'll do some casual searching for a way to output sound in C. Maybe SDL? Allegro? Certainly some game programming library has something nice and easy.
EDIT: or maybe Windows has a native way of doing it?
I'll do some casual searching for a way to output sound in C. Maybe SDL? Allegro? Certainly some game programming library has something nice and easy.
EDIT: or maybe Windows has a native way of doing it?
Monday, March 28, 2011
wrong tree
Well... I got SOME into what I was trying to do:
http://imgur.com/5g351
See.. I have this function that GETS the data, and I wanted to pass that data to another function that does the actual plotting but as you know passing arrays out of a function is...... complicated. Not impossible - just prone to making me cross-eyed.
I decided to just embed the plotting functionality into the reader function. I'm glad I did because I ran into a limitation of the plotting library I'm using. See, the library is actually writing temp files and then calling GnuPlot to read those temp files. I'm having it read the data and plot it fast fast fast (no timing restrictions imposed) and I think it's choking. What you can't see in the screenshot is the waveforms coming in one after the other (each erasing the last - cool effect I guess) but you also can't see the console dumping a lot of "can't read temp file" messages that I think GnuPlot is saying. I THINK I know why this is, but I'm too tired to bump up the temp files allowed number.
I think I've satisfied my curiosity on this project.
http://imgur.com/5g351
See.. I have this function that GETS the data, and I wanted to pass that data to another function that does the actual plotting but as you know passing arrays out of a function is...... complicated. Not impossible - just prone to making me cross-eyed.
I decided to just embed the plotting functionality into the reader function. I'm glad I did because I ran into a limitation of the plotting library I'm using. See, the library is actually writing temp files and then calling GnuPlot to read those temp files. I'm having it read the data and plot it fast fast fast (no timing restrictions imposed) and I think it's choking. What you can't see in the screenshot is the waveforms coming in one after the other (each erasing the last - cool effect I guess) but you also can't see the console dumping a lot of "can't read temp file" messages that I think GnuPlot is saying. I THINK I know why this is, but I'm too tired to bump up the temp files allowed number.
I think I've satisfied my curiosity on this project.
this week
I didn't get as much done over the weekend as I had hoped. This is mostly because I had the last five episodes of The Wire to get through.
K&R and even the other resources I use were not forthcoming with malloc() info. They all had very simple examples.
Typing makes my dinky desk shake and it's shaking my coffee cup. I'm afraid some will spill.
I'd like to maintain storage of the data block for the data I want. It has lots of useful information (timestamps, unit assignments) but not the actual waveform data. I'm thinking of making a new structure to hold everything and then saving an array of those to allocated space.
K&R and even the other resources I use were not forthcoming with malloc() info. They all had very simple examples.
Typing makes my dinky desk shake and it's shaking my coffee cup. I'm afraid some will spill.
I'd like to maintain storage of the data block for the data I want. It has lots of useful information (timestamps, unit assignments) but not the actual waveform data. I'm thinking of making a new structure to hold everything and then saving an array of those to allocated space.
Sunday, March 27, 2011
goals for today
I was right about gnuplot_i.c. It wasn't looking in the right place for the gnuplot executable. The function in question claims that it works a lot like "which" but when I remove gnuplot from /usr/bin the "which" command finds it in /usr/local/bin, so I don't know.
Anyways, today I am going to work on dynamic memory allocation.
The file reading program right now just spits out samples to printf and doesn't store them. I'd like to find a way to dump the samples to somewhere in memory then give back the location of that memory.
What I need to figure out is this:
1) Should I pre-allocate memory in main() and then pass a pointer to that memory to my function? If so, I guess I have to create a new function that scans the file and figures out how much memory I'd need to allocate.
2) Lets say I do the allocation in my reader function and pass back a pointer to that memory location - the pointer is still valid after the function ends, right? If I allocate memory with malloc() and pass out a pointer to that memory I think it will be legit until I free() that memory... I'll have to test that.
3) How do I know what the end of the memory is? Do I need to keep track of how deep I am when reading into the data I stored, or is there a /0 to look out for? I feel like I should know that already.
I'll probably build up a test program to make sure I'm doing things sanely before diving into my real program.
Anyways, today I am going to work on dynamic memory allocation.
The file reading program right now just spits out samples to printf and doesn't store them. I'd like to find a way to dump the samples to somewhere in memory then give back the location of that memory.
What I need to figure out is this:
1) Should I pre-allocate memory in main() and then pass a pointer to that memory to my function? If so, I guess I have to create a new function that scans the file and figures out how much memory I'd need to allocate.
2) Lets say I do the allocation in my reader function and pass back a pointer to that memory location - the pointer is still valid after the function ends, right? If I allocate memory with malloc() and pass out a pointer to that memory I think it will be legit until I free() that memory... I'll have to test that.
3) How do I know what the end of the memory is? Do I need to keep track of how deep I am when reading into the data I stored, or is there a /0 to look out for? I feel like I should know that already.
I'll probably build up a test program to make sure I'm doing things sanely before diving into my real program.
Saturday, March 26, 2011
linking
I figured out what was going wrong, but I'm not happy about it.
There were two problems.
1) The documentation for the gnuplot_i program said that all I had to do was compile the gnuplot_i.c program into a gnuplot_i.o file and then link that against any .c program using the gnuplot_i.h header and subsequent functions. This works fine (in the terminal) with the example .c programs.
I copied the example programs into XCode and then later Eclipse and despite figuring out how to link .o files in those programs I couldn't get anything to work. The fix (and kudos to me for thinking of this) was to step backwards a bit and just include the gnuplot_i.c program WITH the example program so that you compile both gnuplot_i.c and example.c and link them together at the same time.
This eliminated the compiler errors, but then that led to the next error: "GnuPlot not found".
2) "GnuPlot not found" is an error message the program generates (located in gnuplot_i.c again kudos to me for being able to read someone else's code) when invoking gnuplot fails. The program SEEMS to be smart enough to look in the usual locations such as /usr/bin and /usr/local/bin but that didn't seem to be good enough. Running Gnuplot from the command line works fine because it's in usr/local/bin. On a whim I copied Gnuplot from /usr/local/bin to /usr/bin and now the program works fine. I'll have to take a second look at gnuplot_i.c to see if it REALLY is looking for gnuplot in /usr/local/lib OR maybe if this is something about running the program in the XCode/Eclipse console is preventing my user directories from being in the path.
Tricky tricky.
There were two problems.
1) The documentation for the gnuplot_i program said that all I had to do was compile the gnuplot_i.c program into a gnuplot_i.o file and then link that against any .c program using the gnuplot_i.h header and subsequent functions. This works fine (in the terminal) with the example .c programs.
I copied the example programs into XCode and then later Eclipse and despite figuring out how to link .o files in those programs I couldn't get anything to work. The fix (and kudos to me for thinking of this) was to step backwards a bit and just include the gnuplot_i.c program WITH the example program so that you compile both gnuplot_i.c and example.c and link them together at the same time.
This eliminated the compiler errors, but then that led to the next error: "GnuPlot not found".
2) "GnuPlot not found" is an error message the program generates (located in gnuplot_i.c again kudos to me for being able to read someone else's code) when invoking gnuplot fails. The program SEEMS to be smart enough to look in the usual locations such as /usr/bin and /usr/local/bin but that didn't seem to be good enough. Running Gnuplot from the command line works fine because it's in usr/local/bin. On a whim I copied Gnuplot from /usr/local/bin to /usr/bin and now the program works fine. I'll have to take a second look at gnuplot_i.c to see if it REALLY is looking for gnuplot in /usr/local/lib OR maybe if this is something about running the program in the XCode/Eclipse console is preventing my user directories from being in the path.
Tricky tricky.
fiddling
I made some structural changes to my file reader. I'm trying to get each data type extraction into its own function - I have one down, two to go. What's funny is that I actually used some (what I consider to be) advanced pointer usage almost without thinking.
I create a FILE pointer almost first thing in main(), and then each function for extracting a data type uses that pointer so I need to pass the function that pointer.
The prototype looks like:
getdata(FILE**)
and in main() I have:
FILE *file;
getdata(&file);
and then in the getdata() function I remembered to dereference the local FILE** to get to my FILE pointer in main().
Not a big deal, but there were about a dozen posts last summer about trouble with passing pointers to functions.
I got that working well enough and moved on to a "sanity check" project. There is a neat tool called GNUPlot, and someone made an ANSI C front end called gnuplot_i. It basically gives you a bunch of functions to call from C and then it does the rest. To use it you first compile the gnuplot_i.c program to gnuplot_i.o, and then link any C program using the functions against that. I can do this from the command line, but doing it through XCode fails. I'm not sure why - I'll try Eclipse tomorrow.
I create a FILE pointer almost first thing in main(), and then each function for extracting a data type uses that pointer so I need to pass the function that pointer.
The prototype looks like:
getdata(FILE**)
and in main() I have:
FILE *file;
getdata(&file);
and then in the getdata() function I remembered to dereference the local FILE** to get to my FILE pointer in main().
Not a big deal, but there were about a dozen posts last summer about trouble with passing pointers to functions.
I got that working well enough and moved on to a "sanity check" project. There is a neat tool called GNUPlot, and someone made an ANSI C front end called gnuplot_i. It basically gives you a bunch of functions to call from C and then it does the rest. To use it you first compile the gnuplot_i.c program to gnuplot_i.o, and then link any C program using the functions against that. I can do this from the command line, but doing it through XCode fails. I'm not sure why - I'll try Eclipse tomorrow.
yo dawg, I herd you like operating systems
I got Ubuntu set up pretty well in VirtualBox and the development tools are all set up like my netbook. GTK works and everything. That's good. I think I'll move all my "Learning C" folders across the various systems to my DropBox folder.
Friday, March 25, 2011
libraries
http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
I read through this a bit and I bet I can give it a go over the weekend. How BBSS (big baller shot caller) would it be to put the file reading functions in library and then write another program to link against it? I'm not sure why that's useful for this example, but it would be pushing my knowledge base a bit.
I still don't understand shared/static libraries. I'm mad because I saw a GREAT overview of the benefits and I didn't save the link. I think a lot of it has to do with when/if parts of the program are loaded into memory.
I read through this a bit and I bet I can give it a go over the weekend. How BBSS (big baller shot caller) would it be to put the file reading functions in library and then write another program to link against it? I'm not sure why that's useful for this example, but it would be pushing my knowledge base a bit.
I still don't understand shared/static libraries. I'm mad because I saw a GREAT overview of the benefits and I didn't save the link. I think a lot of it has to do with when/if parts of the program are loaded into memory.
Thursday, March 24, 2011
up next
Ok, next up is a few more Project Euler posts. Might just be some feelers of how to tackle the next thing.
I MIGHT take the time to just pull in all the old ones to this platform so I have them to refer to. Might be enough to toss them on DropBox.
Then to learn some memory management stuff I might abuse OpenCV a bit.
I MIGHT take the time to just pull in all the old ones to this platform so I have them to refer to. Might be enough to toss them on DropBox.
Then to learn some memory management stuff I might abuse OpenCV a bit.
VirtualBox
I'm installing Ubuntu 10.10 via VirtualBox in OS X to see if I can compile/run GTK applications in it.
I couldn't really get Ubuntu installed - it was very very slow and wasn't responding well to kb/mouse input. A little searching showed that this is a known issue:
http://forums.virtualbox.org/viewtopic.php?f=8&t=39070
Booting into 32-bit mode fixed it.
I couldn't really get Ubuntu installed - it was very very slow and wasn't responding well to kb/mouse input. A little searching showed that this is a known issue:
http://forums.virtualbox.org/viewtopic.php?f=8&t=39070
Booting into 32-bit mode fixed it.
Tuesday, March 22, 2011
now what
I'm in a weird state of knowledge. I don't know enough to do anything interesting, but I know just enough to download a play with a few open source libraries (GTK, OpenCV, gnuplot) to keep me from doing stuff I think I should be doing.
I NEED to get a grip on allocating memory. I NEED to knock out some more Project Euler tasks (or optimize old ones).
Instead I'm doing instant gratification stuff.
I NEED to get a grip on allocating memory. I NEED to knock out some more Project Euler tasks (or optimize old ones).
Instead I'm doing instant gratification stuff.
Monday, March 21, 2011
finally
I finally got OpenCV to work with Python in OS X. It's a bitter victory because I'm not sure what I did to make it work.
Yesterday I deleted the install files when I decided to give up. Ana's working this evening so I had some free time and decided to take a desperate whack at it one last time. I used ccmake instead of the cmake.app with the fancy GUI, but I doubt that's why it worked. I was not very rigorous about noting what variations to the setup procedure or makefile settings I made. So, mostly it works. I can segfault it with one of the demo programs, but I'm not sweating it. My security program works so that's something.
There is a fine line between determination and angry obsession.
Yesterday I deleted the install files when I decided to give up. Ana's working this evening so I had some free time and decided to take a desperate whack at it one last time. I used ccmake instead of the cmake.app with the fancy GUI, but I doubt that's why it worked. I was not very rigorous about noting what variations to the setup procedure or makefile settings I made. So, mostly it works. I can segfault it with one of the demo programs, but I'm not sweating it. My security program works so that's something.
There is a fine line between determination and angry obsession.
Python and Reaper?
http://www.reaper.fm/sdk/reascript/reascript.php
I added some code to the security camera program to add a directory to my Dropbox folder with the current day's date (if it doesn't already exist) and then add the pictures to that directory. The more I do the more ideas I have - like now I want to write a quick and dirty web page that always displays the last-taken picture (and refreshes accordingly).
The next C vacation I take will probably involve getting Reaper's Python integration figured out. It's the next step in my rat-controlled midi actions goal. I'm fairly certain I can get the object tracking working fairly quickly and then have it dump out an x,y pair that I can shuffle out as a midi command such that it behaves like when I bind the wheel on my keyboard to a midi event range.
I added some code to the security camera program to add a directory to my Dropbox folder with the current day's date (if it doesn't already exist) and then add the pictures to that directory. The more I do the more ideas I have - like now I want to write a quick and dirty web page that always displays the last-taken picture (and refreshes accordingly).
The next C vacation I take will probably involve getting Reaper's Python integration figured out. It's the next step in my rat-controlled midi actions goal. I'm fairly certain I can get the object tracking working fairly quickly and then have it dump out an x,y pair that I can shuffle out as a midi command such that it behaves like when I bind the wheel on my keyboard to a midi event range.
Sunday, March 20, 2011
giving up
I've spent the past hour trying again to get the Python 2.7 and OpenCV 2.2 on my Mac to work. The problem is that there isn't a binary installer. You have to build from source. I can't tell if it's something I'm mis-configuring in the makefiles or if it's something I'm missing on the Mac that I'm unfamiliar with.
Lets start with a basic thing: where Python is installed. I found Python 2.5 and 2.6 here:
/System/Library/Frameworks/Python.framework/Versions/2.5
/System/Library/Frameworks/Python.framework/Versions/2.6
I KNEW that Python 2.7 was installed because it tells me what version it is when I start it, so after MUCH searching I found 2.7 here:
/Library/Frameworks/Python.framework/Versions/2.7
Why? Because. That's why. Seriously - I did some searching and basically the Python shipped on Mac systems goes in one place, and the Python in staller from the website puts it in another. Just because.
So that was an issue because I realized this morning I was pointing my makefiles in the wrong direction for where the python headers were. The python module it dumped out still crashes Python, but at least Python doesn't complain about possible wrong version of the module first.
-sigh-
Not knowing where anything goes has been quite the headache the past few days. Not knowing what happens after I type "make" is even more annoying. I unzip the OpenCV package in one place, then I configure the makefiles with CMake. This creates a new directory one step up from my unzipped directory called /usr/lib/... which after I run "make" it dumps more stuff and then I guess compiles from that directory. Where it places the files generated has been an irritating hunt. It took me forever to find them in /usr/local/lib. I'm having to re-learn a lot of Unix stuff. I find it hard to swallow that I have two "user" directories. One that's /Users/Cheydrick and another that's /usr/local/. Oh, even being allowed to SEE the Unix-specific directories was a chore. I'm not complaining (it was a quick Google search away) but still. I don't know if this is true of Unix in general, but it's symbolic link nightmare central here.
Ironically, I've had no problems getting the OpenCV libraries to build in XCode. I'd have figured that to be the more difficult task but the nakedness of C allows me to read the error messages and fix it. It was just a matter of saying ".dylib files are here, bro" and "header files are over here, bro" and everything was happy.
I might have to just be happy getting Python+OpenCV working on the PC and then maybe later take a stab getting it to work on the Ubuntu box.
In the meantime, I'll get back to C on the laptop. I don't know if I'll have time to knock out anything else in Python on the PC.
If OpenCV goes to version 2.3 maybe I'll try again.
EDIT: Because I'm a glutton for punishment I'm going to give it a shot on the Ubuntu netbook. Actually that could be pretty neat...
Lets start with a basic thing: where Python is installed. I found Python 2.5 and 2.6 here:
/System/Library/Frameworks/Python.framework/Versions/2.5
/System/Library/Frameworks/Python.framework/Versions/2.6
I KNEW that Python 2.7 was installed because it tells me what version it is when I start it, so after MUCH searching I found 2.7 here:
/Library/Frameworks/Python.framework/Versions/2.7
Why? Because. That's why. Seriously - I did some searching and basically the Python shipped on Mac systems goes in one place, and the Python in staller from the website puts it in another. Just because.
So that was an issue because I realized this morning I was pointing my makefiles in the wrong direction for where the python headers were. The python module it dumped out still crashes Python, but at least Python doesn't complain about possible wrong version of the module first.
-sigh-
Not knowing where anything goes has been quite the headache the past few days. Not knowing what happens after I type "make" is even more annoying. I unzip the OpenCV package in one place, then I configure the makefiles with CMake. This creates a new directory one step up from my unzipped directory called /usr/lib/... which after I run "make" it dumps more stuff and then I guess compiles from that directory. Where it places the files generated has been an irritating hunt. It took me forever to find them in /usr/local/lib. I'm having to re-learn a lot of Unix stuff. I find it hard to swallow that I have two "user" directories. One that's /Users/Cheydrick and another that's /usr/local/. Oh, even being allowed to SEE the Unix-specific directories was a chore. I'm not complaining (it was a quick Google search away) but still. I don't know if this is true of Unix in general, but it's symbolic link nightmare central here.
Ironically, I've had no problems getting the OpenCV libraries to build in XCode. I'd have figured that to be the more difficult task but the nakedness of C allows me to read the error messages and fix it. It was just a matter of saying ".dylib files are here, bro" and "header files are over here, bro" and everything was happy.
I might have to just be happy getting Python+OpenCV working on the PC and then maybe later take a stab getting it to work on the Ubuntu box.
In the meantime, I'll get back to C on the laptop. I don't know if I'll have time to knock out anything else in Python on the PC.
If OpenCV goes to version 2.3 maybe I'll try again.
EDIT: Because I'm a glutton for punishment I'm going to give it a shot on the Ubuntu netbook. Actually that could be pretty neat...
Security camera todo
Now that I've got basic functionality in place, here is a list of what I want to do next:
1) On start look for a directory of today's date and put the pictures there (and if it's not there, create it)
2) Timed start/stop so that it runs from 9am-6pm (for example)
3) Create a log of pictures taken (might be helpful for debugging if the log says pics were taken but no pics show up)
4) IF I can get the camera resolution to increase I'll try to figure out a way to add a date/time watermark
The hardest one of those will be the first one since I'll have to figure out how to detect if a directory already exists and then create it if not and then use it in the file save path. It's OS specific (based on my quick glance at the docs) and might be tricky.
That should cover the rest of the day and my C vacation will be over. If I decide to circle back and work on this some more I'm going to try to apply better "pythony" structure to the program.
I'm only scratching the surface of what OpenCV can do. It looks like there are some pretty canned functions for motion/face detection so I could probably play with those.
1) On start look for a directory of today's date and put the pictures there (and if it's not there, create it)
2) Timed start/stop so that it runs from 9am-6pm (for example)
3) Create a log of pictures taken (might be helpful for debugging if the log says pics were taken but no pics show up)
4) IF I can get the camera resolution to increase I'll try to figure out a way to add a date/time watermark
The hardest one of those will be the first one since I'll have to figure out how to detect if a directory already exists and then create it if not and then use it in the file save path. It's OS specific (based on my quick glance at the docs) and might be tricky.
That should cover the rest of the day and my C vacation will be over. If I decide to circle back and work on this some more I'm going to try to apply better "pythony" structure to the program.
I'm only scratching the surface of what OpenCV can do. It looks like there are some pretty canned functions for motion/face detection so I could probably play with those.
added timing
Added some code to deal with timed capture. It works but I'm wondering if it's the best way to handle detecting elapsed time. That test loop is a "run as fast as possible" thing and I'm not sure how much processor it's using (although I won't be using the PC while it's running once it's done).
I'm pretty happy with this.
I'm furious that I still can't get the CV module to work in OS X. There will be a very detailed post about that soon.
EDIT: It's worth mentioning that setting the resolution isn't working. I think I need to install the Logitech drivers that may or may not work with Win7.
Saturday, March 19, 2011
First test
Jeez, I blocked out the whole day to get this far...
http://imgur.com/6xRVa
So all this does so far is pop up a window with the active webcam and it snaps a picture when I hit the space bar. I started off with the example program that OpenCV comes with that just pops open the camera window until you hit "esc". I added another "cv.WaitKey()" statement and then read the documentation to figure out how to use "cv.SaveImage()". The part that took the longest was figuring out the filename string handling. I googled how to get the time and then figured out with trial and error how to get individual elements of the returned structure (very c-like) and then read a bit into "Dive Into Python" to figure out how to put it all together (I needed a "sprintf" type function).
Total time? Maybe an hour not counting the several hours last night getting Python+numpy+OpenCV installed.
Complaints: No brackets, very white-space sensitive (but this is a big feature of the language so whatever). There seem to be many ways of doing the same thing. I could have handled the string shoveling in line 14 in a thousand different ways. The way I used makes sense to me because it's C-like (printf, sprintf).
Compliments: RAPID development. Notepad++ on the left, command console on the right. Edit, run, edit, run.
For the future: Right now it's just dumping the .jpg files into the same directory it's being run in. I need to learn how to not only point to directories, but MAKE directories (called the date) and then put the files in the right place.
Python project
I'm taking a vacation away from C for a bit. I've been beating my head against various IDEs (CodeBlocks, Eclipse, XCode) on various platforms trying to learn how to set paths to various external libraries and set compiler options to get things like OpenCV and GTK to work and I'm kind of burned out. I'm not burned out on C, I'm burned out on the hoops I have to jump through to do anything that's not vanilla C. I actually solved most of my problems, it's just that I'm resenting the lost afternoons this week doing it.
Anyways, I have an idea for a project that is actually useful and can probably be implemented over the next few days.
I've been trying make my PC be useful during the day while I'm gone by using it as a security camera. Some years (2002ish?) back I did this rather successfully with some light-weight software (Fwink or Dorgem) that would take a pictures every X seconds and upload it to my UTDallas FTP site. This past week I've been trying to recreate that setup with either minimal or frustrating results.
Dorgem/Fwink are Windows XP-era abandon-ware and don't play nice with my rig. Yawcam works but isn't very consistent about working. It crashed on me a few times but that might be my webcam's fault. Yoics is overkill/bloated and extremely slow.
All I want is a program that takes a picture every X seconds and saves it to "date-time.jpg" in directory "date". I don't need motion sensing since this is a low-light environment that's too noisy to do that correctly.
Here's the plan: OpenCV has functions for grabbing and saving an image from video sources, like a webcam. It seems straightforward enough to implement in Python and there are lots of code snippets I could borrow. I don't have a FTP site to use but I do have Dropbox on this machine. I'll save the files to "C:\Users\Chris\Dropbox" and the Dropbox program saves it to the "cloud" and syncs to my other machines when they boot up and have an internet connection.
If OpenCV doesn't work out (or turns out to be overkill) I'll use a somewhat popular Windows-only library (http://videocapture.sourceforge.net/).
So that's the plan. I'll write it in notepad++ for the syntax highlighting and run it from the command line.
Anyways, I have an idea for a project that is actually useful and can probably be implemented over the next few days.
I've been trying make my PC be useful during the day while I'm gone by using it as a security camera. Some years (2002ish?) back I did this rather successfully with some light-weight software (Fwink or Dorgem) that would take a pictures every X seconds and upload it to my UTDallas FTP site. This past week I've been trying to recreate that setup with either minimal or frustrating results.
Dorgem/Fwink are Windows XP-era abandon-ware and don't play nice with my rig. Yawcam works but isn't very consistent about working. It crashed on me a few times but that might be my webcam's fault. Yoics is overkill/bloated and extremely slow.
All I want is a program that takes a picture every X seconds and saves it to "date-time.jpg" in directory "date". I don't need motion sensing since this is a low-light environment that's too noisy to do that correctly.
Here's the plan: OpenCV has functions for grabbing and saving an image from video sources, like a webcam. It seems straightforward enough to implement in Python and there are lots of code snippets I could borrow. I don't have a FTP site to use but I do have Dropbox on this machine. I'll save the files to "C:\Users\Chris\Dropbox" and the Dropbox program saves it to the "cloud" and syncs to my other machines when they boot up and have an internet connection.
If OpenCV doesn't work out (or turns out to be overkill) I'll use a somewhat popular Windows-only library (http://videocapture.sourceforge.net/).
So that's the plan. I'll write it in notepad++ for the syntax highlighting and run it from the command line.
setup
I got OpenCV to work with Windows and Python 2.7. The trick was copy/pasting libraries from the OpenCV directory to the Python directory. -Sigh-.
Friday, March 18, 2011
swingandamiss
I've spent much of this morning and the past few hours trying to get a few things to work.
1) OpenCV in Python on OS X
2) OpenCV in Python in Windows
3) OpenCV C/C++ with XCode on OS X
#1 is a no go because I don't feel like rolling my Python version back to accomodate NumPy. #2 isn't working because I can't get Python to see the CV library, and when I fiddle with the paths it just gives me a different error. #3 is mostly working, but it took some serious setup. Basically it was just tough getting XCode to see the libraries and make the paths happy.
Anyways, with both Python situations I've had enough problems to put me off it for a few days.
1) OpenCV in Python on OS X
2) OpenCV in Python in Windows
3) OpenCV C/C++ with XCode on OS X
#1 is a no go because I don't feel like rolling my Python version back to accomodate NumPy. #2 isn't working because I can't get Python to see the CV library, and when I fiddle with the paths it just gives me a different error. #3 is mostly working, but it took some serious setup. Basically it was just tough getting XCode to see the libraries and make the paths happy.
Anyways, with both Python situations I've had enough problems to put me off it for a few days.
Tuesday, March 15, 2011
One goal was writing a .plx loader. That's pretty much a solved problem.
Another was writing a small game, like a Lunar Lander clone. I kind of stopped aiming for this because I can't find a graphics library that doesn't get really involved really fast. All I really need is the ability to render a sprite and some terrain (which could also be an image - not procedurally generated). I've looked into SDL, OpenGL, Cairo, and a few others I can't recall. I dunno - it's been a few months since I dug into it last and maybe I could try again. GTK+ and Canvas is an option, but that's not really what it's for. There aren't a lot of Cairo demos/examples/tutorials that are game related.
Another was writing a small game, like a Lunar Lander clone. I kind of stopped aiming for this because I can't find a graphics library that doesn't get really involved really fast. All I really need is the ability to render a sprite and some terrain (which could also be an image - not procedurally generated). I've looked into SDL, OpenGL, Cairo, and a few others I can't recall. I dunno - it's been a few months since I dug into it last and maybe I could try again. GTK+ and Canvas is an option, but that's not really what it's for. There aren't a lot of Cairo demos/examples/tutorials that are game related.
next step
I think what I'll do next is compartmentalize things into functions.
The FILE* variable can take care of itself and as long as it's global I won't have too much issue with using fread() in functions. One of my first reader projects passed pointers (and pointers to pointers) into and out of functions but this is really unnecessary, especially for a simple program like this. If the program dealt with multiple files then it might be necessary to pass a file pointer as a function argument.
I'll experiment with sticking to one style of brackets, and I need to decide whether or not to put a space between functions and the parentheses where the passed variables are held. Since I would call a argument-less function like so: function();, with no space between name and parentheses, I should probably do the same for: function(arg1, arg2, arg3);.
The FILE* variable can take care of itself and as long as it's global I won't have too much issue with using fread() in functions. One of my first reader projects passed pointers (and pointers to pointers) into and out of functions but this is really unnecessary, especially for a simple program like this. If the program dealt with multiple files then it might be necessary to pass a file pointer as a function argument.
I'll experiment with sticking to one style of brackets, and I need to decide whether or not to put a space between functions and the parentheses where the passed variables are held. Since I would call a argument-less function like so: function();, with no space between name and parentheses, I should probably do the same for: function(arg1, arg2, arg3);.
Monday, March 14, 2011
snot bad
I think I rather unintentionally hit a milestone.
So I wrote that program to read in the binary files, but for the most part it was skipping over stuff I didn't know what to do with since each data block header told me how much to skip.
I was idly thinking about it rather quickly banged out the code to give me nice and neatly more data (32 numbers in a row).
It's nice when I go from thought to result in less than a minute and it compiles the first time!
EDIT: Do I use too much indentation? I've always like well indented code but it's tough to embed it...
So I wrote that program to read in the binary files, but for the most part it was skipping over stuff I didn't know what to do with since each data block header told me how much to skip.
I was idly thinking about it rather quickly banged out the code to give me nice and neatly more data (32 numbers in a row).
It's nice when I go from thought to result in less than a minute and it compiles the first time!
EDIT: Do I use too much indentation? I've always like well indented code but it's tough to embed it...
bash operator
I remembered that it's possible to redirect output streams to files.
./myprogram > programoutput.txt
Now I have text file output with no extra programming! Ok that's a cheat but it's still neat.
I've been thinking about compartmentalizing the program to one function per data type. That way I can trigger the function call output by program arguments. Such as:
myprogram 1 0 0
...would output spikes, but suppress events and continuous. If I wanted to be real fancy I'd do:
myprogram -ch 42 -evt all -cont 42
...which would output discontinuous data channel 42, all the events, and continuous channel 42. I haven't had an opportunity to really get a handle on argument handling so maybe how is a good time.
./myprogram > programoutput.txt
Now I have text file output with no extra programming! Ok that's a cheat but it's still neat.
I've been thinking about compartmentalizing the program to one function per data type. That way I can trigger the function call output by program arguments. Such as:
myprogram 1 0 0
...would output spikes, but suppress events and continuous. If I wanted to be real fancy I'd do:
myprogram -ch 42 -evt all -cont 42
...which would output discontinuous data channel 42, all the events, and continuous channel 42. I haven't had an opportunity to really get a handle on argument handling so maybe how is a good time.
Does nothing, but looks good
Ok, this works now. All it's doing is dumping out the start and stop markers, but at this point I can make it do anything I ask.
I think what I'll do next is output all waveforms on a channel to a .txt file. Each waveform consists of 32 (usually) points in A/D values +-2048. Each line in the .txt file can be those points. That would be interesting because I've never generated something in a file in C. Not in recent memory, anyways.
boogers
Well, the program compiled and ran with expected numbers on my Windows machine. This means that it is either a data alignment issue or a size of variable problem. Much research needs to be done.
EDIT: I wrote a short program to dump out the size of all data types used by the structures and found that on the Windows box an unsigned long is 4 bytes, and on the Mac it's 8 bytes. That explains the problem but now I'm not sure what to do. Can I just alter the struct (swap unsigned long for unsigned int) and hope for the best?
EDIT: I wrote a short program to dump out the size of all data types used by the structures and found that on the Windows box an unsigned long is 4 bytes, and on the Mac it's 8 bytes. That explains the problem but now I'm not sure what to do. Can I just alter the struct (swap unsigned long for unsigned int) and hope for the best?
Sunday, March 13, 2011
Mleh
Well, I've hacked away at this program most of the evening and I can't get it to dump out the values I expect. The data blocks are just structures, and certain values of those structures should only be certain things, and I'm getting numeric garbage for those certain things.
I think I need to compile this on a different machine to rule out structure padding/packing/whatever things I might be overlooking.
I think I need to compile this on a different machine to rule out structure padding/packing/whatever things I might be overlooking.
almost there
I got my program to read into the file all the way past the header data up to right before the actual recorded data starts.
So far I'm getting away with using arrays of structs that are just declared on the stack (I apologize if this isn't correct terminology).
These arrays aren't unreasonably large so I'm going to let it slide.
The rest of the data is large, but not large all in once place. I think I wrote before how in order to get the data pertinent to one channel of one data type I'd have to scan through the whole file. Dynamically declaring memory to hold all the data of a channel would mean first scanning through the data to get the total size of the channel, declaring my memory space, and then rescanning and saving the data. Is this normal?!
I've decided to try making this a program that will return one channel of data called by name via the command line. For example:
./readfile filename.plx CH01
would get all the data for CH01 and return it appropriately... somehow. Appropriately might wind up being a big text file. Most data comes out in pairs - timestamp and value. Not sure how to handle that yet.
I have been reading more of the Python documentation, and the free ebook "Dive Into Python". I haven't coded much. When I have done something I've used TextWrangler to write it (does various syntax highlighting) and I've run it from the console. Nothing fancy. I actually ran into a problem that Python might be well suited for. I got into the habit of taking pictures of things and then making a copy of a dozen or so pictures into a different folder for resizing and uploading to Facebook. Resizing the pictures one-by-one is kind of annoying. I dont think I have any programs that do whole folder resizing. Anyways, I bet there are Python modules for image manipulation and I've already seen examples of viewing directory contents and executing commands form the console from Python. It should be simple to tell a Python script to apply a resizing package to all the files in a directory. I've been working with C for a while and I can't think of how to do this at all. I'm not even sure how to get a list of files in a directory or run a console command....
So far I'm getting away with using arrays of structs that are just declared on the stack (I apologize if this isn't correct terminology).
These arrays aren't unreasonably large so I'm going to let it slide.
The rest of the data is large, but not large all in once place. I think I wrote before how in order to get the data pertinent to one channel of one data type I'd have to scan through the whole file. Dynamically declaring memory to hold all the data of a channel would mean first scanning through the data to get the total size of the channel, declaring my memory space, and then rescanning and saving the data. Is this normal?!
I've decided to try making this a program that will return one channel of data called by name via the command line. For example:
./readfile filename.plx CH01
would get all the data for CH01 and return it appropriately... somehow. Appropriately might wind up being a big text file. Most data comes out in pairs - timestamp and value. Not sure how to handle that yet.
I have been reading more of the Python documentation, and the free ebook "Dive Into Python". I haven't coded much. When I have done something I've used TextWrangler to write it (does various syntax highlighting) and I've run it from the console. Nothing fancy. I actually ran into a problem that Python might be well suited for. I got into the habit of taking pictures of things and then making a copy of a dozen or so pictures into a different folder for resizing and uploading to Facebook. Resizing the pictures one-by-one is kind of annoying. I dont think I have any programs that do whole folder resizing. Anyways, I bet there are Python modules for image manipulation and I've already seen examples of viewing directory contents and executing commands form the console from Python. It should be simple to tell a Python script to apply a resizing package to all the files in a directory. I've been working with C for a while and I can't think of how to do this at all. I'm not even sure how to get a list of files in a directory or run a console command....
Saturday, March 12, 2011
Eclipse
I spent the day learning the Eclipse IDE. I was worried I was using it wrong, but I think I'm ok. It's so flexible and capable of doing anything you'd ever possibly want to do that it's hard to just use it in a plan vanilla way.
Friday, March 11, 2011
meandering
I complained before that it's hard to write a program without a specific purpose in mind. I've been writing a file reader without knowing what I wanted to read, and what to do with what I've read after it's been read.
Fortunately (unfortunately?) the file I'm reading is efficient for writing, awkward for reading. Regardless of what I do with the data I still have to write a program that knows how to read any of it (or skip over it).
Assert assumptions:
1) The file header comes first and tells us how many channels (of various types) that there are.
2) Next are all the channel headers for one data type (followed by the other two types). We read in and store them, or skip over them.
3) Here is where we encounter actual data block headers. We read in the header, and in this header we see what kind of data follows it, and how much of that data exists.
3a) If we care about the data we read in (number of data * size of one unit of that data) the data.
3b) If we don't care about the data we skip (number of data * size of one unit of that data) past it.
4) EOF is reached and program ends the reading section.
This is somewhat irritating because you MUST read the whole file (storing or skipping the data as needed) and that's going to have consequences the larger the file gets.
There is another company that uses a database-heavy storage scheme that I think has the right idea.
Anyways, tonight was about understanding the steps needed to get from start to end for reading the data. Tomorrow is going to be about setting up some constants infrastructure. I want a macro for all the numbers I'll commonly use, like all the data sizes so that I can just say skip/read (numdata * sizeofdata) instead of (numdata * (sizeof(double)) or something similarly cryptic.
I wonder if I can call SQL from C....
Fortunately (unfortunately?) the file I'm reading is efficient for writing, awkward for reading. Regardless of what I do with the data I still have to write a program that knows how to read any of it (or skip over it).
Assert assumptions:
1) The file header comes first and tells us how many channels (of various types) that there are.
2) Next are all the channel headers for one data type (followed by the other two types). We read in and store them, or skip over them.
3) Here is where we encounter actual data block headers. We read in the header, and in this header we see what kind of data follows it, and how much of that data exists.
3a) If we care about the data we read in (number of data * size of one unit of that data) the data.
3b) If we don't care about the data we skip (number of data * size of one unit of that data) past it.
4) EOF is reached and program ends the reading section.
This is somewhat irritating because you MUST read the whole file (storing or skipping the data as needed) and that's going to have consequences the larger the file gets.
There is another company that uses a database-heavy storage scheme that I think has the right idea.
Anyways, tonight was about understanding the steps needed to get from start to end for reading the data. Tomorrow is going to be about setting up some constants infrastructure. I want a macro for all the numbers I'll commonly use, like all the data sizes so that I can just say skip/read (numdata * sizeofdata) instead of (numdata * (sizeof(double)) or something similarly cryptic.
I wonder if I can call SQL from C....
Wednesday, March 9, 2011
new function
I had a heck of a time getting my basic .plx file header reader functional. I toss in a liberal amount of error messages for if things go wrong and I kept getting NULL returned for my file pointer, meaning the file wasn't found to be read.
I decided that I didn't understand WHERE to put the file to be read, so I had to figure out where the program was looking for the file. I had assumed it was in the same directory as the executable itself, but I turned out to be wrong.
There is a Unix command called "pwd" that returns the directory you're currently in (in a terminal). I did some searching and found that a library "unistd.h" existed with a function called "getcwd" that passed the current working directory to a character array. I printf'd that bad boy out and found where my program was looking (in one folder up in the tree). I copied my .plx file there and bam - working program.
So, huzzah Unix is the sentiment tonight!
I decided that I didn't understand WHERE to put the file to be read, so I had to figure out where the program was looking for the file. I had assumed it was in the same directory as the executable itself, but I turned out to be wrong.
There is a Unix command called "pwd" that returns the directory you're currently in (in a terminal). I did some searching and found that a library "unistd.h" existed with a function called "getcwd" that passed the current working directory to a character array. I printf'd that bad boy out and found where my program was looking (in one folder up in the tree). I copied my .plx file there and bam - working program.
So, huzzah Unix is the sentiment tonight!
Here we go
I'm going to try to use Eclipse as an IDE for a while. No particular reason. CodeBlocks is good, but I want to try something else for a while. Eclipse is cross-platform which is important now.
The first thing I want to get back to is the program that reads in files from work. I've made all my largest leaps in knowledge with that program since it's forcing me to do advanced stuff. I'm going to port the basic program from my Linux box to my OS X box.
Once the basic program works I'll pick a task for it to do. I want to use this as an opportunity to learn how to allocate memory.
The first thing I want to get back to is the program that reads in files from work. I've made all my largest leaps in knowledge with that program since it's forcing me to do advanced stuff. I'm going to port the basic program from my Linux box to my OS X box.
Once the basic program works I'll pick a task for it to do. I want to use this as an opportunity to learn how to allocate memory.
Wednesday, March 2, 2011
blop
Neck deep in work. Probably won't do any programming until next week. Ana has some wonky late shifts coming up so I'll have some alone time to make a few long stretches of coding.
Subscribe to:
Posts (Atom)