Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
Okay, Here's the first working version of my progress monitor. Yes, it's very, very un-Mac-like.


// read a text file and match certain items on separate lines



import java.io.*;



class Keyboard

{

InputStreamReader inStream;

BufferedReader stdInStream;



// override implicit constructor to open the input stream and attach it

// to a stream reader

Keyboard()

{

inStream = new InputStreamReader(System.in);

stdInStream = new BufferedReader(inStream);

}



// get one character

char read()

{

char aChar = ' ';



try

{

aChar = (char)stdInStream.read();

}

// empty exception handling

catch (Exception e)

{

}

return aChar;

} // end of read()



// get a whole line and return it as a String

String readln()

{

String aString = " ";



try

{

aString = (String)stdInStream.readLine();

}

// empty exception handling

catch (Exception e)

{

}

return aString;

} // end of readln()



} // end of Keyboard class



class ReadAndParse

{

private static String fileName;

private static String line;

private static String proteinName = "";

private static float completed = -1;

private static float remaining = -1;

private static float totalNbrOfFrames = -1;

private static float currentFrame = -1;

private static int progressPercentage = -1;

private static String junk;

private static boolean proteinFound = false;

private static boolean totalsFound = false;

private static boolean framesFound = false;



public static String match(String toSearch, String toMatch, String start, String end)

{

int posFrom = -1, posTo = -1;

String matchFound = "";



posFrom = toSearch.indexOf(toMatch);



if(posFrom >= 0)

{

posFrom = toSearch.indexOf(start, posFrom); // character after search word



posFrom++;

posTo = toSearch.indexOf(end , posFrom); // character after parameter

if(posTo >= 0)

{

// get the token that follows

matchFound = toSearch.substring(posFrom, posTo);

}

else

{

// extra space not found before end of line

// get the token that follows

matchFound = toSearch.substring(posFrom);

}



}



return matchFound;

}



public static void main(String []args)

{

Keyboard kb = new Keyboard();



System.out.println("Please enter the file name to be searched");



fileName = new String(kb.readln());



try

{



BufferedReader inputFile = new BufferedReader(new FileReader(fileName));



// file should be open, read it



proteinFound = false;

line = inputFile.readLine();

while(line != null && proteinFound == false)

{



// find Protein name



proteinName = match(line, "Protein:", " ", " ");

if(proteinName != "") // non-blank

{

proteinFound = true;

break;

}

line = inputFile.readLine();

} // end while ! proteinFound



framesFound = false;

line = inputFile.readLine();

while(line != null && totalsFound == false)

{

// find total number of frames



junk = match(line, "Completed:", " ", ",");

if(junk != "")

{

completed = Float.parseFloat(junk);

}



junk = match(line, "Remaining:", " ", " ");

if(junk != "")

{

remaining = Float.parseFloat(junk);

totalNbrOfFrames = completed + remaining;

totalsFound = true;

}

line = inputFile.readLine();

} // while ! totalsFound



// find highest frame number

framesFound = false;

line = inputFile.readLine();

while(line != null && framesFound == false)

{

junk = match(line, "Finished a frame", "(", ")");

if(junk != "")

{

currentFrame = Float.parseFloat(junk);

framesFound = true;

}

line = inputFile.readLine();

} // end while ! framesFound



// got at least one, check for the highest

line = inputFile.readLine();

while(line != null && framesFound == true)

{

junk = match(line, "Finished a frame", "(", ")");

if(junk != "")

{

currentFrame = Float.parseFloat(junk);

}

else

{

framesFound = false;

}

line = inputFile.readLine();

} // end while framesFound



// do the math



progressPercentage = (int) ( 100 * (currentFrame / totalNbrOfFrames));



System.out.println("Protein is " + proteinName);

System.out.println("Latest frame is " + currentFrame);

System.out.println("Total number of frames are " + totalNbrOfFrames);

System.out.println("Progress is currently at: " + progressPercentage + "%");



}

catch(IOException e)

{

System.out.println("The file was not found. Please check file name and/or path");

}

} // end main()

} // end class



You may compile it by putting it in a folder and typing javac ReadAndParse.java.

This will produce two class files:

Keyboard.class
ReadAndParse.class

You may then run it within the Terminal app. by typing java ReadAndParse.

When it requests, please provide it the file name (and full path if it's in a different folder) where the logfile exists.

If I put it in the same folder with the logfile, it asks for the file name and I type logfile_01.txt.

If I put in in a different folder, I must type something like ~/FAH2/work/logfile_01.txt or if I can see the file in the Finder, I can drag it to the Terminal and the name will magically be pasted there.

Anyway, it's a start. I should have a working GUI version sometime in the coming week.
 

pepeleuepe

macrumors 6502
Oct 27, 2002
252
0
Los Angeles, California
I copied the code and pasted it into Project Builder, saved as "ReadAndParse.java," followed your insturctions and it works perfectly. Just wondering if the percentages are displayed in integers only? My percentage is currently at 0.3, so thats probably why the program was returning 0%. It's nice to see how many frames you have done, and how many are left without looking through the log file though. Also, is there anyway to keep the app open and refreshing every couple of seconds? If so, let me know, otherwise, thanks for making this, I'm sure it will be useful to everyone thats folding. I'm looking forward to the GUI version :) .
 

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
I actually did the percentage as an integer because most thermometers, progress bars, etc. use an integer value. Since I'm going toward GUI, I felt it was just as well to push it that way early.

As far as automatically updating the figures, I want to do that, but I have to learn that part of Java first. It's probably not a big deal, but I haven't encountered that yet. :D The first version will have an Update button to give the user absolute control.
 

dwaxman

macrumors newbie
Dec 4, 2002
10
0
My chair
Re: folding@home progress monitor

Absolutely wonderful! is there a chance you can make it so we can pass the filename into the command line (IE java ReadAndParse /users/volumes/dave/F@H1/work/logfile_01.txt) that way I can make a quick little shell script to display the info more quickly?
 

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
Here's an early screenshot of the application actually running.
 

Attachments

  • foldingprogressapp.jpg
    foldingprogressapp.jpg
    20.9 KB · Views: 684

MrMacMan

macrumors 604
Jul 4, 2001
7,002
11
1 Block away from NYC.
Originally posted by bousozoku
Here's an early screenshot of the application actually running.
Ohhhhh

Ahhhhh

:crowd applauds:
Are you gonna give a readme and or tech support for your app? Or is it - it works, good. doesn't- too bad. basis?
 

pepeleuepe

macrumors 6502
Oct 27, 2002
252
0
Los Angeles, California
Originally posted by bousozoku
Here's an early screenshot of the application actually running.

Very nice, I can't wait :confused: :D :confused: :D . Thanks again for making this program. Is the first version going to include the option to display the progress in the dock as well? Because that would be amazing :) .
 

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
Originally posted by MrMacman
Ohhhhh

Ahhhhh

:crowd applauds:
Are you gonna give a readme and or tech support for your app? Or is it - it works, good. doesn't- too bad. basis?

How about i make it open source and the community can take care of it? <ducks>

I'm usually more particular than most so I will do my best to give you all something that won't break or cause trouble.
 

MrMacMan

macrumors 604
Jul 4, 2001
7,002
11
1 Block away from NYC.
Now... Does this mean I can shut down my graphical client and the Folding processor still runs or can I hide it.

Or (when this comes out) someone will need to help me on putting it in the terminal. :eek:
 

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
Originally posted by MrMacman
Now... Does this mean I can shut down my graphical client and the Folding processor still runs or can I hide it.

Or (when this comes out) someone will need to help me on putting it in the terminal. :eek:

This is only a progress monitor. It does not initiate folding or control it in any other way.

I really intended it for all of us who use the command line client, and because it's written using Java, that means that it will work on any platform supporting JDK 1.2 or higher.
 

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
Okay, here's a better version. Some clean up, some new stuff. I finally figured out how to get Java preferences to work--in part. I have to figure out at what point to write them before exiting the application. In C++, I would put them in the destructor, but..there isn't such a thing in Java. I suppose the finalize() method may be okay.

If anyone knows how to work a checkbox and tell the state without a state change, please let me know. Otherwise, we won't have a 2nd processor progress bar active--at least, with the checkbox.
 

Attachments

  • foldingprogress2.jpg
    foldingprogress2.jpg
    29 KB · Views: 611

MrMacMan

macrumors 604
Jul 4, 2001
7,002
11
1 Block away from NYC.
Originally posted by bousozoku
Okay, here's a better version. Some clean up, some new stuff. I finally figured out how to get Java preferences to work--in part. I have to figure out at what point to write them before exiting the application. In C++, I would put them in the destructor, but..there isn't such a thing in Java. I suppose the finalize() method may be okay.

If anyone knows how to work a checkbox and tell the state without a state change, please let me know. Otherwise, we won't have a 2nd processor progress bar active--at least, with the checkbox.

Very nice work man. Post it up here whever you feel it is ready for some people ready to see it (and check it is macrumors public worthy).
 

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
Okay, I just loaded the new Java 1.4.1 update. Things look different as you can see. In contrast, I will also upload the thing running on Windows.

Things are improving but there is so much documentation to read to get even little things done. Thanks for your patience--it's coming.

The checkbox is working and properties (preferences) are partially implemented. Along with that, I need to change the file chooser dialog to select directories only.
 

Attachments

  • foldingprogressjdk141.jpg
    foldingprogressjdk141.jpg
    24 KB · Views: 620

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
Now for something different, a Windows/Metal look-and-feel.
 

Attachments

  • foldingprogressjavawin.jpg
    foldingprogressjavawin.jpg
    22.6 KB · Views: 608

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
Originally posted by pepeleuepe
Very nice, I can't wait :confused: :D :confused: :D . Thanks again for making this program. Is the first version going to include the option to display the progress in the dock as well? Because that would be amazing :) .

You know something...that would be amazing. I found the code and it's...well, it's QuickDraw. I need to find someone who knows how to convert QD code to Quartz.

I'd like to make everything work in the first version but it's going to take a lot. I'm learning a lot too. :D
 

maradong

macrumors 65816
Mar 7, 2003
1,058
0
Luxembourg
Looks very nice.
I might perhaps help you, if you are interessted in. Actually my java knowledge is not the best but perhaps i can grap some of your tricks and you some of mine :)
 

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
Originally posted by maradong
Looks very nice.
I might perhaps help you, if you are interessted in. Actually my java knowledge is not the best but perhaps i can grap some of your tricks and you some of mine :)

