1

Imagine I have a model that generates cells and each year it generates a different amound of cells over the year. Each end of the year I want to catch all existing cells and properties in a 3-d array with information on the year, the postition of the cell, and some other properties, so let's say 3 columns

I have n numbers of years, something which I do know at the beginning, let's say I have 10 years

I do not know how many cells there are until the end of the year, so this is variable.

,,'year 1']
   [,1][,2][,3]
[1]
[2]
[..]
[?]

[,,'year 2']
   [,1][,2][,3]
[1]
[2]
[..]

I am wondering how I can best dynamically create and apend to the first dimension of this array?!

I have all the end of the year information I need at the, currently located in vectors (eg.): [,1] - is easy, that would contain the year , e.g. 2009

Tor the cell properties, I fill this in this by looping through the different vectors that contain those properties and put them into the

     [,1]  [,2][,3]
[1] 2009

with

[,2] - the position of the cell , taken from a pos_cell array at i =1
[,3] - a property of the cell, taken from the prop_cell array at i =1

so we have:

     [,1]  [,2]  [,3]
[1] 2009   1     0.4

Now,

with

[,2] - the position of the cell , taken from a pos_cell array at i =2
[,3] - a property of the cell, taken from the prop_cell array at i =2

     [,1]  [,2]  [,3]
[1] 2009   1     0.40
[2] 2009   2     0.44

I don't think this all is the most efficient way of doing it. Currently I just need something that works a bit better than what I am currently working with, which is an array that has 3 pre-defined dimensions, because I am constantly hitting new max values for the first dimension.

I was thinking of something along the lines like this:

How to add new element to dynamical array in Fortran90

But I am not sure it is actually allowed to have different dimensions, and is this a good way forward? But firstly, how would I start going about it?

I have looked at

https://libatoms.github.io/QUIP/table.html but this is too new and only for 2D

I am using Fortran 90.

Oh and please don't tell me how it could be done better in a newer fortran. In other forum's entries on this subject people had the tendency to not answer the question, but simply say how it could be done with new fortran versions. Looking forward to your suggestions.

  • Please use [tag:fortran] for all Fortran questions. Fortran 90 is just one old and obsolete version. – Vladimir F Героям слава Mar 15 '18 at 16:09
  • Done. Unfortunately I am using fortran 90.. – Annemarie Eckes Mar 15 '18 at 16:12
  • From your title it appears to me you want jagged arrays. These do not exist in Fortran. See https://stackoverflow.com/questions/8557106/allocate-dynamic-array-with-interdependent-dimensions and https://stackoverflow.com/questions/14857366/are-there-any-problems-with-using-jagged-arrays-in-fortran-with-multiple-levels and other related questions and answers. – Vladimir F Героям слава Mar 15 '18 at 16:13
  • 2
    Many people think that they are using Fortran 90 when actually they are not. There are even no Fortran 90 comppilers available, all of them are at least Fortran 95. Notable, file name `.f90` does NOT mean Fortran 90. It can be Fortran 2008 or 2018 or whatever. – Vladimir F Героям слава Mar 15 '18 at 16:15
  • I didn't know that..What cues in my code could help me find out what fortran I actually have? – Annemarie Eckes Mar 15 '18 at 16:17
  • Thanks! 'jagged array' was probably the keyword that I was unaware of! (: – Annemarie Eckes Mar 15 '18 at 16:23
  • Actually, my own answer to https://stackoverflow.com/questions/18316592/multidimensional-array-with-different-lengths/18316726 might be a more apposite dupe. But I can't dupe-hammer this twice. – High Performance Mark Mar 15 '18 at 16:31
  • Re the standard version. It is not that much important, but there are options like `gfortran -std=f95` or `gfortran -std=f2003` and you can try which is the lowest standard your code will compile with. But really, not too important now or here. – Vladimir F Героям слава Mar 15 '18 at 16:31
  • Thanks thanks @HighPerformanceMark. I think I am struggling the most is the dynamically allocating the different lengths at runtime. I don't know one of the dimensions at the beginning. I am a super novice and maybe I don't even see that your answer contains my needed information? I think I am looking for a procedure ( that I can make a subroutine) that creates/shapes this array type rather dynamically. – Annemarie Eckes Mar 15 '18 at 16:43
  • I repeat, these arrays do NOT exist in Fortran. You have to make some similar structures manually. It will not be a simple array and there is no procedure to be used, you must do everything yourself. It is not f9r beginners at all. Did you read the links I or Mark gave you, they say the same. It does not exist, you must make it yourself and it is not that simple. – Vladimir F Героям слава Mar 15 '18 at 16:47
  • Yes. I understand, thanks @Vladimir. breaking down the problem, I need a procedure that appends my 1st dimension, like the one mentioned in https://stackoverflow.com/questions/28048508/how-to-add-new-element-to-dynamical-array-in-fortran90 which I mentioned above. Anyways, thanks for pointing me into new directions, I will take it from here I gues.. – Annemarie Eckes Mar 15 '18 at 16:52

0 Answers0