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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I 'slice' an array in fortran

Status
Not open for further replies.

PumpedUpKicks

Programmer
Apr 24, 2016
1
GB
Essentially i have function that gives an output as REAL, DIMENSION(1:3, 1:1), but i only want the first two variables so i want REAL, DIMENSION(1:2, 1:1), basically keeping the x and y values and ignoring the z value
sorry if this is not clear and thank you
 
Here is a generic slicing example
Code:
program main
   integer:: p3d(1:3,1:1), p2d(1:2)
   
   p3d = reshape((/ 10, 20, 30 /), shape(p3d))
   p2d = p3d(1:2,1)
   
   print *, p2d(1), p2d(2)
   p2d = p3d(2:3,1)
   print *, p2d(1), p2d(2)
   stop
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top