int SR865::outpNumberFromString(const QString &outp_string) const { if (isValidString(this->outputNumberListLongName, outp_string)) return numberFromString(this->outputNumberListLongName, outp_string); if (isValidString(this->outputNumberListShortName, outp_string)) return numberFromString(this->outputNumberListShortName, outp_string); return -1; }
double SR865::getOUTP(const QString &i) const { if (isValidString(this->outputNumberListLongName, i)) return getOUTP(numberFromString(this->outputNumberListLongName, i)); if (isValidString(this->outputNumberListShortName, i)) return getOUTP(numberFromString(this->outputNumberListShortName, i)); return 0; }
static inline bool logInit(logDestinationT dst, const char *arg, bool multiProcess, bool date, int debugLevel) { bool ret = false; if (dst == emit_File || dst == emit_Unknown) { int oFd = -INT_MAX; logFinal(); if (isValidString(arg) == true && dst == emit_File) { oFd = open(arg, O_RDWR | O_CREAT | O_APPEND, 0600); if (oFd >= 0) { logFd = fdopen(oFd, "a+"); if (logFd != NULL) { ret = true; } } } else { logFd = NULL; /* use stderr. */ ret = true; } } #ifdef NATA_API_POSIX else if (dst == emit_Syslog) { if (isValidString(arg) == true) { logFinal(); openlog(arg, 0, LOG_USER); ret = true; } } #endif /* NATA_API_POSIX */ if (ret == true) { logDst = dst; freeIfNotNULL(logArg); logArg = (isValidString(arg) == true) ? strdup(arg) : NULL; doMultiProcess = multiProcess; doDate = date; dbgLevel = debugLevel; } return ret; }
SEXP dotRb(SEXP args) { SEXP ans; char *cmd; mrb_value val; //non utilisé pour l'instant!!! if(!isValidString(CADR(args))) error("invalid argument"); cmd = (char*)CHAR(STRING_ELT(CADR(args), 0)); //printf("instruction à executer %s\n",cmd); val=mrb_load_string_cxt(mrb,cmd,mrb_cxt); //printf("state\n"); if(mrb->exc) { if (!mrb_undef_p(val)) { mrb_print_error(mrb); } //rb_p(state); printf("MRuby error !!!\n"); printf("in executing : %s\n",cmd); return R_NilValue; } else { //ans=(SEXP)newRbObj(val); ans=mrbArray2RVector(val); return ans; } }
BOOL CIVPlaybackDataBuf::ChannelTarget::Open( const char* pPath, const FILETIME& time) { if ( !isValidString(pPath) ) { return FALSE; } if ( m_Reader.is_open() ) { m_Reader.close(); } m_Reader.clear(); string strPath = pPath; strPath += c_szIVFileExt; m_Reader.open( strPath.c_str(), ios::binary |ios::in | ios::_Nocreate ); if ( !m_Reader.is_open() ) { return FALSE; } if ( !ParseFile() ) { m_Reader.close(); return FALSE; } return MoveToAndReadSome(time); }
/* Origin: SEXP attribute_hidden do_stop(). */ SEXP api_R_stop(SEXP args){ SEXP call, c_call; args = CDR(args); /* get caller name */ call = CAR(args); args = CDR(args); if(asLogical(CAR(args))){ /* find context -> "... in: ..:" */ c_call = call; } else{ c_call = R_NilValue; } args = CDR(args); if(CAR(args) != R_NilValue){ /* message */ SETCAR(args, coerceVector(CAR(args), STRSXP)); if(!isValidString(CAR(args))){ Rf_errorcall(c_call, " [invalid string in comm.stop(.)]\n"); } Rf_errorcall(c_call, "%s", translateChar(STRING_ELT(CAR(args), 0))); } else{ Rf_errorcall(c_call, "\n"); } return c_call; } /* End of api_R_stop(). */
void initialize_intrinsic() { int i; SYMBOL sp; intrinsic_entry *ep; for (i = 0, ep = &intrinsic_table[0]; INTR_OP((ep = &intrinsic_table[i])) != INTR_END; i++){ if ((ep->langSpec & langSpecSet) == 0) { continue; } if (!(isValidString(INTR_NAME(ep)))) { continue; } if (INTR_HAS_KIND_ARG(ep)) { if (((INTR_OP(ep) != INTR_MINLOC) && (INTR_OP(ep) != INTR_MAXLOC)) && INTR_RETURN_TYPE_SAME_AS(ep) != -1) { fatal("%: Invalid intrinsic initialization.", __func__); } } sp = find_symbol((char *)INTR_NAME(ep)); SYM_TYPE(sp) = S_INTR; SYM_VAL(sp) = i; } }
int main(void) { char cmd[1024]; char *l, *lines; int x_p, offset; s_cgi **c; printf("Pragma: no-cache\nContent-type: text/plain\n\n"); fflush(stdout); c = cgiInit(); if(!c) return 0; if(!isFileExisted(RRDTOOL_PATH)){ printf("no_rrdtool"); return 0; } if(! (l = cgiGetValue(c, "w")) ){ return 0; } x_p = atoi(l); if(! (l = cgiGetValue(c, "offset")) ){ printf("no offset"); return 0; } offset = atoi(l); if(! x_p || !offset) return 0; if(! (l = cgiGetValue(c, "lines")) ){ printf("no lines"); return 0; } if(! (lines = strdup(l)) ) return 0; cgiDecodeString(lines); if(! isValidString(lines)){ goto end; } snprintf(cmd, 1024, "%s graph /var/anything %s -w %d -s %d", RRDTOOL_PATH, lines, x_p, time(NULL)+offset ); system(cmd); system("ls / > /var/wow"); fflush(stdout); end: free(lines); return 0; }
static inline bool logReinit(void) { char *arg = (isValidString(logArg) == true) ? strdup(logArg) : NULL; bool ret = logInit(logDst, arg, doMultiProcess, doDate, dbgLevel); freeIfNotNULL(arg); return ret; }
main(){ /*getHammingDistance() test cases:*/ getHammingDistance("AACCTT","GGCCTT"); //return 2 getHammingDistance("TCGGA","AAAAG"); //returns 5 getHammingDistance("A","AG"); //error message prompt returns 0 /*countSubstrPattern() test cases:*/ countSubstrPattern("AATATATAGG","GG");// returns 1 countSubstrPattern("AATATATAGG","ATA");// returns 3 countSubstrPattern("AATATATAGG","ACTGACTGACTG");// returns 0 /*isValidString() test cases:*/ isValidString("AAGGCTATGC","ACGT");//returns 1 / true isValidString("AAGGCTATGa","ACGT");// returns 0 / false isValidString("ACGT","ACGT");// returns 1 / true isValidString("ACGT101_","ACGT");// returns 0 / false isValidString("091212345","0123456789");// returns 1 / true /*getSkew() test cases:*/ getSkew("GGCCAC", 1);// returns 1 getSkew("GGCCAC", 2);// returns 2 getSkew("GGCCAC", 3);// returns 1 getSkew("GGCCAC", 4);// returns 0 getSkew("GGCCAC", 5);// returns 0 /*getMaxSkewN() test cases:*/ getMaxSkewN("GGCCAC", 1);// returns 1 getMaxSkewN("GGCCAC", 2);// returns 2 getMaxSkewN("GGCCAC", 3);// returns 2 getMaxSkewN("GGCCAC", 4);// returns 2 getMaxSkewN("GGCCAC", 5);// returns 2 /*getMinSkewN() test cases:*/ getMinSkewN("GGCCAC", 1);// returns 1 getMinSkewN("GGCCAC", 2);// returns 1 getMinSkewN("GGCCAC", 3);// returns 1 getMinSkewN("GGCCAC", 4);// returns 0 getMinSkewN("GGCCAC", 5);// returns 0 }
SEXP mrb4R_get_iv(SEXP args) { SEXP ans; mrb_value rbobj; char *var; if(!inherits(CADR(args),"rbObj")) error("invalid first argument"); rbobj=*((mrb_value*) R_ExternalPtrAddr(CADR(args))); if(!isValidString(CADDR(args))) error("invalid second argument"); var = (char*)CHAR(STRING_ELT(CADDR(args), 0)); ans=mrbArray2RVector(mrb_iv_get(mrb,rbobj,mrb_intern_cstr(mrb,var))); return ans; }
//MRuby global variable!!! SEXP mrb4R_get_gv(SEXP args) { SEXP ans; mrb_value rbobj; char *name; if(!isValidString(CADR(args))) error("invalid argument"); name = (char*)CHAR(STRING_ELT(CADR(args), 0)); rbobj=mrb_gv_get(mrb,mrb_intern_cstr(mrb,name)); ans=mrbArray2RVector(rbobj); return ans; }
void isValidStringTest(char *str1, char *str2, int expectedResult) { int result = isValidString(str1, str2); printf("isValidString(\"%s\", \"%s\") ", str1, str2); if(result == expectedResult) { printf("PASSED\n"); } else { printf("FAILED (Expected %i, got %i.)\n", expectedResult, result); errorCount++; } }
SEXP mrb4R_set_gv(SEXP args) { SEXP vect; mrb_value rbval; char *name; if(!isValidString(CADR(args))) error("invalid argument"); name = (char*)CHAR(STRING_ELT(CADR(args), 0)); vect=CADDR(args); rbval=(mrb_value)RVector2mrbArray(vect); mrb_gv_set(mrb,mrb_intern_cstr(mrb,name),rbval); return R_NilValue; }
SEXP mrb4R_set_iv(SEXP args) { SEXP vect; mrb_value rbobj,rbval; char *var; if(!inherits(CADR(args),"rbObj")) error("invalid first argument"); rbobj=*((mrb_value*) R_ExternalPtrAddr(CADR(args))); if(!isValidString(CADDR(args))) error("invalid second argument"); var = (char*)CHAR(STRING_ELT(CADDR(args), 0)); vect=CADDDR(args); rbval=(mrb_value)RVector2mrbArray(vect); mrb_iv_set(mrb,rbobj,mrb_intern_cstr(mrb,var),rbval); return R_NilValue; }
SEXP dotTcl(SEXP args) { SEXP ans; const char *cmd; Tcl_Obj *val; const void *vmax = vmaxget(); if(!isValidString(CADR(args))) error(_("invalid argument")); cmd = translateChar(STRING_ELT(CADR(args), 0)); val = tk_eval(cmd); ans = makeRTclObject(val); vmaxset(vmax); return ans; }
SEXP jl4R_init(SEXP args) { char *julia_home_dir; if(!jl4R_julia_running) { if(!isValidString(CADR(args))) error("invalid argument"); julia_home_dir=(char*)CHAR(STRING_ELT(CADR(args), 0)); Rprintf("julia_home_dir=%s\n",julia_home_dir); jl_init(julia_home_dir); jl4R_julia_running=1; //printf("julia initialized!!!\n"); } return R_NilValue; }
/* Origin: SEXP attribute_hidden do_warning(). */ SEXP api_R_warning(SEXP args){ SEXP call, c_call; args = CDR(args); /* get caller name */ call = CAR(args); args = CDR(args); if(asLogical(CAR(args))){ /* find context -> "... in: ..:" */ c_call = call; } else{ c_call = R_NilValue; } args = CDR(args); if(asLogical(CAR(args))){ /* immediate = TRUE */ immediateWarning = 1; } else{ immediateWarning = 0; } args = CDR(args); if(CAR(args) != R_NilValue){ SETCAR(args, coerceVector(CAR(args), STRSXP)); if(!isValidString(CAR(args))){ Rf_warningcall(c_call, " [invalid string in comm.warning(.)]\n"); } else{ Rf_warningcall(c_call, "%s", translateChar(STRING_ELT(CAR(args), 0))); } } else{ Rf_warningcall(c_call, ""); } immediateWarning = 0; /* reset to internal calls */ return CAR(args); } /* End of api_R_warning(). */
int PutChannelData ( FILE *ptr , DBlist tree ) { char sta[6], chan[4], auxid[ 5 ] , lat[ 10 ] , lon[ 11 ] , elev[ 8 ] , depth[ 7 ] , hang[ 7 ], vang[ 6 ], samprat[ 12 ], inst[8], ondate[25], offdate[25]; int dots = 0; float fLat , fLon , fElev ; struct CSStree *Tree = (struct CSStree *) tree ; struct sitechanList *sc = Tree->scHead ; if(!sc) return -1 ; printf("Writing channel data "); fprintf(ptr,"DATA_TYPE CHANNEL\n"); fprintf(ptr, "Sta Chan Aux Latitude Longitude Elev Depth Hang Vang Sample_Rate Inst On Date Off Date\n"); while(sc){ struct siteList *si = Tree->slHead ; struct wfdiscList *wf = Tree->wfHead ; putchar('.'); dots++; if(dots == 80){ putchar('\n'); dots = 0; } fflush(stdout); /* sta */ if ( isValidString ( dbl_LIST_SITECHAN, dbl_SITEC_STA , sc->element->sta ) && strcmp( sc->element->sta , "- " ) ) sprintf ( sta , "%-5.5s" , sc->element->sta ) ; else strcpy ( sta , " " ) ; /* 5 spaces */ /* chan */ if ( isValidString ( dbl_LIST_SITECHAN, dbl_SITEC_CHAN , sc->element->chan ) && strcmp( sc->element->chan , "- " ) ) sprintf ( chan , "%-3.3s" , sc->element->chan ) ; else strcpy ( chan , " " ) ; /* 3 spaces */ /* auxid */ strcpy ( auxid , " " ) ; /* 4 spaces */ /* lat, lon, & elev */ GetSiteInfo ( si , sc->element->sta , sc->element->ondate , sc->element->offdate , &fLat , &fLon , &fElev ) ; if ( isValidFloat ( dbl_LIST_SITE, dbl_SITE_LAT , fLat ) ) sprintf ( lat , "%9.5f" , fLat ) ; else strcpy ( lat , " " ) ; /* 9 spaces */ if ( isValidFloat ( dbl_LIST_SITE, dbl_SITE_LON , fLon ) ) sprintf ( lon , "%10.5f" , fLon ) ; else strcpy ( lon , " " ) ; /* 10 spaces */ if ( isValidFloat ( dbl_LIST_SITE, dbl_SITE_ELEV , fElev ) ) sprintf ( elev , "%7.3f" , fElev ) ; else strcpy ( elev , " " ) ; /* 7 spaces */ /* depth */ if ( isValidFloat ( dbl_LIST_SITECHAN, dbl_SITEC_EDEPTH , sc->element->edepth ) ) sprintf ( depth , "%6.3f" , sc->element->edepth ) ; else strcpy ( depth , " " ) ; /* 6 spaces */ /* hang & vang */ if ( isValidFloat ( dbl_LIST_SITECHAN, dbl_SITEC_HANG , sc->element->hang ) ) sprintf ( hang , "%6.1f" , sc->element->hang ) ; else strcpy ( hang , " " ) ; /* 6 spaces */ if ( isValidFloat ( dbl_LIST_SITECHAN, dbl_SITEC_VANG , sc->element->vang ) ) sprintf ( vang , "%5.1f" , sc->element->vang ) ; else strcpy ( vang , " " ) ; /* 5 spaces */ /* samprat */ strcpy ( samprat , " " ) ; /* 11 spaces */ /* inst */ GetWfdiscInfo ( wf, sta , chan , sc->element->ondate , sc->element->offdate , inst ) ; if ( isValidString ( dbl_LIST_WFDISC, dbl_WFDIS_INSTYPE , inst ) && strcmp( inst , "- " ) ) { if ( strlen ( inst ) < 7 ) { int kdx ; for ( kdx = strlen ( inst ) ; kdx < 7 ; kdx++ ) { inst[ kdx ] = ' ' ; } inst[ 7 ] = '\0' ; } } else sprintf ( inst , " " ) ; /* 7 spaces */ /* ondate */ if ( isValidInt ( dbl_LIST_SITECHAN, dbl_SITEC_ONDATE , sc->element->ondate ) ) { int doy, mm, id, iyyy , jdate = sc->element->ondate ; iyyy = jdate / 1000 ; doy = jdate - ( iyyy * 1000 ) ; mnday ( doy , isleap ( iyyy ) , &mm , &id ) ; sprintf(ondate, "%04d/%02d/%02d" , iyyy, mm, id ); } else strcpy ( ondate , " " ) ; /* 10 spaces */ /* offdate */ if ( isValidInt ( dbl_LIST_SITECHAN, dbl_SITEC_OFFDATE , sc->element->offdate ) ) { int doy, mm, id, iyyy , jdate = sc->element->offdate ; iyyy = jdate / 1000 ; doy = jdate - ( iyyy * 1000 ) ; mnday ( doy , isleap ( iyyy ) , &mm , &id ) ; sprintf(offdate, "%04d/%02d/%02d" , iyyy, mm, id ); } else strcpy ( offdate , " " ) ; /* 10 spaces */ fprintf(ptr,"%s %s %s %s %s %s %s %s %s %s %s %s %s\n", sta, chan, auxid, lat, lon, elev, depth, hang, vang, samprat, inst, ondate, offdate ); sc = sc->next; } fprintf(ptr,"\n"); printf("\n"); return 0 ; } /* end PutChannelData */
int main(int argc, char * argv[]) { // gets the hash table size from the command line int hashSize = Table::HASH_SIZE; Table * grades; // Table is dynamically allocated below, so we can call // different constructors depending on input from the user. if (argc > 1) { hashSize = atoi(argv[1]); // atoi converts c-string to int if (hashSize < 1) { cout << "Command line argument (hashSize) must be a positive number" << endl; return 1; } grades = new Table(hashSize); } else { // no command line args given -- use default table size grades = new Table(); } grades->hashStats(cout); // add more code here // Reminder: use -> when calling Table methods, since grades is type Table* printCmdSummary();//print out command lines //initialize some data char c; string name; int score; bool isValid=true; //while isvalid it will keep going ask client to enter untill quit do{ cout<<"\n Please enter the command shows above [i , c , l , r , p , s , h , t , q]: "; cin>>c; if(cin.fail()){//if cin fail promt fail info and quit cout<<"exit"<<endl; cout<<"ERROR: invalid command!"<<endl; isValid=false; } else{ switch (c){//switch method provide client to choose case 'i': cout<<"You are now in the insert method: "<<endl; cout<<"here is the example: "<<endl; cout<<"---Name: James ---"<<endl; cout<<"---Score: 86 ---"<<endl;; do{ cout<<"Please enter name: "<<endl; cin>>name; }while(isValidString(name)==false);//check valid or not do{ cout<<"Please enter score: "<<endl; cin>>score; }while(isValidInt(score)==false);//check valid or not if(grades->insert(name,score)==true){//if no same key existed then record entry cout<<"Entry recorded!"<<endl; }else{ cout<<"Entry has already existed, Nothing changes!"<<endl; } break; case 'c': cout<<"You are now in the change method: "<<endl; cout<<"here is the example: "<<endl; cout<<"---Name: James ---"<<endl; cout<<"---Score: 86 ---"<<endl;; do{ cout<<"Please enter name: "<<endl; cin>>name; }while(isValidString(name)==false); do{ cout<<"Please enter new score: "<<endl; cin>>score; }while(isValidInt(score)==false); if(grades->lookup(name)!=NULL){//if found grades->remove(name);//remove grades->insert(name,score);//then insert again cout<<"Record changed!"<<endl; }else{ cout<<"No such entry"<<endl; } break; case 'l': cout<<"You are now in the lookup method: "<<endl; cout<<"here is the example: "<<endl; cout<<"---Name: James ---"<<endl; do{ cout<<"Please enter name you want to lookup: "<<endl; cin>>name; }while(isValidString(name)==false); if(grades->lookup(name)!=NULL){//if found int* address=grades->lookup(name);//assign address to it cout<<"Record found!"<<endl; cout<<"the address is :"<<address<<endl; }else{ cout<<"No such entry"<<endl; } break; case 'r': cout<<"You are now in the remove method: "<<endl; cout<<"here is the example: "<<endl; cout<<"---Name: James ---"<<endl; do{ cout<<"Please enter name: "<<endl; cin>>name; }while(isValidString(name)==false); if(grades->remove(name)==true){//if found cout<<"Entry removed!"<<endl;//target removed }else{ cout<<"No such entry!"<<endl; } break; case 'p': cout<<"You are now in the print method: "<<endl; cout<<"here is the table: "<<endl; if(grades->numEntries()==0){ cout<<"<empty>"<<endl; }else{ grades->printAll();//print out all the entries } break; case 's': cout<<"You are now in the size method: "<<endl; cout<<"here is the total number of entries: "<<endl; cout<<grades->numEntries();//print out entries numbers break; case 'h': cout<<"You are now in the help method: "<<endl; cout<<"here is the comands: "<<endl; printCmdSummary();//print summary break; case 't': cout<<"You are now in the stats method: "<<endl; cout<<"here is the stats of this table: "<<endl; grades->hashStats(cout);//print out hashstats break; case 'q': cout<<"quitting this program"<<endl; isValid=false;//end the loop and quit break; default: cout<<"Invalid Command,Please try again."<<endl; break; } } }while(isValid); return 0; }
expv compile_intrinsic_call(ID id, expv args) { intrinsic_entry *ep = NULL; int found = 0; int nArgs = 0; int nIntrArgs = 0; int i; expv ret = NULL; expv a = NULL; TYPE_DESC tp = NULL, ftp; list lp; INTR_OPS iOps = INTR_END; const char *iName = NULL; expv kindV = NULL; int typeNotMatch = 0; int isVarArgs = 0; EXT_ID extid; if (SYM_TYPE(ID_SYM(id)) != S_INTR) { //fatal("%s: not intrinsic symbol", __func__); // declarea as intrinsic but not defined in the intrinc table SYM_TYPE(ID_SYM(id)) = S_INTR; if (args == NULL) { args = list0(LIST); } if (ID_TYPE(id) == NULL) implicit_declaration(id); tp = ID_TYPE(id); //tp = BASIC_TYPE_DESC(TYPE_SUBR); expv symV = expv_sym_term(F_FUNC, NULL, ID_SYM(id)); ftp = function_type(tp); TYPE_SET_INTRINSIC(ftp); extid = new_external_id_for_external_decl(ID_SYM(id), ftp); ID_TYPE(id) = ftp; PROC_EXT_ID(id) = extid; if (TYPE_IS_EXTERNAL(tp)){ ID_STORAGE(id) = STG_EXT; } else{ EXT_PROC_CLASS(extid) = EP_INTRINSIC; } ret = expv_cons(FUNCTION_CALL, tp, symV, args); return ret; } ep = &(intrinsic_table[SYM_VAL(ID_SYM(id))]); iOps = INTR_OP(ep); iName = ID_NAME(id); /* Count a number of argument, first. */ nArgs = 0; if (args == NULL) { args = list0(LIST); } FOR_ITEMS_IN_LIST(lp, args) { nArgs++; } /* Search an intrinsic by checking argument types. */ found = 0; for (; ((INTR_OP(ep) == iOps) && ((strcasecmp(iName, INTR_NAME(ep)) == 0) || !(isValidString(INTR_NAME(ep))))); ep++) { kindV = NULL; typeNotMatch = 0; isVarArgs = 0; /* Check a number of arguments. */ if (INTR_N_ARGS(ep) < 0 || INTR_N_ARGS(ep) == nArgs) { /* varriable args or no kind arg. */ if (INTR_N_ARGS(ep) < 0) { isVarArgs = 1; } nIntrArgs = nArgs; } else if (INTR_HAS_KIND_ARG(ep) && ((INTR_N_ARGS(ep) + 1) == nArgs)) { /* could be intrinsic call with kind arg. */ expv lastV = expr_list_get_n(args, nArgs - 1); if (lastV == NULL) { return NULL; /* error recovery */ } if (EXPV_KW_IS_KIND(lastV)) { goto gotKind; } tp = EXPV_TYPE(lastV); if (!(isValidType(tp))) { return NULL; /* error recovery */ } if (TYPE_BASIC_TYPE(tp) != TYPE_INT) { /* kind arg must be integer type. */ continue; } gotKind: nIntrArgs = INTR_N_ARGS(ep); kindV = lastV; } else { continue; } /* The number of arguments matchs. Then check types. */ for (i = 0; i < nIntrArgs; i++) { a = expr_list_get_n(args, i); if (a == NULL) { return NULL; /* error recovery */ } tp = EXPV_TYPE(a); if (!(isValidType(tp))) { //return NULL; /* error recovery */ continue; } if (compare_intrinsic_arg_type(a, tp, ((isVarArgs == 0) ? INTR_ARG_TYPE(ep)[i] : INTR_ARG_TYPE(ep)[0])) != 0) { /* Type mismatch. */ typeNotMatch = 1; break; } } if (typeNotMatch == 1) { continue; } else { found = 1; break; } } if (found == 1) { /* Yes we found an intrinsic to use. */ SYMBOL sp = NULL; expv symV = NULL; /* Then we have to determine return type. */ if (INTR_RETURN_TYPE(ep) != INTR_TYPE_NONE) { tp = get_intrinsic_return_type(ep, args, kindV); if (!(isValidType(tp))) { //fatal("%s: can't determine return type.", __func__); //return NULL; tp = BASIC_TYPE_DESC(TYPE_GNUMERIC_ALL); } } else { tp = BASIC_TYPE_DESC(TYPE_SUBR); } /* Finally find symbol for the intrinsic and make it expv. */ sp = find_symbol((char *)iName); if (sp == NULL) { fatal("%s: symbol '%s' is not created??", __func__, INTR_NAME(ep)); /* not reached */ return NULL; } symV = expv_sym_term(F_FUNC, NULL, sp); if (symV == NULL) { fatal("%s: symbol expv creation failure.", __func__); /* not reached */ return NULL; } ftp = function_type(tp); TYPE_SET_INTRINSIC(ftp); /* set external id for functionType's type ID. * dont call declare_external_id() */ extid = new_external_id_for_external_decl(ID_SYM(id), ftp); ID_TYPE(id) = ftp; PROC_EXT_ID(id) = extid; if(TYPE_IS_EXTERNAL(tp)){ ID_STORAGE(id) = STG_EXT; }else{ EXT_PROC_CLASS(extid) = EP_INTRINSIC; } ret = expv_cons(FUNCTION_CALL, tp, symV, args); } if (ret == NULL) { error_at_node((expr)args, "argument(s) mismatch for an intrinsic '%s()'.", iName); } return ret; }
int PutOriginData ( FILE *ptr , DBlist tree ) { char HeaderLine1[] = " Date Time Latitude Longitude Depth Ndef Nsta " "Gap Mag1 N Mag2 N Mag3 N Author ID\n"; char HeaderLine2[] = " rms OT_Error Smajor Sminor Az Err mdist" " Mdist Err Err Err Quality\n"; char time[ 25 ] , fixf = ' ' , lat[ 9 ] , lon[ 10 ] , depth[ 6 ] , ndef[ 5 ] , nsta[ ] = " " , gap[ ] = " " , magtype1[ 3 ] , mag1[ 5 ] , magtype2[ 3 ] , mag2[ 5 ] , magtype3[ 3 ] , mag3[ 5 ] , N[] = " " , author[ 9 ] , id[ 9 ] , line2[] = "\n +- +- +- +- +- \n\n" ; struct CSStree *Tree = (struct CSStree *) tree ; struct originList *orig = Tree->orHead ; if(!orig) return -1; printf("Writing origin data "); fprintf(ptr,"DATA_TYPE ORIGIN GSE2.0\n"); fprintf(ptr, "%s", HeaderLine1); fprintf(ptr, "%s\n", HeaderLine2); while(orig){ putchar('.'); fflush(stdout); /* time */ if ( isValidFloat ( dbl_LIST_ORIGIN, dbl_ORIGI_TIME, orig->element->time ) ) { sprintf ( time , "%-21.21s" , tmListEpochTime ( orig->element->time , 14 ) ) ; time[ 10 ] = ' ' ; } else strcpy ( time , " " ) ; /* 21 spaces */ /* lat */ if ( isValidFloat ( dbl_LIST_ORIGIN, dbl_ORIGI_LAT, orig->element->lat ) ) sprintf ( lat , "%8.4f" , orig->element->lat ) ; else strcpy ( lat , " " ) ; /* 8 spaces */ /* lon */ if ( isValidFloat ( dbl_LIST_ORIGIN, dbl_ORIGI_LON, orig->element->lon ) ) sprintf ( lon , "%9.4f" , orig->element->lon ) ; else strcpy ( lon , " " ) ; /* 9 spaces */ /* depth */ if ( isValidFloat ( dbl_LIST_ORIGIN, dbl_ORIGI_DEPTH, orig->element->depth ) ) sprintf ( depth , "%5.1f" , orig->element->depth ) ; else strcpy ( depth , " " ) ; /* 5 spaces */ /* ndef */ if ( isValidInt ( dbl_LIST_ORIGIN, dbl_ORIGI_NDEF, orig->element->ndef ) ) sprintf ( ndef , "%4d" , orig->element->ndef ) ; else strcpy ( ndef , " " ) ; /* 4 spaces */ /* magnitudes */ if ( isValidFloat ( dbl_LIST_ORIGIN, dbl_ORIGI_MB, orig->element->mb ) ) { sprintf ( mag1 , "%4.1f" , orig->element->mb ) ; strcpy ( magtype1 , "mb" ) ; } else { strcpy ( mag1 , " " ) ; /* 4 spaces */ strcpy ( magtype1 , " " ) ; /* 2 spaces */ } if ( isValidFloat ( dbl_LIST_ORIGIN, dbl_ORIGI_MB, orig->element->ms ) ) { sprintf ( mag2 , "%4.1f" , orig->element->ms ) ; strcpy ( magtype2 , "ms" ) ; } else { strcpy ( mag2 , " " ) ; /* 4 spaces */ strcpy ( magtype2 , " " ) ; /* 2 spaces */ } if ( isValidFloat ( dbl_LIST_ORIGIN, dbl_ORIGI_MB, orig->element->ml ) ) { sprintf ( mag3 , "%4.1f" , orig->element->ml ) ; strcpy ( magtype3 , "ml" ) ; } else { strcpy ( mag3 , " " ) ; /* 4 spaces */ strcpy ( magtype3 , " " ) ; /* 2 spaces */ } /* author */ if ( isValidString ( dbl_LIST_ORIGIN, dbl_ORIGI_AUTH, orig->element->auth ) && strcmp( orig->element->auth , "- " ) ) { if ( strlen ( orig->element->auth ) <= 8 ) sprintf ( author , "%-8.8s" , orig->element->auth ) ; else { strncpy ( author , orig->element->auth , 8 ) ; author[ 8 ] = '\0' ; } } else strcpy ( author , " " ) ; /* 8 spaces */ /* id */ if ( isValidInt ( dbl_LIST_ORIGIN, dbl_ORIGI_ORID, orig->element->orid ) ) sprintf ( id , "%8d" , orig->element->orid ) ; else strcpy ( id , " " ) ; /* 8 spaces */ /* out put the strings */ fprintf ( ptr , "%s %c %s %s %c %s %c %s %s %s %s%s %s %s%s %s %s%s %s %s %s%s", time, fixf, lat, lon, fixf, depth, fixf, ndef, nsta, gap, magtype1, mag1, N, magtype2, mag2, N, magtype3, mag3, N, author, id , line2 ) ; orig = orig->next; } fprintf(ptr,"\n"); printf("\n"); return 0 ; } /* end PutOriginData */
/* non-empty ("") valid string :*/ INLINE_FUN Rboolean isValidStringF(SEXP x) { return isValidString(x) && CHAR(STRING_ELT(x, 0))[0]; }
void nata_Log(logLevelT lv, int debugLevel, const char *file, int line, const char *func, const char *fmt, ...) { if (lv != log_Debug || (lv == log_Debug && debugLevel <= dbgLevel)) { va_list args; char dateBuf[32]; char msg[4096]; size_t hdrLen; size_t leftLen; char thdInfoBuf[1024]; uint32_t tId; const char *thdName = NULL; if (doDate == true) { getDateStr(dateBuf, sizeof(dateBuf)); } else { dateBuf[0] = '\0'; } #if defined(NATA_API_POSIX) tId = (unsigned int)pthread_self(); #elif defined(NATA_API_WIN32API) tId = (unsigned int)GetCurrentThreadId(); #else #error Unknown/Non-supported API. #endif // NATA_API_POSIX, NATA_API_WIN32API thdName = Thread::findThreadName(tId); #ifdef NATA_API_POSIX #ifdef NATA_OS_LINUX tId = Thread::getLinuxThreadId(); #endif // NATA_OS_LINUX #endif // NATA_API_POSIX if (isValidString(thdName) == true) { snprintf(thdInfoBuf, sizeof(thdInfoBuf), "[%u:%u:%s]", (unsigned int)getpid(), (unsigned int)tId, thdName); } else { snprintf(thdInfoBuf, sizeof(thdInfoBuf), "[%u:%u]", (unsigned int)getpid(), (unsigned int)tId); } va_start(args, fmt); va_end(args); hdrLen = snprintf(msg, sizeof(msg), "%s%s%s:%s:%d:%s: ", dateBuf, getLevelStr(lv), thdInfoBuf, file, line, func); /* * hdrLen indicates the buffer length WITHOUT '\0'. */ leftLen = sizeof(msg) - hdrLen; if (leftLen > 1) { (void)vsnprintf(msg + hdrLen, leftLen -1, fmt, args); } doLog(lv, msg); } }
void ProfileProcess::run() { RIL_LOG_VERBOSE("ProfileProcess::run() - Enter\r\n"); bool isTeWriteNeeded = true; bool isMtWriteNeeded = true; // Char array that holds MT profile read in NVM char szReadMtProfile[UsatInitStateMachine::MAX_SIZE_PROFILE * 2 + 1] = {'\0'}; // Char array that holds TE profile to write read from repository.txt char szDefaultTeProfile[UsatInitStateMachine::MAX_SIZE_PROFILE * 2 + 1] = {'\0'}; // Char array that holds calculated TE profile to write char szTeCalculatedProfile[UsatInitStateMachine::MAX_SIZE_PROFILE * 2 + 1] = {'\0'}; // Char array that holds calculated MT profile to write char szMtCalculatedProfile[UsatInitStateMachine::MAX_SIZE_PROFILE * 2 + 1] = {'\0'}; // Array of char array that holds all of the profiles read in NVM char** ppszProfiles = NULL; // Byte array that holds TE profile to write read in repository.txt const BYTE* achDefaultTeProfile; // Byte array that holds MT mask to apply read in repository.txt const BYTE* achDefaultMtMask; // Char array that holds TE profile read in NVM const char* pszReadTeProfile; // Char array that holds MT profile read in NVM const char* pszReadMtProfile; // Char array that holds MT only profile read in NVM const char* pszReadMtOnlyProfile; // Features that can be both supported by MT and TE : see 3GPP 31.111 Annex Q // Byte 3.8: REFRESH // Byte 5.1: SET_UP_EVENT_LIST // Byte 12.1: OPEN_CHANNEL // Byte 12.2: CLOSE_CHANNEL // Byte 12.3: RECEIVE_DATA // Byte 12.4: SEND_DATA // Byte 12.5: GET_CHANNEL_STATUS // Byte 12.6: SERVICE_SEARCH // Byte 12.7: GET_SERVICE_INFORMATION // Byte 12.8: DECLARE_SERVICE const char TE_MT_SUPPORTED[] = "0000800001000000000000FF0000000000000000000000000000000000000000"; CCatProfile* pCatProfile = m_usatInitStateMachine.GetCatProfile(); ppszProfiles = m_usatInitStateMachine.GetProfileArray(); if (NULL == ppszProfiles) { RIL_LOG_CRITICAL("ProfileProcess::run() - Profile array is NULL\r\n"); goto Out; } pszReadTeProfile = isValidString(ppszProfiles[TE_PROFILE_STORAGE]) ? ppszProfiles[TE_PROFILE_STORAGE] : UsatInitStateMachine::DEFAULT_PROFILE; pszReadMtProfile = isValidString(ppszProfiles[MT_PROFILE_STORAGE]) ? ppszProfiles[MT_PROFILE_STORAGE] : UsatInitStateMachine::DEFAULT_PROFILE; pszReadMtOnlyProfile = isValidString(ppszProfiles[MT_ONLY_PROFILE_STORAGE]) ? ppszProfiles[MT_ONLY_PROFILE_STORAGE] : UsatInitStateMachine::DEFAULT_PROFILE; if (NULL == pCatProfile) { RIL_LOG_CRITICAL("ProfileProcess::run() - pCatProfile is NULL\r\n"); goto Out; } // Set new TE profile to use to the value in NVM in case of an error pCatProfile->SetTeProfile(pszReadTeProfile, strlen(pszReadTeProfile)); // Get TE profile read in repository.txt that should be written in NVM achDefaultTeProfile = pCatProfile->GetTeDefaultProfile(); if (NULL == achDefaultTeProfile) { RIL_LOG_CRITICAL("ProfileProcess::run() - TE profile read is NULL\r\n"); goto Out; } // Get MT mask read in repository.txt that should be apply to MT profile to disable // some modem features achDefaultMtMask = pCatProfile->GetMtMask(); if (NULL == achDefaultMtMask) { RIL_LOG_CRITICAL("ProfileProcess::run() - MT mask read is NULL\r\n"); goto Out; } if (!convertByteArrayIntoString(achDefaultTeProfile, UsatInitStateMachine::MAX_SIZE_PROFILE, szDefaultTeProfile)) { RIL_LOG_CRITICAL("ProfileProcess::run() - Could not convert TE into string\r\n"); goto Out; } // compare if TE read is equal to TE to write read in repository.txt if (CompareProfiles(pszReadTeProfile, szDefaultTeProfile)) { RIL_LOG_VERBOSE("ProfileProcess::run() - Same TE\r\n"); isTeWriteNeeded = false; // copy read TE to calculated TE memcpy(szTeCalculatedProfile, szDefaultTeProfile, strlen(szDefaultTeProfile) + 1); } else { // calculate new TE profile by doing Te = TeRepository AND NOT MtOnly if (!CalculateTeProfile(szDefaultTeProfile, pszReadMtOnlyProfile, szTeCalculatedProfile)) { RIL_LOG_CRITICAL("ProfileProcess::run() - Cannot calculate TE profile\r\n"); goto Out; } // Check if TE writing is needed by comparing calculated TE to the modem TE isTeWriteNeeded = !CompareProfiles(szTeCalculatedProfile, pszReadTeProfile); // Set new calculated TE profile pCatProfile->SetTeProfile(szTeCalculatedProfile, strlen(szTeCalculatedProfile)); } // Calculate new MT profile by doing Mt = MtModem AND NOT Te // then the MT mask is applied to remove some modem features if (!CalculateMtProfile(pszReadMtProfile, szTeCalculatedProfile, TE_MT_SUPPORTED, achDefaultMtMask, szMtCalculatedProfile)) { RIL_LOG_CRITICAL("ProfileProcess::run() - Cannot calculate MT profile\r\n"); goto Out; } // Check if writing MT is needed by comparing it to MT read in NVM isMtWriteNeeded = !CompareProfiles(szMtCalculatedProfile, pszReadMtProfile); if (!isMtWriteNeeded && !isTeWriteNeeded) { RIL_LOG_INFO("ProfileProcess::run() - No need to write profiles\r\n"); goto Out; } // Write profiles CTE::GetTE().WriteUsatProfiles(szTeCalculatedProfile, isTeWriteNeeded, szMtCalculatedProfile, isMtWriteNeeded); return; Out: if (m_usatInitStateMachine.GetReadyToActivate() && m_usatInitStateMachine.GetUiccState() == UsatInitStateMachine::UICC_ACTIVE) { m_usatInitStateMachine.PassToNextEvent(UsatInitStateMachine::SIM_READY_TO_ACTIVATE); } }
void sacHeaderFromCSS(DBlist tree, struct SACheader *header, struct wfdiscList *w, int RefTimeType, double *RefTime, MagType Mtype) { struct sitechanList *sc; struct siteList *si; struct originList *orig; struct eventList *ev; struct assocList *aso; struct assocList *as; struct affiliationList *af; struct arrivalList *ar, *arm; struct sacdataList *sd; struct wftagList *wt = 0 ; int year, month, day, hour, min; float second; int i; char SACfield[3]; float TmpMilliSeconds; *header = NullSacHeader; header->npts = w->element->nsamp; if( CSSchrDefined(w->element->instype) ) strcpy(header->kinst,w->element->instype); header->nwfid = w->element->wfid; /* Find an origin struct matched to w and copy its info to header. */ if( (orig = sacFindOrigin(tree, w) ) ){ if( CSSfltDefined(orig->element->lat) ) header->evla = orig->element->lat; if( CSSfltDefined(orig->element->lon) ) header->evlo = orig->element->lon; if( CSSfltDefined(orig->element->depth) ) header->evdp = orig->element->depth * 1000.0; if( CSSlngDefined(orig->element->grn) ) header->ievreg = orig->element->grn + REGCONV ; if( CSSlngDefined(orig->element->orid) )header->norid = orig->element->orid; if( CSSlngDefined(orig->element->evid) ){ header->nevid = orig->element->evid; } header->ievtyp = sacSetEvType(orig->element->etype); if( (as = sacFindAssoc(tree, orig->element->orid, w->element->sta) ) ){ if(isValidFloat(dbl_LIST_ASSOC, dbl_ASSOC_DELTA, as->element->delta) ) header->gcarc = as->element->delta; if( CSSfltDefined(as->element->seaz) ) header->baz = as->element->seaz; if( CSSfltDefined(as->element->esaz) )header->az = as->element->esaz; } SetMagnitudeInHeader(header, orig, Mtype); SetMagnitudeSource(header, orig); } if(orig && RefTimeType == IO && CSSdblDefined(orig->element->time)){ header->iztype = IO; *RefTime = orig->element->time; } else{ header->iztype = IB; *RefTime = w->element->time; } header->b = (float) (w->element->time - *RefTime); if(orig && CSSdblDefined(orig->element->time) ){ header->o = orig->element->time - *RefTime; strcpy(header->ko, "O"); } if(w->element->samprate) header->delta = 1.0 / w->element->samprate; else header->delta = 1.0; header->e = header->b + (float) ( (header->npts -1) * header->delta); tmDecodeEpochTime(*RefTime, &year, &month, &day, &hour, &min, &second); header->nzyear = year; header->nzjday = yrday( month, day, isleap( year) ); header->nzhour = hour; header->nzmin = min; header->nzsec = (int) second; TmpMilliSeconds = (second - (int) second) * 1000; header->nzmsec = Round(TmpMilliSeconds); if(w->seis->Cmplx){ header->iftype = IXY; header->leven = FALSE; } else{ header->iftype = ITIME; header->leven = TRUE; header->depmin = FLT_MAX; header->depmax = -header->depmin; header->depmen = 0.0; for(i=0;i<header->npts;i++){ header->depmen += *(w->seis->i + i); if(header->depmin > *(w->seis->i + i) ) header->depmin = *(w->seis->i + i); if(header->depmax < *(w->seis->i + i) ) header->depmax = *(w->seis->i + i); } if(header->npts) header->depmen /= header->npts; } /* Get A variable if any are marked as such. */ strcpy(SACfield, "A"); arm = MatchingArrival(tree, w->element->sta, w->element->chan, w->element->time, w->element->endtime, SACfield, w->element->wfid); if(arm){ header->a = arm->element->time - *RefTime; aso = sacFindAssocFromArid( tree , arm->element->arid ) ; if ( aso && isValidString ( dbl_LIST_ASSOC , dbl_ASSOC_PHASE , aso->element->phase ) ) strncpy(header->ka, aso->element->phase,8); else strncpy(header->ka, arm->element->iphase,8); } /* Get T0 - T9 */ ar = 0; for(i=0;i<10;i++){ sprintf(SACfield,"T%d",i); SACfield[2] = '\0'; arm = MatchingArrival(tree, w->element->sta, w->element->chan, w->element->time, w->element->endtime, SACfield, w->element->wfid); if(!arm){ /* If you can't find an arrival marked for Ti, take the next unmarked arrival. */ ar = sacFindNextMatchingArrival(ar, tree, w->element->sta, w->element->chan, w->element->time, w->element->endtime, w->element->wfid); if ( !ar ) continue ; arm = ar; } aso = sacFindAssocFromArid( tree , arm->element->arid ) ; if ( aso && isValidString ( dbl_LIST_ASSOC , dbl_ASSOC_PHASE , aso->element->phase ) ) { if ( toupper(aso->element->phase[0]) == 'F' ) continue; char *kt = sac_header_kt_number(header, i); if(kt) { strncpy(kt, aso->element->phase,8); } } else { if( toupper(arm->element->iphase[0]) == 'F' ) continue; char *kt = sac_header_kt_number(header, i); if(kt) { strncpy(kt, arm->element->iphase,8); } } *(&(header->t0) + i) = arm->element->time - *RefTime; strcpy(arm->element->SACfield, SACfield); } /* Now get the Fini arrival if present. */ strcpy(SACfield, "F"); arm = MatchingArrival(tree, w->element->sta, w->element->chan, w->element->time, w->element->endtime, SACfield, w->element->wfid); if(arm){ header->f = arm->element->time - *RefTime; aso = sacFindAssocFromArid( tree , arm->element->arid ) ; if ( aso && isValidString ( dbl_LIST_ASSOC , dbl_ASSOC_PHASE , aso->element->phase ) ) strncpy(header->kf, aso->element->phase,8); else strcpy( header->kf, arm->element->iphase); } else{ ar = 0; do { ar = sacFindNextMatchingArrival(ar, tree, w->element->sta, w->element->chan, w->element->time, w->element->endtime, w->element->wfid); if(!ar)break; aso = sacFindAssocFromArid( tree , ar->element->arid ) ; if ( aso && isValidString ( dbl_LIST_ASSOC , dbl_ASSOC_PHASE , aso->element->phase ) ) { if( toupper(aso->element->phase[0]) == 'F' ){ header->f = ar->element->time - *RefTime; strcpy( header->kf, aso->element->phase); } } else { if( toupper(ar->element->iphase[0]) == 'F' ){ header->f = ar->element->time - *RefTime; strcpy( header->kf, ar->element->iphase); } } }while(ar); } if( CSSchrDefined(w->element->sta) ) strncpy(header->kstnm, w->element->sta, 8); if( CSSchrDefined(w->element->chan) ) strncpy(header->kcmpnm, w->element->chan, 8); sc = sacFindSiteChan(tree, w->element->sta, w->element->chan, w->element->jdate, w->element->wfid ); if(sc ){ if ( isValidFloat ( dbl_LIST_SITECHAN , dbl_SITEC_VANG , sc->element->vang ) ) header->cmpinc = sc->element->vang; else header->cmpinc = -12345.0 ; if ( isValidFloat ( dbl_LIST_SITECHAN , dbl_SITEC_HANG , sc->element->hang ) ) header->cmpaz = sc->element->hang; else header->cmpaz = -12345.0 ; if(!header->cmpinc) header->cmpaz = 0.0; header->stdp = sc->element->edepth * 1000.0 ; } if( (si = sacFindSite(tree, w->element->sta, w->element->jdate, w->element->wfid) ) ){ if( CSSfltDefined(si->element->lat) ) header->stla = si->element->lat; if( CSSfltDefined(si->element->lon) ) header->stlo = si->element->lon; if( CSSfltDefined(si->element->elev) ) header->stel = si->element->elev * 1000; strncpy(header->kuser1 , si->element->refsta , 6 ) ; header->kuser1[6] = '\0' ; } else { DEBUG("warning: Could not find Site: %s [%d]\n", w->element->sta, w->element->wfid); } SetDistAzValues(header); /* lpspol - true if station components have positive polarity */ header->lpspol = FALSE; /* lcalca - true if event info is to be calculated from position */ header->lcalda = TRUE; /* lovrok - true if the file can be overwritten */ header->lovrok = TRUE; /* SAC header version number */ header->nvhdr = 6; sd = findSacData(tree, w->element->wfid); if( sd ) { strcpy(header->kuser0, sd->element->userdata.label[0]); strcpy(header->kuser1, sd->element->userdata.label[1]); strcpy(header->kuser2, sd->element->userdata.label[2]); header->user0 = sd->element->userdata.value[0]; header->user1 = sd->element->userdata.value[1]; header->user2 = sd->element->userdata.value[2]; header->user3 = sd->element->userdata.value[3]; header->user4 = sd->element->userdata.value[4]; header->user5 = sd->element->userdata.value[5]; header->user6 = sd->element->userdata.value[6]; header->user7 = sd->element->userdata.value[7]; header->user8 = sd->element->userdata.value[8]; header->user9 = sd->element->userdata.value[9]; header->isynth = sd->element->synthflag; header->lpspol = sd->element->lpspol; header->idep = sd->element->idep; header->iftype = sd->element->iftype; header->nsnpts = sd->element->nsnpts; header->nxsize = sd->element->nxsize; header->nysize = sd->element->nysize; header->leven = sd->element->leven; header->fmt = sd->element->fmt; header->sb = sd->element->sb; header->sdelta = sd->element->sdelta; header->xminimum = sd->element->xminimum; header->xmaximum = sd->element->xmaximum; header->yminimum = sd->element->yminimum; header->ymaximum = sd->element->ymaximum; header->odelta = sd->element->odelta; header->resp0 = sd->element->resp[0]; header->resp1 = sd->element->resp[1]; header->resp2 = sd->element->resp[2]; header->resp3 = sd->element->resp[3]; header->resp4 = sd->element->resp[4]; header->resp5 = sd->element->resp[5]; header->resp6 = sd->element->resp[6]; header->resp7 = sd->element->resp[7]; header->resp8 = sd->element->resp[8]; header->resp9 = sd->element->resp[9]; header->evel = sd->element->evel; header->az = sd->element->az; header->baz = sd->element->baz; header->gcarc = sd->element->gcarc; header->dist = sd->element->dist; header->iinst = sd->element->iinst; if ( lngDefined ( sd->element->istreg ) ) header->istreg = sd->element->istreg + REGCONV ; header->iqual = sd->element->iqual; header->lovrok = sd->element->lovrok; header->lcalda = sd->element->lcalda; strcpy(header->khole, sd->element->khole); strcpy(header->ko, sd->element->ko); strcpy(header->kdatrd, sd->element->kdatrd ); } strncpy(header->kdatrd, tmListEpochTime( tmGetEpochTime(), 18 ) , 8 ); header->kdatrd[ 8 ] = '\0' ; if( (af = sacFindAffiliation(tree, header->kstnm) ) ){ strcpy(header->knetwk, af->element->net); } if( ( wt = sacFindWftag( tree, w->element->wfid, "evid" ) ) ) { if( (ev = sacFindEvent(tree, wt->element->tagid) ) ){ if( CSSchrDefined(ev->element->evname) ) strcpy(header->kevnm, ev->element->evname); } } }
bool SR865::isValidBaudrate(const int &new_baudrate) const { return isValidString(this->baudrateList, QString::number(new_baudrate)); }
bool DS345::isValidAmplitudeType(const QString &unit) const { return isValidString(this->amplitudeTypeList, unit); }
int main(){ int choice = 7, result, n; char *str1, *str2; while(choice != 0){ //while user has not chosen to exit the program printMenu(&choice); //calls function printMenu str1 = (char *)malloc(100*sizeof(char)); str2 = (char *)malloc(100*sizeof(char)); switch(choice){ case 1: printf("\n*****************************************\n"); printf("*\t Get Hamming Distance\t\t*\n"); printf("*****************************************\n"); printf("\nEnter string 1: "); scanf("%s", str1); printf("Enter string 2: "); scanf("%s", str2); //return value of function getHammingDistance stored in result result = getHammingDistance(str1, str2); if(result == 0){ //if the strings have unequal length printf("\nError! Strings have unequal length!\n"); }else{ //if the strings have equal length printf("\nHamming Distance: %d\n", result); } break; case 2: printf("\n*****************************************\n"); printf("*\t Count Substring Pattern\t*\n"); printf("*****************************************\n"); printf("\nEnter original string: "); scanf("%s", str1); printf("Enter pattern: "); scanf("%s", str2); //return value of function countSubstrPattern stored in result result = countSubstrPattern(str1, str2); printf("\nNumber of occurence of pattern in orginal: %d\n", result); break; case 3: printf("\n*****************************************\n"); printf("*\t Is String Valid\t\t*\n"); printf("*****************************************\n"); printf("\nEnter alphabet: "); scanf("%s", str1); printf("Enter string: "); scanf("%s", str2); //return value of function isValidString stored in result result = isValidString(str2, str1); if(result == 1){ printf("\nString is valid.\n"); }else{ printf("\nString is not valid.\n"); } break; case 4: printf("\n*****************************************\n"); printf("*\t\tGet Skew\t\t*\n"); printf("*****************************************\n"); printf("\nEnter genome string: "); scanf("%s", str1); printf("Enter number: "); scanf("%d", &n); if(n > (strlen(str1)+1) || n <= 0){ printf("\nError! Number must be within string length!\n"); }else{ //return value of function getSkew stored in result result = getSkew(str1, n); printf("\nNumber of G-C: %d\n", result); } break; case 5: printf("\n*****************************************\n"); printf("*\t Get Maximum Skew of N\t\t*\n"); printf("*****************************************\n"); printf("\nEnter genome string: "); scanf("%s", str1); printf("Enter number: "); scanf("%d", &n); if(n > (strlen(str1)+1) || n <= 0){ printf("\nError! Number must be within string length!\n"); }else{ //return value of function getMaxSkewN stored in result result = getMaxSkewN(str1, n); printf("\nMaximum Skew: %d\n", result); } break; case 6: printf("\n*****************************************\n"); printf("*\t Get Minimum Skew of N\t\t*\n"); printf("*****************************************\n"); printf("\nEnter genome string: "); scanf("%s", str1); printf("Enter number: "); scanf("%d", &n); if(n > (strlen(str1)+1) || n <= 0){ printf("\nError! Number must be within string length!\n"); }else{ //return value of function getMinSkewN stored in result result = getMinSkewN(str1, n); printf("\nMinimum Skew: %d\n", result); } break; case 0: free(str1); free(str2); printf("\nProgram Terminated...\n"); break; default: printf("\nInvalid input!\n"); break; } } }
int PutArrivalData ( FILE *ptr , DBlist tree ) { char sta[ 6 ] , dist[ 7 ] , evaz[ 6 ] , picktype = ' ' , direction , detchar , phase[ 8 ] , time[ 25 ] , tres[] = " " , azim[ 6 ] , azres[ 7 ] , slow[ 6 ] , sres[ 6 ] , tdef , adef , sdef , snr[ 6 ] , amp[ 10 ] , per[ 6 ] , mdef1[ 3 ] , mag1[ 5 ] , mdef2[ 3 ] , mag2[ 5 ] , id [ 9 ] ; struct CSStree *Tree = (struct CSStree *) tree ; struct arrivalList *ar = Tree->arHead ; int dots = 0; char HeaderLine[] = "Sta Dist EvAz Phase Date Time TRes Azim" " AzRes Slow SRes Def SNR Amp Per Mag1 Mag2 ID"; if(!ar) return -1 ; printf("Writing arrival data "); fprintf(ptr,"DATA_TYPE ARRIVAL GSE2.0\n"); fprintf(ptr, "%s\n", HeaderLine); while(ar){ struct assocList *as = Tree->asHead ; struct originList *orig = Tree->orHead ; struct siteList *si = Tree->slHead ; putchar('.'); dots++; if(dots == 80){ putchar('\n'); dots = 0; } fflush(stdout); /* sta */ if ( isValidString ( dbl_LIST_ARRIVAL, dbl_ARRIV_STA , ar->element->sta ) && strcmp( ar->element->sta , "- " ) ) sprintf ( sta , "%-5.5s" , ar->element->sta ) ; else strcpy ( sta , " " ) ; /* 5 spaces */ /* dist & evaz */ /* find assoc in order to find origin, then find sitechan */ while ( as ) { if ( as->element->arid == ar->element->arid ) break ; as = as->next ; } if ( as ) while ( orig ) { if ( as->element->orid == orig->element->orid ) break ; orig = orig->next ; } /* end while ( orig ) */ while ( si ) { if ( !strcmp ( ar->element->sta , si->element->sta ) && si->element->ondate <= ar->element->jdate && (si->element->offdate >= ar->element->jdate || si->element->offdate == -1 ) ) break ; si = si->next ; } /* end while ( si ) */ if ( orig && si && isValidFloat ( dbl_LIST_ORIGIN, dbl_ORIGI_LAT, orig->element->lat ) && isValidFloat ( dbl_LIST_ORIGIN, dbl_ORIGI_LON, orig->element->lon ) && isValidFloat ( dbl_LIST_SITE, dbl_SITE_LAT, si->element->lat ) && isValidFloat ( dbl_LIST_SITE, dbl_SITE_LON, si->element->lon ) ) { float slat = si->element->lat , slon = si->element->lon , elat = orig->element->lat , elon = orig->element->lon , delt, fDist, fAzim, bazim ; dbDelaz(&slat, &slon, &elat, &elon, &delt, &fDist, &fAzim, &bazim); if ( fDist < 1000 ) sprintf ( dist , "%6.2f" , fDist ) ; else sprintf ( dist , "%6.1f" , fDist ) ; sprintf ( evaz , "%5.1f" , fAzim ) ; } else { strcpy ( dist , " " ) ; /* 6 spaces */ strcpy ( evaz , " " ) ; /* 5 spaces */ } /* direction */ if ( isValidString ( dbl_LIST_ARRIVAL, dbl_ARRIV_FM , ar->element->fm ) ) { char *fm = ar->element->fm ; if ( fm[ 0 ] == 'c' || fm[ 1 ] == 'c' ) direction = 'c' ; else if ( fm[ 0 ] == 'd' || fm[ 1 ] == 'd' ) direction = 'd' ; else if ( fm[ 0 ] == 'u' || fm[ 1 ] == 'u' ) direction = 'c' ; else if ( fm[ 0 ] == 'r' || fm[ 1 ] == 'r' ) direction = 'd' ; else direction = ' ' ; } else direction = ' ' ; /* detchar */ if ( isValidString ( dbl_LIST_ARRIVAL, dbl_ARRIV_QUAL , ar->element->qual ) ) { if ( ar->element->qual[ 0 ] == 'i' || ar->element->qual[ 0 ] == 'e' ) detchar = ar->element->qual[ 0 ] ; else if ( ar->element->qual[ 0 ] == 'q' || ar->element->qual[ 0 ] == 'w' ) detchar = 'q' ; else detchar = ' ' ; } else detchar = ' ' ; /* phase */ if ( isValidString ( dbl_LIST_ARRIVAL, dbl_ARRIV_IPHASE , ar->element->iphase ) && strcmp( ar->element->iphase , "- " ) ) sprintf ( phase , "%-7.7s" , ar->element->iphase ) ; else strcpy ( phase , " " ) ; /* 7 spaces */ /* time */ if ( isValidFloat ( dbl_LIST_ARRIVAL, dbl_ARRIV_TIME, ar->element->time ) ) { sprintf ( time , "%-21.21s" , tmListEpochTime ( ar->element->time , 14 ) ) ; time[ 10 ] = ' ' ; } else strcpy ( time , " " ) ; /* 21 spaces */ /* azim */ if ( isValidFloat ( dbl_LIST_ARRIVAL, dbl_ARRIV_AZIMUTH , ar->element->azimuth ) ) sprintf ( azim , "%5.1f" , ar->element->azimuth ) ; else strcpy ( azim , " " ) ; /* 5 spaces */ /* azres */ if ( isValidFloat ( dbl_LIST_ARRIVAL, dbl_ARRIV_DELAZ , ar->element->delaz ) ) sprintf ( azres , "%6.1f" , ar->element->delaz ) ; else strcpy ( azres , " " ) ; /* 6 spaces */ /* slow */ if ( isValidFloat ( dbl_LIST_ARRIVAL, dbl_ARRIV_SLOW , ar->element->slow ) ) sprintf ( slow , "%5.1f" , ar->element->slow ) ; else strcpy ( slow , " " ) ; /* 5 spaces */ /* sres */ if ( isValidFloat ( dbl_LIST_ARRIVAL, dbl_ARRIV_DELSLO , ar->element->delslo ) ) sprintf ( sres , "%5.1f" , ar->element->delslo ) ; else strcpy ( sres , " " ) ; /* 5 spaces */ /* tdef, adef, & sdef */ if ( as && as->element->timedef[0] == 'd' ) tdef = 'T' ; else tdef = ' ' ; if ( as && as->element->azdef[0] == 'd' ) adef = 'A' ; else adef = ' ' ; if ( as && as->element->slodef[0] == 'd' ) sdef = 'S' ; else sdef = ' ' ; /* snr */ if ( isValidFloat ( dbl_LIST_ARRIVAL, dbl_ARRIV_SNR , ar->element->snr ) ) sprintf ( snr , "%5.1f" , ar->element->snr ) ; else strcpy ( snr , " " ) ; /* 5 spaces */ /* amp */ if ( isValidFloat ( dbl_LIST_ARRIVAL, dbl_ARRIV_AMP , ar->element->amp ) ) sprintf ( amp , "%9.1f" , ar->element->amp ) ; else strcpy ( amp , " " ) ; /* 9 spaces */ /* per */ if ( isValidFloat ( dbl_LIST_ARRIVAL, dbl_ARRIV_PER , ar->element->per ) ) sprintf ( per , "%5.2f" , ar->element->per ) ; else strcpy ( per , " " ) ; /* 5 spaces */ /* mdef1, mag1, mdef2, & mag2 */ if ( orig ) { if ( isValidFloat ( dbl_LIST_ORIGIN , dbl_ORIGI_MB , orig->element->mb ) && isValidFloat ( dbl_LIST_ORIGIN , dbl_ORIGI_MS , orig->element->ms ) ) { strcpy ( mdef1 , "mb" ) ; sprintf( mag1 , "%4.1f" , orig->element->mb ) ; strcpy ( mdef2 , "ms" ) ; sprintf( mag2 , "%4.1f" , orig->element->ms ) ; } else if ( isValidFloat ( dbl_LIST_ORIGIN , dbl_ORIGI_MB , orig->element->mb ) && isValidFloat ( dbl_LIST_ORIGIN , dbl_ORIGI_ML , orig->element->ml ) ) { strcpy ( mdef1 , "mb" ) ; sprintf( mag1 , "%4.1f" , orig->element->mb ) ; strcpy ( mdef2 , "ml" ) ; sprintf( mag2 , "%4.1f" , orig->element->ml ) ; } else if ( isValidFloat ( dbl_LIST_ORIGIN , dbl_ORIGI_MS , orig->element->ms ) && isValidFloat ( dbl_LIST_ORIGIN , dbl_ORIGI_ML , orig->element->ml ) ) { strcpy ( mdef1 , "ms" ) ; sprintf( mag1 , "%4.1f" , orig->element->ms ) ; strcpy ( mdef2 , "ml" ) ; sprintf( mag2 , "%4.1f" , orig->element->ml ) ; } else { strcpy ( mdef2 , " " ) ; strcpy ( mag2 , " " ) ; if ( isValidFloat ( dbl_LIST_ORIGIN , dbl_ORIGI_MB , orig->element->mb ) ) { strcpy ( mdef1 , "mb" ) ; sprintf( mag1 , "%4.1f" , orig->element->mb ) ; } else if ( isValidFloat ( dbl_LIST_ORIGIN , dbl_ORIGI_MS , orig->element->ms ) ) { strcpy ( mdef1 , "ms" ) ; sprintf( mag1 , "%4.1f" , orig->element->ms ) ; } else if ( isValidFloat ( dbl_LIST_ORIGIN , dbl_ORIGI_ML , orig->element->ml ) ) { strcpy ( mdef1 , "ml" ) ; sprintf( mag1 , "%4.1f" , orig->element->ml ) ; } else { strcpy ( mdef1 , " " ) ; strcpy ( mag1 , " " ) ; } } } else { strcpy ( mdef1 , " " ) ; strcpy ( mag1 , " " ) ; strcpy ( mdef2 , " " ) ; strcpy ( mag2 , " " ) ; } /* id */ if ( isValidInt ( dbl_LIST_ARRIVAL, dbl_ARRIV_ARID , ar->element->arid ) ) sprintf ( id , "%8d" , ar->element->arid ) ; else strcpy ( id , " " ) ; /* 8 spaces */ fprintf ( ptr , "%s %s %s %c%c%c %s %s %s %s %s %s %s %c%c%c %s %s %s %s%s %s%s %s", sta, dist, evaz, picktype, direction, detchar, phase, time, tres, azim, azres, slow, sres, tdef, adef, sdef, snr, amp, per, mdef1, mag1, mdef2, mag2, id ) ; fprintf(ptr, "\n"); ar = ar->next; } fprintf(ptr,"\n"); printf("\n"); return 0 ; } /* end PutArrivalData */