Hello,
I am trying to write X,Y values to a file from a 2D array, but the data does not output correctly in 2 columns for X and Y. At present in writes X as 2 columns and then Y appended on the end. How to write X to col 1 and Y to col 2. Sorry if this is a basic query - using ftn95.
program linear_test
! Purpose: create X and Y 2D arrays
! write file with 2 columns X,Y of 120x120 (14400) values
! z-data has same geometry
implicit none
real :: dxy, xmin, xmax, xrange, ymin, ymax, yrange
integer :: npoints, i, sv, nx, ny, xydim
real,allocatable :: xx(:), yy(:)
real, allocatable :: X(:,:), Y(:,:)
open (25, file='xy-data.dat', status='new') ! open new file for write
npoints=120
allocate(xx(npoints))
xmin = -5.0
xmax = -3.0
allocate(yy(npoints))
ymin = -5.0
ymax = -3.0
xrange = xmax - xmin
!yrange = ymax - ymin
! Linspace
dxy = xrange / real(npoints-1) ! calculate increment
do i = 1,npoints
xx(i) = xmin + (i-1)*dxy
yy(i) = ymin + (i-1)*dxy !same increment in y
end do
sv=0
nx = size(xx, dim=1)
ny = size(yy, dim=1)
xydim = nx*ny
allocate(X(ny,nx),Y(ny,nx),stat=sv)
allocate(X1(xydim),Y1(xydim),stat=sv)
! Meshgrid
X(1,:) = xx
X(2:ny,:) = spread(xx, dim=1, ncopies=ny-1)
Y(:,1) = yy
Y(:,2:nx) = spread(yy, dim=2, ncopies=nx-1)
! write 2 columns (X,Y)
write (25,'(f15.10,f15.10)') X, Y
deallocate(xx,yy,X,Y)
close(25)
end program linear_test
The code is fine if I just want X or Y and generates the 14400 values expected.
Thanks for any pointers
Lester