Thanks much!

I may need the help.

I finally figured out how to use a FilenameFilter with a File so that I can automatically use my path settings to avoid selecting the files each time. It's funny. The FilenameFilter class is so powerful and yet, it's barely shown in examples at all.

I'll probably have a feature-complete version ready this weekend for everyone to test.
 

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
Okay, it's working and I've added some web pages to host it. The double-click-able file is only 12K, so you might just have the space to keep it.

Go to the following web site to check it out and download it.

http://www.mindspring.com/~us019818/fp/

Your thoughts are appreciated. :)

There will be a timer on the way to automatically update it.
 

MrMacMan

macrumors 604
Jul 4, 2001
7,002
11
1 Block away from NYC.
Originally posted by bousozoku
Okay, it's working and I've added some web pages to host it. The double-click-able file is only 12K, so you might just have the space to keep it.

Go to the following web site to check it out and download it.

http://www.mindspring.com/~us019818/fp/

Your thoughts are appreciated. :)

There will be a timer on the way to automatically update it.

Okay so it runs good on Java 1.3.1.

I noticed a small really insignificant glitch, when I slected the protien first and hit update it didn't but when I re-launched the app it loaded fine
 

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
It's been updated to remove that annoying 1st time glitch and the new version is on the website.
 

bousozoku

Moderator emeritus
Original poster
Jun 25, 2002
15,716
1,890
Lard
I'm currently adding support for the Gromacs and SPG log file formats.

When the Gromacs core is brought online for Macintosh, the progress monitor will be ready to handle it, even if that's this week.
 

MrMacMan

macrumors 604
Jul 4, 2001
7,002
11
1 Block away from NYC.
Originally posted by bousozoku
I'm currently adding support for the Gromacs and SPG log file formats.

When the Gromacs core is brought online for Macintosh, the progress monitor will be ready to handle it, even if that's this week.

How could you do work on something that hasn't been implemented on the mac yet? :confused:

sure PC's have it... but... is it the same exact file and file log?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.