Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the name of an array from a string

Status
Not open for further replies.

usermg

Programmer
Jul 2, 2014
6
ES
Hello everybody,

I have a question related to fortran 90. I have a subroutine named for instance f1 that needs an array 'a' (defined as double precision) and gives some output. That is ----> f1(a,output).

Now, imagine that I would like to call the subroutine f1, but giving the name of the array 'a' from a string. For example, imagine that I have three arrays named 'array1', 'array2' and 'array_test' and at a given stage of the program I create a string named 'array1' and I try that the subroutine gets it as the double percision array (array1). I think there should be some way to do it, but as I am sure that someone, a part from me, should have thought on this question, I would appreciate if you could give me a posible solution.

Thank you very much in advance
 
But why cannot you use simple subroutine arguments like
Code:
subroutine do_with_array(my_array)
  ...
end subroutine do_with_array
and than call it with your arrays
Code:
if (my_string .eq. 'array1') then 
  call do_with_array(array1)
else if (my_string .eq. 'array2') then
  call do_with_array(array2)
...
 
Or, the same thing, but...if the subroutine is contained inside a module where the arrays have been declared and, thus, are readily available inside the subroutine, you can pass the string and put the above if-then-else clause inside the subroutine (not identical, but very similar one).
 
Thanks guys. 'Mikrom', what you propose is what I did from the beginning. The problem is that I want to avoid using 'if' statements, as the whole program consumes lot of memory. This is why I want to create the string. For instance, if my arrays are called array1, array2, array3, and array4, and, for example, in a do loop, I am at i=3 (at this stage I would like to use array3), I could create first a string called 'array', concatenate it with i=3 to obtain the string 'array3' and then pass it to the subroutine. I would like to know if it is possible. This is my particular question. Of course, that I have other solutions like those you have proposed with the if statements, but I would like to avoi using them.

Many thanks in advance
 
usermg said:
The problem is that I want to avoid using 'if' statements, as the whole program consumes lot of memory.
IMO if it will not be more memory consuming when you add some IF-logic.

usermg said:
... I want to create the string ...
For instance, if my arrays are called array1, array2, array3, and array4, and, for example, in a do loop, I am at i=3 (at this stage I would like to use array3), I could create first a string called 'array', concatenate it with i=3 to obtain the string 'array3' and then pass it to the subroutine.
Of course you can create the string and pass it to the procedure but you will still need the IF logic in the procedure, for example you can declare a subroutine which argument ist the string:

Code:
subroutine process_arrays(my_string)
character(*), intent(in) :: my_string
if (my_string .eq. 'array1') then 
  call do_with_array(array1)
else if (my_string .eq. 'array2') then
  call do_with_array(array2)
...
end subroutine process_arrays

and then in your main program create the string and then call the subroutine like this
Code:
! TODO create string ARR_NAME which contains 
! the array name (array name + stage number)
..
! call the procedure
call process_arrays(ARR_NAME)
 
Well, when I said memory consuming I just referred to time consuming (sorry). When 'if statements' are present, there is an evaluation to choose the condition and it makes the caluclations to go slower, this is why I wanted to avoid if statements in this case. However, I have found a way, playing with 'goto' to go faster.

Thanks you very much for your fast answers. I like to enter this forum to share things with programmers
 
Goto?...come on...this is highly discourage.

By the way, if you think that an "if" evaluation is time consuming, you should check how long the string concatenation operation takes.

Another thing I would suggest doing is simply to create a short array of pointers and have them point to the beginning of each of the arrays:

arrptr(1) => array1(1)
arrptr(2) => array2(1)
arrptr(3) => array3(1)
arrptr(4) => array4(1)

then, getting back to your loop, you don't need an 'if' statement and you can simply use the loop variable:

do i = 1,4
do_with_array( arrptr(i) )
end do

 
Thanks salgerman for your suggestion. In fact, in my case, I have arrays defined such as 'array1:),:)', 'array2:),:)', 'array3:),:)'.... which I allocate during the program. I have tried to create a short array of pointers pointing to the first element of each of these matrices, but it seems to fail (I have tried different ways to write the assignation =>). I do not know if, in this case, it is still possible to do what you suggested to me (I like the whole idea, so I wanted to ask to you if I could be doing something wrong during the way).

Thanks
 
