/*ARGSUSED*/ void lex_init(char **av, const char *cppargs, int lexecho) { int i; #ifdef ESC const char *ptr; #endif /* ESC */ Lexecho = lexecho; Tokcount = stats_new_counter("lex.tokens", "total tokens in", 1); Filecount = stats_new_counter("lex.files", "total files read", 0); Lexelapse = stats_new_elapse("lex.time", "elapsed lex/parse time", 1); #ifdef ESC Cppargs = cppargs; /* allow user to tell us where cpp is if it is some weird place */ if (ptr = getenv("_ESC_CPP")) Cpp = ptr; /* and in case it takes some special stdargs */ if (ptr = getenv("_ESC_CPP_STDARGS")) Cppstdargs = ptr; /* verify we can find cpp */ if (access(Cpp, X_OK) < 0) { Cpp = "/usr/lib/cpp"; if (access(Cpp, X_OK) < 0) out(O_DIE, "can't locate cpp"); } #endif /* ESC */ Files = av; /* verify we can find all the input files */ while (*av) { if (strlen(*av) >= MAXTOK - strlen(Cpp) - 3) out(O_DIE, "filename too long: %.100s...", *av); if (access(*av, R_OK) < 0) out(O_DIE|O_SYS, "%s", *av); av++; stats_counter_bump(Filecount); } /* put reserved words into the string table & a lookup table */ for (i = 0; i < sizeof (Rwords) / sizeof (*Rwords); i++) Rwordslut = lex_s2i_lut_add(Rwordslut, stable(Rwords[i].word), Rwords[i].val); /* initialize table of timeval suffixes */ for (i = 0; i < sizeof (Timesuffix) / sizeof (*Timesuffix); i++) { Timesuffixlut = lex_s2ullp_lut_add(Timesuffixlut, stable(Timesuffix[i].suffix), &Timesuffix[i].nsec); } /* record start time */ stats_elapse_start(Lexelapse); }
//光流定点算法 void loiter(float x, float y, float yaw) { rt_uint32_t dump; if (check_safe(SAFE_ADNS3080)) { x_v_pid.out = 0; y_v_pid.out = 0; return; } if (rt_event_recv(&ahrs_event, AHRS_EVENT_ADNS3080, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, &dump) == RT_EOK) { PID_SetTarget(&x_d_pid, pos_X); PID_SetTarget(&y_d_pid, pos_y); PID_xUpdate(&x_d_pid, ahrs.x); PID_xUpdate(&y_d_pid, ahrs.y); PID_SetTarget(&x_v_pid, -RangeValue(x_d_pid.out, -10, 10)); PID_SetTarget(&y_v_pid, -RangeValue(y_d_pid.out, -10, 10)); PID_xUpdate(&x_v_pid, ahrs.dx); PID_xUpdate(&y_v_pid, ahrs.dy); } stable(+RangeValue(y_v_pid.out, -10, 10), -RangeValue(x_v_pid.out, -10, 10), yaw); }
/* * dodictionary -- handle "#pragma dictionary" directives */ static void dodictionary() { int c; char *ptr = Tok; char *eptr = &Tok[MAXTOK]; /* skip white space and quotes */ while ((c = getc(Fp)) != EOF && (c == ' ' || c == '\t' || c == '"')) ; if (c == EOF || c == '\n') outfl(O_DIE, File, Line, "bad dictionary"); /* pull in next token */ ptr = Tok; *ptr++ = c; while ((c = getc(Fp)) != EOF && c != '"' && c != '\n') if (ptr < eptr - 1) *ptr++ = c; *ptr++ = '\0'; if (c != '\n') { /* skip to end of line (including close quote, if any) */ while ((c = getc(Fp)) != EOF && c != '\n') ; } (void) ungetc(c, Fp); Dicts = lut_add(Dicts, (void *)stable(Tok), (void *)0, NULL); outfl(O_VERB, File, Line, "pragma set: dictionary \"%s\"", Tok); }
const Choice* Space::choice(void) { if (!stable()) throw SpaceNotStable("Space::choice"); if (failed() || (b_status == Brancher::cast(&bl))) { // There are no more choices to be generated // Delete all branchers Brancher* b = Brancher::cast(bl.next()); while (b != Brancher::cast(&bl)) { Brancher* d = b; b = Brancher::cast(b->next()); rfree(d,d->dispose(*this)); } bl.init(); b_status = b_commit = Brancher::cast(&bl); return NULL; } /* * The call to choice() says that no older choices * can be used. Hence, all branchers that are exhausted can be deleted. */ Brancher* b = Brancher::cast(bl.next()); while (b != b_status) { Brancher* d = b; b = Brancher::cast(b->next()); d->unlink(); rfree(d,d->dispose(*this)); } // Make sure that b_commit does not point to a deleted brancher! b_commit = b_status; return b_status->choice(*this); }
// Synchronize remote notebooks with the current database // If there is a conflict, the remote wins void SyncRunner::syncRemoteNotebooks(QList<Notebook> books, qint32 account) { QLOG_TRACE() << "Entering SyncRunner::syncRemoteNotebooks"; NotebookTable notebookTable(db); LinkedNotebookTable ltable(db); SharedNotebookTable stable(db); for (int i=0; i<books.size() && keepRunning; i++) { Notebook t = books.at(i); // There are a few to get the notebook. // We can get it by the guid, the share key, the uri, or the name. qint32 lid = account; if (lid == 0) lid = notebookTable.getLid(t.guid); if (lid == 0) lid = ltable.getLid(t.guid); if (lid == 0 && t.sharedNotebooks.isSet()) { QList<SharedNotebook> sharedNotebooks = t.sharedNotebooks; for (int j=0; j<sharedNotebooks.size() && lid == 0; j++) { lid = stable.findById(sharedNotebooks[j].id); } } Publishing publishing; if (t.publishing.isSet()) publishing = t.publishing; if (lid == 0 && publishing.uri.isSet()) { lid = notebookTable.findByUri(publishing.uri); } if (lid == 0) lid = notebookTable.findByName(t.name); if (lid > 0) { notebookTable.sync(lid, t); } else { lid = notebookTable.sync(t); } changedNotebooks.insert(t.guid, t.name); QString stack = ""; if (t.stack.isSet()) stack = t.stack; bool shared = false; if (t.sharedNotebookIds.isSet() || t.sharedNotebooks.isSet()) shared = true; if (account > 0) { LinkedNotebookTable ltb(db); LinkedNotebook lbook; ltb.get(lbook, account); if (lbook.username.isSet()) stack = QString::fromStdString(username); } if (!finalSync) { if (t.name.isSet()) emit notebookUpdated(lid, t.name, stack, false, shared); else emit notebookUpdated(lid, "", stack, false, shared); } } QLOG_TRACE() << "Leaving SyncRunner::syncRemoteNotebooks"; }
// Synchronize a new notebook with what is in the database. We basically // just delete the old one & give it a new entry qint32 LinkedNotebookTable::sync(qint32 lid, LinkedNotebook ¬ebook) { qint32 lastUSN = 0; NotebookTable ntable(db); SharedNotebookTable stable(db); if (lid == 0 && notebook.shareKey.isSet()) { lid = stable.findByShareKey(notebook.shareKey); } if (lid == 0 && notebook.uri.isSet()) { lid = ntable.findByUri(notebook.uri); } if (lid > 0) { lastUSN = getLastUpdateSequenceNumber(lid); // Delete the old record NSqlQuery query(*db); query.prepare("Delete from DataStore where lid=:lid and key>=3200 and key<3300"); query.bindValue(":lid", lid); query.exec(); query.finish(); } if (lid == 0) { lid = ntable.getLid(notebook.guid); if (lid == 0) { ConfigStore cs(db); lid = cs.incrementLidCounter(); NotebookTable ntable(db); // Build the dummy notebook entry Notebook book; book.guid = notebook.guid; book.name = notebook.shareName; book.updateSequenceNum = notebook.updateSequenceNum; book.published = true; Publishing publishing; publishing.uri = notebook.uri; book.publishing = publishing; if (notebook.stack.isSet()) { book.stack = notebook.stack; } ntable.sync(lid, book); } } add(lid, notebook, false); if (lastUSN > 0) { setLastUpdateSequenceNumber(lid, lastUSN); } return lid; }
/* Drift all the capitals */ static int drift(void) { int i, turns; for (turns = 0; turns < DRIFT_MAX; ++turns) { if (turns > DRIFT_BEFORE_CHECK && (mind = stable())) return 1; for (i = 0; i < nc; ++i) fl_move(i); } return 0; }
int main() { int i, j, n; scanf("%d",&n); for (i = 0; i < n; i++) for (j = 0; j < n; j++) scanf("%d",&vpref[i][j]); for (i = 0; i < n; i++) for (j = 0; j < n; j++) scanf("%d",&upref[i][j]); convert(vrank,vpref,n); convert(urank,upref,n); stable(n); for (i = 0; i < n; i++) printf("%d %d\n",i+1,suitors[i][0]+1); return 0; }
// Upload any saved searchs qint32 SyncRunner::uploadSavedSearches() { QLOG_TRACE_IN(); qint32 usn; qint32 maxUsn = 0; SearchTable stable(db); QList<qint32> lids; stable.getAllDirty(lids); if (lids.size() == 0) { QLOG_TRACE_OUT(); return 0; } for (int i = 0; i < lids.size(); i++) { SavedSearch search; stable.get(search, lids[i]); if (!stable.isDeleted(lids[i])) { qint32 oldUsn = search.updateSequenceNum; usn = comm->uploadSavedSearch(search); if (usn == 0) { this->communicationErrorHandler(); error = true; QLOG_TRACE_OUT(); return maxUsn; } if (usn > maxUsn) { maxUsn = usn; if (oldUsn == 0) stable.updateGuid(lids[i], search.guid); stable.setUpdateSequenceNumber(lids[i], usn); } else { error = true; } } else { QString guid = stable.getGuid(lids[i]); stable.expunge(lids[i]); if (search.updateSequenceNum > 0) { usn = comm->expungeSavedSearch(guid); if (usn > maxUsn) maxUsn = usn; } } } QLOG_TRACE_OUT(); return maxUsn; }
//自稳模式 rt_err_t stable_mode(u8 var) { if (pwm.throttle > 0.05f && abs(ahrs.degree_pitch) < 40 && abs(ahrs.degree_roll) < 40) { yaw_exp += pwm.yaw * 0.5f; if (yaw_exp > 360.0f) yaw_exp -= 360.0f; if (yaw_exp < 0.0f) yaw_exp += 360.0f; stable(pwm.pitch * 30.0f, pwm.roll * 30.0f, yaw_exp); motor_update(pwm.throttle * 1000); } else Motor_Set(60, 60, 60, 60); return RT_EOK; }
// Calcule et renvoie la matrice # d'une matrice dans R Matrice creer_matrice_diese(Matrice m){ if(!estMatriceR(m)){ printf("erreur"); return NULL; } Matrice ma=creer_matrice(m->taille); ma->mot = tree_diese(m->mot); int i,j; for(i=0;i<m->taille;i++) for(j=0;j<m->taille;j++){ if(m->tab[i][j]==1 && !stable(i,j,m)) ma->tab[i][j]=OMEGA; else ma->tab[i][j]=m->tab[i][j]; } return ma; }
//定高模式 rt_err_t althold_mode(u8 height) { const u16 basic_thought = 530; if (pwm.throttle > 0.3f && abs(ahrs.degree_pitch) < 40 && abs(ahrs.degree_roll) < 40) { yaw_exp += pwm.yaw * 0.5f; if (yaw_exp > 360.0f) yaw_exp -= 360.0f; if (yaw_exp < 0.0f) yaw_exp += 360.0f; stable(pwm.pitch * 30.0f, pwm.roll * 30.0f, yaw_exp); althold(height); motor_hupdate(basic_thought); } else Motor_Set(60, 60, 60, 60); return RT_EOK; }
FILE * eftread_fopen(const char *fname, char *idbuf, size_t idbufsz) { FILE *fp; FILE *tfp; struct eftheader hdr; #define BUFLEN 8192 char buf[BUFLEN]; int cc; uint32_t csum = 0; char *ptr; if ((ptr = strrchr(fname, '.')) == NULL || strcmp(ptr, ".eft") != 0) { out(O_ERR, "%s: not a valid EFT (bad extension)", fname); return (NULL); } if ((fp = fopen(fname, "r")) == NULL) { out(O_ERR|O_SYS, "%s", fname); return (NULL); } if (fread(&hdr, 1, sizeof (hdr), fp) < sizeof (hdr)) { (void) fclose(fp); out(O_ERR, "%s: not a valid EFT (too short)", fname); return (NULL); } hdr.magic = ntohl(hdr.magic); hdr.major = ntohs(hdr.major); hdr.minor = ntohs(hdr.minor); hdr.cmajor = ntohs(hdr.cmajor); hdr.cminor = ntohs(hdr.cminor); hdr.identlen = ntohl(hdr.identlen); hdr.dictlen = ntohl(hdr.dictlen); hdr.csum = ntohl(hdr.csum); if (Showheader) out(O_VERB, "%s: magic %x EFT version %d.%d esc version %d.%d", fname, hdr.magic, hdr.major, hdr.minor, hdr.cmajor, hdr.cminor); if (hdr.magic != EFT_HDR_MAGIC) { (void) fclose(fp); out(O_ERR, "%s: not a valid EFT (bad magic)", fname); return (NULL); } if (hdr.major != EFT_HDR_MAJOR || hdr.minor > EFT_HDR_MINOR) { (void) fclose(fp); out(O_ERR, "%s is version %d.%d, " "this program supports up to %d.%d", fname, hdr.major, hdr.minor, EFT_HDR_MAJOR, EFT_HDR_MINOR); return (NULL); } bzero(idbuf, idbufsz); if (hdr.identlen != 0) { long npos = ftell(fp) + (long)hdr.identlen; /* after ident */ size_t rsz = MIN(hdr.identlen, idbufsz - 1); if (fread(idbuf, 1, rsz, fp) != rsz) out(O_DIE|O_SYS, "%s: fread", fname); if (fseek(fp, npos, SEEK_SET) == -1) out(O_DIE|O_SYS, "%s: fseek", fname); } if (hdr.dictlen && (hdr.dictlen < 2 || hdr.dictlen > 1000)) { (void) fclose(fp); out(O_ERR, "%s: bad dictlen: %d", fname, hdr.dictlen); return (NULL); } /* read in dict strings */ if (hdr.dictlen) { char *dbuf = alloca(hdr.dictlen); char *dptr; if ((cc = fread(dbuf, 1, hdr.dictlen, fp)) != hdr.dictlen) out(O_DIE|O_SYS, "short fread on %s (dictlen %d)", fname, hdr.dictlen); /* work from end of string array backwards, finding names */ for (dptr = &dbuf[hdr.dictlen - 2]; dptr > dbuf; dptr--) if (*dptr == '\0') { /* found separator, record string */ Dicts = lut_add(Dicts, (void *)stable(dptr + 1), (void *)0, NULL); } /* record the first string */ Dicts = lut_add(Dicts, (void *)stable(dptr), (void *)0, NULL); } if ((tfp = tmpfile()) == NULL) out(O_DIE|O_SYS, "cannot create temporary file"); while ((cc = fread(buf, 1, BUFLEN, fp)) > 0) { char *ptr; for (ptr = buf; ptr < &buf[cc]; ptr++) { *ptr = ~((unsigned char)*ptr); csum += (uint32_t)*ptr; } if (cc != fwrite(buf, 1, cc, tfp) || ferror(tfp)) out(O_DIE|O_SYS, "fwrite on tmpfile"); } if (ferror(fp)) out(O_DIE|O_SYS, "fread on %s", fname); (void) fclose(fp); if (hdr.csum != csum) { out(O_ERR, "%s: bad checksum (%x != %x)", fname, hdr.csum, csum); (void) fclose(tfp); return (NULL); } if (Showheader) { int len = strlen(hdr.comment); if (len > 0 && hdr.comment[len - 1] == '\n') hdr.comment[len - 1] = '\0'; out(O_OK, "%s:\n\t%s", fname, hdr.comment); } rewind(tfp); return (tfp); }
// Implement of dropEvent so dropMimeData gets called void FavoritesView::dropEvent(QDropEvent *event) { QTreeView::dropEvent(event); const QMimeData* data = event->mimeData(); QModelIndex droppedIndex = indexAt( event->pos() ); if (!droppedIndex.isValid()) return; int row = droppedIndex.row(); qint32 lid = 0; if (data->hasFormat("application/x-nixnote-tag")) { QByteArray d = data->data("application/x-nixnote-tag"); lid = d.trimmed().toInt(); addRecord(lid, FavoritesRecord::Tag, row); } if (data->hasFormat("application/x-nixnote-note")) { QByteArray d = data->data("application/x-nixnote-note"); lid = d.trimmed().toInt(); addRecord(lid, FavoritesRecord::Note, row); } if (data->hasFormat("application/x-nixnote-search")) { QByteArray d = data->data("application/x-nixnote-search"); lid = d.trimmed().toInt(); addRecord(lid, FavoritesRecord::Search, row); } if (data->hasFormat("application/x-nixnote-favorite")) { QByteArray d = data->data("application/x-nixnote-favorite"); lid = d.trimmed().toInt(); FavoritesTable ftable(global.db); FavoritesRecord rec; if (ftable.get(rec,lid)) { ftable.expunge(lid); rec.order = row; ftable.insert(rec); } } if (data->hasFormat("application/x-nixnote-notebook")) { QString d = data->data("application/x-nixnote-notebook"); int pos = d.indexOf("/"); if (pos == -1) return; int type = d.mid(0,pos).toInt(); d = d.mid(pos+1); pos = d.indexOf("/"); if (pos == -1) return; lid= d.mid(0,pos).toInt(); QString stack = d.mid(pos+1); FavoritesRecord::FavoritesRecordType rectype = FavoritesRecord::LocalNotebook; switch (type) { case NNotebookViewItem::Local : rectype = FavoritesRecord::LocalNotebook; break; case NNotebookViewItem::Synchronized : rectype = FavoritesRecord::SynchronizedNotebook; break; case NNotebookViewItem::LinkedStack : rectype = FavoritesRecord::LinkedStack; break; case NNotebookViewItem::Conflict : rectype = FavoritesRecord::ConflictNotebook; break; case NNotebookViewItem::Stack : rectype = FavoritesRecord::NotebookStack; break; case NNotebookViewItem::Shared: rectype = FavoritesRecord::SharedNotebook; break; case NNotebookViewItem::Linked : rectype = FavoritesRecord::LinkedNotebook; break; } if (lid > 0) addRecord(lid, rectype, row); else { FavoritesTable table(global.db); FavoritesRecord record; record.type = rectype; record.target= stack; record.lid = 0; record.order = row; record.parent = 0; qint32 newLid = table.insert(record); QList<qint32> lids; NotebookTable ntable(global.db); ntable.findByStack(lids, stack); for (int i=0; i<lids.size(); i++) { Notebook book; if (ntable.get(book, lids[i])) { FavoritesRecord rec; rec.parent = newLid; if (book.name.isSet()) rec.displayName = book.name; rec.type = FavoritesRecord::SynchronizedNotebook; if (ntable.isLocal(lids[i])) rec.type = FavoritesRecord::LocalNotebook; LinkedNotebookTable ltable(global.db); if (ltable.exists(lids[i])) rec.type = FavoritesRecord::LinkedNotebook; SharedNotebookTable stable(global.db); if (stable.exists(lids[i])) rec.type = FavoritesRecord::SharedNotebook; rec.target = lids[i]; rec.order = 1; table.add(rec); } } } } rebuildFavoritesTreeNeeded = true; this->loadData(); }
int yylex() { int c; int nextc; char *ptr = Tok; char *eptr = &Tok[MAXTOK]; const char *cptr; int startline; int val; static int bol = 1; /* true if we're at beginning of line */ for (;;) { while (Fp == NULL) { char ibuf[80]; if (*Files == NULL) return (record(EOF, NULL)); Fileopened = stable(*Files++); #ifdef ESC sprintf(Tok, "%s %s %s %s", Cpp, Cppstdargs, Cppargs, Fileopened); if ((Fp = popen(Tok, "r")) == NULL) out(O_DIE|O_SYS, "%s", Tok); #else Fp = eftread_fopen(Fileopened, ibuf, sizeof (ibuf)); #endif /* ESC */ Line = 1; bol = 1; /* add name to stats for visibility */ if (Fp != NULL) { static int fnum; char nbuf[100]; struct filestats *nfs = MALLOC(sizeof (*nfs)); (void) sprintf(nbuf, "lex.file%d", fnum); nfs->stats = stats_new_string(nbuf, "", 0); stats_string_set(nfs->stats, Fileopened); if (ibuf[0] != '\0') { (void) sprintf(nbuf, "lex.file%d-ident", fnum); nfs->idstats = stats_new_string(nbuf, "", 0); stats_string_set(nfs->idstats, ibuf); } else { nfs->idstats = NULL; } nfs->next = Fstats; Fstats = nfs; fnum++; } } switch (c = getc(Fp)) { case '#': /* enforce that we're at beginning of line */ if (!bol) return (record(c, NULL)); while ((c = getc(Fp)) != EOF && (c == ' ' || c == '\t')) ; if (!isdigit(c)) { /* * three cases here: * #pragma * #ident * #something-we-don't-understand * anything we don't expect we just ignore. */ *ptr++ = c; while ((c = getc(Fp)) != EOF && isalnum(c)) if (ptr < eptr - 1) *ptr++ = c; *ptr++ = '\0'; if (strcmp(Tok, "pragma") == 0) { /* skip white space */ while ((c = getc(Fp)) != EOF && (c == ' ' || c == '\t')) ; if (c == EOF || c == '\n') outfl(O_DIE, File, Line, "bad #pragma"); /* pull in next token */ ptr = Tok; *ptr++ = c; while ((c = getc(Fp)) != EOF && !isspace(c)) if (ptr < eptr - 1) *ptr++ = c; *ptr++ = '\0'; (void) ungetc(c, Fp); dopragma(Tok); } else if (strcmp(Tok, "ident") == 0) doident(); } else { /* handle file & line info from cpp */ Line = 0; do { if (!isdigit(c)) break; Line = Line * 10 + c - '0'; } while ((c = getc(Fp)) != EOF); Line--; /* newline will increment it */ while (c != EOF && isspace(c)) c = getc(Fp); if (c != '"') outfl(O_DIE, File, Line, "bad # statement (file name)"); while ((c = getc(Fp)) != EOF && c != '"') if (ptr < eptr - 1) *ptr++ = c; *ptr++ = '\0'; if (c != '"') outfl(O_DIE, File, Line, "bad # statement (quotes)"); File = stable(Tok); } /* skip the rest of the cpp line */ while ((c = getc(Fp)) != EOF && c != '\n' && c != '\r') ; if (c == EOF) return (record(c, NULL)); else (void) ungetc(c, Fp); ptr = Tok; break; case EOF: closefile(); continue; case '\n': Line++; bol = 1; break; case '\r': case ' ': case '\t': bol = 0; break; case '/': bol = 0; /* comment handling */ if ((nextc = getc(Fp)) == EOF) outfl(O_DIE, File, Line, "unexpected EOF"); else if (nextc == '*') { startline = Line; while ((c = getc(Fp)) != EOF) { if (c == '\n') Line++; else if (c == '*' && (((c = getc(Fp)) == EOF) || (c == '/'))) break; } if (c == EOF) { outfl(O_DIE, File, Line, "end of comment not seen " "(started on line %d)", startline); } } else { /* wasn't a comment, return the '/' token */ (void) ungetc(nextc, Fp); return (record(c, NULL)); } break; case '"': { int prevc; bol = 0; prevc = '\0'; /* quoted string handling */ startline = Line; for (;;) { c = getc(Fp); if (c == EOF) outfl(O_DIE, File, Line, "end of string not seen " "(started on line %d)", startline); else if (c == '\n') Line++; else if (c == '"' && prevc != '\\') break; else if (ptr < eptr) *ptr++ = c; prevc = c; } if (ptr >= eptr) out(O_DIE, File, Line, "string too long"); *ptr++ = '\0'; return (record(QUOTE, stable(Tok))); } case '&': bol = 0; /* && */ if ((nextc = getc(Fp)) == '&') return (record(AND, NULL)); else { (void) ungetc(nextc, Fp); return (record(c, NULL)); } /*NOTREACHED*/ break; case '|': bol = 0; /* || */ if ((nextc = getc(Fp)) == '|') return (record(OR, NULL)); else { (void) ungetc(nextc, Fp); return (record(c, NULL)); } /*NOTREACHED*/ break; case '!': bol = 0; /* ! or != */ if ((nextc = getc(Fp)) == '=') return (record(NE, NULL)); else { (void) ungetc(nextc, Fp); return (record(c, NULL)); } /*NOTREACHED*/ break; case '=': bol = 0; /* == */ if ((nextc = getc(Fp)) == '=') return (record(EQ, NULL)); else { (void) ungetc(nextc, Fp); return (record(c, NULL)); } /*NOTREACHED*/ break; case '-': bol = 0; /* -> */ if ((nextc = getc(Fp)) == '>') return (record(ARROW, stable(Tok))); else { (void) ungetc(nextc, Fp); return (record(c, NULL)); } /*NOTREACHED*/ break; case '<': bol = 0; if ((nextc = getc(Fp)) == '=') /* <= */ return (record(LE, NULL)); else if (nextc == '<') /* << */ return (record(LSHIFT, NULL)); else { (void) ungetc(nextc, Fp); return (record(c, NULL)); } /*NOTREACHED*/ break; case '>': bol = 0; if ((nextc = getc(Fp)) == '=') /* >= */ return (record(GE, NULL)); else if (nextc == '>') /* >> */ return (record(RSHIFT, NULL)); else { (void) ungetc(nextc, Fp); return (record(c, NULL)); } /*NOTREACHED*/ break; default: bol = 0; if (isdigit(c)) { int base; /* collect rest of number */ if (c == '0') { *ptr++ = c; if ((c = getc(Fp)) == EOF) { *ptr++ = '\0'; return (record(NUMBER, stable(Tok))); } else if (c == 'x' || c == 'X') { *ptr++ = c; base = 16; } else { (void) ungetc(c, Fp); base = 8; } } else { *ptr++ = c; base = 10; } while ((c = getc(Fp)) != EOF) { if (ptr >= eptr) out(O_DIE, File, Line, "number too long"); switch (base) { case 16: if (c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F') { *ptr++ = c; continue; } /*FALLTHRU*/ case 10: if (c >= '8' && c <= '9') { *ptr++ = c; continue; } /*FALLTHRU*/ case 8: if (c >= '0' && c <= '7') { *ptr++ = c; continue; } /* not valid for this base */ *ptr++ = '\0'; (void) ungetc(c, Fp); return (record(NUMBER, stable(Tok))); } } *ptr++ = '\0'; return (record(NUMBER, stable(Tok))); } else if (isalpha(c)) { /* collect identifier */ *ptr++ = c; for (;;) { c = getc(Fp); if ((isalnum(c) || c == '_') && ptr < eptr) *ptr++ = c; else { (void) ungetc(c, Fp); break; } } if (ptr >= eptr) out(O_DIE, File, Line, "identifier too long"); *ptr++ = '\0'; cptr = stable(Tok); if (val = lex_s2i_lut_lookup(Rwordslut, cptr)) { return (record(val, cptr)); } return (record(ID, cptr)); } else return (record(c, NULL)); } /*NOTREACHED*/ } }
void turbfluxes() { int iter; int crit; /*criterium for stable or unstable conditions*/ int itermax = 40; /* max number of iterations*/ float Tkel = 273.16; float karman = 0.40; /*Karmans constant*/ float g = 9.81; /*gravitational constant*/ float cp = 1005.; /*specific heat air at constant pressure J K-1 kg-1 */ float theta,tsurf; double Lmo,Lmo_old; float Lmocrit = 0.01; /* accuracy of final MO-length (relative) */ float Phimin, z0tmin, z0emin; /* lower limits of stability correction and roughness length */ int nostabil = 1; /*logical yes (1) or no (0) stability correction */ int nosurfstabil = 1; /*logical yes (1) or no (0) stability correction at surface level*/ jd2=jd; if ((zeit == 24) && (inter == factinter)) jd2 = (int)jd + 1; airpress(); tspechum = tempint[i][j]; kspechum = 1; spechum(); tspechum = surftemp[i][j]; kspechum = 2; spechum(); /*First step, calculate u*, th*, q* under neutral conditions*/ roughnesslength(); ustar = (karman * (wind - 0.0 )) / log(z2/z0w); frictionveloc = ustar; if(method_z0Te == 2) /*method to compute z0T and z0e*/ roughnesslengthAndreas(); if(method_z0Te == 3) /*method to compute z0T and z0e*/ roughnesslengthAndreasmodified(); theta = tempint[i][j] + Tkel + z2*g/cp; tsurf = surftemp[i][j]+ Tkel; thstar = (karman * (theta - tsurf)) / log(z2/z0T); qstar = (karman * (q - q0)) / log(z2/z0e); Lmo = 10.E4; Lmo_old = 1.E4; Phimin = -2.; z0tmin=1.0E-10; z0emin=1.0E-10; iter = 0; PhiM = 0.; PhiH = 0.; PhiE = 0.; PhiM0 = 0.; PhiH0 = 0.; PhiE0 = 0.; /*printf("Turbulent fluxes %f \n",jd2);*/ if (theta > tsurf) crit = 1; /* stable conditions */ if (theta <= tsurf) crit = -1; /* unstable conditions */ if (nostabil == 1) { while ((fabs((Lmo_old-Lmo)/Lmo_old) > Lmocrit) && (iter < itermax)) { iter = iter + 1; /* printf("B %d \n",iter);*/ MoninL = Lmo; /*Now add stability and iterate */ if (crit < 0.) { unstable(); /* only small change with respect to stabilityunstable()*/ /* fprintf(outcontrol,"Unstable %d %f %f %f %f %f %f %f %f %f \n", iter,MoninL,PhiM,PhiH,temp,surftemp[i][j],wind,z0w,z0T,z0e);*/ } if (crit > 0.) { stable(); /* only small change with respect to stabilityBeljaar()*/ /* fprintf(outcontrol,"Stable %d %f %f %f %f %f %f %f %f %f \n", iter,MoninL,PhiM,PhiH,temp,surftemp[i][j],wind,z0w,z0T,z0e);*/ } if (crit == 1) { /* limit stability correction */ if (Lmo == 0.) iter = iter + itermax; if (PhiM < Phimin) PhiM = Phimin; if (PhiH < Phimin) PhiH = Phimin; if (PhiE < Phimin) PhiE = Phimin; if (PhiM0 < Phimin) PhiM0 = Phimin; if (PhiH0 < Phimin) PhiH0 = Phimin; if (PhiE0 < Phimin) PhiE0 = Phimin; } /*Recalculate the u*, th* and q* */ ustar = (karman * (wind - 0.0 )) / ( log(z2/z0w) - PhiM + PhiM0); if (nosurfstabil == 0) ustar = (karman * (wind - 0.0 )) / ( log(z2/z0w) - PhiM ); if (crit == 1 && ustar < 0.) ustar = (karman * (wind - 0.0 )) / ( log(z2/z0w)); /*Calculate roughness length for heat and moisture, necessary to calculate th* and q* */ frictionveloc = ustar; if(method_z0Te == 1) /*method to compute z0T and z0e*/ roughnesslength(); /*z0T and z0e fixed ratio to z0w*/ if(method_z0Te == 2) roughnesslengthAndreas(); /* z0T,e according to Andreas, 1987, needs friction velocity*/ if(method_z0Te == 3) /*method to compute z0T and z0e*/ roughnesslengthAndreasmodified(); if (z0T < z0tmin) z0T = z0tmin; if (z0e < z0emin) z0e = z0emin; thstar = (karman * (theta - tsurf)) / ( log(z2/z0T) - PhiH + PhiH0); qstar = (karman * (q - q0)) / ( log(z2/z0e) - PhiE + PhiE0); if (nosurfstabil == 0) { thstar = (karman * (theta - tsurf)) / ( log(z2/z0T) - PhiH ); qstar = (karman * (q - q0)) / ( log(z2/z0e) - PhiE ); } Lmo_old = Lmo; /* Calculate the Monin Obukhov length including stability*/ Lmo = pow(ustar,2.) / ( (karman*g/(tempint[i][j]+Tkel)) * (thstar + 0.62 * (tempint[i][j]+Tkel) * qstar ) ); crit = 1; /* stable */ if (Lmo < 0.) crit = -1; /*Unstable */ } /* iteration loop */ } /*end yes stability correction*/ MoninL = Lmo; if (iter > itermax) { Ch = 0.; Cq = 0.; ustar = 0.; /* results in H and LE being 0 */ thstar = 0.; qstar = 0.; PhiM = 0.; PhiH = 0.; PhiE = 0.; } else if (Lmo == 0.) { Ch = 0.; Cq = 0.; ustar = 0.; /* results in H and LE being 0 */ thstar = 0.; qstar = 0.; PhiM = 0.; PhiH = 0.; PhiE = 0.; } else { Ch = pow(karman,2)/((log(z2/z0w) - PhiM + PhiM0)*(log(z2/z0T) - PhiH + PhiH0)); Cq = pow(karman,2)/((log(z2/z0w) - PhiM + PhiM0)*(log(z2/z0e) - PhiE + PhiE0)); } /* Finally calculate the fluxes */ sensiblenew(); latentnew(); if (iter > itermax) fprintf(outcontrol," function turbfluxes %.2f %.0f %d temp=%.2f surftemp=%.2f wind=%.2f L=%f \n", jd2,zeit,iter,tempint[i][j],surftemp[i][j],wind,MoninL); /* printf(" %f %d %f %f %f %f %f %f \n ",jd2,iter,Ch,Cq,SENSIBLE[i][j],LATENT[i][j],tempint[i][j],surftemp[i][j]);*/ return; }
void CharFnTest(Real u, Real alpha, Real beta, int N, Stable::Notation notation) { Real au = fabs(u); int su = (u > 0) ? 1 : (u < 0) ? -1 : 0; Real re_f = 0.0, im_f = 0.0; if (alpha != 1.0) { if (notation == Stable::Kalpha) { Real ka = 1.0 - fabs(1.0 - alpha); Real arg = -1.570796327 * beta * ka * su; Real px = - pow(au, alpha); Real re_e = px * cos(arg); Real im_e = px * sin(arg); Real av = exp(re_e); re_f = av * cos(im_e); im_f = av * sin(im_e); } else if (notation == Stable::Standard) { Real re = - pow(au, alpha); Real im = - re * beta * tan(1.570796327 * alpha) * su; Real av = exp(re); re_f = av * cos(im); im_f = av * sin(im); } else if (notation == Stable::Chambers) { Real re = - pow(au, alpha); Real im = - (u + re * su) * beta * tan(1.570796327 * alpha); Real av = exp(re); re_f = av * cos(im); im_f = av * sin(im); } else if (notation == Stable::Default) { Real re = - pow(au, alpha); re_f = exp(re); im_f = 0; } } else { Real av = exp(-au); Real im = - beta * log(au) * u / 1.570796327; re_f = av * cos(im); im_f = av * sin(im); } Real re_sum = 0.0, im_sum = 0.0; Real re_sum_sq = 0.0, im_sum_sq = 0.0; Real count0 = 0; Real count1 = 0; Real count2 = 0; Stable stable(alpha, beta, notation); for (int i = 1; i <= N; ++i) { Real x = stable.Next(); Real re, im; if (fabs(x) > 1.0E12) re = im = 0.0; else { re = cos(u * x); im = sin(u * x); } re_sum += re; re_sum_sq += re * re; im_sum += im; im_sum_sq += im * im; if (x > 0) ++count0; if (x > 1) ++count1; if (x > 2) ++count2; } Real re_av = re_sum / N; Real re_var = (re_sum_sq - re_av * re_sum) / (N-1) / N; Real im_av = im_sum / N; Real im_var = (im_sum_sq - im_av * im_sum) / (N-1) / N; //cout << "*** " << u << " " << alpha << " " << beta << " " << stable.beta_prime() << " ***" << endl; NormalTestTwoSided ntts_re("Stable re_cf", re_av, re_f, re_var); ntts_re.DoTest(); NormalTestTwoSided ntts_im("Stable im_cf", im_av, im_f, im_var); ntts_im.DoTest(); //cout << setw(15) << setprecision(10) << count0 / N << " "; //cout << setw(15) << setprecision(10) << count1 / N << " "; //cout << setw(15) << setprecision(10) << count2 / N << endl; }
Space* Space::_clone(bool share) { if (failed()) throw SpaceFailed("Space::clone"); if (!stable()) throw SpaceNotStable("Space::clone"); // Copy all data structures (which in turn will invoke the constructor) Space* c = copy(share); if (c->d_fst != &Actor::sentinel) throw SpaceNotCloned("Space::clone"); // Setup array for actor disposal in c { unsigned int n = static_cast<unsigned int>(d_cur - d_fst); if (n == 0) { // No actors c->d_fst = c->d_cur = c->d_lst = NULL; } else { // Leave one entry free c->d_fst = c->alloc<Actor*>(n+1); c->d_cur = c->d_fst; c->d_lst = c->d_fst+n+1; for (Actor** d_fst_iter = d_fst; d_fst_iter != d_cur; d_fst_iter++) { if ((*d_fst_iter)->prev()) *(c->d_cur++) = Actor::cast((*d_fst_iter)->prev()); } } } // Update variables without indexing structure VarImp<NoIdxVarImpConf>* x = static_cast<VarImp<NoIdxVarImpConf>*>(c->pc.c.vars_noidx); while (x != NULL) { VarImp<NoIdxVarImpConf>* n = x->next(); x->b.base = NULL; x->u.idx[0] = 0; if (sizeof(ActorLink**) > sizeof(unsigned int)) *(1+&x->u.idx[0]) = 0; x = n; } // Update variables with indexing structure c->update(static_cast<ActorLink**>(c->mm.subscriptions())); // Re-establish prev links (reset forwarding information) { ActorLink* p_a = &pl; ActorLink* c_a = p_a->next(); // First update propagators and advisors while (c_a != &pl) { Propagator* p = Propagator::cast(c_a); if (p->u.advisors != NULL) { ActorLink* a = p->u.advisors; p->u.advisors = NULL; do { a->prev(p); a = a->next(); } while (a != NULL); } c_a->prev(p_a); p_a = c_a; c_a = c_a->next(); } } { ActorLink* p_a = &bl; ActorLink* c_a = p_a->next(); // Update branchers while (c_a != &bl) { c_a->prev(p_a); p_a = c_a; c_a = c_a->next(); } } // Reset links for shared objects for (SharedHandle::Object* s = c->pc.c.shared; s != NULL; s = s->next) s->fwd = NULL; // Reset links for local objects for (ActorLink* l = c->pc.c.local; l != NULL; l = l->next()) l->prev(NULL); // Initialize propagator queue c->pc.p.active = &c->pc.p.queue[0]-1; for (int i=0; i<=PropCost::AC_MAX; i++) c->pc.p.queue[i].init(); // Copy propagation only data c->pc.p.n_sub = pc.p.n_sub; c->pc.p.branch_id = pc.p.branch_id; return c; }