Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8303501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:33:39+00:00 2026-06-08T17:33:39+00:00

Below is a block of code that does two things – the function readBCInputDataFromTextFile

  • 0

Below is a block of code that does two things – the function readBCInputDataFromTextFile reads in a text file, and stores the read data in the variable textData which is a string array (i.e, String[]) The array size is populated using the int variable numOfLines (again in function readBCInputDataFromTextFile). This function works perfectly.

the second thing that the code does (in function checkBCInput) – and which doesn’t work right now – is separate data using regular expresssions and store it in 4 “containers” (all of which are vectors): bcStringConstant, bcNameVec, bcTempVec & bcHTCVec.

Now my question is: how do I pass the variable textData to function checkBCInput. If I combine code from both functions into one single java file, the code works on execution. But this way of getting things to work isn’t very good – modularising suffers. Hence the need on my part to separate the code into two functions – one that reads a text file and passes the read contents to the second function, which using regex stores the read data into specific containers.

I tried returning textData from readBCInputDataFromTextFile, but that won’t work in the current simulation that I’m running. I also tried to pass the read data to checkBCInput – but that lead to another error message: “Cannot find symbol: Symbol textData”. The second method (shown in bold below) is going to work, but I can’t see the solution yet :-/

/*
 * inputReader
 * Last Revision: July 19, 2012.
 */
// package below is specific to software
package macro;

import java.util.*;
import java.text.*;
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

// Imports below are specific to the software
import star.base.neo.*;
import star.base.report.*;
import star.common.*;
import star.energy.*;
import star.flow.*;
import star.keturb.*;
import star.material.*;
import star.meshing.*;
import star.metrics.*;
import star.prismmesher.*;
import star.resurfacer.*;
import star.segregatedenergy.*;
import star.segregatedflow.*;
import star.solidmesher.*;
import star.trimmer.*;
import star.turbulence.*;
import star.vis.*;

// base class (StarMacro) is derived from software 
public class inputReader extends StarMacro {
/*************************************************** 
* 
* Global definitions
* 
***************************************************/
// Print output to screen?
int print_to_screen = 0;

// Variables to store BCs             

int noOfBounds = 0;
String inputBCTextFile = null;

Vector bcStringConstant = new Vector();
Vector bcNameVec = new Vector();
Vector bcTempValVec = new Vector();
Vector bcHTCValVec = new Vector();

public void execute(){
    // does nothing but function is required
}

public void readBCInputDataFromTextFile(String inputBCTextFile){

/*  
* READ INPUT FILE CONTENTS
*/

File dir = new File(System.getProperty("user.dir").toString() + File.separatorChar);  
if(print_to_screen == 0){
    sim.println("Directory where input text file is located: " + dir);
}
else{
    System.out.println("Directory where input text file is located: " + dir);
}

this.inputBCTextFile = inputBCTextFile;

if(print_to_screen == 0){
    sim.println("File name is: " + inputBCTextFile);
}
else{
    System.out.println("File name is: " + inputBCTextFile);
}


BufferedReader bf = null;        

try{
    bf = new BufferedReader(new FileReader(inputBCTextFile));

    if(print_to_screen == 0){
        sim.println("FILE EXISTS!!");
    }
    else{
        System.out.println("FILE EXISTS!!");
    }

}

catch (FileNotFoundException e){

    if(print_to_screen == 0){
        sim.println("FILE NOT FOUND!!!");
    }
    else{
        System.err.println("FILE NOT FOUND!!!");
    }

    e.printStackTrace();
}

int numOfLines = 0;
String aLine;

try{
    while (( aLine = bf.readLine()) != null){
        numOfLines++;
    }
} 
catch (IOException e){
    if(print_to_screen == 0){
        sim.println("FILE NOT READ => NUMBER OF LINES IN FILE SET TO NULL");
    }
    else{
        System.err.println("FILE NOT READ => NUMBER OF LINES IN FILE SET TO NULL");
    }
    e.printStackTrace();

}

try{
    bf.close();
}
catch (IOException e){
    if(print_to_screen == 0){
        sim.println("FILE NOT CLOSED PROPERLY!!!");
    }
    else{
        System.err.println("FILE NOT CLOSED PROPERLY!!!");
    }

    e.printStackTrace();
}
BufferedReader textReader = null;

try{
    textReader = new BufferedReader(new FileReader(inputBCTextFile));
    if(print_to_screen == 0){
        sim.println("READING INPUT DATA FROM TEXT FILE");
    }
    else{
        System.out.println("READING INPUT DATA FROM TEXT FILE");
    }

} 
catch (FileNotFoundException e){
    if(print_to_screen == 0){
        sim.println("FILE NOT FOUND!!!");
    }
    else{
        System.err.println("FILE NOT FOUND!!!");
    }

    e.printStackTrace();
}

String[] textData = new String[numOfLines];

try{
for (int i = 0; i < numOfLines; i++){
    textData[i] = textReader.readLine();
    }
}
catch (IOException e){
    if(print_to_screen == 0){
        sim.println("FILE NOT READ!!!");
    }
    else{
        System.err.println("FILE NOT READ!!");                
    }

    e.printStackTrace();
}

 **checkBCInput(textData);**

try{
    if(print_to_screen == 0){
        sim.println("FILE READ AND CLOSED");
    }
    else{
        System.out.println("FILE READ AND CLOSED");
    }

    textReader.close();
    }
catch (IOException e){
    if(print_to_screen == 0){
        sim.println("FILE NOT CLOSED PROPERLY!!!");
    }
    else{
        System.err.println("FILE NOT CLOSED PROPERLY!!!");
    }

    e.printStackTrace();
   }

 }

public void checkBCInput(String[] textData){
    Pattern inputBCTextFileData = Pattern.compile("(.*)\t(.*)\t-?((\\d+\\.\\d*|\\d*\\.\\d+)|\\d+)\t-?((\\d+\\.\\d*|\\d*\\.\\d+)|\\d+)");

for (int i =0; i < textData.length; i++){
    Matcher inputBCTextFileDataMatcher = inputBCTextFileData.matcher(textData[i]);

    if(inputBCTextFileDataMatcher.find()){
        // 1st match is variable name
            bcStringConstant.add(inputBCTextFileDataMatcher.group(1)); // this is the 1st column in the text file
        bcNameVec.add(inputBCTextFileDataMatcher.group(2));
        bcTempValVec.add(inputBCTextFileDataMatcher.group(4)); // gets numbers in decimal notation
        bcHTCValVec.add(inputBCTextFileDataMatcher.group(6)); // gets numbers in decimal notation
    }
 }

 }  

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:33:41+00:00Added an answer on June 8, 2026 at 5:33 pm

    I tried returning textData from readBCInputDataFromTextFile, but that
    won’t work in the current simulation that I’m running.

    Why not? Something like this should work:

    String[] textData = readBCInputDataFromTextFile(...);
    checkBCInput(textData);
    

    Then change the return type of readBCInputDataFromTextFile to String[] and add a return textData; at the end of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How exactly does the below code block work? More specifically, how does the program
In the below code, I want to understand what does the Collections.sort function is
I'm struggling with code that looks like the example below (but actually does something
The simple code block below can be served up in a static HTML page
I have the code block below, I deleted all unnecessary parts, just left the
I'd like to retrieve the image source within the below HTML code block, but
I am using the below code to block the taskbar which is working perfectly.
in the code below at first if statements block (there will be more than
The offending block of code is below. The code almost always works, but sometimes
I have a block of code below with a single line commented out. What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.