@@ -643,48 +643,37 @@ subroutine CECE_InitializeRealize(comp, importState, exportState, clock, rc)
643643 g_start_time_seconds = real (yy* 365 * 24 * 3600 + mm* 30 * 24 * 3600 + dd* 24 * 3600 + &
644644 h* 3600 + m* 60 + s, c_double)
645645
646- ! Extract coordinates from ESMF grid and call enhanced writer initialization
646+
647+ ! Build 1-D cell-center coordinates directly from configured YAML grid bounds.
648+ ! This keeps standalone NetCDF output lon/lat metadata consistent with the
649+ ! configured CECE output grid and avoids falling back to the legacy writer,
650+ ! which hard-codes global -180..180 / -90..90 coordinates.
647651 block
648- real (ESMF_KIND_R8 ), pointer :: grid_lon(:,:), grid_lat(:,:)
649652 real (c_double), allocatable :: lon_coords(:), lat_coords(:)
653+ real (c_double) :: dlon, dlat
650654 integer :: i
651655
652- ! Get coordinates from ESMF grid (2D arrays)
653- call ESMF_GridGetCoord(grid, coordDim= 1 , localDE= 0 , staggerloc= ESMF_STAGGERLOC_CENTER, &
654- farrayptr= grid_lon, rc= rc)
655- if (rc /= ESMF_SUCCESS) then
656- write (* ,' (A,I0)' ) " WARNING: [CECE] Failed to get longitude coordinates: rc=" , rc
657- ! Fall back to legacy initialization
658- call cece_core_writer_initialize(g_cece_data_ptr, int (nx, c_int), int (ny, c_int), &
659- int (nz, c_int), start_time_str, int (len_trim (start_time_str), c_int), c_rc)
660- else
661- call ESMF_GridGetCoord(grid, coordDim= 2 , localDE= 0 , staggerloc= ESMF_STAGGERLOC_CENTER, &
662- farrayptr= grid_lat, rc= rc)
663- if (rc /= ESMF_SUCCESS) then
664- write (* ,' (A,I0)' ) " WARNING: [CECE] Failed to get latitude coordinates: rc=" , rc
665- ! Fall back to legacy initialization
666- call cece_core_writer_initialize(g_cece_data_ptr, int (nx, c_int), int (ny, c_int), &
667- int (nz, c_int), start_time_str, int (len_trim (start_time_str), c_int), c_rc)
668- else
669- ! Extract 1D coordinate arrays from 2D ESMF grid coordinates
670- allocate (lon_coords(nx), lat_coords(ny))
671- do i = 1 , nx
672- lon_coords(i) = real (grid_lon(i,1 ), c_double) ! First row, all columns
673- end do
674- do i = 1 , ny
675- lat_coords(i) = real (grid_lat(1 ,i), c_double) ! First column, all rows
676- end do
677-
678- write (* ,' (A,2F10.3)' ) " INFO: [CECE] Grid longitude range: " , lon_coords(1 ), lon_coords(nx)
679- write (* ,' (A,2F10.3)' ) " INFO: [CECE] Grid latitude range: " , lat_coords(1 ), lat_coords(ny)
680-
681- ! Call enhanced writer initialization with coordinates
682- call cece_core_writer_initialize_with_coords(g_cece_data_ptr, int (nx, c_int), int (ny, c_int), &
683- int (nz, c_int), lon_coords, lat_coords, &
684- start_time_str, int (len_trim (start_time_str), c_int), c_rc)
685- deallocate (lon_coords, lat_coords)
686- end if
687- end if
656+ allocate (lon_coords(nx), lat_coords(ny))
657+
658+ dlon = real (lon_max - lon_min, c_double) / real (nx, c_double)
659+ dlat = real (lat_max - lat_min, c_double) / real (ny, c_double)
660+
661+ do i = 1 , nx
662+ lon_coords(i) = real (lon_min, c_double) + dlon * (real (i, c_double) - 0.5_c_double )
663+ end do
664+
665+ do i = 1 , ny
666+ lat_coords(i) = real (lat_min, c_double) + dlat * (real (i, c_double) - 0.5_c_double )
667+ end do
668+
669+ write (* ,' (A,2F12.5)' ) " INFO: [CECE] Writer longitude range: " , lon_coords(1 ), lon_coords(nx)
670+ write (* ,' (A,2F12.5)' ) " INFO: [CECE] Writer latitude range: " , lat_coords(1 ), lat_coords(ny)
671+
672+ call cece_core_writer_initialize_with_coords(g_cece_data_ptr, int (nx, c_int), int (ny, c_int), &
673+ int (nz, c_int), lon_coords, lat_coords, &
674+ start_time_str, int (len_trim (start_time_str), c_int), c_rc)
675+
676+ deallocate (lon_coords, lat_coords)
688677 end block
689678
690679 rc = int (c_rc)
0 commit comments