/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! !! !! GNU General Public License !! !! !! !! This file is part of the Flexible Modeling System (FMS). !! !! !! !! FMS is free software; you can redistribute it and/or modify !! !! it and are expected to follow the terms of the GNU General Public !! !! License as published by the Free Software Foundation. !! !! !! !! FMS is distributed in the hope that it will be useful, !! !! but WITHOUT ANY WARRANTY; without even the implied warranty of !! !! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !! !! GNU General Public License for more details. !! !! !! !! You should have received a copy of the GNU General Public License !! !! along with FMS; if not, write to: !! !! Free Software Foundation, Inc. !! !! 59 Temple Place, Suite 330 !! !! Boston, MA 02111-1307 USA !! !! or see: !! !! http://www.gnu.org/licenses/gpl.txt !! !! !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /******************************************************************************* contact: Zhi Liang (Zhi.Liang@noaa.gov) *******************************************************************************/ #include #include #include #include #include "constant.h" #include "mpp.h" #include "mpp_io.h" #include "read_mosaic.h" #include "tool_util.h" char *usage[] = { "", " edit_landXocean --mosaic mosaic_grid ", " ", "edit_landXocean will adjust the landXocean exchange grid cell area to put the flux ", "onto ocean points that are adjacent to land points. ", " ", "edit_landXocean takes the following flags: ", " ", "REQUIRED: ", " ", "--mosaic_grid mosaic_grid specify the mosaic grid file to be edited. This mosaic ", " file should be a coupler mosaic file, which contains link ", " to ocean topog file and the exchange grid file. ", " ", NULL }; int main(int argc, char* argv[]) { unsigned int opcode = 0; int option_index, c, n; char *mosaic_file = NULL; char **lXo_file = NULL; char **lXo_base_file = NULL; char history[1024]; char mosaic_dir[STRING], ocn_mosaic[STRING], lnd_mosaic[STRING]; int **ocn_mask; int *nxgrid; double **area_lXo; int **il_lXo, **jl_lXo, **io_lXo, **jo_lXo; int *nx_ocn, *ny_ocn, *nx_lnd, *ny_lnd; int nlXo, ntiles_ocn, ntiles_lnd; int x_cyclic, y_cyclic, folded_north; int errflg = (argc == 1); static struct option long_options[] = { {"mosaic_grid", required_argument, NULL, 'a'}, {0, 0, 0, 0}, }; mpp_init(&argc, &argv); /* This tool will be run on one processor */ if(mpp_npes() > 1) mpp_error("edit_landXocean: parallel is not supported yet, try running one single processor"); while ((c = getopt_long(argc, argv, "", long_options, &option_index)) != -1) { switch (c) { case 'a': mosaic_file = optarg; break; case '?': errflg++; break; } } if (errflg) { char **u = usage; while (*u) { fprintf(stderr, "%s\n", *u); u++; } exit(2); } /* check the arguments */ if( !mosaic_file ) mpp_error("fregrid: mosaic_grid is not specified"); strcpy(history,argv[0]); for(n=1;n0) { read_mosaic_contact(ocn_mosaic, tile1, tile2, istart1, iend1, jstart1, jend1, istart2, iend2, jstart2, jend2); if(ncontact <= 2) { /* x-cyclic of y-cyclic */ for(n=0; n 0) scale[m] *= (tot_area[jl*nxl+il]/set_area[jl*nxl+il]); else { printf("at point (%d, %d), set_area = %15.12f is negative\n", il, jl, set_area[jl*nxl+il]); mpp_error("program edit_landXocean: set_area is negative for some point"); } } free(tot_area); free(set_area); /* write the scale information into the xgrid file */ if(!strcmp(lXo_file[n], lXo_base_file[n])) { sprintf(orig_file, "%s.orig", lXo_file[n]); sprintf(cmd, "cp %s %s", lXo_file[n], orig_file); system(cmd); } else { sprintf(cmd, "cp %s %s", lXo_file[n], lXo_base_file[n]); system(cmd); } fid = mpp_open(lXo_base_file[n], MPP_APPEND); mpp_redef(fid); id_ncell = mpp_get_dimid(fid, "ncells"); id_scale = mpp_def_var(fid, "scale", MPP_DOUBLE, 1, &id_ncell, 0); mpp_end_def(fid); mpp_put_var_value(fid, id_scale, scale); mpp_close(fid); } } /* free the memory */ for(n=0; n