Fortran Help with declaring arrays in Fortran 90/95

  • Thread starter Thread starter warfreak131
  • Start date Start date
  • Tags Tags
    Arrays Fortran
AI Thread Summary
To calculate the least squares fit line for a user-defined number of points in Fortran, it's essential to use allocatable arrays instead of fixed-size arrays. The initial approach of declaring a fixed-size array based on user input leads to errors, as Fortran requires variable declarations before any read/write operations. By utilizing allocatable arrays, you can dynamically allocate the necessary memory after determining the number of points the user wishes to input. This method resolves the issue of needing to know the size of the arrays beforehand and adheres to Fortran's requirements for variable declarations.
warfreak131
Messages
186
Reaction score
0
I have an assignment to calculate the least squares fit line to a set of points, and I have to read in an arbitrary number of points from the user

So my plan was to have the user enter how many elements they have, and then create an array with that many elements. So let's say I read the value N from the user, and then create an array like:

Code:
real, dimension(N) :: xvals, yvals

But that's a no-no according to fortran. If any read/write statement goes before declaring the variables, I get a whole host of errors. However, if I remove those read/write statements and create a set number of array elements like:

Code:
real, dimension(10) :: xvals, yvals

then all the error go away. Unfortunately, I have to find out how many variables the user wants before creating the array.
 
Technology news on Phys.org
You need to learn how to use allocatable arrays. Googe it and learn the syntax. It is pretty easy.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
4
Views
2K
Replies
2
Views
2K
Replies
4
Views
2K
Replies
13
Views
3K
Replies
13
Views
2K
Replies
5
Views
9K
Replies
5
Views
4K
Replies
19
Views
6K
Back
Top