This works in gfortran, but I'm not sure if it's what you want
Code:
[COLOR=#a020f0]module[/color] arrays
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
  [COLOR=#0000ff]! type pointer on matrix[/color]
  [COLOR=#2e8b57][b]type[/b][/color] pmatrix
[COLOR=#2e8b57][b]      real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:,:), [COLOR=#2e8b57][b]pointer[/b][/color] :: ptr
  [COLOR=#2e8b57][b]end type[/b][/color] pmatrix
  [COLOR=#0000ff]! array of pointers on matrix[/color]
  [COLOR=#2e8b57][b]type[/b][/color](pmatrix), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]pointer[/b][/color]::  pointers 

[COLOR=#a020f0]contains[/color]
  [COLOR=#a020f0]subroutine[/color] print_matrix(mat)
[COLOR=#2e8b57][b]    real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:,:) :: mat
    [COLOR=#2e8b57][b]integer[/b][/color] :: n, i, j
    n [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]size[/color](mat, [COLOR=#ff00ff]1[/color])
    [COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n
      [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) mat(i,:)
    [COLOR=#804040][b]end do[/b][/color]
    [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])
  [COLOR=#a020f0]end subroutine[/color] print_matrix
[COLOR=#a020f0]end module[/color] arrays

[COLOR=#a020f0]program[/color] array_pointers
  [COLOR=#a020f0]use[/color] arrays
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
[COLOR=#2e8b57][b]  real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:,:), [COLOR=#2e8b57][b]allocatable[/b][/color], [COLOR=#2e8b57][b]target[/b][/color] :: matrix
  [COLOR=#2e8b57][b]integer[/b][/color], [COLOR=#2e8b57][b]parameter[/b][/color] :: N [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]4[/color]
  [COLOR=#2e8b57][b]integer[/b][/color] :: i

  [COLOR=#804040][b]allocate[/b][/color](pointers(N))

  [COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], N
    [COLOR=#0000ff]! allocate array[/color]
    [COLOR=#804040][b]allocate[/b][/color](matrix(i,i))

    [COLOR=#0000ff]! set the values[/color]
    matrix [COLOR=#804040][b]=[/b][/color] i
    
    [COLOR=#0000ff]! set pointer to the array[/color]
    pointers(i)%ptr [COLOR=#804040][b]=>[/b][/color] matrix

    [COLOR=#0000ff]! print resulting array[/color]
    [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'array of dimension'[/color], i
    [COLOR=#008080]call[/color] print_matrix(pointers(i)%ptr)

    [COLOR=#0000ff]! deallocate array[/color]
    [COLOR=#804040][b]deallocate[/b][/color](matrix)
  [COLOR=#804040][b]end do[/b][/color]
[COLOR=#a020f0]end program[/color] array_pointers

Output:
Code:
$ gfortran array_pointers.f95 -o array_pointers

$ array_pointers
 array of dimension           1
   1.00000000

 array of dimension           2
   2.00000000       2.00000000
   2.00000000       2.00000000

 array of dimension           3
   3.00000000       3.00000000       3.00000000
   3.00000000       3.00000000       3.00000000
   3.00000000       3.00000000       3.00000000

 array of dimension           4
   4.00000000       4.00000000       4.00000000       4.00000000
   4.00000000       4.00000000       4.00000000       4.00000000
   4.00000000       4.00000000       4.00000000       4.00000000
   4.00000000       4.00000000       4.00000000       4.00000000
 
I don't think that what is shown in the previous post is what is being requested, after all, those matrices do not even co-exist.

In any case, I'll be honest...I think I spoke too soon, as I am yet to use pointers in Fortran. I was just thinking back to my C days where you could get a pointer point to a spot in memory and pass that address around.

A little googling and, apparently, that is not the case in Fortran; in Fortran, for some reason, the pointer needs to be the same rank as the target.

So, I tried to do something similar to what mikrom shows and while I was able to have the matrices co-exist and display them one a time with separate calls to the subroutine, I started to get an error as soon as I tried to display them with the same, single subroutine call within a DO-loop...things got fixed as soon as I added an interface to the subroutine...go figure.

Here is the approach:
[ul]
[li]Declare (target) 2D matrices to process[/li]
[li]Define a derived type containing a single 2D-matrix pointer[/li]
[li]Declare 1D-array variable of the derived type[/li]
[li]Define an interface to the processing subroutine[/li]
[/ul]

Here is the source code:
Code:
program p123
  integer i
  real, target, dimension(3,3) :: arr1, arr2, arr3
  
  type d2
    real, pointer, dimension(:,:) :: ptr
  end type
  type(d2), dimension(3) :: parr

  interface display
    subroutine arrdisp(a)
      real, dimension(:,:) :: a
    end subroutine arrdisp
  end interface
  
  data arr1/ 1, 2, 3, 4, 5, 6, 7, 8, 9/
  data arr2/11,12,13,14,15,16,17,18,19/
  data arr3/21,22,23,24,25,26,27,28,29/
    
  parr(1)%ptr => arr1
  parr(2)%ptr => arr2
  parr(3)%ptr => arr3
  
  do i = 1,3
    call display( parr(i)%ptr )
  end do
  
end program p123

subroutine arrdisp(a)
    real, dimension(:,:) :: a
    write(*,'(3f5.1)') ((a(i,j),j=1,3),i=1,3)
    write(*,*)
end subroutine arrdisp
Results:
Code:
  1.0  4.0  7.0
  2.0  5.0  8.0
  3.0  6.0  9.0

 11.0 14.0 17.0
 12.0 15.0 18.0
 13.0 16.0 19.0

 21.0 24.0 27.0
 22.0 25.0 28.0
 23.0 26.0 29.0

Needless to say, my data blocks initialize the matrices column-wise as Fortran internal storage scheme is column-major.





 
salgerman said:
I don't think that what is shown in the previous post is what is being requested, after all, those matrices do not even co-exist.
There is no problem with coexisting matrices, it's similar I need only a little bit modify the code:

Code:
[COLOR=#a020f0]module[/color] arrays
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
  [COLOR=#0000ff]! type pointer on matrix[/color]
  [COLOR=#2e8b57][b]type[/b][/color] pmatrix
[COLOR=#2e8b57][b]      real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:,:), [COLOR=#2e8b57][b]pointer[/b][/color] :: ptr
  [COLOR=#2e8b57][b]end type[/b][/color] pmatrix
  [COLOR=#0000ff]! array of pointers on matrix[/color]
  [COLOR=#2e8b57][b]type[/b][/color](pmatrix), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]pointer[/b][/color]::  pointers 

[COLOR=#a020f0]contains[/color]
  [COLOR=#a020f0]subroutine[/color] print_matrix(mat)
[COLOR=#2e8b57][b]    real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:,:) :: mat
    [COLOR=#2e8b57][b]integer[/b][/color] :: n, i, j
    n [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]size[/color](mat, [COLOR=#ff00ff]1[/color])
    [COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n
      [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) mat(i,:)
    [COLOR=#804040][b]end do[/b][/color]
    [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])
  [COLOR=#a020f0]end subroutine[/color] print_matrix
[COLOR=#a020f0]end module[/color] arrays

[COLOR=#a020f0]program[/color] array_pointers
  [COLOR=#a020f0]use[/color] arrays
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
[COLOR=#2e8b57][b]  real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:,:), [COLOR=#2e8b57][b]allocatable[/b][/color], [COLOR=#2e8b57][b]target[/b][/color] :: m1, m2, m3, m4
  [COLOR=#2e8b57][b]integer[/b][/color], [COLOR=#2e8b57][b]parameter[/b][/color] :: N [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]4[/color]
  [COLOR=#2e8b57][b]integer[/b][/color] :: i

  [COLOR=#804040][b]allocate[/b][/color](pointers(N))

  [COLOR=#0000ff]! allocate arrays[/color]
  [COLOR=#804040][b]allocate[/b][/color](m1([COLOR=#ff00ff]1[/color],[COLOR=#ff00ff]1[/color]))
  [COLOR=#804040][b]allocate[/b][/color](m2([COLOR=#ff00ff]2[/color],[COLOR=#ff00ff]2[/color]))
  [COLOR=#804040][b]allocate[/b][/color](m3([COLOR=#ff00ff]3[/color],[COLOR=#ff00ff]3[/color]))
  [COLOR=#804040][b]allocate[/b][/color](m4([COLOR=#ff00ff]4[/color],[COLOR=#ff00ff]4[/color]))

  [COLOR=#0000ff]! set the values[/color]
  m1 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]1[/color]
  m2 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]2[/color]
  m3 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]3[/color]
  m4 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]4[/color]
    
  [COLOR=#0000ff]! set pointers to the arrays[/color]
  pointers([COLOR=#ff00ff]1[/color])%ptr [COLOR=#804040][b]=>[/b][/color] m1
  pointers([COLOR=#ff00ff]2[/color])%ptr [COLOR=#804040][b]=>[/b][/color] m2
  pointers([COLOR=#ff00ff]3[/color])%ptr [COLOR=#804040][b]=>[/b][/color] m3
  pointers([COLOR=#ff00ff]4[/color])%ptr [COLOR=#804040][b]=>[/b][/color] m4

  [COLOR=#0000ff]! process arrays[/color]
  [COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], N
    [COLOR=#0000ff]! print resulting array[/color]
    [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'array of dimension'[/color], i
    [COLOR=#008080]call[/color] print_matrix(pointers(i)%ptr)
  [COLOR=#804040][b]end do[/b][/color]

  [COLOR=#0000ff]! deallocate arrays[/color]
  [COLOR=#804040][b]deallocate[/b][/color](m1)
  [COLOR=#804040][b]deallocate[/b][/color](m2)
  [COLOR=#804040][b]deallocate[/b][/color](m3)
  [COLOR=#804040][b]deallocate[/b][/color](m4)
[COLOR=#a020f0]end program[/color] array_pointers

Output:
Code:
$ gfortran array_pointers.f95 -o array_pointers

$ array_pointers
 array of dimension           1
   1.00000000

 array of dimension           2
   2.00000000       2.00000000
   2.00000000       2.00000000

 array of dimension           3
   3.00000000       3.00000000       3.00000000
   3.00000000       3.00000000       3.00000000
   3.00000000       3.00000000       3.00000000

 array of dimension           4
   4.00000000       4.00000000       4.00000000       4.00000000
   4.00000000       4.00000000       4.00000000       4.00000000
   4.00000000       4.00000000       4.00000000       4.00000000
   4.00000000       4.00000000       4.00000000       4.00000000
 
Good.

While I am using Fortran 90 features with the pointer and the explicit interface, let's go ahead and truly do it the proper Fortran 90 style of using a module as mikrom does. The thing is that modules do a bit more than simply grouping stuff, as shown by the two programs above...mine without module needs an explicit interface, mikrom's with a module does not need an explicit interface...it is provided by the module, behind the scenes, as a free service.
 
Yes sal, you are right.
Although I do not know detailed technical differences between using of modules and not using them, but I have learned that using them can save me a lot of troubles :)

 
If somebody don't want to have module of any reason, then using CONTAINS in the program is other way to go - like this:

Code:
[COLOR=#a020f0]program[/color] array_pointers2
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
  [COLOR=#0000ff]! type pointer on matrix[/color]
  [COLOR=#2e8b57][b]type[/b][/color] pmatrix
[COLOR=#2e8b57][b]      real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:,:), [COLOR=#2e8b57][b]pointer[/b][/color] :: ptr
  [COLOR=#2e8b57][b]end type[/b][/color] pmatrix
  [COLOR=#0000ff]! array of pointers on matrix[/color]
  [COLOR=#2e8b57][b]type[/b][/color](pmatrix), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]pointer[/b][/color]::  pointers 
  [COLOR=#0000ff]![/color]
[COLOR=#2e8b57][b]  real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:,:), [COLOR=#2e8b57][b]allocatable[/b][/color], [COLOR=#2e8b57][b]target[/b][/color] :: m1, m2, m3, m4
  [COLOR=#2e8b57][b]integer[/b][/color], [COLOR=#2e8b57][b]parameter[/b][/color] :: N [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]4[/color]
  [COLOR=#2e8b57][b]integer[/b][/color] :: i

  [COLOR=#804040][b]allocate[/b][/color](pointers(N))

  [COLOR=#0000ff]! allocate arrays[/color]
  [COLOR=#804040][b]allocate[/b][/color](m1([COLOR=#ff00ff]1[/color],[COLOR=#ff00ff]1[/color]))
  [COLOR=#804040][b]allocate[/b][/color](m2([COLOR=#ff00ff]2[/color],[COLOR=#ff00ff]2[/color]))
  [COLOR=#804040][b]allocate[/b][/color](m3([COLOR=#ff00ff]3[/color],[COLOR=#ff00ff]3[/color]))
  [COLOR=#804040][b]allocate[/b][/color](m4([COLOR=#ff00ff]4[/color],[COLOR=#ff00ff]4[/color]))

  [COLOR=#0000ff]! set the values[/color]
  m1 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]1[/color]
  m2 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]2[/color]
  m3 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]3[/color]
  m4 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]4[/color]
    
  [COLOR=#0000ff]! set pointers to the arrays[/color]
  pointers([COLOR=#ff00ff]1[/color])%ptr [COLOR=#804040][b]=>[/b][/color] m1
  pointers([COLOR=#ff00ff]2[/color])%ptr [COLOR=#804040][b]=>[/b][/color] m2
  pointers([COLOR=#ff00ff]3[/color])%ptr [COLOR=#804040][b]=>[/b][/color] m3
  pointers([COLOR=#ff00ff]4[/color])%ptr [COLOR=#804040][b]=>[/b][/color] m4

  [COLOR=#0000ff]! process arrays[/color]
  [COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], N
    [COLOR=#0000ff]! print resulting array[/color]
    [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'array of dimension'[/color], i
    [COLOR=#008080]call[/color] print_matrix(pointers(i)%ptr)
  [COLOR=#804040][b]end do[/b][/color]

  [COLOR=#0000ff]! deallocate arrays[/color]
  [COLOR=#804040][b]deallocate[/b][/color](m1)
  [COLOR=#804040][b]deallocate[/b][/color](m2)
  [COLOR=#804040][b]deallocate[/b][/color](m3)
  [COLOR=#804040][b]deallocate[/b][/color](m4)

[COLOR=#a020f0]contains[/color]
  [COLOR=#a020f0]subroutine[/color] print_matrix(mat)
[COLOR=#2e8b57][b]    real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:,:) :: mat
    [COLOR=#2e8b57][b]integer[/b][/color] :: n, i, j
    n [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]size[/color](mat, [COLOR=#ff00ff]1[/color])
    [COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n
      [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) mat(i,:)
    [COLOR=#804040][b]end do[/b][/color]
    [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])
  [COLOR=#a020f0]end subroutine[/color] print_matrix
[COLOR=#a020f0]end program[/color] array_pointers2

Code:
$ gfortran array_pointers2.f95 -o array_pointers2

$ array_pointers2
 array of dimension           1
   1.00000000

 array of dimension           2
   2.00000000       2.00000000
   2.00000000       2.00000000

 array of dimension           3
   3.00000000       3.00000000       3.00000000
   3.00000000       3.00000000       3.00000000
   3.00000000       3.00000000       3.00000000

 array of dimension           4
   4.00000000       4.00000000       4.00000000       4.00000000
   4.00000000       4.00000000       4.00000000       4.00000000
   4.00000000       4.00000000       4.00000000       4.00000000
   4.00000000       4.00000000       4.00000000       4.00000000

 
Hello everyone. Excuse me because I have been abroad for three days and was just able to look at the e-mail thorugh the mobile phone. I understand the idea of your codes, and they work. However, I will maybe end by using another time the if statements. My problem is that the arrays 'array1', array2', array3' and so on have different sizes (the dimension of the first one is (n,20) for instance, the dimension of the second is (n/4,22) as an example, and for the rest are also different). This is why I have to use the if statements, because in the case we are in a do loop at i=2 (for example), we have to consider the array2, and if we are at i=4 we use array4 with its size. These matrices are very big and I can not define a general matrix Agen:),:,:) where the first index accounts for i, because of problems of internal memory (and I have to define each of the matrices with just its size).

Thanks
 
usermg said:
My problem is that the arrays 'array1', array2', array3' and so on have different sizes ...
concerning the array size - you can use function size as you see in the procedure print_matrix.
 
yes.

As you can see, mikrom is already showing that the same kind of pointer can be use to point to matrices if different sizes...for as long as all your matrices are 2D, you should be o.k. If, one of your matrices a different number of dimensions, like 3, 4, or 5 or whatever, than, you can not use the same array of pointers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top