How can I store values for every iteration in FORTRAN 90 using arrays?

In summary, the conversation discusses an issue with writing numerical values into arrays and using iteration to calculate values for model 2. The speaker is seeking advice on how to write l(m0), l(m1) and how to allocate and store l for every iteration. They have attempted a loop but it is not working due to inconsistencies in array dimensions.
  • #1
Milentije
48
0
Well the issue here is that I will have 21 numerical values written into one array,but then goes iterative procedure and get 21 values for model 2.How to write l(m0),l(m1)?I will need these arrays later for calculations.
 
Technology news on Phys.org
  • #2
I don't understand what you're asking. It looks like you have two arrays, each with 21 values. What do you mean "how to write l(m0), l(m1)"? What are m0 and m1? Are you asking about what sort of WRITE statement you need to use? If so, show us the kind of output you are trying to get.
 
  • #3
Well the problem is iteration,how to allocate l.Part of the code:
call version3_solve_mt2d_directsens
dmfnorm= (sum(dmf(1:20,1:4)**2))
write(*,*)dmfnorm
rewind(214)
call readsens
ist=transpose(sens)
rewind(17)
call readwd
wd2=matmul(wd,wd)
ftw=matmul(ist,wd2)
p=matmul(ftw,dmf)
rewind(18)
call readwm
wm2=matmul(wm,wm)
wm3=alpha*wm2
rewind(222)
call deltard
q=matmul(wm3,dlm)
l=p+q
This will repeat for every model but I need to allocate l,and to use it later.
 
  • #4
do i=1,iter
l(nc)=l(nc,iter)
end do
I tried the above but it doesn't work.l is vector dimension 21,every iteration gives me l.I do not know the number of iterations.How to store l for every iteration?
 
  • #5
Milentije said:
do i=1,iter
l(nc)=l(nc,iter)
end do
I tried the above but it doesn't work.l is vector dimension 21,every iteration gives me l.I do not know the number of iterations.How to store l for every iteration?

In the loop above, the loop counter is i. nc is not defined and is not a function of i. You appear to have one single dimensional array l and a two dimensional array, also called l. Arrays must have consistent dimensions. Until you work out these problems, your program will not work.
 

What is an array in FORTRAN 90?

An array in FORTRAN 90 is a data structure that allows you to store multiple values of the same type in a single variable. It is declared using the DIMENSION statement and can be used to efficiently handle large sets of data.

How do you declare an array in FORTRAN 90?

To declare an array in FORTRAN 90, you need to use the DIMENSION statement followed by the name of the array and the number of elements in each dimension. For example, DIMENSION array(10) would declare an array with 10 elements.

What is the difference between a one-dimensional and multi-dimensional array in FORTRAN 90?

A one-dimensional array in FORTRAN 90 is a simple list of elements, while a multi-dimensional array is an array of arrays. This means that a multi-dimensional array can store data in a table-like structure with rows and columns.

How do you access elements in an array in FORTRAN 90?

In FORTRAN 90, elements in an array are accessed using their index numbers. The first element in a one-dimensional array has an index of 1, while the first element in a multi-dimensional array has an index of (1,1). For example, to access the third element in a one-dimensional array, you would use array(3).

What are some common problems when working with arrays in FORTRAN 90?

Some common problems that can occur when working with arrays in FORTRAN 90 include out-of-bounds errors, where you try to access an element that does not exist, and errors in array dimensions, where the array is not declared with the correct number of elements. It is important to carefully declare and access arrays in order to avoid these types of errors.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
7
Views
3K
  • Programming and Computer Science
Replies
21
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
Back
Top