Skip to content
Snippets Groups Projects
Commit de7ae09c authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Extract function to create lonlat grid.

parent 3bdd7e82
No related branches found
No related tags found
No related merge requests found
......@@ -12,28 +12,13 @@
#include "pio_write_setup_grid.h"
#include "cdi_uuid.h"
#include "simple_model_helper.h"
int
setupGrid(struct model_config *setup, MPI_Comm comm)
{
int nlon = setup->nlon, nlat = setup->nlat;
int gridID = gridCreate ( GRID_LONLAT, nlon*nlat );
gridDefXsize ( gridID, nlon );
gridDefYsize ( gridID, nlat );
{
double *lons = (double *)Malloc((size_t)nlon * sizeof (lons[0]));
for (size_t i = 0; i < (size_t)nlon; ++i)
lons[i] = ((double)(i * 360))/nlon;
gridDefXvals ( gridID, lons );
Free(lons);
}
{
double *lats = (double *)Malloc((size_t)nlat * sizeof (lats[0]));
for (size_t i = 0; i < (size_t)nlat; ++i)
lats[i] = ((double)(i * 180))/nlat - 90.0;
gridDefYvals ( gridID, lats );
Free(lats);
}
int gridID = createGlobalLatLonGrid(nlon, nlat);
if (setup->create_uuid)
{
int rank = 0;
......
......@@ -111,6 +111,27 @@ composeStream(char **buf, const char *fname_prefix, int tfID,
return streamID;
}
int
createGlobalLatLonGrid(int nlon, int nlat)
{
int gridID = gridCreate(GRID_LONLAT, nlon*nlat);
gridDefXsize(gridID, nlon);
gridDefYsize(gridID, nlat);
size_t maxAxisSize = (size_t)(nlon > nlat ? nlon : nlat);
double *restrict coords = (double *)Malloc(maxAxisSize * sizeof (coords[0]));
{
for (size_t i = 0; i < (size_t)nlon; ++i)
coords[i] = ((double)(i * 360))/nlon;
gridDefXvals(gridID, coords);
}
{
for (size_t i = 0; i < (size_t)nlat; ++i)
coords[i] = ((double)(i * 180))/nlat - 90.0;
gridDefYvals(gridID, coords);
}
Free(coords);
return gridID;
}
#if defined USE_MPI && ! defined HAVE_PPM_CORE
......
......@@ -48,6 +48,9 @@ int
composeStream(char **buf, const char *fname_prefix, int tfID,
const char *suffix, int filetype);
int
createGlobalLatLonGrid(int nlon, int nlat);
#if defined (USE_MPI) && ! defined(HAVE_PPM_CORE)
struct PPM_extent
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment