@@ -870,24 +870,28 @@ subroutine med_io_write_FB(io_file, FB, whead, wdata, nx, ny, nt, &
870870
871871 ng = maxval (maxIndexPTile)
872872 if (tiles) then
873- lnx = nx
874- lny = ny
875- lntile = ng/ (lnx* lny)
876- write (tmpstr,* ) subname, ' ng,lnx,lny,lntile = ' ,ng,lnx,lny,lntile
877- call ESMF_LogWrite(trim (tmpstr), ESMF_LOGMSG_INFO)
878- if (lntile /= ntile) then
879- call ESMF_LogWrite(trim (subname)// ' ERROR: grid2d size and ntile are not consistent ' , ESMF_LOGMSG_INFO)
880- call ESMF_Finalize(endflag= ESMF_END_ABORT)
881- endif
873+ lnx = ng
874+ lny = 1
875+ lntile = 1
876+ if (nx > 0 ) lnx = nx
877+ if (ny > 0 ) lny = ny
878+ if (ntile > 0 ) lntile = ntile
879+ write (tmpstr,* ) subname, ' ng,lnx,lny,lntile = ' ,ng,lnx,lny,lntile
880+ call ESMF_LogWrite(trim (tmpstr), ESMF_LOGMSG_INFO)
881+ if (lnx* lny* lntile /= ng) then
882+ write (tmpstr,* ) subname,' ERROR: grid size not consistent ' ,ng,lnx,lny,lntile
883+ call ESMF_LogWrite(trim (tmpstr), ESMF_LOGMSG_INFO)
884+ call ESMF_Finalize(endflag= ESMF_END_ABORT)
885+ end if
882886 else
883- lnx = ng
884- lny = 1
885- if (nx > 0 ) lnx = nx
886- if (ny > 0 ) lny = ny
887- if (lnx* lny /= ng) then
888- write (tmpstr,* ) subname,' WARNING: grid2d size not consistent ' ,ng,lnx,lny
889- call ESMF_LogWrite(trim (tmpstr), ESMF_LOGMSG_INFO)
890- endif
887+ lnx = ng
888+ lny = 1
889+ if (nx > 0 ) lnx = nx
890+ if (ny > 0 ) lny = ny
891+ if (lnx* lny /= ng) then
892+ write (tmpstr,* ) subname,' WARNING: grid2d size not consistent ' ,ng,lnx,lny
893+ call ESMF_LogWrite(trim (tmpstr), ESMF_LOGMSG_INFO)
894+ endif
891895 end if
892896 deallocate (minIndexPTile, maxIndexPTile)
893897
@@ -902,7 +906,7 @@ subroutine med_io_write_FB(io_file, FB, whead, wdata, nx, ny, nt, &
902906 if (tiles) then
903907 rcode = pio_def_dim(io_file, trim (lpre)// ' _nx' , lnx, dimid3(1 ))
904908 rcode = pio_def_dim(io_file, trim (lpre)// ' _ny' , lny, dimid3(2 ))
905- rcode = pio_def_dim(io_file, trim (lpre)// ' _ntile' , ntile , dimid3(3 ))
909+ rcode = pio_def_dim(io_file, trim (lpre)// ' _ntile' , lntile , dimid3(3 ))
906910 if (present (nt)) then
907911 dimid4(1 :3 ) = dimid3
908912 rcode = pio_inq_dimid(io_file, ' time' , dimid4(4 ))
@@ -1020,10 +1024,18 @@ subroutine med_io_write_FB(io_file, FB, whead, wdata, nx, ny, nt, &
10201024 write (tmpstr,* ) subname,' dof = ' ,ns,size (dof),dof(1 ),dof(ns) ! ,minval(dof),maxval(dof)
10211025 call ESMF_LogWrite(trim (tmpstr), ESMF_LOGMSG_INFO)
10221026 if (tiles) then
1023- call pio_initdecomp(io_subsystem, pio_double, (/ lnx,lny,ntile/ ), dof, iodesc)
1027+ if (luse_float) then
1028+ call pio_initdecomp(io_subsystem, pio_real, (/ lnx,lny,lntile/ ), dof, iodesc)
1029+ else
1030+ call pio_initdecomp(io_subsystem, pio_double, (/ lnx,lny,lntile/ ), dof, iodesc)
1031+ end if
10241032 else
1025- call pio_initdecomp(io_subsystem, pio_double, (/ lnx,lny/ ), dof, iodesc)
1026- ! call pio_writedof(lpre, (/lnx,lny/), int(dof,kind=PIO_OFFSET_KIND), mpicom)
1033+ if (luse_float) then
1034+ call pio_initdecomp(io_subsystem, pio_real, (/ lnx,lny/ ), dof, iodesc)
1035+ else
1036+ call pio_initdecomp(io_subsystem, pio_double, (/ lnx,lny/ ), dof, iodesc)
1037+ end if
1038+ ! call pio_writedof(lpre, (/lnx,lny/), int(dof,kind=PIO_OFFSET_KIND), mpicom)
10271039 end if
10281040 deallocate (dof)
10291041
@@ -1056,10 +1068,18 @@ subroutine med_io_write_FB(io_file, FB, whead, wdata, nx, ny, nt, &
10561068 rcode = pio_inq_varid(io_file, trim (name1), varid)
10571069 call pio_setframe(io_file,varid,frame)
10581070
1059- if (gridToFieldMap(1 ) == 1 ) then
1060- call pio_write_darray(io_file, varid, iodesc, fldptr2(:,n), rcode, fillval= lfillvalue)
1061- else if (gridToFieldMap(1 ) == 2 ) then
1062- call pio_write_darray(io_file, varid, iodesc, fldptr2(n,:), rcode, fillval= lfillvalue)
1071+ if (luse_float) then
1072+ if (gridToFieldMap(1 ) == 1 ) then
1073+ call pio_write_darray(io_file, varid, iodesc, real (fldptr2(:,n),r4 ), rcode, fillval= real (lfillvalue,r4 ))
1074+ else if (gridToFieldMap(1 ) == 2 ) then
1075+ call pio_write_darray(io_file, varid, iodesc, real (fldptr2(n,:),r4 ), rcode, fillval= real (lfillvalue,r4 ))
1076+ end if
1077+ else
1078+ if (gridToFieldMap(1 ) == 1 ) then
1079+ call pio_write_darray(io_file, varid, iodesc, fldptr2(:,n), rcode, fillval= lfillvalue)
1080+ else if (gridToFieldMap(1 ) == 2 ) then
1081+ call pio_write_darray(io_file, varid, iodesc, fldptr2(n,:), rcode, fillval= lfillvalue)
1082+ end if
10631083 end if
10641084 end do
10651085 else if (rank == 1 .or. rank == 0 ) then
@@ -1068,7 +1088,11 @@ subroutine med_io_write_FB(io_file, FB, whead, wdata, nx, ny, nt, &
10681088 call pio_setframe(io_file,varid,frame)
10691089 ! fix for writing data on exchange grid, which has no data in some PETs
10701090 if (rank == 0 ) nullify(fldptr1)
1071- call pio_write_darray(io_file, varid, iodesc, fldptr1, rcode, fillval= lfillvalue)
1091+ if (luse_float) then
1092+ call pio_write_darray(io_file, varid, iodesc, real (fldptr1,r4 ), rcode, fillval= real (lfillvalue,r4 ))
1093+ else
1094+ call pio_write_darray(io_file, varid, iodesc, fldptr1, rcode, fillval= lfillvalue)
1095+ end if
10721096 end if ! end if rank is 2 or 1 or 0
10731097
10741098 end if ! end if not "hgt"
@@ -1077,12 +1101,19 @@ subroutine med_io_write_FB(io_file, FB, whead, wdata, nx, ny, nt, &
10771101 ! Fill coordinate variables - why is this being done each time?
10781102 rcode = pio_inq_varid(io_file, trim (coordvarnames(1 )), varid)
10791103 call pio_setframe(io_file,varid,frame)
1080- call pio_write_darray(io_file, varid, iodesc, ownedElemCoords_x, rcode, fillval= lfillvalue)
1104+ if (luse_float) then
1105+ call pio_write_darray(io_file, varid, iodesc, real (ownedElemCoords_x,r4 ), rcode, fillval= real (lfillvalue,r4 ))
1106+ else
1107+ call pio_write_darray(io_file, varid, iodesc, ownedElemCoords_x, rcode, fillval= lfillvalue)
1108+ end if
10811109
10821110 rcode = pio_inq_varid(io_file, trim (coordvarnames(2 )), varid)
10831111 call pio_setframe(io_file,varid,frame)
1084- call pio_write_darray(io_file, varid, iodesc, ownedElemCoords_y, rcode, fillval= lfillvalue)
1085-
1112+ if (luse_float) then
1113+ call pio_write_darray(io_file, varid, iodesc, real (ownedElemCoords_y,r4 ), rcode, fillval= real (lfillvalue,r4 ))
1114+ else
1115+ call pio_write_darray(io_file, varid, iodesc, ownedElemCoords_y, rcode, fillval= lfillvalue)
1116+ end if
10861117 call pio_syncfile(io_file)
10871118 call pio_freedecomp(io_file, iodesc)
10881119 endif
0 commit comments