@@ -590,7 +590,6 @@ subroutine mom_export(ocean_public, ocean_grid, ocean_state, exportState, clock,
590590 integer :: isc, iec, jsc, jec ! indices
591591 integer :: iloc, jloc ! indices
592592 integer :: iglob, jglob ! indices
593- integer :: i0, j0 ! indices
594593 integer :: n
595594 integer :: icount
596595 real :: slp_L, slp_R, slp_C
@@ -607,9 +606,13 @@ subroutine mom_export(ocean_public, ocean_grid, ocean_state, exportState, clock,
607606 real (ESMF_KIND_R8 ), allocatable :: ssh(:,:)
608607 real (ESMF_KIND_R8 ), allocatable :: dhdx(:,:), dhdy(:,:)
609608 real (ESMF_KIND_R8 ), allocatable :: dhdx_rot(:,:), dhdy_rot(:,:)
609+ character (len=* ) , parameter :: subname = ' (mom_export)'
610+ ! debug
611+ integer :: i0,j0
610612 real (ESMF_KIND_R8 ), allocatable :: uc(:,:)
611613 real (ESMF_KIND_R8 ), allocatable :: vc(:,:)
612- character (len=* ) , parameter :: subname = ' (mom_export)'
614+ real (ESMF_KIND_R8 ), allocatable :: worka(:,:)
615+ real (ESMF_KIND_R8 ), allocatable :: workb(:,:)
613616
614617 rc = ESMF_SUCCESS
615618
@@ -631,17 +634,6 @@ subroutine mom_export(ocean_public, ocean_grid, ocean_state, exportState, clock,
631634 !- ---------------
632635
633636 call mpp_get_compute_domain(ocean_public% domain, isc, iec, jsc, jec)
634- ! call mpp_get_data_domain(ocean_public%domain, isd, ied, jsd, jed)
635- print * ,' XXXX0 ' ,isc,iec, jsc, jec
636- ! print *,'XXXX1 ',isd,ied, jsd, jed
637- ! 'd' arrays are == to 'c' arrays when retrieved from ocean_public
638- ! both are global; do not contain halos
639-
640- print * ,' XXX1 ' ,ocean_grid% idg_offset,ocean_grid% jdg_offset
641-
642- print * ,' YYYY0 ' ,ocean_grid% isc,ocean_grid% iec,ocean_grid% jsc,ocean_grid% jec
643- print * ,' YYYY1 ' ,ocean_grid% isd,ocean_grid% ied,ocean_grid% jsd,ocean_grid% jed
644- ! ocean_grid 'c' arrays are local indices with halos
645637
646638 ! -------
647639 ! ocean mask
@@ -679,22 +671,6 @@ subroutine mom_export(ocean_public, ocean_grid, ocean_state, exportState, clock,
679671 allocate (ocz(isc:iec, jsc:jec))
680672 allocate (ocm(isc:iec, jsc:jec))
681673
682- <<<<<<< HEAD
683- allocate (ocz(isc:iec, jsc:jec))
684- allocate (ocm(isc:iec, jsc:jec))
685-
686- if (ocean_state_stagger == ' C' ) then
687- call State_SetExport(exportState, ' So_uc' , isc, iec, jsc, jec, ocean_public% u_surf, ocean_grid, rc= rc)
688- if (ChkErr(rc,__LINE__,u_FILE_u)) return
689-
690- call State_SetExport(exportState, ' So_vc' , isc, iec, jsc, jec, ocean_public% v_surf, ocean_grid, rc= rc)
691- if (ChkErr(rc,__LINE__,u_FILE_u)) return
692-
693- ! Local copy of C-grid velocities with halos to calculate A-grid exports
694- allocate (uc(ocean_grid% isd:ocean_grid% ied, ocean_grid% jsd:ocean_grid% jed), source= 0.0_ESMF_KIND_R8 )
695- allocate (vc(ocean_grid% isd:ocean_grid% ied, ocean_grid% jsd:ocean_grid% jed), source= 0.0_ESMF_KIND_R8 )
696-
697- =======
698674 if (exportCgrid) then
699675 call State_SetExport(exportState, ' So_uc' , isc, iec, jsc, jec, ocean_public% u_surf, ocean_grid, rc= rc)
700676 if (ChkErr(rc,__LINE__,u_FILE_u)) return
@@ -706,7 +682,6 @@ subroutine mom_export(ocean_public, ocean_grid, ocean_state, exportState, clock,
706682 allocate (uc(ocean_grid% isd:ocean_grid% ied, ocean_grid% jsd:ocean_grid% jed), source= 0.0_ESMF_KIND_R8 )
707683 allocate (vc(ocean_grid% isd:ocean_grid% ied, ocean_grid% jsd:ocean_grid% jed), source= 0.0_ESMF_KIND_R8 )
708684
709- >>>>>>> 60ebeb044 (messy slope fixes)
710685 uc(ocean_grid% isc:ocean_grid% iec, ocean_grid% jsc:ocean_grid% jec) = ocean_public% u_surf(isc:iec, jsc:jec)
711686 vc(ocean_grid% isc:ocean_grid% iec, ocean_grid% jsc:ocean_grid% jec) = ocean_public% v_surf(isc:iec, jsc:jec)
712687 call pass_var(uc, ocean_grid% Domain)
@@ -802,14 +777,6 @@ subroutine mom_export(ocean_public, ocean_grid, ocean_state, exportState, clock,
802777 ! Sea-surface zonal and meridional slopes
803778 !- ---------------
804779
805- ! allocate(ssh(ocean_grid%isd:ocean_grid%ied,ocean_grid%jsd:ocean_grid%jed), & ! local indices with halos
806- ! dhdx(isc:iec, jsc:jec), & !global indices without halos
807- ! dhdy(isc:iec, jsc:jec), & !global indices without halos
808- ! source=0.0_ESMF_KIND_R8)
809-
810- ! print *,'XXXX1 ',ocean_grid%isd,ocean_grid%ied,ocean_grid%jsd,ocean_grid%jed
811- ! print *,'XXXX2 ',ocean_grid%isd_global,ocean_grid%jsd_global
812-
813780 allocate (ssh(ocean_grid% isd:ocean_grid% ied,ocean_grid% jsd:ocean_grid% jed), & ! local indices with halos
814781 dhdx(ocean_grid% isd:ocean_grid% ied,ocean_grid% jsd:ocean_grid% jed), & ! global indices with halos
815782 dhdy(ocean_grid% isd:ocean_grid% ied,ocean_grid% jsd:ocean_grid% jed), & ! global indices with halos
@@ -825,7 +792,6 @@ subroutine mom_export(ocean_public, ocean_grid, ocean_state, exportState, clock,
825792 ssh(i,j) = ocean_public% sea_lev(iloc,jloc)
826793 enddo
827794 enddo
828- ! print *,'YYY0 ssh ',lbound(ssh,1),ubound(ssh,1),lbound(ssh,2),ubound(ssh,2)
829795
830796 ! Update halo of ssh so we can calculate gradients (local indexing)
831797 call pass_var(ssh, ocean_grid% domain)
@@ -897,25 +863,33 @@ subroutine mom_export(ocean_public, ocean_grid, ocean_state, exportState, clock,
897863 call pass_var(dhdx, ocean_grid% domain)
898864 call pass_var(dhdy, ocean_grid% domain)
899865
900- ! if (exportCgrid) then
901- ! allocate(workx, source = dhdx)
902- ! allocate(worky, source = dhdy)
903- ! workx = 0.0
904- ! worky = 0.0
905- ! i0 = ocean_grid%isc-isc
906- ! j0 = ocean_grid%jsc-jsc
907- ! do j=jsc,jec ; do i=isc,iec
908- ! workx(i,j) = 0.5*(dhdx(i+i0,j+j0) + dhdx(i+i0+1,j+j0))
909- ! worky(i,j) = 0.5*(dhdy(i+i0,j+j0) + dhdy(i+i0,j+j0+1))
910- ! enddo; enddo
911-
912- ! call State_SetExport(exportState, 'So_dhdx', isc, iec, jsc, jec, dhdx, ocean_grid, rc=rc)
913- ! if (ChkErr(rc,__LINE__,u_FILE_u)) return
914-
915- ! call State_SetExport(exportState, 'So_dhdy', isc, iec, jsc, jec, dhdy, ocean_grid, rc=rc)
916- ! if (ChkErr(rc,__LINE__,u_FILE_u)) return
917- ! else
918- ! rotate slopes from tripolar grid back to lat/lon grid, x,y => latlon (CCW)
866+ if (exportCgrid) then
867+ allocate (worka, source = dhdx)
868+ allocate (workb, source = dhdy)
869+ worka = 0.0
870+ workb = 0.0
871+ ! i0 = ocean_grid%isc-isc
872+ ! j0 = ocean_grid%jsc-jsc
873+ ! do j=jsc,jec ; do i=isc,iec
874+ ! worka(i,j) = 0.5*(dhdx(i+i0,j+j0) + dhdx(i+i0+1,j+j0))
875+ ! workb(i,j) = 0.5*(dhdy(i+i0,j+j0) + dhdy(i+i0,j+j0+1))
876+ ! enddo; enddo
877+ do jglob = jsc, jec
878+ j = jglob + ocean_grid% jsc - jsc
879+ do iglob = isc,iec
880+ i = iglob + ocean_grid% isc - isc
881+ worka(i,j) = 0.5 * (dhdx(i,j) + dhdx(i+1 ,j))
882+ workb(i,j) = 0.5 * (dhdy(i,j) + dhdy(i,j+1 ))
883+ enddo
884+ enddo
885+
886+ call State_SetExport(exportState, ' So_dhdx' , isc, iec, jsc, jec, worka, ocean_grid, rc= rc)
887+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
888+
889+ call State_SetExport(exportState, ' So_dhdy' , isc, iec, jsc, jec, workb, ocean_grid, rc= rc)
890+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
891+ else
892+ ! rotate slopes from tripolar grid back to lat/lon grid, x,y => latlon (CCW)
919893 ! "ocean_grid" uses has halos and uses local indexing.
920894 do j = jsc, jec
921895 jg = j + ocean_grid% jsc - jsc
@@ -925,15 +899,14 @@ subroutine mom_export(ocean_public, ocean_grid, ocean_state, exportState, clock,
925899 dhdy_rot(i,j) = ocean_grid% cos_rot(ig,jg)* dhdy(ig,jg) - ocean_grid% sin_rot(ig,jg)* dhdx(ig,jg)
926900 enddo
927901 enddo
928- ! dhdx_rot = 0.0
929- ! dhdy_rot = 0.0
930902
931903 call State_SetExport(exportState, ' So_dhdx' , isc, iec, jsc, jec, dhdx_rot, ocean_grid, rc= rc)
932904 if (ChkErr(rc,__LINE__,u_FILE_u)) return
933905
934906 call State_SetExport(exportState, ' So_dhdy' , isc, iec, jsc, jec, dhdy_rot, ocean_grid, rc= rc)
935907 if (ChkErr(rc,__LINE__,u_FILE_u)) return
936- ! endif
908+ endif
909+
937910 ! -------
938911 ! CO2 Flux
939912 ! -------
@@ -945,6 +918,10 @@ subroutine mom_export(ocean_public, ocean_grid, ocean_state, exportState, clock,
945918 endif
946919
947920 deallocate (ssh, dhdx, dhdy, dhdx_rot, dhdy_rot)
921+ if (allocated (uc)) deallocate (uc)
922+ if (allocated (vc)) deallocate (vc)
923+ if (allocated (worka)) deallocate (worka)
924+ if (allocated (workb)) deallocate (workb)
948925
949926end subroutine mom_export
950927
0 commit comments