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 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

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