In my computational methods class, our homework problems are given as Python scripts, however my instructor said as long as we can translate them into our language of choice, we can solve them in our language of choice. I am trying to learn Fortran, so that is what I chose.
In one of our problems, the setup contains a list of lists of strings, like such:
q = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', h']]
When trying to rewrite this, I ran into a problem. Ususally, I'd define a type like character, however the values stored in each spot aren't characters, they're whole other arrays. My first thought was doing something like:
character(1) :: letters(3), arr1(3), arr2(3), arr3(2)
arr1 = ['a', 'b', 'c']
arr2 = ['d', 'e', 'f']
arr3 = ['g', 'h']
letters(1) = [arr1, arr2, arr3]
and so on. This however does not work as letters does not expect three arrays, rather three characters.
How could I go about nesting arrays inside letters? I need to do this because the problem has us indexing the arrays inside.
You would have to do it as an array of a derived type containing an allocatable array of characters. Fortran doesn't have the concept of an array of arrays.
Here's an example: