/** Basilisk programme to write outputs as netcdf files. Written by Cyprien Bosserelle cyprien.bosserelle@niwa.co.nz 2018-2019 Usage: //Save this file in $BASILISK. In the modelling programme include this file with other includes at the top of the file: #include "writenetcdf.h" // First create a netcdf file - define name char ncfile[]="TPacGebco-out.nc"; // In an initialisation event create file printf("Create netcdf file for output \n"); //Prepare netcdf file for output int nx=(int) 1 << MAXLEVEL; scalar * outvars = {eta,h,hmax,l,u.x,u.y}; create2dnc(ncfile,nx, L0, 0.0, outvars); // Output at designated timesteps (i.e. in ongoing event) printf("Saving step: t=%f\n",t); int nx=1< double BiInterp(double q11, double q12, double q21, double q22, double x1, double x2, double y1, double y2, double x, double y) { double x2x1, y2y1, x2x, y2y, yy1, xx1; x2x1 = x2 - x1; y2y1 = y2 - y1; x2x = x2 - x; y2y = y2 - y; yy1 = y - y1; xx1 = x - x1; return 1.0 / (x2x1 * y2y1) * ( q11 * x2x * y2y + q21 * xx1 * y2y + q12 * x2x * yy1 + q22 * xx1 * yy1 ); } void create2dnc(char * ncfilename,int n, double len, double totaltime, scalar * outvars) { int status; int ncid, xx_dim, yy_dim, time_dim, p_dim; int * tvar_id; int nvars = list_len(outvars); tvar_id=(int*)malloc(nvars*sizeof(int)); double *xx,*yy, *var; double dx=len/n; xx = (double *)malloc(n*sizeof(double)); yy = (double *)malloc(n*sizeof(double)); var = (double *)malloc(n*n*sizeof(double)); for (int ix=0; ix