简体   繁体   English

如何在Fortran 90中连接两个数组

[英]How to concatenate two arrays in Fortran 90

I have an original array called pres_lev3d , whose size is defined by pres_lev3d(im*jm, levsi) , where im*jm is 72960 and levsi is 64. This corresponds to global atmospheric data, thus the size. 我有一个名为pres_lev3d的原始数组,其大小由pres_lev3d(im*jm, levsi) ,其中im*jm为72960, levsi为64。这对应于全球大气数据,即大小。 The array is allocatable: real (kind=kind_io8), allocatable :: pres_lev3d(:, :) . 该数组是可分配的: real (kind=kind_io8), allocatable :: pres_lev3d(:, :) I have a second array, press_1d , whose size is also defined in a similar fashion pres_1d(im*jm, levsi) , but in this array levsi is 1. 我有第二个数组press_1d ,它的大小也以类似的方式pres_1d(im*jm, levsi) ,但是在这个数组中levsi是1。

I need to concatenate both arrays (technically a 2d and 1d array) to an array of the shape (/72960, 65/) . 我需要将两个数组(技术上是2d和1d数组)连接到形状为(/72960, 65/)的数组。 In MATLAB this seems like a very simple process, however, I can't seem to find an easy way to go around it in Fortran 90. 在MATLAB中,这似乎是一个非常简单的过程,但是,在Fortran 90中,我似乎找不到一种简单的方法来解决它。

I have tried to create a third array 我试图创建第三个数组

pres_lev=(/pres_lev3d, pres_1d/)

and also tried to use merge , but none of these approaches seem to work out. 并尝试使用merge ,但是这些方法似乎都没有奏效。

I am fairly new to Fortran. 我对Fortran还是陌生的。

If I've followed your explanation correctly this would probably work 如果我正确遵循了您的解释,这可能会起作用

   real(kind_io8), dimension(72960,65) :: out_array
   ...
   out_array(:,1:64) = pres_lev3d
   out_array(:,65) = pres_1d

If that's not easy enough, or if I've misunderstood your question, explain further. 如果那还不够简单,或者我误解了您的问题,请进一步解释。 To allocate out_array to conform to your input arrays, try something like 要分配out_array以符合您的输入数组,请尝试类似

   real(kind_io8), dimension(:,:), allocatable :: out_array
   ...
   allocate(out_array(size(pres_lev3d,1),size(pres_lev3d,2)+1))
   ...
   out_array(:,1:64) = pres_lev3d
   out_array(:,65) = pres_1d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM