Reading data from a table file

In summary, the conversation discusses the task of using Fortran to read a text file containing data on people's names, age, height, and weight. The goal is to have Fortran only read the data for specific names and assign them to specific variables. The person seeking help has attempted various do loops and if statements but has not been successful. They request assistance and provide a suggested approach for accomplishing the task.
  • #1
Arez
1
0
Hello
I am very new to programming and fortran. I have a text file formatted the following way:

Name Peter John Sally Joseph Luke Vader etc...
age XXXX XXXX XXXX XXXX XXXX XXXX XXXX
height XXXX XXXX XXXX XXXX XXXX XXXX XXXX
weigh XXXX XXXX XXXX XXXX XXXX XXXX XXXX
etc...​

I want fortran to only read the data of the people I ask him to. If I ask for Luke and Sally, I want him to return their respective age, height and weight while assigning them to specific variables.

I have played around with various do loops with if statements but I can't get it to work properly... I don't know how to do this. Can anyone help ?

Thank you
 
Last edited:
Technology news on Phys.org
  • #2
It would help if you showed what you have attempted so far. Please use the code tags for your code also.
 
  • #3
You could also provide the steps you think need to be done in plain english to accomplish the task.

Code:
0 ask for names you want to report on
1 open file
2 read line
3 if line starts with name ...
 
  • Like
Likes Logical Dog

Related to Reading data from a table file

1. How do I read data from a table file?

To read data from a table file, you will need to use a programming language or tool that has the capability to read and manipulate data. Some examples include Python, R, Excel, or SQL. You will need to specify the location and format of the table file in your code and use functions or commands to read and access the data within the file.

2. What is the most common format for a table file?

The most common format for a table file is a comma-separated values (CSV) file. This means that the data is organized into rows and columns, with each value separated by a comma. Other common formats include tab-delimited, space-delimited, and Excel files.

3. How can I ensure that the data is read correctly from the table file?

To ensure that the data is read correctly from the table file, it is important to check the file format and structure. Make sure that the column headers and data types are correct, and that there are no missing or extra rows or columns. It is also helpful to preview the data in a spreadsheet or text editor before reading it into your program.

4. Can I read specific rows or columns from a table file?

Yes, most programming languages and tools have functions or commands that allow you to specify which rows or columns of data you want to read from a table file. This can be done based on index numbers or by using conditional statements to filter the data.

5. How do I handle missing or incorrect data in the table file?

This will depend on your specific needs and the capabilities of your programming language or tool. Some options for handling missing or incorrect data include removing those rows or columns from the data set, replacing the missing values with a placeholder, or using statistical methods to impute the missing data. It is important to carefully consider the impact of these choices on your analysis or research.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
2
Views
928
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
4
Views
769
  • Programming and Computer Science
Replies
22
Views
3K
Back
Top