I wrote the program below, which is supposed to read in a text (.txt) file, perform some operations on it, and export another file. I want some graphics to show up in the window at the same time as this is happening. I can't figure out why the line and the text I ask it to output in the draw() function aren't showing up. If I delete the call of the main function, it works! Why can't I do both at the same time?
Code is below:
String[] lines;
PFont font; // Declaring the font variable
void setup() {
colorMode(HSB, 100); //Hue/Saturation/Brightness
size(800, 200);
background(100, 0, 100);
stroke(0);
strokeWeight(4);
fill(0);
font = loadFont("NewsGothicMT-13.vlw"); // Loads the font
textFont(font); // Sets "font" as the current font
// frameRate(300);
}
void draw() {
background(100, 0, 100);
textAlign(LEFT); textSize(11);
text("Created with Processing (www.processing.org)", 0,20);
String[] allFileLines = new String[lines.length]; //Creates string array for all lines of the converted file, for text file export
for (int i=0; i < lines.length*1; i++) { //Counts through each line of the tab-seperated table, starting with the 3rd
String pieces[] = split(lines[i], '\t');
if (i == 0) { //On first run only
println("This weather file has " + lines.length + " lines and " + pieces.length + " columns.");
}
for (int j=0; j < pieces.length; j++) { //Counts through each column of the tab-seperated table, starting with the 1st
if (pieces[j].equals("---")) { //If "No Data" is indicated in the weather file by three --- characters
pieces[j] = "-999"; //Changes all "No Data" entries to -999 for E+ Weather File Converter
}
if (pieces[j].equals("N")) {
pieces[j] = "0";
}
if (pieces[j].equals("NNE")) {
pieces[j] = "22.5";
}
if (pieces[j].equals("NE")) {
pieces[j] = "45";
}
if (pieces[j].equals("ENE")) {
pieces[j] = "67.5";
}
if (pieces[j].equals("E")) {
pieces[j] = "90";
}
if (pieces[j].equals("ESE")) {
pieces[j] = "112.5";
}
if (pieces[j].equals("SE")) {
pieces[j] = "135";
}
if (pieces[j].equals("SSE")) {
pieces[j] = "157.5";
}
if (pieces[j].equals("S")) {
pieces[j] = "180";
}
if (pieces[j].equals("SSW")) {
pieces[j] = "202.5";
}
if (pieces[j].equals("SW")) {
pieces[j] = "225";
}
if (pieces[j].equals("WSW")) {
pieces[j] = "247.5";
}
if (pieces[j].equals("W")) {
pieces[j] = "270";
}
if (pieces[j].equals("WNW")) {
pieces[j] = "292.5";
}
if (pieces[j].equals("NW")) {
pieces[j] = "315";
}
if (pieces[j].equals("NNW")) {
pieces[j] = "337.5";
}
} // Ends the counter that counts through columns
String fileLine = join(pieces, "\t"); //Joins the column pieces back into a single line of text, seperated by tabs
allFileLines[i] = fileLine; // Stores each line of the file into the string array
} // Ends the counter that counts through lines
int filepathLength = loadPath.length();
String newLoadpath = loadPath.substring(0, filepathLength-4); //Subtracts the .txt from the end of the original file name
saveStrings(newLoadpath + "CONVERTED.txt", allFileLines); //Exports the string array to the same directory as original file, with "CONVERTED.txt" appended
} //Ends the if statement that deals with whether a file was selected
println("File has been converted. Program will now exit.");
I'm a grad student writing my first Processing program, and I'm having trouble with some string manipulation.
Basically, I'm trying to find a way to use a FOR loop to take a string generated each time the loop runs and make it an element in another string array. After the FOR loop, I would then like to export that string array to a text file using the saveStrings command.
Can anybody help with a few lines of sample code that could accomplish this? I'd really appreciate it!!