#include #include #include #include #include "get_contact.h" #include "constant.h" #include "mpp_io.h" #include "mpp.h" char *usage[] = { "", " make_solo_mosaic --num_tiles ntiles --dir directory [--mosaic_name mosaic_name] ", " [--tile_file tile_file] [--periodx #] [--periody #] ", " ", "make_solo_mosaic generates Mosaic information between tiles. The mosaic ", "information includes: list of tile files, list of contact region ", "specified by index, contact type. ", " ", "make_solo_mosaic takes the following flags: ", " ", "REQUIRED: ", " ", "--num_tiles ntiles Number of tiles in the mosaic. ", " ", "--dir directory The directory that contains all the tile grid file. ", " ", "OPTIONAL FLAGS ", " ", "--mosaic_name name mosaic name. The output file will be mosaic_name.nc. ", " default is 'mosaic'. ", " ", "--tile_file tile_file Grid file name of all tiles in the mosaic. The file name ", " should be relative file name ( exclude the absolute ", " file path). The absolute file path will be dir/tile_file. ", " If this option is not specified, the tile_file will be ", " 'horizontal_grid.tile#.nc' ", " ", "--periodx # Specify the period in x-direction of mosaic. Default ", " value is 0 (not periodic). ", " ", "--periody # Specify the period in y-direction of mosaic. Default ", " value is 0 (not periodic). ", " ", " Example 1: create solo mosaic for tripolar grid(grid file name is ocean_grid.nc.", " make_solo_mosaic --num_tiles 1 --dir ./ --mosaic_name ocean_mosaic ", " --tile_file ocean_hgrid.nc --periodx 360 ", " ", " Example 2: create solo mosaic for torus. ", " make_solo_mosaic --num_tiles 1 --dir ./ --mosaic_name ocean_mosaic ", " --tile_file ocean_hgrid.nc --periodx 360 --periody 360 ", " ", " Example 3: create solo mosaic for C48 grid. ", " make_solo_mosaic --num_tiles 6 --dir ./ --mosaic C48_mosaic --tile_file ", " C48_grid.tile1.nc,C48_grid.tile2.nc,C48_grid.tile3.nc,C48_grid.tile4.nc, ", " C48_grid.tile5.nc,C48_grid.tile6.nc ", " ", NULL}; const int MAXTILE = 100; const int MAXCONTACT = 100; const int SHORTSTRING = 32; char grid_version[] = "0.2"; char tagname[] = "$Name: fre-nctools-bronx-10 $"; main (int argc, char *argv[]) { extern char *optarg; char *pch=NULL, *dir=NULL, history[512], entry[1280]; char tilefile[MAXTILE][STRING], tiletype[MAXTILE][SHORTSTRING]; char tile_name[MAXTILE][STRING]; int ntiles=0, nfiles=0, ncontact=0; int *nxp, *nyp; double **x, **y; double periodx=0, periody=0; int contact_tile1[MAXCONTACT], contact_tile2[MAXCONTACT]; int contact_tile1_istart[MAXCONTACT], contact_tile1_iend[MAXCONTACT]; int contact_tile1_jstart[MAXCONTACT], contact_tile1_jend[MAXCONTACT]; int contact_tile2_istart[MAXCONTACT], contact_tile2_iend[MAXCONTACT]; int contact_tile2_jstart[MAXCONTACT], contact_tile2_jend[MAXCONTACT]; char mosaic_name[128] = "solo_mosaic"; char grid_descriptor[128] = ""; int c, i, n, m, l, errflg; int option_index = 0; static struct option long_options[] = { {"mosaic_name", required_argument, NULL, 'm'}, {"num_tiles", required_argument, NULL, 'n'}, {"grid_descriptor", required_argument, NULL, 'g'}, {"tile_file", required_argument, NULL, 'f'}, {"periodx", required_argument, NULL, 'x'}, {"periody", required_argument, NULL, 'y'}, {"directory", required_argument, NULL, 'd'}, {NULL, 0, NULL, 0} }; mpp_init(&argc, &argv); /* this tool must be run one processor */ if(mpp_npes()>1) mpp_error("make_solo_mosaic: this tool must be run on one processor"); errflg = (argc == 1); /* First read command line arguments. */ while ((c = getopt_long(argc, argv, "h", long_options, &option_index)) != -1) { switch (c) { case 'n': ntiles = atoi(optarg); break; case 'm': strcpy(mosaic_name, optarg); break; case 'g': strcpy(grid_descriptor, optarg); break; case 'f': strcpy(entry, optarg); pch = strtok(entry, ", "); nfiles = 0; while( pch != NULL) { strcpy(tilefile[nfiles++], pch); pch = strtok(NULL, ", "); } break; case 'x': periodx = atof(optarg); break; case 'y': periody = atof(optarg); break; case 'd': // path of the simple grid file. dir = optarg; break; case '?': errflg++; } } if (errflg || ntiles < 1 || !dir ) { char **u = usage; while (*u) { fprintf(stderr, "%s\n", *u); u++; } exit(2); } strcpy(history,argv[0]); for(i=1;i MAXTILE) { mpp_error("make_solo_mosaic: number of tiles is greater than MAXTILE."); } /*--- if file name is not specified through -f, file name will be horizontal_grid.tile#.nc */ if(nfiles == 0) { if(ntiles == 1) { sprintf(tilefile[0],"horizontal_grid.nc"); } else { for(n=0; nMAXCONTACT) mpp_error("make_solo_mosaic: number of contacts is more than MAXCONTACT 1"); for(l=0; lMAXCONTACT) mpp_error("make_solo_mosaic: number of contacts is more than MAXCONTACT 2"); for(l=0; l0) dim_ncontact = mpp_def_dim(fid, "ncontact", ncontact); dim_string = mpp_def_dim(fid, "string", STRING); /* define variable */ id_mosaic = mpp_def_var(fid, "mosaic", MPP_CHAR, 1, &dim_string, 4, "standard_name", "grid_mosaic_spec", "children", "gridtiles", "contact_regions", "contacts", "grid_descriptor", grid_descriptor); dim[0] = dim_ntiles; dim[1] = dim_string; id_griddir = mpp_def_var(fid, "gridlocation", MPP_CHAR, 1, &dim[1], 1, "standard_name", "grid_file_location"); id_gridfiles = mpp_def_var(fid, "gridfiles", MPP_CHAR, 2, dim, 0); id_gridtiles = mpp_def_var(fid, "gridtiles", MPP_CHAR, 2, dim, 0); if(ncontact>0) { dim[0] = dim_ncontact; dim[1] = dim_string; id_contacts = mpp_def_var(fid, "contacts", MPP_CHAR, 2, dim, 5, "standard_name", "grid_contact_spec", "contact_type", "boundary", "alignment", "true", "contact_index", "contact_index", "orientation", "orient"); id_contact_index = mpp_def_var(fid, "contact_index", MPP_CHAR, 2, dim, 1, "standard_name", "starting_ending_point_index_of_contact"); } mpp_def_global_att(fid, "grid_version", grid_version); mpp_def_global_att(fid, "code_version", tagname); mpp_def_global_att(fid, "history", history); mpp_end_def(fid); /* write out data */ for(i=0; i<4; i++) { start[i] = 0; nwrite[i] = 1; } nwrite[0] = strlen(mosaic_name); mpp_put_var_value_block(fid, id_mosaic, start, nwrite, mosaic_name); nwrite[0] = strlen(dir); mpp_put_var_value_block(fid, id_griddir, start, nwrite, dir); nwrite[0] = 1; for(n=0; n