Commit 1da43871 authored by dingwell's avatar dingwell
Browse files

Finished F90 migration. Tested with netcdf4 only.

The netcdf3 routines have also been updated but not tested...
parent 10f811dd
......@@ -45,16 +45,18 @@ subroutine write_ncconc(itime,outnum,ks,kp,nage,tot_mu_scalar,rho_recept,nesting
! the writing procedure. bug fixes for backtrajectory mode *
! Feb 2014: A. Dingwell: bug fix *
! 2015-05-04: A. Dingwell: Added receptor points to netcdf output *
! 2015-06-04: A. Dingwell: Updated subroutine to use NetCDF F90 module. *
!*****************************************************************************
use point_mod
use outg_mod
use par_mod
use com_mod
use netcdf
implicit none
include 'netcdf.inc'
!include 'netcdf.inc'
real :: outnum ! Number of samples for each concentration calculation
integer :: itime ! Current simulation time [s]
......@@ -107,7 +109,7 @@ subroutine write_ncconc(itime,outnum,ks,kp,nage,tot_mu_scalar,rho_recept,nesting
elseif (ncirec.eq.ncnumrec) then ! new file
! print*,'file is closing'
ncirec = 1 ! reset record index
ncret=nf_close(ncid) ! close the old file
ncret=NF90_CLOSE(ncid) ! close the old file
call check_ncerror(ncret)
! print*,'file is closed'
else
......@@ -151,7 +153,7 @@ subroutine write_ncconc(itime,outnum,ks,kp,nage,tot_mu_scalar,rho_recept,nesting
if ((ks.eq.1).and.(kp.eq.1).and.(nage.eq.1)) then
if (option_verbose.ge.10) write(*,*)'write_ncconc: record index',ncirec
write(datestr,'(I8.8,A1,I6.6)') jjjjmmdd,'_',ihmmss
ncret = nf_put_vara_text(ncid,ncrecvid,(/1,ncirec/),(/15,1/),datestr)
ncret = NF90_PUT_VAR(ncid,ncrecvid,datestr,start=(/1,ncirec/),count=(/15,1/))
call check_ncerror(ncret)
endif
......@@ -168,19 +170,22 @@ subroutine write_ncconc(itime,outnum,ks,kp,nage,tot_mu_scalar,rho_recept,nesting
if (kp.eq.maxpointspec_act .and. nage.eq.nageclass) then
if (ldirect.eq.-1) then
ncret = nf_put_vara_real(ncid,nccovid, &
(/1,1,1,1,1,ncirec/),(/grid_nx,grid_ny,numzgrid,kp,nage,1/), &
grid2(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1:kp,1:nage))
ncret = NF90_PUT_VAR(ncid,nccovid, &
grid2(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1:kp,1:nage), &
start = (/1,1,1,1,1,ncirec/), &
count = (/grid_nx,grid_ny,numzgrid,kp,nage,1/) )
call check_ncerror(ncret)
else
if (kp.gt.1) then
ncret = nf_put_vara_real(ncid,nccovid, &
(/1,1,1,1,ks,1,ncirec/),(/grid_nx,grid_ny,numzgrid,kp,1,nage,1/), &
grid2(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1:kp,1:nage))
ncret = NF90_PUT_VAR(ncid,nccovid, &
grid2(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1:kp,1:nage), &
start = (/1,1,1,1,ks,1,ncirec/), &
count = (/grid_nx,grid_ny,numzgrid,kp,1,nage,1/) )
else
ncret = nf_put_vara_real(ncid,nccovid, &
(/1,1,1,ks,1,ncirec/),(/grid_nx,grid_ny,numzgrid,1,nage,1/), &
grid2(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1,1:nage))
ncret = NF90_PUT_VAR(ncid,nccovid, &
grid2(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1,1:nage), &
start = (/1,1,1,ks,1,ncirec/), &
count = (/grid_nx,grid_ny,numzgrid,1,nage,1/) )
endif
call check_ncerror(ncret)
endif
......@@ -199,19 +204,22 @@ subroutine write_ncconc(itime,outnum,ks,kp,nage,tot_mu_scalar,rho_recept,nesting
enddo ! kz=1,numzgrid
if (kp.eq.maxpointspec_act .and. nage.eq.nageclass) then
if (ldirect.eq.-1) then
ncret = nf_put_vara_real(ncid,ncravid, &
(/1,1,1,1,1,ncirec/),(/grid_nx,grid_ny,numzgrid,kp,nage,1/), &
grid3(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1:kp,1:nage))
ncret = NF90_PUT_VAR(ncid,ncravid, &
grid3(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1:kp,1:nage), &
start = (/1,1,1,1,1,ncirec/), &
count = (/grid_nx,grid_ny,numzgrid,kp,nage,1/) )
call check_ncerror(ncret)
else
if (kp.gt.1) then
ncret = nf_put_vara_real(ncid,ncravid, &
(/1,1,1,1,ks,1,ncirec/),(/grid_nx,grid_ny,numzgrid,kp,1,nage,1/), &
grid3(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1:kp,1:nage))
ncret = NF90_PUT_VAR(ncid,ncravid, &
grid3(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1:kp,1:nage), &
start = (/1,1,1,1,ks,1,ncirec/), &
count = (/grid_nx,grid_ny,numzgrid,kp,1,nage,1/) )
else
ncret = nf_put_vara_real(ncid,ncravid, &
(/1,1,1,ks,1,ncirec/),(/grid_nx,grid_ny,numzgrid,1,nage,1/), &
grid3(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1,1:nage))
ncret = NF90_PUT_VAR(ncid,ncravid, &
grid3(0:grid_nx-1,0:grid_ny-1,1:numzgrid,1,1:nage), &
start = (/1,1,1,ks,1,ncirec/), &
count = (/grid_nx,grid_ny,numzgrid,1,nage,1/) )
endif
call check_ncerror(ncret)
endif
......@@ -228,19 +236,22 @@ subroutine write_ncconc(itime,outnum,ks,kp,nage,tot_mu_scalar,rho_recept,nesting
enddo ! jy=1,grid_ny-1
if (kp.eq.maxpointspec_act .and. nage.eq.nageclass) then
if (ldirect.eq.-1) then
ncret = nf_put_vara_real(ncid,ncwdvid, &
(/1,1,1,1,ncirec/),(/grid_nx,grid_ny,kp,nage,1/), &
wetgrid2(0:grid_nx-1,0:grid_ny-1,1:kp,1:nage))
ncret = NF90_PUT_VAR(ncid,ncwdvid, &
wetgrid2(0:grid_nx-1,0:grid_ny-1,1:kp,1:nage), &
start = (/1,1,1,1,ncirec/), &
count = (/grid_nx,grid_ny,kp,nage,1/) )
call check_ncerror(ncret)
else
if (kp.gt.1) then
ncret = nf_put_vara_real(ncid,ncwdvid, &
(/1,1,1,ks,1,ncirec/),(/grid_nx,grid_ny,kp,1,nage,1/), &
wetgrid2(0:grid_nx-1,0:grid_ny-1,1:kp,1:nage))
ncret = NF90_PUT_VAR(ncid,ncwdvid, &
wetgrid2(0:grid_nx-1,0:grid_ny-1,1:kp,1:nage), &
start = (/1,1,1,ks,1,ncirec/), &
count = (/grid_nx,grid_ny,kp,1,nage,1/) )
else
ncret = nf_put_vara_real(ncid,ncwdvid, &
(/1,1,ks,1,ncirec/),(/grid_nx,grid_ny,1,nage,1/), &
wetgrid2(0:grid_nx-1,0:grid_ny-1,1,1:nage))
ncret = NF90_PUT_VAR(ncid,ncwdvid, &
wetgrid2(0:grid_nx-1,0:grid_ny-1,1,1:nage), &
start = (/1,1,ks,1,ncirec/), &
count = (/grid_nx,grid_ny,1,nage,1/) )
endif
call check_ncerror(ncret)
endif
......@@ -265,19 +276,22 @@ subroutine write_ncconc(itime,outnum,ks,kp,nage,tot_mu_scalar,rho_recept,nesting
enddo ! jy=1,grid_ny-1
if (kp.eq.maxpointspec_act .and. nage.eq.nageclass) then
if (ldirect.eq.-1) then
ncret = nf_put_vara_real(ncid,ncddvid, &
(/1,1,1,1,ncirec/),(/grid_nx,grid_ny,kp,nage,1/), &
drygrid2(0:grid_nx-1,0:grid_ny-1,1:kp,1:nage))
ncret = NF90_PUT_VAR(ncid,ncddvid, &
drygrid2(0:grid_nx-1,0:grid_ny-1,1:kp,1:nage), &
start = (/1,1,1,1,ncirec/), &
count = (/grid_nx,grid_ny,kp,nage,1/) )
call check_ncerror(ncret)
else
if (kp.gt.1) then
ncret = nf_put_vara_real(ncid,ncddvid, &
(/1,1,1,ks,1,ncirec/),(/grid_nx,grid_ny,kp,1,nage,1/), &
drygrid2(0:grid_nx-1,0:grid_ny-1,1:kp,1:nage))
ncret = NF90_PUT_VAR(ncid,ncddvid, &
drygrid2(0:grid_nx-1,0:grid_ny-1,1:kp,1:nage), &
start = (/1,1,1,ks,1,ncirec/), &
count = (/grid_nx,grid_ny,kp,1,nage,1/) )
else
ncret = nf_put_vara_real(ncid,ncddvid, &
(/1,1,ks,1,ncirec/),(/grid_nx,grid_ny,1,nage,1/), &
drygrid2(0:grid_nx-1,0:grid_ny-1,1,1:nage))
ncret = NF90_PUT_VAR(ncid,ncddvid, &
drygrid2(0:grid_nx-1,0:grid_ny-1,1,1:nage), &
start = (/1,1,ks,1,ncirec/), &
count = (/grid_nx,grid_ny,1,nage,1/) )
endif
call check_ncerror(ncret)
endif
......@@ -297,20 +311,23 @@ subroutine write_ncconc(itime,outnum,ks,kp,nage,tot_mu_scalar,rho_recept,nesting
if (option_verbose.ge.10) &
write(*,*) "write_ncconc: Receptor output, ks =",ks
if (iout.eq.2 .or. iout.eq.3) then ! mixing ratio output
ncret = nf_put_vara_real(ncid,ncrmivid, &
(/1,ks,ncirec/), (/numreceptor,1,1/), &
1.e12*creceptor(:,ks)/outnum*weightair/weightmolar(ks)/rho_recept)
ncret = NF90_PUT_VAR(ncid,ncrmivid, &
1.e12*creceptor(:,ks)/outnum*weightair/weightmolar(ks)/rho_recept, &
start = (/1,ks,ncirec/), &
count = (/numreceptor,1,1/) )
endif ! mixing ratio output
if ((iout.eq.1).or.(iout.eq.3).or.(iout.eq.5)) then ! concentration output
ncret = nf_put_vara_real(ncid,ncrcovid, &
(/1,ks,ncirec/), (/numreceptor,1,1/), &
1.e12*creceptor(:,ks)/outnum)
ncret = NF90_PUT_VAR(ncid,ncrcovid, &
1.e12*creceptor(:,ks)/outnum, &
start = (/1,ks,ncirec/), &
count = (/numreceptor,1,1/) )
endif ! concentration output
endif ! RECEPTOR OUTPUT
ncret=nf_sync(ncid)
ncret=NF90_SYNC(ncid)
call check_ncerror(ncret)
end subroutine write_ncconc
......@@ -43,6 +43,11 @@ subroutine write_ncinfo(itime,nesting_level)
! it's enough with a toggle in the code...? *
!*****************************************************************************
! File created by running removing the following pattern from write_ncinfo.f90:
! ',\s*&\n\s*shuffle =.*\)'
! and replacing it with ')'
! the variable definitions for shuffle and deflate_level have also been removed.
use point_mod
use outg_mod
use com_mod
......@@ -101,6 +106,8 @@ subroutine write_ncinfo(itime,nesting_level)
! NETCDF misc variables
integer ncid ! local container for netcdf file-id (either ncout or ncoutn)
integer ncret ! Return-value of calls to nf_* utils
!integer :: deflate_level=4 ! compression level
!logical :: shuffle=.FALSE. ! shuffle?
! integer :: chunks(2) ! shuffle
! Attribute notation:
descr = 'description'
......@@ -129,7 +136,7 @@ subroutine write_ncinfo(itime,nesting_level)
'write_ncinfo: creating file: ',path(1)(1:length(1))//ncname
! call nf_set_chunk_cache(32000000)
! ncret = nf_create(path(1)(1:length(1))//ncname, nf_clobber,ncid)
ncret = NF90_CREATE(path=path(1)(1:length(1))//ncname, cmode=NF90_CLOBBER,ncid=ncid)
ncret = NF90_CREATE(path=path(1)(1:length(1))//ncname, cmode=NF90_NETCDF4,ncid=ncid)
call check_ncerror(ncret)
......@@ -452,7 +459,7 @@ subroutine write_ncinfo(itime,nesting_level)
if ((ldirect.eq.1).and.(maxpointspec_act.gt.1)) then
ncret = NF90_DEF_VAR(ncid,'MIXINGRATIO',NF90_REAL,ncdimsid32,ncravid)
else
ncret = NF90_DEF_VAR(ncid,'MIXINGRATIO',NF90_REAL,6,ncdimsid3,ncravid)
ncret = NF90_DEF_VAR(ncid,'MIXINGRATIO',NF90_REAL,ncdimsid3,ncravid)
endif
ncret = NF90_PUT_ATT(ncid,ncravid,descr, &
'MASS MIXING RATIO OF AIRBORNE SPECIES')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment