📄 input.c
字号:
ES->wave_type = MONOCHROMATIC; if (num<7) parse_error_message("** Syntax Error: Not enough eta_source inputs"); ES->H = H; ES->frequency = freq; ES->theta = theta; ES->icenter = icenter; if (num==8) /* then the parameter delta is also being specified */ ES->delta = delta; else ES->delta = -1.0; I->ES = ES; return; } if (!strcasecmp(e_str,"random1nb")) { ES->wave_type = RANDOM1; ES->subtype1 = RANDOM1_NARROW_BAND; num = sscanf(s,"%s %s %s %lf %lf %lf %d %lf %d %lf",bub, on_off, e_str, &H, &freq, &fwidth, &nf, &theta, &icenter, &delta); if (num<9) parse_error_message("** Syntax Error: Not enough eta_source inputs for random1 waves"); ES->H = H; ES->frequency = freq; ES->fwidth = fwidth; ES->numfreq = nf; ES->theta = theta; ES->icenter = icenter; if (num==10) /* then the parameter delta is also being specified */ ES->delta = delta; else ES->delta = -1.0; I->ES = ES; return; } if (!strcasecmp(e_str,"random1file")) { ES->wave_type = RANDOM1; ES->subtype1 = RANDOM1_FILE; num = sscanf(s,"%s %s %s %s %lf",bub, on_off, e_str, filename, &delta); ES->spectrum_file = g_string_new(filename); if (num==5) /* then the parameter delta is also being specified */ ES->delta = delta; else ES->delta = -1.0; I->ES = ES; return; } parse_error_message("Bad wave type inputs [monochromatic,random1nb,random1file] for eta_source");}void parse_breaking_info(char *s, inputinfo *I){ char bub[120]; char on_off[120]; int num; double cI, cF, cT, db; breaking_info_t *BR; num = sscanf(s,"%s %s %lf %lf %lf %lf",bub, on_off, &cI, &cF, &cT, &db); if (strcasecmp(bub,"breaking")) { parse_error_message("Bad first line for breaking input"); } if ((num != 2) && (num !=6)) parse_error_message("Not enough inputs for breaking: 'breaking [on,off] (c_eta_tI c_eta_tF cT deltaB)'"); /* next check to make sure coefficients they are > 0 */ BR = (breaking_info_t * ) g_malloc( sizeof(breaking_info_t) ); /* set the breaking defaults */ BR->delta_b = 1.2; BR->c_eta_tI = 0.65; BR->c_eta_tF = 0.15; BR->cT = 5.0; /* check if breaking is on or off */ if (!strcasecmp(on_off,"on")) { BR->breaking_flag = ON; } else { if (!strcasecmp(on_off,"off")) { BR->breaking_flag = OFF; I->BR = BR; return; } else parse_error_message("** Syntax Error: Bad 2nd option for breaking input line, should be [on,off]"); } if (num == 6) { BR->delta_b = db; BR->c_eta_tI = cI; BR->c_eta_tF = cF; BR->cT = cT; } /* I should check the values to make sure they make sense... */ I->BR = BR; }void parse_sponge_layer_info(char *s, inputinfo *I){ char bub[120]; char on_off[120]; int num; int ix0_width, ixL_width; double cspg1, cspg2, cspg3; sponge_layer_info_t *SP; num = sscanf(s,"%s %s %d %d %lf %lf %lf",bub, on_off, &ix0_width, &ixL_width, &cspg1, &cspg2, &cspg3); if (strcasecmp(bub,"sponge")) { parse_error_message("Bad first line for sponge layer input"); } if ((num <2)||(num >7)) parse_error_message("Not enough inputs for sponge_layer: 'sponge_layer [on,off] ix0 ixL cspg1 csgp2 csgp3'"); SP = (sponge_layer_info_t * ) g_malloc( sizeof(sponge_layer_info_t) ); /* check if eta source is on or off */ if (!strcasecmp(on_off,"on")) { if (num<8) SP->sponge_layer_flag = ON; else parse_error_message("** Syntax Error: Missing information arguments on sponge_layer input line"); } else { if (!strcasecmp(on_off,"off")) { SP->sponge_layer_flag = OFF; I->SP = SP; return; } else parse_error_message("** Syntax Error: Bad 2nd option for sponge_layer input line, should be [on,off]"); } if (I->ES->eta_source_flag == ON) { SP->frequency = I->ES->frequency; } else { SP->frequency = 1.0; fprintf(stderr,"* Warning: sponge layer activated without and wave eta source.\n"); } SP->ix0_width = ix0_width; SP->ixL_width = ixL_width; SP->cspg1 = cspg1; SP->cspg2 = cspg2; SP->cspg3 = cspg3; I->SP = SP; }/* This function parses the forcing file */void parse_forcing(inputinfo *I, char *s){ forcing_info_t *FI; int dfx, dfy, num; char fxfile[80], fyfile[80]; char title[80]; num = sscanf(s,"%s %d %s %d %s",title, &dfx, fxfile, &dfy, fyfile); /* this isn't right if the perturbation forcing of ANH is ever to be used */ if (strcasecmp(title,"forcing")) { parse_error_message("Syntax Error: Not a forcing line."); } if (num!=5) parse_error_message("Syntax error: not enough parameters on the forcing line"); FI = (forcing_info_t *) g_malloc(sizeof(forcing_info_t)); FI->dfx = dfx; FI->fxfile = g_string_new(fxfile); FI->dfy = dfy; FI->fyfile = g_string_new(fyfile); // if (dfy==4) // parse_error_message("ANH96 perturbation forcing not implemented!"); I->F = FI;}void parse_floats_info(char *s, inputinfo *I){ floats_info_t *FL; char bub[120]; char floats_f[120]; char floats_type[120]; char ffile[120]; int num, nfloats; double xf, yf; num = sscanf(s,"%s %s %s ", bub, floats_f, floats_type); //%, &ii, &jj, &qsrc, &kappa, &half_life); if (strcasecmp(bub,"floats")) { parse_error_message("Bad first line for float input"); } if ((num<2)||(num>8)) parse_error_message("Not enough inputs for float input."); FL = (floats_info_t * ) g_malloc(sizeof(floats_info_t)); FL-> floats_flag = OFF; FL->floatinit = NO_FLOATS; FL->nfloats = 0; if (!strcasecmp(floats_f,"on")) FL->floats_flag = ON; else { if (!strcasecmp(floats_f,"off")) { FL->floats_flag = OFF; I->FL = FL; return; } else parse_error_message("floats must be set either [on,off]."); } /* Now get the type of floats stuff */ if (!strcasecmp(floats_type,"random")) { FL->floatinit = RANDOM_FLOATS; num = sscanf(s,"%*s %*s %*s %d", &nfloats); FL->nfloats = nfloats; I->FL = FL; return; } if (!strcasecmp(floats_type,"file")) { FL->floatinit = FILE_FLOATS; num = sscanf(s,"%*s %*s %*s %s", ffile); FL->floats_file = g_string_new(ffile); I->FL = FL; return; } if (!strcasecmp(floats_type,"point")) { FL->floatinit = POINT_FLOATS; num = sscanf(s,"%*s %*s %*s %d %lf %lf", &nfloats, &xf, &yf); FL->nfloats = nfloats; FL->x0 = xf; FL->y0 = yf; I->FL = FL; return; } parse_error_message("** input_new.c: unrecognized floats type");}/* Parses the tracer input string and outputs the tracerinfo variable that is part of inputinfo *I */void parse_tracer_info(char *s, inputinfo *I){ char bub[120]; char tracer_f[120]; char tracer_type[120]; int num; int ii, jj; double qsrc; /* flux of tracer units = ?? */ double kappa, half_life; /* tracer diffusivity and half life */ double start_time; /* start time of tracer release */ double end_time; /* end time of tracer release */ tracerinfo *T; num = sscanf(s,"%s %s %s %d %d %lf %lf %lf %lf %lf", bub, tracer_f, tracer_type, &ii, &jj, &qsrc, &kappa, &half_life, &start_time, &end_time); if (strcasecmp(bub,"tracer")) { parse_error_message("Bad first line for tracer input"); } if (num<2) parse_error_message("Not enough inputs for tracer input."); if (num>10) parse_error_message("Too many inputs for tracer input."); T = (tracerinfo * ) g_malloc(sizeof(tracerinfo)); T->source_flag = 0; T->i_source = 1; T->j_source = 1; T->point_source_flux = 0.0; T->kappa = 0.0; T->half_life = 0.0; T->source_start_time = 0.0; /* default: source starts at t=0 */ T->source_end_time = 1e+30; /* essentially source goes on forever */ if (!strcasecmp(tracer_f,"on")) T->tracer_flag = ON; else { if (!strcasecmp(tracer_f,"off")) { T->tracer_flag = OFF; I->TR = T; return; } else parse_error_message("tracer must be set either [on,off]."); } if (!strcasecmp(tracer_type,"pointsource")) { T->source_flag = TRACER_POINT_SOURCE; } else { if (!strcasecmp(tracer_type,"initialcondition")) { T->source_flag = TRACER_INITIAL_CONDITION; parse_error_message("** tracer initial condition not yet implemented."); } else{ parse_error_message("** tracer type is not [pointsource, initialcondition]."); } } if (num<7) parse_error_message("** Syntax Error: not correct number for tracer input. "); T->i_source = ii; T->j_source = jj; T->point_source_flux = qsrc; T->kappa = kappa; if (num>7) { T->half_life = half_life; } if (num == 10) { T->source_start_time = start_time; T->source_end_time = end_time; } I->TR = T;}void parse_UV_initial_condition(inputinfo *I, char *s){ char bub[120]; char uic_file[120],vic_file[120], etaic_file[120], p_file[120]; int uic,vic,etaic, pid; int num; initial_condition_info_t *IC; num = sscanf(s,"%s %d %s %d %s %d %s %d %s",bub, &uic,uic_file,&vic,vic_file,&etaic, etaic_file, &pid,p_file); if (strcasecmp(bub,"UV_initial_cond")) { parse_error_message("Bad first line for U & V initial condition input. Require 'UV_initial_cond' "); } if ((num<7)||(num>9)) parse_error_message("Not enough inputs for UV initial condition input."); IC = (initial_condition_info_t * ) g_malloc(sizeof(initial_condition_info_t)); if ( (uic<0)||(uic>2) ) parse_error_message("Wrong u IC flag in init file: need [0,1,2]"); if ( (vic<0)||(vic>2) ) parse_error_message("Wrong v IC flag in init file: need [0,1,2]"); if ( (etaic<0)||(etaic>2) ) parse_error_message("Wrong eta IC flag in init file: need [0,1,2]"); IC->uic = uic; IC->uic_file = g_string_new(uic_file); IC->vic = vic; IC->vic_file = g_string_new(vic_file); IC->etaic = etaic; IC->etaic_file = g_string_new(etaic_file); IC->streamic = 0; if (num>7) { if ( (pid==0)||(pid==2) ) { IC->streamic = pid; IC->stream_file = g_string_new(p_file); } else { parse_error_message("Wrong streamfunction IC flag in init file: need [0,1,2]"); } } I->IC = IC;}inputinfo* load_init_file(GString *fname){ FILE *finit; char s[200]; inputinfo *I; if ((finit=fopen(fname->str,"r"))==0) { fprintf(stderr,"Error opening init file: %s \n",fname->str); exit(-1); } /* Allocate all the memory needed */ I = (inputinfo * ) g_malloc(sizeof(inputinfo)); /* get 1st line with identifier and dynamics information */ get_next_line(finit, s); parse_dynamics_info(s, I); /* get the values of nx, ny, dx, dy */ get_next_line(finit,s); parse_dimensions(s, I); /* get the type and values of bottom stress (cd) */ get_next_line(finit,s); parse_bottom_stress(s, I); /* get the lateral mixing coefficients */ get_next_line(finit,s); parse_lateral_mixing(s, I); /* next get the bathymetry */ get_next_line(finit,s); parse_bathymetry(s, I); /* next get the wave source function for eta */ get_next_line(finit,s); parse_eta_source(s, I); /* get the breaking wave info */ get_next_line(finit,s); parse_breaking_info(s, I); /* next get the wave source function for eta */ get_next_line(finit,s); parse_sponge_layer_info(s, I); /* need to parse after eta source */ /* Get the forcing strings */ get_next_line(finit,s); parse_forcing(I, s); /* get the velocity IC's strings */ get_next_line(finit,s); parse_UV_initial_condition(I, s); /* get passive tracer information */ get_next_line(finit,s); parse_tracer_info(s, I); /* get floats information */ get_next_line(finit,s); parse_floats_info(s, I); /* load the timing information */ I->T = process_timing(finit); /* parse the output routines */ I->A = parse_output(finit); // need to check that cross & along ouput are in bounds! return I;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -