void update_roughness_veg(double hc, double snowD, double zmu, double zmt, double *z0_ris, double *d0_ris, double *hc_ris){ *hc_ris=hc-snowD;//[mm] *d0_ris=0.667*(*hc_ris);//[mm] //*hc_ris=hc;//[mm] //*d0_ris=0.0;//[mm] *z0_ris=0.1*(*hc_ris);//[mm] *d0_ris=(*d0_ris)*1.E-3;//[m] *z0_ris=(*z0_ris)*1.E-3;//[m] *hc_ris=(*hc_ris)*1.E-3;//[m] if(zmu<(*hc_ris)){ printf("Wind speed measurement height:%f m\n",zmu); printf("Effective vegetation height:%f m\n",*hc_ris); t_error("Temperatute must be measured above vegetation"); } if(zmt<(*hc_ris)){ printf("Temperature measurement height:%f m\n",zmu); printf("Effective vegetation height:%f m\n",*hc_ris); t_error("Temperatute must be measured above vegetation"); } if(*hc_ris-(*d0_ris)<(*z0_ris)){ printf("Effective vegetation height:%f m\n",*hc_ris); printf("Effective 0 displacement height:%f m\n",*d0_ris); printf("Effective roughness length:%f m\n",*z0_ris); t_error("It must be always Hcanopy-d0 >= z0"); } }
void Businger(short a, double zmu, double zmt, double d0, double z0, double v, double T, double DT, double DQ, double z0_z0t, double *rm, double *rh, double *rv, double *Lobukhov, long maxiter){ double L, cm, u_star=0., ch, T_star=0., cv, Q_star=0.; double z0v, z0t, z0q; long cont; double tol; FILE *f; //first guess of Obukhov length if(DT<0){ L=1.E5; }else{ L=-1.E5; } cont=0; tol=1.0E99; do{ if(cont>0) tol=10*T_star+100*u_star+1000*Q_star; //Conductances Star(a, zmu, z0, d0, L, 0.0, v, 1.0, 0.0, 1.0, &u_star, &cm, &z0v, (*Psim), (*roughT)); //momentum if(z0_z0t==0.0){ //rigid surface Star(a, zmt, z0, d0, L, u_star, DT, u_star*z0/1.4E-5, 1.0, 0.0, &T_star, &ch, &z0t, (*Psih), (*roughT)); //heat flux Star(a, zmt, z0, d0, L, u_star, DQ, u_star*z0/1.4E-5, 1.0, 0.0, &Q_star, &cv, &z0q, (*Psih), (*roughQ)); //water vapour flux }else{ //bending surface Star(a, zmt, z0, d0, L, u_star, DT, 1.0, 0.0, 1.0/z0_z0t, &T_star, &ch, &z0t, (*Psih), (*roughT)); //heat flux Star(a, zmt, z0, d0, L, u_star, DQ, 1.0, 0.0, 1.0/z0_z0t, &Q_star, &cv, &z0q, (*Psih), (*roughQ)); //water vapour flux } //Obukhov length L=-u_star*u_star*(T+tk)/(ka*g*(T_star-0.61*Q_star*(T+tk))); cont++; }while(fabs(100*T_star+100*u_star+1000*Q_star-tol)>0.01 && cont<=maxiter); if(d0>zmu || d0>zmt){ f = fopen(FailedRunFile, "w"); fprintf(f,"Error:: Displacement height greater than measurement elevations\n"); fclose(f); t_error("Fatal Error! Geotop is closed. See failing report."); } if(zmu<=z0 || zmt<=z0t || zmt<=z0q){ f = fopen(FailedRunFile, "w"); fprintf(f,"Error:: Elevation of sensors lower than roughness length: zmu=%f zmt=%f z0=%f z0t=%f\n",zmu,zmt,z0,z0t); fclose(f); t_error("Fatal Error! Geotop is closed. See failing report."); } *rm=cm*cm/(ka*ka*v); *rh=ch*cm/(ka*ka*v); *rv=cv*cm/(ka*ka*v); *Lobukhov=L; }
int main(void) { enum {n = 8*1024*1024}; char *s = malloc(n); int i; float f; char c; if (!s) return t_error("out of memory"); t_setrlim(RLIMIT_STACK, 100*1024); for (i = 0; i < n; i++) s[i] = '1'; s[n-3] = ' '; s[n-1] = 0; /* * stack overflow if scanf copies s on the stack (glibc) * same issue with %d except then storing the conversion * result is undefined behaviour */ i = sscanf(s, "%f %c", &f, &c); if (i != 2) t_error("sscanf returned %d, want 2\n", i); if (f != INFINITY) t_error("sscanf(longnum, \"%%f\") read %f, want inf\n", f); if (c != '1') t_error("sscanf(\"1\", %%c) read '%c', want '1'\n", c); free(s); return t_status; }
static void test_align(int dalign, int salign, int len) { char *src = aligned(buf); char *dst = aligned(buf + 128); char *want = aligned(buf + 256); char *p; int i; if (salign + len > N || dalign + len > N) abort(); for (i = 0; i < N; i++) { src[i] = '#'; dst[i] = want[i] = ' '; } for (i = 0; i < len; i++) src[salign+i] = want[dalign+i] = '0'+i; p = pmemcpy(dst+dalign, src+salign, len); if (p != dst+dalign) t_error("memcpy(%p,...) returned %p\n", dst+dalign, p); for (i = 0; i < N; i++) if (dst[i] != want[i]) { t_error("memcpy(align %d, align %d, %d) failed\n", dalign, salign, len); t_printf("got : %.*s\n", dalign+len+1, dst); t_printf("want: %.*s\n", dalign+len+1, want); break; } }
/*----------------------------------------------------------------------------------*/ double doublevector_correlation(DOUBLEVECTOR *v,DOUBLEVECTOR *u,double m1,double m2,long r,double novalue) { long i,n=0; float correlation=0; if(v==NULL || v->co==NULL || u==NULL || u->co==NULL ){ t_error("this vector was never allocated"); } else if(v->nh <1 || v->isdynamic !=1 || u->nh <1 || u->isdynamic !=1) { t_error("this vector was not properly allocated"); } for(i=1;i<v->nh-r;i++){ if(v->co[i]!=novalue && v->co[i]!=novalue){ correlation+=v->co[i]*u->co[i+r]; n++; } } return correlation/n -m1*m2; }
int main(void) { static const long lim = 42; static const int r = RLIMIT_NOFILE; struct rlimit rl; int fd, maxfd = 0; rl.rlim_max = lim; rl.rlim_cur = lim; if (setrlimit(r, &rl)) t_error("setrlimit(%d, %ld) failed: %s\n", r, lim, strerror(errno)); if (getrlimit(r, &rl)) t_error("getrlimit(%d) failed: %s\n", r, strerror(errno)); if (rl.rlim_max != lim || rl.rlim_cur != lim) t_error("getrlimit %d says cur=%ld,max=%ld after setting the limit to %ld\n", r, rl.rlim_cur, rl.rlim_max, lim); while((fd=dup(1)) != -1) if (fd > maxfd) maxfd = fd; if (errno != EMFILE) t_error("dup(1) failed with %s, wanted EMFILE\n", strerror(errno)); if (maxfd+1 != lim) t_error("more fds are open than rlimit allows: fd=%d, limit=%d\n", maxfd, lim); return t_status; }
void visitSelfCall(SelfCall *p) { p->visit_children(this); Symbol * symp; MethodIDImpl * MethIdP = dynamic_cast<MethodIDImpl*>(p->m_methodid); Basetype bargs; char * key = strdup(MethIdP->m_symname->spelling()); symp = InScope(key); // cout<<"After scope "<<key<<endl; std::vector<CompoundType> args; if(symp == NULL){ t_error(no_class_method,p->m_attribute); } // cout<< "the key is: "<<key<<endl; int i = 0; if((p->m_expression_list->size()) != symp->methodType.argsType.size()) { t_error(call_narg_mismatch, p->m_attribute); } typename std::list<Expression_ptr>::iterator it = p->m_expression_list->begin(); for( ; it != p->m_expression_list->end(); ++it) { Expression * Expoin = dynamic_cast<Expression *> (*it); bargs = symp->methodType.argsType[i].baseType; if(bargs != Expoin->m_attribute.m_type.baseType) t_error(call_args_mismatch, p->m_attribute); i++; } p->m_attribute.m_type.baseType = symp->baseType; //WRITE ME }
/*... Double precision variables' vector n-moment estimation */ float floatmatrix_n_moment(FLOATMATRIX *m, float mean,float NN, float novalue) { long i,j; float moment=0, n; if(m==NULL || m->co==NULL ){ t_error("this matrix was never allocated"); } else if(m->nrh <1 || m->nch <1 || m->isdynamic !=1) { t_error("this matrix was not properly allocated"); } n=0; if(NN==1){ for(i=1;i<m->nrh;i++){ for(j=1;j<m->nch;j++){ if(m->co[i][j]!=novalue){ moment+=m->co[i][j]; n++; } } } moment/=n; }else if(NN==2) { for(i=1;i<m->nrh;i++){ for(j=1;j<m->nch;j++){ if(m->co[i][j]!=novalue) { moment+=(m->co[i][j])*(m->co[i][j]); n++; } } } moment=(moment/n-mean*mean); }else { for(i=1;i<m->nrh;i++){ for(j=1;j<m->nch;j++){ if(m->co[i][j]!=novalue){ moment+=pow((m->co[i][j]-mean),NN); n++; } } } moment/=n; } return moment; }
/*----------------------------------------------------------------------------------------------------------*/ double decod(char *ch, long n, double ndef){ short sgn=0; long i,ibeg,idec,j; double a=0; if(ch[0]==42 || ch[0]==44 || ch[0]==-1 || ch[0]==10 || ch[0]==13){ a=ndef; }else{ i=-1; do{ i+=1; }while((ch[i]<46 || ch[i]==47 || ch[i]>57) && (i<n-1)); if((i==n-1) && (ch[i]<46 || ch[i]==47 || ch[i]>57)){ a=ndef; }else{ ibeg=i; if(ibeg>0){ if(ch[ibeg-1]==45) sgn=1; } i-=1; do{ i+=1; }while(ch[i]!=46 && (i<n-1)); if(ch[i]==46){ idec=i; }else{ idec=n; } /*if(i!=n-1){ do{ i+=1; if(ch[i]<48 || ch[i]>57) t_error("ERROR: NUMBER WRITTEN IN A NON-STANDARD FORM"); }while(i<n-1); }*/ j=0; for(i=idec-1;i>=ibeg;i--){ if(ch[i]>=48 && ch[i]<=57){ a+=(ch[i]-48)*pow(10.0,(double)(idec-i-1-j)); }else{ j+=1; if(ch[i]==69) t_error("ERROR:IT IS NOT POSSIBLE TO WRITE NUMBERS IN THE EXPONENTIAL FORMAT"); } } j=0; for(i=idec+1;i<n;i++){ if(ch[i]>=48 && ch[i]<=57){ a+=(ch[i]-48)*pow(10.0,(double)(idec-i+j)); }else{ j+=1; if(ch[i]==69) t_error("ERROR:IT IS NOT POSSIBLE TO WRITE NUMBERS IN THE EXPONENTIAL FORMAT"); } } if(sgn==1) a*=(-1); } } return(a); }
void visitAnd(And *p) { p->m_attribute.m_type.baseType = bt_boolean; p->visit_children(this); if(p->m_expression_1->m_attribute.m_type.baseType != 2) t_error(expr_type_err, p->m_expression_1->m_attribute); if(p->m_expression_2->m_attribute.m_type.baseType != 2) t_error(expr_type_err, p->m_expression_2->m_attribute); //WRITE ME //WRITE ME }
void visitLessThanEqualTo(LessThanEqualTo *p) { p->m_attribute.m_type.baseType = bt_boolean; p->visit_children(this); if(p->m_expression_1->m_attribute.m_type.baseType != 1) t_error(expr_type_err, p->m_expression_1->m_attribute); if(p->m_expression_2->m_attribute.m_type.baseType != 1) t_error(expr_type_err, p->m_expression_2->m_attribute); //WRITE ME }
void visitDivide(Divide *p) { p->m_attribute.m_type.baseType = bt_integer; p->visit_children(this); if(p->m_expression_1->m_attribute.m_type.baseType != 1) t_error(expr_type_err, p->m_expression_1->m_attribute); if(p->m_expression_2->m_attribute.m_type.baseType != 1) t_error(expr_type_err, p->m_expression_2->m_attribute); //WRITE ME }
int main(void) { int i, j, k; char b[2000]; TEST(i, snprintf(0, 0, "%d", 123456), 6, "length returned %d != %d"); TEST(i, snprintf(0, 0, "%.4s", "hello"), 4, "length returned %d != %d"); TEST(i, snprintf(b, 0, "%.0s", "goodbye"), 0, "length returned %d != %d"); strcpy(b, "xxxxxxxx"); TEST(i, snprintf(b, 4, "%d", 123456), 6, "length returned %d != %d"); TEST_S(b, "123", "incorrect output"); TEST(i, b[5], 'x', "buffer overrun"); /* Perform ascii arithmetic to test printing tiny doubles */ TEST(i, snprintf(b, sizeof b, "%.1022f", 0x1p-1021), 1024, "%d != %d"); b[1] = '0'; for (i=0; i<1021; i++) { for (k=0, j=1023; j>0; j--) { if (b[j]<'5') b[j]+=b[j]-'0'+k, k=0; else b[j]+=b[j]-'0'-10+k, k=1; } } TEST(i, b[1], '1', "'%c' != '%c'"); for (j=2; b[j]=='0'; j++); TEST(i, j, 1024, "%d != %d"); #ifndef DISABLE_SLOW_TESTS errno = 0; TEST(i, snprintf(NULL, 0, "%.*u", 2147483647, 0), 2147483647, "cannot print max length %d"); TEST(i, snprintf(NULL, 0, "%.*u ", 2147483647, 0), -1, "integer overflow %d"); TEST(i, errno, EOVERFLOW, "after overflow: %d != %d"); #endif for (j=0; int_tests[j].fmt; j++) { i = snprintf(b, sizeof b, int_tests[j].fmt, int_tests[j].i); if (i != strlen(int_tests[j].expect)) { t_error("snprintf(b, sizeof b, \"%s\", %d) returned %d wanted %d\n", int_tests[j].fmt, int_tests[j].i, i, strlen(int_tests[j].expect)); } if (strcmp(b, int_tests[j].expect) != 0) t_error("bad integer conversion: got \"%s\", want \"%s\"\n", b, int_tests[j].expect); } for (j=0; fp_tests[j].fmt; j++) { i = snprintf(b, sizeof b, fp_tests[j].fmt, fp_tests[j].f); if (i != strlen(fp_tests[j].expect)) { t_error("snprintf(b, sizeof b, \"%s\", %f) returned %d wanted %d\n", fp_tests[j].fmt, fp_tests[j].f, i, strlen(fp_tests[j].expect)); } if (strcmp(b, fp_tests[j].expect) != 0) t_error("bad floating-point conversion: got \"%s\", want \"%s\"\n", b, fp_tests[j].expect); } TEST(i, snprintf(0, 0, "%.4a", 1.0), 11, "%d != %d"); return t_status; }
static void *f(void *arg) { if (tls_fix != 23) t_error("fixed init failed: want 23 got %d\n", tls_fix); if (tls_zero != 0) t_error("zero init failed: want 0 got %d\n", tls_zero); tls_fix++; tls_zero++; return 0; }
void visitClassImpl(ClassImpl *p) { int stop; m_symboltable->open_scope(); Symbol * symPtr = new Symbol; // = new ClassNode; Symbol * symp;// = new Symbol; ClassIDImpl * ClassIdP = dynamic_cast<ClassIDImpl*>(p->m_classid_1); ClassIDImpl * ClassIdP2 = dynamic_cast<ClassIDImpl*>(p->m_classid_2); char * key1 = strdup(ClassIdP->m_classname->spelling()); symPtr->classType.classID = ClassIdP->m_classname->spelling(); char * progFinder = strdup("Program"); ClassName * nm = new ClassName(key1); if(progger == true){ t_error(no_program, p->m_attribute); } if(std::string(key1) == std::string(progFinder)){ progger = true; } //char * key2 = strdup(ClassIdP2->m_classname->spelling()); if(m_classtable->exist(key1)){ t_error(dup_ident_name, p->m_attribute); } else{ if(ClassIdP2->m_classname != NULL){ char * key2 = strdup(ClassIdP2->m_classname->spelling()); ClassName * nm2 = new ClassName(key2); // cout<<"inserted class: " <<key1 <<" from :"<<key2 <<endl; m_classtable->insert(nm, nm2, p, m_symboltable->get_scope()); ClassNode * clasp = m_classtable->getParentOf(key2); // cout<<"Class: " <<key1 <<", Super class: "<<clasp->name->spelling()<<endl; } else{ // cout<< "instered this in class table: "<< key1 <<endl; m_classtable->insert(nm, NULL, p, m_symboltable->get_scope()); } } m_symboltable->insert((char *)"xxx", symPtr); p->visit_children(this); m_symboltable->close_scope(); //WRITE ME }
/*----------------------------------------------------------------------------------*/ float floatvector_n_moment(FLOATVECTOR *v, float mean,float NN, float novalue) { unsigned i,n=0; float moment=0; if(v==NULL || v->co==NULL ){ t_error("this vector was never allocated"); } else if(v->nh <1 || v->isdynamic !=1) { t_error("this vector was not properly allocated"); } if(NN==1){ for(i=1;i<v->nh;i++){ if(v->co[i]!=novalue){ moment+=v->co[i]; n++; } } moment/=n; }else if(NN==2) { for(i=1;i<v->nh;i++){ if(v->co[i]!=novalue){ moment+=(v->co[i])*(v->co[i]); n++; } } moment=(moment/n-mean*mean); }else { for(i=1;i<v->nh;i++){ if(v->co[i]!=novalue){ moment+=pow((v->co[i]-mean),NN); n++; } } moment/=n; } return moment; }
int main(void) { int i, j; wchar_t b[500]; (void)( setlocale(LC_CTYPE, "en_US.UTF-8") || setlocale(LC_CTYPE, "en_GB.UTF-8") || setlocale(LC_CTYPE, "en.UTF-8") || setlocale(LC_CTYPE, "POSIX.UTF-8") || setlocale(LC_CTYPE, "C.UTF-8") || setlocale(LC_CTYPE, "UTF-8") || setlocale(LC_CTYPE, "") ); TEST(i, strcmp(nl_langinfo(CODESET), "UTF-8"), 0, "no UTF-8 locale; tests might fail"); TEST(i, swprintf(0, 0, L"%d", 123456)<0, 1, "%d != %d"); TEST(i, swprintf(b, 2, L"%lc", 0xc0), 1, "%d != %d"); TEST(i, b[0], 0xc0, "wrong character %x != %x"); TEST(i, swprintf(b, 2, L"%lc", 0x20ac), 1, "%d != %d"); TEST(i, b[0], 0x20ac, "wrong character %x != %x"); TEST(i, swprintf(b, 3, L"%s", "\xc3\x80!"), 2, "%d != %d"); TEST(i, b[0], 0xc0, "wrong character %x != %x"); TEST(i, swprintf(b, 2, L"%.1s", "\xc3\x80!"), 1, "%d != %d"); TEST(i, b[0], 0xc0, "wrong character %x != %x"); wcscpy(b, L"xxxxxxxx"); TEST(i, swprintf(b, 4, L"%d", 123456)<0, 1, "%d != %d"); TEST_S(b, L"123", "incorrect output"); TEST(i, b[5], 'x', "buffer overrun"); for (j=0; int_tests[j].fmt; j++) { i = swprintf(b, sizeof b, int_tests[j].fmt, int_tests[j].i); if (i != wcslen(int_tests[j].expect)) { t_error("swprintf(b, sizeof b, \"%ls\", %d) returned %d wanted %d\n", int_tests[j].fmt, int_tests[j].i, i, wcslen(int_tests[j].expect)); } if (wcscmp(b, int_tests[j].expect) != 0) t_error("bad integer conversion: got \"%ls\", want \"%ls\"\n", b, int_tests[j].expect); } for (j=0; fp_tests[j].fmt; j++) { i = swprintf(b, sizeof b, fp_tests[j].fmt, fp_tests[j].f); if (i != wcslen(fp_tests[j].expect)) { t_error("swprintf(b, sizeof b, \"%ls\", %f) returned %d wanted %d\n", fp_tests[j].fmt, fp_tests[j].f, i, wcslen(fp_tests[j].expect)); } if (wcscmp(b, fp_tests[j].expect) != 0) t_error("bad floating-point conversion: got \"%ls\", want \"%ls\"\n", b, fp_tests[j].expect); } return t_status; }
void visitMethodImpl(MethodImpl *p) { m_symboltable->open_scope(); if (p->m_type != NULL) { p->m_type->accept( this ); } else { this->visitNullPointer(); } // cout<<"my type: "<<p->m_type->m_attribute.m_type.baseType<<endl; Symbol *symp = new Symbol; Symbol *Msymp = new Symbol; Symbol *test; MethodIDImpl * MethIdP = dynamic_cast<MethodIDImpl*>(p->m_methodid); p->m_attribute.m_type.baseType = p->m_type->m_attribute.m_type.baseType; //this is dealing with duplicate method names char * key = strdup(MethIdP->m_symname->spelling());//~!~!~!~!~!~!~!~ place here test = InScope(key); if(test != NULL){//change this make Msymp = my function t_error(dup_ident_name, p->m_attribute); } else{ CompoundType arg; p->visit_children(this); //Adding parameters to sym table and each argument to method vector typename std::list<Parameter_ptr>::iterator it = p->m_parameter_list->begin(); for( ; it != p->m_parameter_list->end(); ++it) { ParameterImpl * Pimp = dynamic_cast<ParameterImpl *> (*it); VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(Pimp->m_variableid); //char * key = strdup(VarIdP->m_symname->spelling()); arg.baseType = Pimp->m_type->m_attribute.m_type.baseType; Msymp->methodType.argsType.push_back(arg); } Msymp->methodType.returnType.baseType = p->m_type->m_attribute.m_type.baseType; Msymp->baseType = p->m_type->m_attribute.m_type.baseType; m_symboltable->insert_in_parent_scope(key, Msymp); } if(p->m_type->m_attribute.m_type.baseType != p->m_methodbody->m_attribute.m_type.baseType){ t_error(ret_type_mismatch, p->m_attribute); } m_symboltable->close_scope(); //WRITE ME }
static int get_opt(int fd, int level, int name) { struct t_optmgmt req, res; struct { struct opthdr opt; int value; } reqbuf; reqbuf.opt.level = level; reqbuf.opt.name = name; reqbuf.opt.len = sizeof (int); reqbuf.value = 0; req.flags = T_CURRENT; req.opt.len = sizeof (reqbuf); req.opt.buf = (char *)&reqbuf; res.flags = 0; res.opt.buf = (char *)&reqbuf; res.opt.maxlen = sizeof (reqbuf); if (t_optmgmt(fd, &req, &res) < 0 || res.flags != T_SUCCESS) { t_error("t_optmgmt"); return (-1); } return (reqbuf.value); }
void visitParameterImpl(ParameterImpl *p) { p->visit_children(this); Symbol *symp = new Symbol; Symbol * test; VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(p->m_variableid); char * key = strdup(VarIdP->m_symname->spelling()); test = InScope(key); if(test!=NULL){ t_error(dup_ident_name, p->m_attribute); } else{ symp->baseType = p->m_type->m_attribute.m_type.baseType; // cout<< "param; key: "<< key <<" type : "<< symp->baseType<<endl; if(symp->baseType == 8){ symp->classType.classID = p->m_type->m_attribute.m_type.classType.classID; // cout<< "this is what i'm SEETTTING key: " << symp->classType.classID<<endl; } // cout<<"insertingthis var from param: "<<key <<endl; m_symboltable->insert(key, symp); } //WRITE ME }
static int setopt(int fd, int level, int name, int value) { struct t_optmgmt req, resp; struct { struct opthdr opt; int value; } reqbuf; reqbuf.opt.level = level; reqbuf.opt.name = name; reqbuf.opt.len = sizeof (int); reqbuf.value = value; req.flags = T_NEGOTIATE; req.opt.len = sizeof (reqbuf); req.opt.buf = (char *)&reqbuf; resp.flags = 0; resp.opt.buf = (char *)&reqbuf; resp.opt.maxlen = sizeof (reqbuf); if (t_optmgmt(fd, &req, &resp) < 0 || resp.flags != T_SUCCESS) { t_error("t_optmgmt"); return (-1); } return (0); }
int *ivector(long nl, long nh) /* allocate an integer vector with subscript range v[nl ....nh] */ { int *v; v=(int *)malloc((size_t)((nh-nl+1+NR_END)*sizeof(int))); if (!v) t_error("allocation failure in fvector()"); return v-nl+NR_END; }
LONGMATRIX_VECTOR *read_fine_indices(char *filename,short print) { /*! * \author Emanuele Cordano * date May 2009 * * \param (char*) - name of filename *\param (short) - */ LONGMATRIX_VECTOR *lm; FILE *fd; long j,n_po; fd=t_fopen(filename,"r"); n_po=(long)read_index(fd,no_PRINT); lm=new_longmatrix_vector(n_po); for (j=lm->nl;j<=lm->nh;j++) { if (print==1) printf("Function read_fine_indices element %ld of %ld is being defined \n",j,lm->nh); lm->element[j]=read_longmatrix(fd,"a",no_PRINT); if (print==1) printf("Function read_fine_indices element %ld of %ld is read [%ld,%ld] f.e. %ld \n",j,lm->nh,lm->element[j]->nrh,lm->element[j]->nrh,lm->element[j]->element[1][1]); if (!lm->element[j]) t_error("lm->element[j] in read_fine_indices was not defined"); // if (polygons->element[j]->index!=j) printf ("Error in read_polygonvector (polygon %ld) inconstancy: %ld %ld \n",j,j,polygons->element[j]->index); } t_fclose(fd); if (print==1) printf("Function read_fine_indices was successfully executed! \n"); return lm; }
int main(void) { regex_t re; int r; r = regcomp(&re, "abc", REG_NOSUB); if (r) t_error("regcomp failed: %d\n", r); r = regexec(&re, "zyx abc", 1, 0, 0); if (r == REG_NOMATCH) t_error("regexec failed to match\n"); else if (r) t_error("regexec returned invalid code: %d\n", r); regfree(&re); return t_status; }
static void test_mutexattr() { pthread_mutex_t m; pthread_mutexattr_t a; int r; int i; T(pthread_mutexattr_init(&a)); T(pthread_mutexattr_gettype(&a, &i)); if (i != PTHREAD_MUTEX_DEFAULT) t_error("default mutex type is %d, wanted PTHREAD_MUTEX_DEFAULT (%d)\n", i, PTHREAD_MUTEX_DEFAULT); T(pthread_mutexattr_settype(&a, PTHREAD_MUTEX_ERRORCHECK)); T(pthread_mutexattr_gettype(&a, &i)); if (i != PTHREAD_MUTEX_ERRORCHECK) t_error("setting error check mutex type failed failed: got %d, wanted %d\n", i, PTHREAD_MUTEX_ERRORCHECK); }
static void *tryrdlock(void *arg) { int r = pthread_rwlock_tryrdlock(arg); if (r != EBUSY) t_error("tryrdlock for wrlocked lock returned %s, want EBUSY\n", strerror(r)); return 0; }
void product_using_only_strict_lower_diagonal_part(DOUBLEVECTOR *product, DOUBLEVECTOR *x, LONGVECTOR *Li, LONGVECTOR *Lp, DOUBLEVECTOR *Lx){ long c, r, i; for(i=1;i<=x->nh;i++){ product->co[i] = 0.0; } c = 1; for(i=1;i<=Li->nh;i++){ r = Li->co[i]; if(r > c){ product->co[c] += Lx->co[i] * (x->co[r] - x->co[c]); product->co[r] += Lx->co[i] * (x->co[c] - x->co[r]); }else if(r < c){ printf("r:%ld c:%ld i:%ld Ap[c]:%ld tot:%ld %ld %ld\n",r,c,i,Lp->co[c],Li->nh,Lp->co[x->nh],x->nh); t_error("matrix is not L"); } if(i<Li->nh){ while(i >= Lp->co[c]) c++; } } }
void aero_resistance(double zmu, double zmt, double z0, double d0, double z0_z0t, double v, double Ta, double T, double Qa, double Q, double P, double gmT, double *Lobukhov, double *rm, double *rh, double *rv, short state_turb, short MO, long maxiter){ FILE *f; //calculates resistences //double p=pow((1000.0/P),(0.286*(1-0.23*Qa))); double p=1.0; //double Tpa=(Ta+tk)*p,Tp=(T+tk)*p; //potential temperatures if(state_turb==0){ //Lewis(zmu, zmt, d0, z0, z0_z0t, Tpa, Tp, v, rm, rh, rv, rep); f = fopen(FailedRunFile, "w"); fprintf(f,"Error:: state_turb == 0 not possible, check option file\n"); fclose(f); t_error("Fatal Error! Geotop is closed. See failing report."); }else if(state_turb==1){ Businger(MO, zmu, zmt, d0, z0, v, 0.5*T+0.5*Ta, T-Ta, Q-Qa, z0_z0t, rm, rh, rv, Lobukhov, maxiter); }else if(state_turb==2){ //catabatic flows - OERLEMANS & GRISOGONO (2002) *rm=1.0/(v*ka*ka/(log((zmu-d0)/z0 )*log((zmu-d0)/z0 ))); if(p*(-gmT+0.0098)>0.0015){ *rh=1/( 0.0004*(Ta-T)*pow(g/(tk*p*(gmT+0.0098)*5),0.5) ); }else{ *rh=1/( 0.0004*(Ta-T)*pow(g/(tk*(0.0015)*5),0.5) ); } *rv=*rh; } }
/*-------------------------------------------------------------------------------*/ short file_copy(FILE *destination,FILE *origin) { char ch; long pos=0; if(destination==NULL || origin==NULL) t_error("This file was not opened yet"); ch=getc(origin); while(ch!=EOF){ if(ch=='\n'){ fprintf(destination,"\n"); skip_whitespaces(origin); }else{ fprintf(destination,"%c",ch); } ch=getc(origin); } pos=ftell(origin); if(pos==0){ printf("\nWarning::Empty file encountered"); return 0; } else { return 1; } return 0; }
void product_using_only_strict_lower_diagonal_part_plus_identity_by_vector(DOUBLEVECTOR *product, DOUBLEVECTOR *x, DOUBLEVECTOR *y, LONGVECTOR *Li, LONGVECTOR *Lp, DOUBLEVECTOR *Lx){ long i, r, c; //calculate (A+Iy)*x, A described by its strict lower diagonal part for(i=1;i<=x->nh;i++){ product->co[i] = y->co[i] * x->co[i]; } c = 1; for(i=1;i<=Li->nh;i++){ r = Li->co[i]; if(r > c){ product->co[c] += Lx->co[i] * (x->co[r] - x->co[c]); product->co[r] += Lx->co[i] * (x->co[c] - x->co[r]); }else if(r < c){ printf("r:%ld c:%ld i:%ld Lp[c]:%ld tot:%ld %ld %ld\n",r,c,i,Lp->co[c],Li->nh,Lp->co[x->nh],x->nh); t_error("matrix is not L"); } if(i<Li->nh){ while(i >= Lp->co[c]) c++; } } }