MODULE grid_conversion !----------------------------------------------------------------------- ! NAME ! grid_conversion ! ! DESCRIPTION ! Provides tools to convert data between lon x lat grid format ! and vector format. ! ! AUTHORS & DATE ! JB Clement, 12/2025 ! ! NOTES ! Handles pole duplication differences between the grid format ! and vector format. !----------------------------------------------------------------------- ! DECLARATION ! ----------- implicit none contains !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ !======================================================================= SUBROUTINE lonlat2vect(nlon,nlat,ngrid,v_ll,v_vect) !----------------------------------------------------------------------- ! NAME ! lonlat2vect ! ! DESCRIPTION ! Convert data from lon x lat grid (where values at the poles are ! duplicated) into a vector. ! ! AUTHORS & DATE ! JB Clement, 12/2025 ! ! NOTES ! The longitudes -180 and +180 are not duplicated like in the PCM ! dynamics. ! !----------------------------------------------------------------------- ! DECLARATION ! ----------- implicit none ! Arguments !---------- integer, intent(in) :: nlon, nlat, ngrid real, dimension(nlon,nlat), intent(in) :: v_ll real, dimension(ngrid), intent(out) :: v_vect ! Local variables !---------------- integer :: i, j ! Code !----- ! 1D case #ifdef CPP_1D v_vect(1) = v_ll(1,1) return #else ! Check if (ngrid /= nlon*(nlat - 2) + 2) error stop 'lonlat2vect: problem of dimensions!' ! Initialization v_vect = 0. ! Treatment of the poles v_vect(1) = v_ll(1,1) v_vect(ngrid) = v_ll(1,nlat) ! Treatment of regular points do j = 2,nlat - 1 do i = 1,nlon v_vect(1 + i + (j - 2)*nlon) = v_ll(i,j) enddo enddo #endif END SUBROUTINE lonlat2vect !======================================================================= !======================================================================= SUBROUTINE vect2lonlat(nlon,nlat,ngrid,v_vect,v_ll) !----------------------------------------------------------------------- ! NAME ! vect2lonlat ! ! DESCRIPTION ! Convert data from a vector into lon x lat grid (where values ! at the poles are duplicated). ! ! AUTHORS & DATE ! JB Clement, 12/2025 ! ! NOTES ! The longitudes -180 and +180 are not duplicated like in the PCM ! dynamics. !----------------------------------------------------------------------- ! DECLARATION ! ----------- implicit none ! Arguments !---------- integer, intent(in) :: nlon, nlat, ngrid real, dimension(ngrid), intent(in) :: v_vect real, dimension(nlon,nlat), intent(out) :: v_ll ! Local variables !---------------- integer :: i, j ! Code !----- ! 1D case #ifdef CPP_1D v_ll(1,1) = v_vect(1) return #else ! Check if (ngrid /= nlon*(nlat - 2) + 2) error stop 'vect2lonlat: problem of dimensions!' ! Initialization v_ll = 0. ! Treatment of the poles v_ll(:,1) = v_vect(1) v_ll(:,nlat) = v_vect(ngrid) ! Treatment of regular points do j = 2,nlat - 1 do i = 1,nlon v_ll(i,j) = v_vect(1 + i + (j - 2)*nlon) enddo enddo #endif END SUBROUTINE vect2lonlat !======================================================================= END MODULE grid_conversion