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

  • Context: Fortran 
  • Thread starter Thread starter Milentije
  • Start date Start date
  • Tags Tags
    Array Fortran
Click For Summary

Discussion Overview

The discussion revolves around how to store values from iterative procedures in FORTRAN 90 using arrays. Participants are exploring the challenges of managing multiple arrays and iterations, particularly focusing on the allocation and storage of values for later calculations.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes needing to store 21 numerical values in an array for multiple models but is unclear on how to allocate these values for each iteration.
  • Another participant questions the meaning of "l(m0), l(m1)" and asks for clarification on the WRITE statement needed for output.
  • A participant provides a code snippet and expresses the need to allocate the array 'l' for use in subsequent calculations, indicating that the process repeats for each model.
  • One participant shares a loop structure intended to store values of 'l' for each iteration but notes that it does not work as expected, highlighting issues with the definition of 'nc' and the dimensions of the array.
  • A later reply reiterates the problem with the loop, pointing out that 'nc' is not defined and that there are inconsistencies in the dimensions of the arrays being used.

Areas of Agreement / Disagreement

Participants express differing levels of understanding regarding the problem, with some seeking clarification while others provide code-related insights. There is no consensus on the correct approach to storing the values across iterations.

Contextual Notes

There are unresolved issues regarding the definition of variables such as 'nc' and the dimensionality of the arrays involved. The discussion reflects uncertainty about the number of iterations and how to effectively manage array storage in the context of iterative procedures.

Milentije
Messages
47
Reaction score
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
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.
 
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.
 
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?
 
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.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
8K