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

  • SEARCH
  • Home
  • 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 6803839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:23:35+00:00 2026-05-26T19:23:35+00:00

I have been required to write a function that reads the BSDF data format

  • 0

I have been required to write a function that reads the BSDF data format defined by Zemax
An example of such file can be found at the following page: BSDF file example

I would like to use, if possible, only standard ifstream functions.

I have already prepared all the necessary datamembers inside a dedicated class.

I am now trying to write the function that reads the data from the file.

Problems:

  • how do I exclude comment lines? as documented, they start with an hash # I was going for something like

    void ReadBSDFFile(myclass &object)
    {
    ifstream infile;
    
    infile.open(object.BRDFfilename);
    
    char c;
    infile.get(c);
    while (c == "#") // Problem, apparently I cannot compare in this way. How should I do it?
    {
       getline(infile, line);
       infile.get(c);
    }
    // at this point I would like to go back one character (because I do not want to lose the non-hash character that ended up in *c*)
    infile.seekg(-1, ios_base::cur);
    
    // Do all the rest
    
    infile.close();
    }
    
  • in a similar way, I would like to verify that I am at the correct line later on (e.g. the “AngleOfIncidence” line). Could I do it in this way?

    string AngleInc;
    
    infile >> AngleInc;
    
    if (AngleInc != "AngleOfIncidence")
    {
       //error
    }
    

Thanks to anyone who will comment/help. Constructive criticism is welcomed.

Federico

EDIT:

Thanks to Joachim Pileborg below, I managed to proceed up to the data blocks part of the file.

Now I have the following problem. When reaching the datablocks, I wrote the following piece of code, but at the second iteration (i = 1) i receive the error message for the TIS line.
Could someone help me understand why this does not work?
Thanks

Note: blocks is the number on the AngleOfIncidence line, rows the one on the ScatterAzimuth line and columns the one on the ScatterRadial. I tested and verified that this part of the function works as desired.

// now reading the data blocks.

for (int i=0; i<blocks; i++)
{
    // TIS line
    getline(infile, line);
    if (line.find("TIS") == string::npos)
    {
        // if not, error message
    }

    // Data block
    for (int j=0; j<rows; j++)
    {
        for (int k=0; k<columns; k++)
        {
            infile >> object.BRDFData[i][j][k];
        }
    }
}

EDIT 2:

solved adding infile.seekg(+2, ios_base::cur); as a last line of the i loop.

  • 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-05-26T19:23:36+00:00Added an answer on May 26, 2026 at 7:23 pm

    The reading loop could be simplified like this:

    std::string line;
    while (getline(infile, line))
    {
        if (line[0] != '#')
        {
            // Not a comment, do something with the line
            if (line.find("AngleOfIncidence") != std::string::npos)
            {
                // On the AngleOfIncidence line, do special things here
            }
        }
    }
    

    It’s might not be optimal, just something written at the top of my head, but should work.

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

Sidebar

Related Questions

I have been given a specification that requires the ISO 8601 date format, does
Background I have been asked to write a script that will create a vertical
When evaluating dojo.require statements, dojo tracks which modules and resources have been required and
I have been using XSL-FO and FOP Engine to generate PDF documents for required
Have been looking at the MVC storefront and see that IQueryable is returned from
Have been studying the file system related classes of Adobe AIR 1.5, but so
Please suppose I have a function that accepts a pointer as a parameter. This
I am jQuery newbie and I have been trying to set up a file
I know there have been posts that are almost the same thing I have
I have been developing an app in VB.NET which requires a control object (for

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.