c c save_matrix subroutine c This program saves the output matrix in either binary or text form c created 9/96 c c Need to add netcdf output c subroutine save_matrix(grid,grerror,nx,ny,xres,yres, 1 xleft,xright,ytop,ybot) parameter (ngx=1000,ngy=700) integer nx,ny,choice real xres,yres,xleft,xright,ytop,ybot real grid(ngy,ngx), grerror(ngy,ngx) c prompt user for the type of output file print *,'Do you want to write the output file in: ' print *,' ' print *,' 1> Binary (unformatted)' print *,' 2> Ascii (text)' c print *,' 3> NetCDF' print *,' ' read *,choice print *,' ' if (choice .eq. 1) then call print_binary(grid,grerror,nx,ny,xres,yres,xleft, 1 xright,ytop,ybot) else if (choice .eq. 2) then call print_text(grid,grerror,nx,ny,xres,yres,xleft, 1 xright,ytop,ybot) c call print_netcdf(grid,grerror,nx,ny,xres,yres,xleft, c 1 xright,ytop,ybot) else print*, 'Error in input' endif return end c print_binary subroutine c This program prints the given matrix in binary output c created 9/96 subroutine print_binary(grid,grerror,nx,ny,xres,yres, 1 xleft,xright,ytop,ybot) parameter (ngx=1000,ngy=700) character*40, fout,fouter integer nx,ny real xres,yres,xleft,xright,ytop,ybot, 1 grid(ngy,ngx), grerror(ngy,ngx) c prompt user for output files print *,"Enter the name of the output data file" read *,fout open(10, file=fout, form='unformatted', status='unknown', 1 iostat=icd) if (icd .ne. 0) then write(6,*) 'error opening output file iostat= ',icd stop 99 end if print *,"Enter the name of the output error file" read *,fouter open(11, file=fouter, form='unformatted', status='unknown', 1 iostat=icd) if (icd .ne. 0) then write(6,*) 'error opening output error file iostat= ',icd stop 99 end if c write header write(10) nx,ny,xres,yres,xleft,xright,ytop,ybot write(11) nx,ny,xres,yres,xleft,xright,ytop,ybot do i = 1,ny c write data into output file row by row write(10) (grid(i,j), j=1,nx) write(11) (grerror(i,j), j=1,nx) enddo close(10) close(11) return end c print_text subroutine c This program prints the given matrix in text output c created 9/96 subroutine print_text(grid,grerror,nx,ny,xres,yres, 1 xleft,xright,ytop,ybot) parameter (ngx=1000,ngy=700) character*40, fout,fouter integer nx,ny real xres,yres,xleft,xright,ytop,ybot, 1 grid(ngy,ngx), grerror(ngy,ngx) c prompt user for output file print *,"Enter the name of the output file" read *,fout open(10, file=fout, form='formatted', status='unknown', 1 iostat=icd) if (icd .ne. 0) then write(6,*) 'error opening output file iostat= ',icd stop 99 end if print *,"Enter the name of the output error file" read *,fouter open(11, file=fouter, form='formatted', status='unknown', 1 iostat=icd) if (icd .ne. 0) then write(6,*) 'error opening output error file iostat= ',icd stop 99 end if c write header information to the output files write(10,101)nx,ny write(10,102)xleft write(10,103)xright write(10,104)ytop write(10,105)ybot write(10,106)xres write(10,107)yres write(11,101)nx,ny write(11,102)xleft write(11,103)xright write(11,104)ytop write(11,105)ybot write(11,106)xres write(11,107)yres c header format 101 format('Grid Dimensions: ',i3,' X ',i3) 102 format('Left X Grid Point:',f9.2) 103 format('Right X Grid Point:',f9.2) 104 format('Top Y Grid Point:',f9.2) 105 format('Bottom Y Grid Point:',f9.2) 106 format('Grid Resolution in X direction: ',f9.2) 107 format('Grid Resolution in Y direction: ',f9.2) n10 = nx/10 nls11 = mod(nx,10) do i = 1, ny do k = 1, n10 ib = 10*(k-1)+1 ie = 10*k c write data in 10 columns write(10,111) (grid(i,j),j=ib,ie) write(11,111) (grerror(i,j),j=ib,ie) enddo c write the remaining data write(10,111) (grid(i,j),j=ie+1,nx) write(11,111) (grerror(i,j),j=ie+1,nx) enddo 111 format(10(f6.2,2x)) close(2) return end