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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

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
3K
Replies
19
Views
6K
Back
Top