We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › writing / updating application log files
Page Index Toggle Pages: 1
writing / updating application log files (Read 1313 times)
writing / updating application log files
Feb 28th, 2006, 10:49am
 
hi all

this seems like an obvious question but i couldn't find through searching the forum: i need to write a log file for my application (running locally, don't need to be able to distribute it to others) which will be updating with about 100 values approx. 5 times a second.

what is the best way to do this? savestrings doesn't sound that efficient since i would have to keep the entire string in ram which would get pretty huge after a few hours running -- basically i need just to append to a text file.

i'm pretty new to all this so getting deep into java is not necessarily a good option....... any suggestions anyone?

many thanks...
Re: writing / updating application log files
Reply #1 - Feb 28th, 2006, 2:27pm
 
Are these values floats or ints or text? Saving the stuff as bytes would be an option if its ints or you can figure out how to convert the stuff into similar.

Code:

byte [] int4Bytes (int source){
byte [] sendBack = new byte[4];
sendBack[0]=byte((source&0xFF000000)>>24);
sendBack[1]=byte((source&0x00FF0000)>>16);
sendBack[2]=byte((source&0x0000FF00)>>8);
sendBack[3]=byte((source&0x000000FF));
return sendBack;
}

and to read back into an int
Code:

int returnInt (byte [] source){
int [] returnInt = new int[source.length];
for (int i = 0; i < source.length; i++){
returnInt[i] = int(source[i]);
}
return (returnInt[0] << 24)
| (returnInt[1] << 16)
| (returnInt[2] << 8)
| returnInt[3];
}

So you would be jumping in 4 byte steps through an array of bytes

byte [] mydata = new byte[totalValues * 4];

And it will take up very little memory or disk space, plus it would be quick.

It might not be appropriate for your task but its a thought.
Re: writing / updating application log files
Reply #2 - Feb 28th, 2006, 4:51pm
 
thanks for the suggestion: yes, i considered bytes as well and realise it would be smaller. the problem is that i am updating values 5 times a second so i would still need a two dimensional array sized at

mydata[432000][100] per day of run time

which i presume will get slower and slower to write to a file as it gets larger.

simplest would be if only i could find a way to append to a text file........
Re: writing / updating application log files
Reply #3 - Feb 28th, 2006, 6:59pm
 
Ah, yes - I also had to run my project for days on end. I got around the file size problem by having a numbered file system.

filename = "myData"+saveNumber+".dat"

You can use nf() to append zeros to make it tidier as well. It isn't the prettiest way round the problem but if you want the path of least resistance...

If you want a constant stream to a file then Java's FileOutputStream might be a method you could use. I think I read of an implementation of it in Processing which is in the works or might be finished by now.

Either way, if you start blitzing Strings into a file (thats two bytes a character my friend), you're going to end up with some hulking amount of data.
Re: writing / updating application log files
Reply #4 - Feb 28th, 2006, 8:45pm
 
hallelujah!

found the answer here:

http://processing.org/discourse/yabb/YaBB.cgi?board=Integrate;action=display;num=1113338206

(this is on the "old" alpha board -- moderators, is there any way to get the search function to work across both boards? i found this purely by accident searching for something completely different on google).

anyway, it's a great little shortcut to appending to a file..... just in case that board ever disappears, thanks to nay for this one:

FileWriter file;
String test = "teststring";
try  
  {  
 file = new FileWriter("test.txt", true); //bool tells to append
 file.write("\n"+test, 0, test.length()+1); //(string, start char, end char)
 file.close();
       }  
    catch(Exception e)  
  {  
    println("Error: Can't open file!");
   }

Re: writing / updating application log files
Reply #5 - Feb 28th, 2006, 9:50pm
 
ch wrote on Feb 28th, 2006, 8:45pm:
(this is on the "old" alpha board -- moderators, is there any way to get the search function to work across both boards i found this purely by accident searching for something completely different on google).

that would be the "search processing.org" thing at the top of every forum page, which uses google to search both forums and the rest of the site. the results aren't great because google won't recognize our robots.txt file (anyone who knows about these things please pipe up), but should improve over time.
Page Index Toggle Pages: 1