void fixedbase_read ( FILE* fp ) { if ( ( parsetext(fp, "fixedbase_input_dt", 'd', &theBaseFixedDT ) != 0) || ( parsetext(fp, "fixedbase_input_dir", 's', &theBaseFixedDir ) != 0) || ( parsetext(fp, "fixedbase_input_startindex", 'i', &theBaseFixedStartIndex ) != 0) || ( parsetext(fp, "fixedbase_input_sufix", 's', &theBaseFixedSufix ) != 0) ) { solver_abort ( __FUNCTION_NAME, "Parsetext returned non-zero", "Error parsing fixed-based options" ); } return; }
static TCHAR *parsetextpath (const TCHAR *s) { TCHAR *s3 = parsetext (s); //TCHAR *s3 = target_expand_environment (s2); //xfree (s2); return s3; }
Datum to_tsvector_byid(PG_FUNCTION_ARGS) { Oid cfgId = PG_GETARG_OID(0); text *in = PG_GETARG_TEXT_P(1); ParsedText prs; TSVector out; prs.lenwords = (VARSIZE(in) - VARHDRSZ) / 6; /* just estimation of * word's number */ if (prs.lenwords == 0) prs.lenwords = 2; prs.curwords = 0; prs.pos = 0; prs.words = (ParsedWord *) palloc(sizeof(ParsedWord) * prs.lenwords); parsetext(cfgId, &prs, VARDATA(in), VARSIZE(in) - VARHDRSZ); PG_FREE_IF_COPY(in, 1); if (prs.curwords) out = make_tsvector(&prs); else { pfree(prs.words); out = palloc(CALCDATASIZE(0, 0)); SET_VARSIZE(out, CALCDATASIZE(0, 0)); out->size = 0; } PG_RETURN_POINTER(out); }
// Scans src and writes pointers to the lexical bounds of JSON values // to elements of part. // // Returns the total number of values in src, regardless of npart. // If src is not well-formed JSON, returns 0. int jsonparse(char *src, JSON *part, int npart) { Parser p = {}; p.s = src; p.j = part; p.nj = npart; skipws(&p); must(parsetext(&p)); skipws(&p); must(*p.s == '\0'); if (part) { if (p.n < npart) { npart = p.n; } for (int i = 0; i < npart; i++) { part[i].len = part[i].end - part[i].src; } } return p.n; }
static Datum tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column) { TriggerData *trigdata; Trigger *trigger; Relation rel; HeapTuple rettuple = NULL; int tsvector_attr_num, i; ParsedText prs; Datum datum; bool isnull; text *txt; Oid cfgId; /* Check call context */ if (!CALLED_AS_TRIGGER(fcinfo)) /* internal error */ elog(ERROR, "tsvector_update_trigger: not fired by trigger manager"); trigdata = (TriggerData *) fcinfo->context; if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) elog(ERROR, "tsvector_update_trigger: must be fired for row"); if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event)) elog(ERROR, "tsvector_update_trigger: must be fired BEFORE event"); if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event)) rettuple = trigdata->tg_trigtuple; else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event)) rettuple = trigdata->tg_newtuple; else elog(ERROR, "tsvector_update_trigger: must be fired for INSERT or UPDATE"); trigger = trigdata->tg_trigger; rel = trigdata->tg_relation; if (trigger->tgnargs < 3) elog(ERROR, "tsvector_update_trigger: arguments must be tsvector_field, ts_config, text_field1, ...)"); /* Find the target tsvector column */ tsvector_attr_num = SPI_fnumber(rel->rd_att, trigger->tgargs[0]); if (tsvector_attr_num == SPI_ERROR_NOATTRIBUTE) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_COLUMN), errmsg("tsvector column \"%s\" does not exist", trigger->tgargs[0]))); if (!IsBinaryCoercible(SPI_gettypeid(rel->rd_att, tsvector_attr_num), TSVECTOROID)) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("column \"%s\" is not of tsvector type", trigger->tgargs[0]))); /* Find the configuration to use */ if (config_column) { int config_attr_num; config_attr_num = SPI_fnumber(rel->rd_att, trigger->tgargs[1]); if (config_attr_num == SPI_ERROR_NOATTRIBUTE) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_COLUMN), errmsg("configuration column \"%s\" does not exist", trigger->tgargs[1]))); if (!IsBinaryCoercible(SPI_gettypeid(rel->rd_att, config_attr_num), REGCONFIGOID)) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("column \"%s\" is not of regconfig type", trigger->tgargs[1]))); datum = SPI_getbinval(rettuple, rel->rd_att, config_attr_num, &isnull); if (isnull) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("configuration column \"%s\" must not be null", trigger->tgargs[1]))); cfgId = DatumGetObjectId(datum); } else { List *names; names = stringToQualifiedNameList(trigger->tgargs[1]); /* require a schema so that results are not search path dependent */ if (list_length(names) < 2) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("text search configuration name \"%s\" must be schema-qualified", trigger->tgargs[1]))); cfgId = get_ts_config_oid(names, false); } /* initialize parse state */ prs.lenwords = 32; prs.curwords = 0; prs.pos = 0; prs.words = (ParsedWord *) palloc(sizeof(ParsedWord) * prs.lenwords); /* find all words in indexable column(s) */ for (i = 2; i < trigger->tgnargs; i++) { int numattr; numattr = SPI_fnumber(rel->rd_att, trigger->tgargs[i]); if (numattr == SPI_ERROR_NOATTRIBUTE) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_COLUMN), errmsg("column \"%s\" does not exist", trigger->tgargs[i]))); if (!IsBinaryCoercible(SPI_gettypeid(rel->rd_att, numattr), TEXTOID)) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("column \"%s\" is not of a character type", trigger->tgargs[i]))); datum = SPI_getbinval(rettuple, rel->rd_att, numattr, &isnull); if (isnull) continue; txt = DatumGetTextP(datum); parsetext(cfgId, &prs, VARDATA(txt), VARSIZE(txt) - VARHDRSZ); if (txt != (text *) DatumGetPointer(datum)) pfree(txt); } /* make tsvector value */ if (prs.curwords) { datum = PointerGetDatum(make_tsvector(&prs)); rettuple = SPI_modifytuple(rel, rettuple, 1, &tsvector_attr_num, &datum, NULL); pfree(DatumGetPointer(datum)); } else { TSVector out = palloc(CALCDATASIZE(0, 0)); SET_VARSIZE(out, CALCDATASIZE(0, 0)); out->size = 0; datum = PointerGetDatum(out); rettuple = SPI_modifytuple(rel, rettuple, 1, &tsvector_attr_num, &datum, NULL); pfree(prs.words); } if (rettuple == NULL) /* internal error */ elog(ERROR, "tsvector_update_trigger: %d returned by SPI_modifytuple", SPI_result); return PointerGetDatum(rettuple); }
/** * initparameters: Open material database and initialize various * static global variables. Return 0 if OK, -1 on error. */ int32_t initparameters(const char *physicsin, const char *numericalin, double *px, double *py, double *pz) { FILE *fp; double freq; int32_t samples; double region_origin_latitude_deg, region_origin_longitude_deg; double region_depth_shallow_m, region_length_east_m; double region_length_north_m, region_depth_deep_m; #ifdef USECVMDB dbctl_t *myctl; #endif /* Obtain the specficiation of the simulation */ if ((fp = fopen(physicsin, "r")) == NULL) { fprintf(stderr, "Error opening %s\n", physicsin); return -1; } if ((parsetext(fp, "region_origin_latitude_deg", 'd', ®ion_origin_latitude_deg) != 0) || (parsetext(fp, "region_origin_longitude_deg", 'd', ®ion_origin_longitude_deg) != 0) || (parsetext(fp, "region_depth_shallow_m", 'd', ®ion_depth_shallow_m) != 0) || (parsetext(fp, "region_length_east_m", 'd', ®ion_length_east_m) != 0) || (parsetext(fp, "region_length_north_m", 'd', ®ion_length_north_m) != 0) || (parsetext(fp, "region_depth_deep_m", 'd', ®ion_depth_deep_m) != 0)) { fprintf(stderr, "Error parsing fields from %s\n", physicsin); return -1; } fclose(fp); if ((fp = fopen(numericalin, "r")) == NULL) { fprintf(stderr, "Error opening %s\n", numericalin); return -1; } if ((parsetext(fp, "simulation_wave_max_freq_hz", 'd', &freq) != 0) || (parsetext(fp, "simulation_node_per_wavelength", 'i', &samples) != 0)|| (parsetext(fp, "simulation_shear_velocity_min", 'd', &theVsCut) != 0)){ fprintf(stderr, "Error parsing fields from %s\n", numericalin); return -1; } fclose(fp); theFreq = freq; theFactor = freq * samples; #ifdef USECVMDB /* Obtain the material database application control/meta data */ if ((myctl = cvm_getdbctl(theCVMEp)) == NULL) { fprintf(stderr, "Error reading CVM etree control data\n"); return -1; } /* Check the ranges of the mesh and the scope of the CVM etree */ if ((region_origin_latitude_deg < myctl->region_origin_latitude_deg) || (region_origin_longitude_deg < myctl->region_origin_longitude_deg) || (region_depth_shallow_m < myctl->region_depth_shallow_m) || (region_depth_deep_m > myctl->region_depth_deep_m) || (region_origin_latitude_deg + region_length_north_m / DIST1LAT > myctl->region_origin_latitude_deg + myctl->region_length_north_m / DIST1LAT) || (region_origin_longitude_deg + region_length_east_m / DIST1LON > myctl->region_origin_longitude_deg + myctl->region_length_north_m / DIST1LON)) { fprintf(stderr, "Mesh area out of the CVM etree\n"); return -1; } /* Compute the coordinates of the origin of the mesh coordinate system in the CVM etree domain coordinate system */ theXForMeshOrigin = (region_origin_latitude_deg - myctl->region_origin_latitude_deg) * DIST1LAT; theYForMeshOrigin = (region_origin_longitude_deg - myctl->region_origin_longitude_deg) * DIST1LON; theZForMeshOrigin = region_depth_shallow_m - myctl->region_depth_shallow_m; /* Free memory used by myctl */ cvm_freedbctl(myctl); #endif *px = region_length_north_m; *py = region_length_east_m; *pz = region_depth_deep_m - region_depth_shallow_m; return 0; }
/* * This function is used for morph parsing. * * The value is passed to parsetext which will call the right dictionary to * lexize the word. If it turns out to be a stopword, we push a QI_VALSTOP * to the stack. * * All words belonging to the same variant are pushed as an ANDed list, * and different variants are ORred together. */ static void pushval_morph(Datum opaque, TSQueryParserState state, char *strval, int lenval, int2 weight, bool prefix) { int4 count = 0; ParsedText prs; uint32 variant, pos, cntvar = 0, cntpos = 0, cnt = 0; Oid cfg_id = DatumGetObjectId(opaque); /* the input is actually * an Oid, not a pointer */ prs.lenwords = 4; prs.curwords = 0; prs.pos = 0; prs.words = (ParsedWord *) palloc(sizeof(ParsedWord) * prs.lenwords); parsetext(cfg_id, &prs, strval, lenval); if (prs.curwords > 0) { while (count < prs.curwords) { pos = prs.words[count].pos.pos; cntvar = 0; while (count < prs.curwords && pos == prs.words[count].pos.pos) { variant = prs.words[count].nvariant; cnt = 0; while (count < prs.curwords && pos == prs.words[count].pos.pos && variant == prs.words[count].nvariant) { pushValue(state, prs.words[count].word, prs.words[count].len, weight, ((prs.words[count].flags & TSL_PREFIX) || prefix) ? true : false); pfree(prs.words[count].word); if (cnt) pushOperator(state, OP_AND); cnt++; count++; } if (cntvar) pushOperator(state, OP_OR); cntvar++; } if (cntpos) pushOperator(state, OP_AND); cntpos++; } pfree(prs.words); } else pushStop(state); }
void TestChoiceFormat::TestComplexExample( void ) { UErrorCode status = U_ZERO_ERROR; const double filelimits[] = {-1, 0,1,2}; const UnicodeString filepart[] = {"are corrupted files", "are no files","is one file","are {2} files"}; ChoiceFormat* fileform = new ChoiceFormat( filelimits, filepart, 4); if (!fileform) { it_errln("*** test_complex_example fileform"); return; } Format* filenumform = NumberFormat::createInstance( status ); if (!filenumform) { dataerrln((UnicodeString)"*** test_complex_example filenumform - " + u_errorName(status)); delete fileform; return; } if (!chkstatus( status, "*** test_simple_example filenumform" )) { delete fileform; delete filenumform; return; } //const Format* testFormats[] = { fileform, NULL, filenumform }; //pattform->setFormats( testFormats, 3 ); MessageFormat* pattform = new MessageFormat("There {0} on {1}", status ); if (!pattform) { it_errln("*** test_complex_example pattform"); delete fileform; delete filenumform; return; } if (!chkstatus( status, "*** test_complex_example pattform" )) { delete fileform; delete filenumform; delete pattform; return; } pattform->setFormat( 0, *fileform ); pattform->setFormat( 2, *filenumform ); Formattable testArgs[] = {(int32_t)0, "Disk_A", (int32_t)0}; UnicodeString str; UnicodeString res1, res2; pattform->toPattern( res1 ); it_logln("MessageFormat toPattern: " + res1); fileform->toPattern( res1 ); it_logln("ChoiceFormat toPattern: " + res1); if (res1 == "-1#are corrupted files|0#are no files|1#is one file|2#are {2} files") { it_logln("toPattern tested!"); }else{ it_errln("*** ChoiceFormat to Pattern result!"); } FieldPosition fpos(FieldPosition::DONT_CARE); UnicodeString checkstr[] = { "There are corrupted files on Disk_A", "There are no files on Disk_A", "There is one file on Disk_A", "There are 2 files on Disk_A", "There are 3 files on Disk_A" }; // if (status != U_ZERO_ERROR) return; // TODO: analyze why we have such a bad bail out here! if (U_FAILURE(status)) { delete fileform; delete filenumform; delete pattform; return; } int32_t i; int32_t start = -1; for (i = start; i < 4; ++i) { str = ""; status = U_ZERO_ERROR; testArgs[0] = Formattable((int32_t)i); testArgs[2] = testArgs[0]; res2 = pattform->format(testArgs, 3, str, fpos, status ); if (!chkstatus( status, "*** test_complex_example format" )) { delete fileform; delete filenumform; delete pattform; return; } it_logln(i + UnicodeString(" -> ") + res2); if (res2 != checkstr[i - start]) { it_errln("*** test_complex_example res string"); it_errln(UnicodeString("*** ") + i + UnicodeString(" -> '") + res2 + UnicodeString("' unlike '") + checkstr[i] + UnicodeString("' ! ")); } } it_logln(); it_logln("------ additional testing in complex test ------"); it_logln(); // #if 0 // ICU 4.8 deprecates and disables the ChoiceFormat getters. int32_t retCount; const double* retLimits = fileform->getLimits( retCount ); if ((retCount == 4) && (retLimits) && (retLimits[0] == -1.0) && (retLimits[1] == 0.0) && (retLimits[2] == 1.0) && (retLimits[3] == 2.0)) { it_logln("getLimits tested!"); }else{ it_errln("*** getLimits unexpected result!"); } const UnicodeString* retFormats = fileform->getFormats( retCount ); if ((retCount == 4) && (retFormats) && (retFormats[0] == "are corrupted files") && (retFormats[1] == "are no files") && (retFormats[2] == "is one file") && (retFormats[3] == "are {2} files")) { it_logln("getFormats tested!"); }else{ it_errln("*** getFormats unexpected result!"); } #endif UnicodeString checkstr2[] = { "There is no folder on Disk_A", "There is one folder on Disk_A", "There are many folders on Disk_A", "There are many folders on Disk_A" }; fileform->applyPattern("0#is no folder|1#is one folder|2#are many folders", status ); if (status == U_ZERO_ERROR) it_logln("status applyPattern OK!"); if (!chkstatus( status, "*** test_complex_example pattform" )) { delete fileform; delete filenumform; delete pattform; return; } pattform->setFormat( 0, *fileform ); fpos = 0; for (i = 0; i < 4; ++i) { str = ""; status = U_ZERO_ERROR; testArgs[0] = Formattable((int32_t)i); testArgs[2] = testArgs[0]; res2 = pattform->format(testArgs, 3, str, fpos, status ); if (!chkstatus( status, "*** test_complex_example format 2" )) { delete fileform; delete filenumform; delete pattform; return; } it_logln(UnicodeString() + i + UnicodeString(" -> ") + res2); if (res2 != checkstr2[i]) { it_errln("*** test_complex_example res string"); it_errln(UnicodeString("*** ") + i + UnicodeString(" -> '") + res2 + UnicodeString("' unlike '") + checkstr2[i] + UnicodeString("' ! ")); } } const double limits_A[] = {1,2,3,4,5,6,7}; const UnicodeString monthNames_A[] = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}; ChoiceFormat* form_A = new ChoiceFormat(limits_A, monthNames_A, 7); ChoiceFormat* form_A2 = new ChoiceFormat(limits_A, monthNames_A, 7); const double limits_B[] = {1,2,3,4,5,6,7}; const UnicodeString monthNames_B[] = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat_BBB"}; ChoiceFormat* form_B = new ChoiceFormat(limits_B, monthNames_B, 7); if (!form_A || !form_B || !form_A2) { it_errln("*** test-choiceFormat not allocatable!"); }else{ if (*form_A == *form_A2) { it_logln("operator== tested."); }else{ it_errln("*** operator=="); } if (*form_A != *form_B) { it_logln("operator!= tested."); }else{ it_errln("*** operator!="); } ChoiceFormat* form_A3 = (ChoiceFormat*) form_A->clone(); if (!form_A3) { it_errln("*** ChoiceFormat->clone is nil."); }else{ if ((*form_A3 == *form_A) && (*form_A3 != *form_B)) { it_logln("method clone tested."); }else{ it_errln("*** ChoiceFormat clone or operator==, or operator!= ."); } } ChoiceFormat form_Assigned( *form_A ); UBool ok = (form_Assigned == *form_A) && (form_Assigned != *form_B); form_Assigned = *form_B; ok = ok && (form_Assigned != *form_A) && (form_Assigned == *form_B); if (ok) { it_logln("copy constructor and operator= tested."); }else{ it_errln("*** copy constructor or operator= or operator == or operator != ."); } delete form_A3; } delete form_A; delete form_A2; delete form_B; const char* testPattern = "0#none|1#one|2#many"; ChoiceFormat form_pat( testPattern, status ); if (!chkstatus( status, "*** ChoiceFormat contructor( newPattern, status)" )) { delete fileform; delete filenumform; delete pattform; return; } form_pat.toPattern( res1 ); if (res1 == "0#none|1#one|2#many") { it_logln("ChoiceFormat contructor( newPattern, status) tested"); }else{ it_errln("*** ChoiceFormat contructor( newPattern, status) or toPattern result!"); } double d_a2[] = { 3.0, 4.0 }; UnicodeString s_a2[] = { "third", "forth" }; form_pat.setChoices( d_a2, s_a2, 2 ); form_pat.toPattern( res1 ); it_logln(UnicodeString("ChoiceFormat adoptChoices toPattern: ") + res1); if (res1 == "3#third|4#forth") { it_logln("ChoiceFormat adoptChoices tested"); }else{ it_errln("*** ChoiceFormat adoptChoices result!"); } str = ""; fpos = 0; status = U_ZERO_ERROR; double arg_double = 3.0; res1 = form_pat.format( arg_double, str, fpos ); it_logln(UnicodeString("ChoiceFormat format:") + res1); if (res1 != "third") it_errln("*** ChoiceFormat format (double, ...) result!"); str = ""; fpos = 0; status = U_ZERO_ERROR; int64_t arg_64 = 3; res1 = form_pat.format( arg_64, str, fpos ); it_logln(UnicodeString("ChoiceFormat format:") + res1); if (res1 != "third") it_errln("*** ChoiceFormat format (int64_t, ...) result!"); str = ""; fpos = 0; status = U_ZERO_ERROR; int32_t arg_long = 3; res1 = form_pat.format( arg_long, str, fpos ); it_logln(UnicodeString("ChoiceFormat format:") + res1); if (res1 != "third") it_errln("*** ChoiceFormat format (int32_t, ...) result!"); Formattable ft( (int32_t)3 ); str = ""; fpos = 0; status = U_ZERO_ERROR; res1 = form_pat.format( ft, str, fpos, status ); if (!chkstatus( status, "*** test_complex_example format (int32_t, ...)" )) { delete fileform; delete filenumform; delete pattform; return; } it_logln(UnicodeString("ChoiceFormat format:") + res1); if (res1 != "third") it_errln("*** ChoiceFormat format (Formattable, ...) result!"); Formattable fta[] = { (int32_t)3 }; str = ""; fpos = 0; status = U_ZERO_ERROR; res1 = form_pat.format( fta, 1, str, fpos, status ); if (!chkstatus( status, "*** test_complex_example format (int32_t, ...)" )) { delete fileform; delete filenumform; delete pattform; return; } it_logln(UnicodeString("ChoiceFormat format:") + res1); if (res1 != "third") it_errln("*** ChoiceFormat format (Formattable[], cnt, ...) result!"); ParsePosition parse_pos = 0; Formattable result; UnicodeString parsetext("third"); form_pat.parse( parsetext, result, parse_pos ); double rd = (result.getType() == Formattable::kLong) ? result.getLong() : result.getDouble(); if (rd == 3.0) { it_logln("parse( ..., ParsePos ) tested."); }else{ it_errln("*** ChoiceFormat parse( ..., ParsePos )!"); } form_pat.parse( parsetext, result, status ); rd = (result.getType() == Formattable::kLong) ? result.getLong() : result.getDouble(); if (rd == 3.0) { it_logln("parse( ..., UErrorCode ) tested."); }else{ it_errln("*** ChoiceFormat parse( ..., UErrorCode )!"); } /* UClassID classID = ChoiceFormat::getStaticClassID(); if (classID == form_pat.getDynamicClassID()) { it_out << "getStaticClassID and getDynamicClassID tested." << endl; }else{ it_errln("*** getStaticClassID and getDynamicClassID!"); } */ it_logln(); delete fileform; delete filenumform; delete pattform; }
int32_t buildings_initparameters ( const char *parametersin ) { FILE *fp; int iBldg, bldgsNfactor, numBldgs; double min_oct_size, surface_shift; double *auxiliar; char consider_fixed_base[16]; noyesflag_t fixedbase = -1; /* Opens parametersin file */ if ( ( fp = fopen(parametersin, "r" ) ) == NULL ) { fprintf( stderr, "Error opening %s\n at buildings_initparameters", parametersin ); return -1; } /* Parses parametersin to capture building single-value parameters */ if ( ( parsetext(fp, "number_of_buildings", 'i', &numBldgs ) != 0) || ( parsetext(fp, "buildings_n_factor", 'i', &bldgsNfactor ) != 0) || ( parsetext(fp, "min_octant_size_m", 'd', &min_oct_size ) != 0) || ( parsetext(fp, "surface_shift_m", 'd', &surface_shift ) != 0) || ( parsetext(fp, "consider_fixed_base", 's', &consider_fixed_base) != 0) ) { fprintf( stderr, "Error parsing building parameters from %s\n", parametersin ); return -1; } /* Performs sanity checks */ if ( numBldgs < 0 ) { fprintf( stderr, "Illegal number of buildings %d\n", numBldgs ); return -1; } if ( bldgsNfactor < 0 ) { fprintf( stderr, "Illegal buildings_n_factor for buildings %d\n", bldgsNfactor ); return -1; } if ( min_oct_size < 0 ) { fprintf( stderr, "Illegal minimum octant size for buildings %f\n", min_oct_size ); return -1; } if ( surface_shift < 0 ) { fprintf( stderr, "Illegal surface_shift for buildings %f\n", surface_shift ); return -1; } if ( strcasecmp(consider_fixed_base, "yes") == 0 ) { fixedbase = YES; } else if ( strcasecmp(consider_fixed_base, "no") == 0 ) { fixedbase = NO; } else { solver_abort( __FUNCTION_NAME, NULL, "Unknown response for considering" "fixed base option (yes or no): %s\n", consider_fixed_base ); } /* Initialize the static global variables */ theNumberOfBuildings = numBldgs; theBuildingsNFactor = bldgsNfactor; theMinOctSizeMeters = min_oct_size; theSurfaceShift = surface_shift; areBaseFixed = fixedbase; /* Detour for fixed base option */ if ( areBaseFixed == YES ) { fixedbase_read( fp ); } auxiliar = (double*)malloc( sizeof(double) * numBldgs * 12 ); theBuildingsXMin = (double*)malloc( sizeof(double) * numBldgs ); theBuildingsXMax = (double*)malloc( sizeof(double) * numBldgs ); theBuildingsYMin = (double*)malloc( sizeof(double) * numBldgs ); theBuildingsYMax = (double*)malloc( sizeof(double) * numBldgs ); theBuildingsZMin = (double*)malloc( sizeof(double) * numBldgs ); theBuildingsZMax = (double*)malloc( sizeof(double) * numBldgs ); theBuildingsDepth = (double*)malloc( sizeof(double) * numBldgs ); theBuildingsHeight = (double*)malloc( sizeof(double) * numBldgs ); theBuildingsDepth = (double*)malloc( sizeof(double) * numBldgs ); theBuildingsVp = (double*)malloc( sizeof(double) * numBldgs ); theBuildingsVs = (double*)malloc( sizeof(double) * numBldgs ); theBuildingsRho = (double*)malloc( sizeof(double) * numBldgs ); theFoundationsVp = (double*)malloc( sizeof(double) * numBldgs ); theFoundationsVs = (double*)malloc( sizeof(double) * numBldgs ); theFoundationsRho = (double*)malloc( sizeof(double) * numBldgs ); if ( ( auxiliar == NULL ) || ( theBuildingsXMin == NULL ) || ( theBuildingsXMax == NULL ) || ( theBuildingsYMin == NULL ) || ( theBuildingsYMax == NULL ) || ( theBuildingsDepth == NULL ) || ( theBuildingsHeight == NULL ) || ( theBuildingsVp == NULL ) || ( theBuildingsVs == NULL ) || ( theBuildingsRho == NULL ) || ( theFoundationsVp == NULL ) || ( theFoundationsVs == NULL ) || ( theFoundationsRho == NULL ) ) { fprintf( stderr, "Errror allocating transient building arrays" "in buildings_initparameters " ); return -1; } if ( parsedarray( fp, "building_properties", numBldgs*12, auxiliar ) != 0) { fprintf( stderr, "Error parsing building_properties list from %s\n", parametersin ); return -1; } /* We DO NOT convert physical coordinates into etree coordinates here */ for (iBldg = 0; iBldg < numBldgs; iBldg++) { theBuildingsXMin [ iBldg ] = auxiliar [ iBldg * 12 ]; theBuildingsXMax [ iBldg ] = auxiliar [ iBldg * 12 + 1 ]; theBuildingsYMin [ iBldg ] = auxiliar [ iBldg * 12 + 2 ]; theBuildingsYMax [ iBldg ] = auxiliar [ iBldg * 12 + 3 ]; theBuildingsDepth [ iBldg ] = auxiliar [ iBldg * 12 + 4 ]; theBuildingsHeight [ iBldg ] = auxiliar [ iBldg * 12 + 5 ]; theBuildingsVp [ iBldg ] = auxiliar [ iBldg * 12 + 6 ]; theBuildingsVs [ iBldg ] = auxiliar [ iBldg * 12 + 7 ]; theBuildingsRho [ iBldg ] = auxiliar [ iBldg * 12 + 8 ]; theFoundationsVp [ iBldg ] = auxiliar [ iBldg * 12 + 9 ]; theFoundationsVs [ iBldg ] = auxiliar [ iBldg * 12 + 10 ]; theFoundationsRho [ iBldg ] = auxiliar [ iBldg * 12 + 11 ]; } fclose(fp); free( auxiliar ); return 0; }
static void parse_cmdline (int argc, TCHAR **argv) { int i; for (i = 1; i < argc; i++) { if (!_tcsncmp (argv[i], "-diskswapper=", 13)) { TCHAR *txt = parsetext (argv[i] + 13); parse_diskswapper (txt); xfree (txt); } else if (_tcsncmp (argv[i], "-cfgparam=", 10) == 0) { ; } else if (_tcscmp (argv[i], "-cfgparam") == 0) { if (i + 1 < argc) i++; } else if (_tcsncmp (argv[i], "-config=", 8) == 0) { TCHAR *txt = parsetext (argv[i] + 8); currprefs.mountitems = 0; target_cfgfile_load (&currprefs, txt, -1, 0); xfree (txt); } else if (_tcsncmp (argv[i], "-statefile=", 11) == 0) { TCHAR *txt = parsetext (argv[i] + 11); savestate_state = STATE_DORESTORE; _tcscpy (savestate_fname, txt); xfree (txt); } else if (_tcscmp (argv[i], "-f") == 0) { /* Check for new-style "-f xxx" argument, where xxx is config-file */ if (i + 1 == argc) { write_log ("Missing argument for '-f' option.\n"); } else { TCHAR *txt = parsetext (argv[++i]); currprefs.mountitems = 0; target_cfgfile_load (&currprefs, txt, -1, 0); xfree (txt); } } else if (_tcscmp (argv[i], "-s") == 0) { if (i + 1 == argc) write_log ("Missing argument for '-s' option.\n"); else cfgfile_parse_line (&currprefs, argv[++i], 0); } else if (_tcscmp (argv[i], "-h") == 0 || _tcscmp (argv[i], "-help") == 0) { usage (); exit (0); } else if (_tcsncmp (argv[i], "-cdimage=", 9) == 0) { TCHAR *txt = parsetext (argv[i] + 9); TCHAR *txt2 = xmalloc(TCHAR, _tcslen(txt) + 2); _tcscpy(txt2, txt); if (_tcsrchr(txt2, ',') != NULL) _tcscat(txt2, ","); cfgfile_parse_option (&currprefs, "cdimage0", txt2, 0); xfree(txt2); xfree (txt); } else { if (argv[i][0] == '-' && argv[i][1] != '\0') { const TCHAR *arg = argv[i] + 2; int extra_arg = *arg == '\0'; if (extra_arg) arg = i + 1 < argc ? argv[i + 1] : 0; if (parse_cmdline_option (&currprefs, argv[i][1], arg) && extra_arg) i++; } } } }
/* * This function is used for morph parsing. * * The value is passed to parsetext which will call the right dictionary to * lexize the word. If it turns out to be a stopword, we push a QI_VALSTOP * to the stack. * * All words belonging to the same variant are pushed as an ANDed list, * and different variants are ORed together. */ static void pushval_morph(Datum opaque, TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix) { int32 count = 0; ParsedText prs; uint32 variant, pos = 0, cntvar = 0, cntpos = 0, cnt = 0; MorphOpaque *data = (MorphOpaque *) DatumGetPointer(opaque); prs.lenwords = 4; prs.curwords = 0; prs.pos = 0; prs.words = (ParsedWord *) palloc(sizeof(ParsedWord) * prs.lenwords); parsetext(data->cfg_id, &prs, strval, lenval); if (prs.curwords > 0) { while (count < prs.curwords) { /* * Were any stop words removed? If so, fill empty positions with * placeholders linked by an appropriate operator. */ if (pos > 0 && pos + 1 < prs.words[count].pos.pos) { while (pos + 1 < prs.words[count].pos.pos) { /* put placeholders for each missing stop word */ pushStop(state); if (cntpos) pushOperator(state, data->qoperator, 1); cntpos++; pos++; } } /* save current word's position */ pos = prs.words[count].pos.pos; /* Go through all variants obtained from this token */ cntvar = 0; while (count < prs.curwords && pos == prs.words[count].pos.pos) { variant = prs.words[count].nvariant; /* Push all words belonging to the same variant */ cnt = 0; while (count < prs.curwords && pos == prs.words[count].pos.pos && variant == prs.words[count].nvariant) { pushValue(state, prs.words[count].word, prs.words[count].len, weight, ((prs.words[count].flags & TSL_PREFIX) || prefix)); pfree(prs.words[count].word); if (cnt) pushOperator(state, OP_AND, 0); cnt++; count++; } if (cntvar) pushOperator(state, OP_OR, 0); cntvar++; } if (cntpos) { /* distance may be useful */ pushOperator(state, data->qoperator, 1); } cntpos++; } pfree(prs.words); } else pushStop(state); }
/** * Saves coordinates and data of specified elements as an output binary file * for MATLAB. also print damping ratios for rayleigh */ void saveMeshCoordinatesForMatlab( mesh_t *myMesh, int32_t myID, const char *parametersin, double ticksize, damping_type_t theTypeOfDamping, double xoriginm, double yoriginm, double zoriginm, noyesflag_t includeBuildings) { int i, j, k, counter = 0; double double_message[6]; double *auxiliar; double x_coord, y_coord, z_coord; edata_t *edata_temp; FILE *meshcoordinates; FILE *meshdata; FILE *fp; static char filename_coord [256]; static char filename_data [256]; /*Allocate memory to temporarily store coordinates of region to be plotted*/ auxiliar = (double*)malloc( sizeof(double) * 6 ); if ( auxiliar == NULL ) { fprintf( stderr, "Err allocing mem in saveMeshCoordinatesForMatlab" ); } /** * Parsing the name of the directory of mesh coordinates and corners of * region to be plotted for Matlab . */ if ( myID == 0 ) { if ( (fp = fopen ( parametersin, "r")) == NULL ) { solver_abort ("saveMeshCoordinatesForMatlab", parametersin, "Error opening parameters.in configuration file"); } if ( parsetext ( fp, "mesh_coordinates_directory_for_matlab",'s', theMeshDirMatlab )!= 0 ) { solver_abort ( "saveMeshCoordinatesForMatlab", NULL, "Error parsing fields from %s\n", parametersin); } if ( parsedarray( fp, "mesh_corners_matlab", 6 , auxiliar ) != 0) { fprintf(stderr, "Error parsing mesh_corners_matlab list from %s\n", parametersin); } /** *We convert physical coordinates into etree coordinates *(divide by ticksize) * */ theMatlabXMin = auxiliar[0] / ticksize; theMatlabYMin = auxiliar[1] / ticksize; theMatlabXMax = auxiliar[2] / ticksize; theMatlabYMax = auxiliar[3] / ticksize; theMatlabZMin = auxiliar[4] / ticksize; theMatlabZMax = auxiliar[5] / ticksize; free( auxiliar ); hu_fclose( fp ); } /* Broadcasting data */ double_message[0] = theMatlabXMin; double_message[1] = theMatlabYMin; double_message[2] = theMatlabXMax; double_message[3] = theMatlabYMax; double_message[4] = theMatlabZMin; double_message[5] = theMatlabZMax; MPI_Bcast( double_message , 6 , MPI_DOUBLE , 0 , comm_solver); theMatlabXMin = double_message[0] ; theMatlabYMin = double_message[1] ; theMatlabXMax = double_message[2] ; theMatlabYMax = double_message[3] ; theMatlabZMin = double_message[4] ; theMatlabZMax = double_message[5] ; broadcast_char_array( theMeshDirMatlab, sizeof(theMeshDirMatlab), 0, comm_solver ); /** *Coordinates and data in the specified region are written to a binary file *within each processor */ for ( i = 0; i < ( myMesh->lenum ); ++i ) { /* j is like a node id here */ j = myMesh->elemTable[i].lnid[0]; /* looking at first node of the element(at top) */ edata_temp = myMesh->elemTable[i].data; /* these are lower left coordinates */ x_coord = myMesh->nodeTable[j].x; y_coord = myMesh->nodeTable[j].y; z_coord = myMesh->nodeTable[j].z; if ( (z_coord >= theMatlabZMin) && (z_coord < theMatlabZMax) ) { if ( (y_coord >= theMatlabYMin) && (y_coord < theMatlabYMax) ) { if ( (x_coord >= theMatlabXMin) && (x_coord < theMatlabXMax)) { if ( counter == 0 ) { /* In order to open file just once and not creating any * empty files */ sprintf(filename_coord, "%s/mesh_coordinates.%d", theMeshDirMatlab, myID); sprintf(filename_data, "%s/mesh_data.%d", theMeshDirMatlab, myID); meshcoordinates = hu_fopen ( filename_coord, "wb" ); meshdata = hu_fopen ( filename_data, "wb" ); } counter++; for ( k = 0 ; k < 8 ; ++k ) { /* j is like a node id here */ j = myMesh->elemTable[i].lnid[k]; fwrite( &(myMesh->nodeTable[j].x), sizeof(myMesh->nodeTable[j].x), 1,meshcoordinates); fwrite( &(myMesh->nodeTable[j].y), sizeof(myMesh->nodeTable[j].y), 1,meshcoordinates); fwrite( &(myMesh->nodeTable[j].z), sizeof(myMesh->nodeTable[j].z), 1,meshcoordinates); } fwrite( &(edata_temp->Vs), sizeof(edata_temp->Vs), 1, meshdata ); fwrite( &(edata_temp->Vp), sizeof(edata_temp->Vp), 1, meshdata ); fwrite( &(edata_temp->rho), sizeof(edata_temp->rho), 1, meshdata ); /** * If you want to have damping ratios, change the 0. */ if (theTypeOfDamping == RAYLEIGH && 0) { int32_t n_0; double x_m,y_m,z_m; float zeta; n_0 = myMesh->elemTable[i].lnid[0]; z_m = zoriginm + (ticksize)*myMesh->nodeTable[n_0].z; x_m = xoriginm + (ticksize)*myMesh->nodeTable[n_0].x; y_m = yoriginm + (ticksize)*myMesh->nodeTable[n_0].y; /* Shift the domain if buildings are considered */ if ( includeBuildings == YES ) { z_m -= get_surface_shift(); } //if ( softerSoil == YES ) { /* Get it from the damping vs strain curves */ // zeta = get_damping_ratio(x_m,y_m,z_m,xoriginm,yoriginm,zoriginm); // } // else { /* New formula for damping according to Graves */ // zeta = 10 / edata_temp->Vs; // } //If element is not in the soft-soil box, use the Graves damping formula if (zeta == -1) { zeta = 10 / edata_temp->Vs; } //If element is in the building, use 5% damping. if (z_m < 0) { zeta = 0.05; } fwrite( &(zeta), sizeof(zeta), 1, meshdata ); } } } } } if ( counter != 0 ) { hu_fclose( meshcoordinates ); hu_fclose( meshdata ); } }