/* * Load a char and inventory into a new ch structure. */ bool load_char_obj( DESCRIPTOR_DATA *d, char *name ) { static PC_DATA pcdata_zero; char strsave[MAX_INPUT_LENGTH]; char buf [MAX_STRING_LENGTH]; CHAR_DATA *ch; FILE *fp; bool found; if ( char_free == NULL ) { ch = alloc_perm( sizeof(*ch) ); } else { ch = char_free; char_free = char_free->next; } clear_char( ch ); if ( pcdata_free == NULL ) { ch->pcdata = alloc_perm( sizeof(*ch->pcdata) ); } else { ch->pcdata = pcdata_free; pcdata_free = pcdata_free->next; } *ch->pcdata = pcdata_zero; d->character = ch; ch->desc = d; ch->name = str_dup( name ); ch->prompt = str_dup( "<%hhp %mm %vmv> " ); ch->last_note = 0; ch->act = PLR_BLANK | PLR_COMBINE | PLR_PROMPT; ch->pcdata->pwd = str_dup( "" ); ch->pcdata->bamfin = str_dup( "" ); ch->pcdata->bamfout = str_dup( "" ); ch->pcdata->title = str_dup( "" ); ch->pcdata->perm_str = 13; ch->pcdata->perm_int = 13; ch->pcdata->perm_wis = 13; ch->pcdata->perm_dex = 13; ch->pcdata->perm_con = 13; ch->pcdata->condition[COND_THIRST] = 48; ch->pcdata->pagelen = 20; ch->pcdata->condition[COND_FULL] = 48; found = FALSE; fclose( fpReserve ); /* parsed player file directories by Yaz of 4th Realm */ /* decompress if .gz file exists - Thx Alander */ #if !defined(macintosh) && !defined(MSDOS) sprintf( strsave, "%s%s%s%s%s", PLAYER_DIR, initial( ch->name ), "/", capitalize( name ), ".gz" ); if ( ( fp = fopen( strsave, "r" ) ) != NULL ) { fclose( fp ); sprintf( buf, "gzip -dfq %s", strsave ); system( buf ); } #endif #if !defined(machintosh) && !defined(MSDOS) sprintf( strsave, "%s%s%s%s", PLAYER_DIR, initial( ch->name ), "/", capitalize( name ) ); #else sprintf( strsave, "%s%s", PLAYER_DIR, capitalize( name ) ); #endif if ( ( fp = fopen( strsave, "r" ) ) != NULL ) { int iNest; for ( iNest = 0; iNest < MAX_NEST; iNest++ ) rgObjNest[iNest] = NULL; found = TRUE; for ( ; ; ) { char letter; char *word; letter = fread_letter( fp ); if ( letter == '*' ) { fread_to_eol( fp ); continue; } if ( letter != '#' ) { bug( "Load_char_obj: # not found.", 0 ); break; } word = fread_word( fp ); if ( !str_cmp( word, "PLAYER" ) ) fread_char ( ch, fp ); else if ( !str_cmp( word, "OBJECT" ) ) fread_obj ( ch, fp ); else if ( !str_cmp( word, "END" ) ) break; else { bug( "Load_char_obj: bad section.", 0 ); break; } } fclose( fp ); } fpReserve = fopen( NULL_FILE, "r" ); return found; }
void set_B_fields( struct domain * theDomain ){ int i,j,k; struct cell ** theCells = theDomain->theCells; int Nr = theDomain->Nr; int Nz = theDomain->Nz; int * Np = theDomain->Np; double * r_jph = theDomain->r_jph; double * z_kph = theDomain->z_kph; for( j=0 ; j<Nr ; ++j ){ for( k=0 ; k<Nz ; ++k ){ int jk = j+Nr*k; for( i=0 ; i<Np[jk] ; ++i ){ struct cell * c = &(theCells[jk][i]); double phip = c->piph; double phim = phip-c->dphi; double xp[3] = { r_jph[j] , phip , z_kph[k] }; double xm[3] = { r_jph[j-1] , phim , z_kph[k-1] }; double r = get_moment_arm( xp , xm ); double x[3] = { r , phip , .5*(z_kph[k]+z_kph[k-1])}; double prim[NUM_Q]; initial( prim , x ); double dA = get_dA( xp , xm , 0 ); double Phi = 0.0; if( NUM_Q > BPP ) Phi = prim[BPP]*dA; c->Phi[0] = Phi; } } } int NRZ1 = theDomain->N_ftracks_r; setup_faces( theDomain , 1 ); int n; for( n=0 ; n<theDomain->fIndex_r[NRZ1] ; ++n ){ struct face * f = theDomain->theFaces_1 + n; double prim[NUM_Q]; initial( prim , f->cm ); double Phi = 0.0; if( NUM_Q > BRR ) Phi = prim[BRR]*f->dA; if( f->LRtype == 0 ){ f->L->Phi[2] = Phi; }else{ f->R->Phi[1] = Phi; } } if( NUM_FACES==5 && theDomain->Nz > 1 ){ int NRZ2 = theDomain->N_ftracks_z; setup_faces( theDomain , 2 ); for( n=0 ; n<theDomain->fIndex_z[NRZ2] ; ++n ){ struct face * f = theDomain->theFaces_2 + n; double prim[NUM_Q]; initial( prim , f->cm ); double Phi = 0.0; if( NUM_Q > BZZ ) Phi = prim[BZZ]*f->dA; if( f->LRtype == 0 ){ f->L->Phi[4] = Phi; }else{ f->R->Phi[3] = Phi; } } } B_faces_to_cells( theDomain , 0 ); B_faces_to_cells( theDomain , 1 ); free( theDomain->theFaces_1 ); if( theDomain->theFaces_2 ) free( theDomain->theFaces_2 ); }
int Pserv12() { initial(); clear(); mvaddstr( 2, 0, "================================================================================"); mvaddstr(5, 0, " CI 服 务 申 请 "); mvaddstr( 8, 0, "================================================================================"); mvaddstr(10, 4, " 请选择您需要的服务类型: "); mvaddstr(12, 4, " [1] . BEA Weblogic 813; "); mvaddstr(13, 4, " [2] . BEA Weblogic 816; "); mvaddstr(14, 4, " [3] . BEA Weblogic 920; "); mvaddstr(15, 4, " [4] . IBM Websphere 5.2; "); mvaddstr(16, 4, " [5] . IBM Websphere 6.0; "); mvaddstr(17, 4, " [6] . Tomcat 5.0; "); mvaddstr(18, 4, " [7] . Tomcat 6.0; "); mvaddstr(19, 4, " [8] . 退出; "); int ch, opt=0; mvaddstr(12+opt, 1, "->"); do { ch=getch(); switch (ch) { case KEY_UP: if (opt!=0) { opt--; } else { opt+=7; } break; case KEY_DOWN: if (opt!=7) { opt++; } else { opt-=7; } break; case KEY_RIGHT: return opt; break; case KEY_LEFT: return -1; break; case '\r': return opt; break; default: break; } mvaddstr(12, 1, " "); mvaddstr(13, 1, " "); mvaddstr(14, 1, " "); mvaddstr(15, 1, " "); mvaddstr(16, 1, " "); mvaddstr(17, 1, " "); mvaddstr(18, 1, " "); mvaddstr(19, 1, " "); mvaddstr(12+opt, 1, "->"); } while (1); echo(); char string1[80]; getstr(string1); return -2; }
int main(int argc, char *args[]) { int initArray[6]; int goalArray[6]; std::ifstream initFile; std::ifstream goalFile; initFile.open(args[1]); goalFile.open(args[2]); for (int i = 0; i < 6; i++) { initFile >> initArray[i]; goalFile >> goalArray[i]; initFile.get(); goalFile.get(); } initFile.close(); goalFile.close(); GameState initial(initArray[0],initArray[1],initArray[2],initArray[3],initArray[4],initArray[5]); GameState goal(goalArray[0],goalArray[1],goalArray[2],goalArray[3],goalArray[4],goalArray[5]); GameState *solution; int expandedNodes = 0; GameState::Fringe dfs_fringe(0); GameState::Fringe bfs_fringe(1); GameState::Fringe iddfs_fringe(0); GameState::Fringe astar_fringe(2); if (args[3][0] == 'd') { solution = GraphSearch(&initial,&goal,&dfs_fringe,&expandedNodes,false); } else if (args[3][0] == 'b') { solution = GraphSearch(&initial,&goal,&bfs_fringe,&expandedNodes,false); } else if (args[3][0] == 'i') { solution = GraphSearch(&initial,&goal,&iddfs_fringe,&expandedNodes,true); } else { solution = GraphSearch(&initial,&goal,&astar_fringe,&expandedNodes,false); } if(solution){ std::ofstream outputfile; outputfile.open(args[4]); solution->showStuffs(&outputfile); while(solution->parent) { solution = solution->parent; solution->showStuffs(&outputfile); } outputfile << "Expanded Nodes: " << expandedNodes << std::endl; outputfile.close(); } else { std::cout<< "No solution\n"; return 1; } return 0; }
SplineDensitySmileSection::SplineDensitySmileSection( const boost::shared_ptr<SmileSection> source, const Real atm, const Real lowerBound, const Real upperBound, const bool deleteArbitragePoints, const std::vector<Real> &moneynessGrid) : SmileSection(*source), source_(source), lowerBound_(lowerBound), upperBound_(upperBound) { adjustment_ = 1.0; ssutils_ = boost::shared_ptr<SmileSectionUtils>(new SmileSectionUtils( *source, moneynessGrid, atm, deleteArbitragePoints)); std::pair<Size, Size> af = ssutils_->arbitragefreeIndices(); Size leftIndex = af.first; Size rightIndex = af.second; f_ = ssutils_->atmLevel(); const std::vector<Real> &strikes = ssutils_->strikeGrid(); const std::vector<Real> &calls = ssutils_->callPrices(); k_.clear(); c_.clear(); d_.clear(); k_.push_back(lowerBound_); c_.push_back(f_-lowerBound_); d_.push_back(0.0); Real vol = 0.10; // start with a lognormal density Real mu = std::log(f_) - vol*vol*exerciseTime()/2.0; NormalDistribution norm(mu,vol*sqrt(exerciseTime())); std::vector<Real> initialv; for(Size i=leftIndex; i<=rightIndex; i++) { if( strikes[i] > lowerBound_ && strikes[i] < upperBound_ ) { k_.push_back(strikes[i]); c_.push_back(calls[i]); d_.push_back( norm(std::log(strikes[i]))/ strikes[i] ); initialv.push_back(std::sqrt(d_.back())); } } Array initial(initialv.begin(),initialv.end()); k_.push_back(upperBound_); c_.push_back(0.0); d_.push_back(0.0); // density_ = boost::shared_ptr<CubicInterpolation>(new CubicInterpolation(k_.begin(), k_.end(), // d_.begin(), CubicInterpolation::Spline, true, // CubicInterpolation::SecondDerivative, 0.0, // CubicInterpolation::SecondDerivative, 0.0)); density_ = boost::shared_ptr<LinearInterpolation>(new LinearInterpolation(k_.begin(), k_.end(), d_.begin())); // // global calibration // SplineDensityCostFunction cost(this); // NoConstraint constraint; // Problem p(cost,constraint,initial); // LevenbergMarquardt lm; // //Simplex lm(0.01); // //BFGS lm; // EndCriteria ec(5000,100,1e-16,1e-16,1e-16); // EndCriteria::Type ret = lm.minimize(p,ec); // QL_REQUIRE(ret!=EndCriteria::MaxIterations,"Optimizer returns maxiterations"); // Array res = p.currentValue(); // setDensity(res); // just to make really sure, we are at the optimal point // iterative calibration // for(Size i=1; i<k_.size()-1; i++) { // SplineDensityCostFunction2 cost(this,i); // NoConstraint constraint; // Array initial2(1,initial[i-1]); // Problem p(cost,constraint,initial2); // LevenbergMarquardt lm; // //Simplex lm(0.01); // //BFGS lm; // EndCriteria ec(5000,100,1e-35,1e-35,1e-35); // EndCriteria::Type ret = lm.minimize(p,ec); // QL_REQUIRE(ret!=EndCriteria::MaxIterations,"Optimizer returns maxiterations"); // Array res = p.currentValue(); // setDensity(res[0],i); // just to make really sure, we are at the optimal point // } update(); }
DBstatus varkon_pat_rotloft ( /*-------------- Argument declarations -----------------------------*/ /* */ /* In: */ GMPATL *p_patl, /* Pointer to the conic lofting patch */ DBint icase, /* Calculation case: */ /* Eq. 0: Only coordinates */ /* Eq. 1: Coordinates and dr/du derivative */ /* Eq. 2: Coordinates and dr/dv derivative */ /* Eq. : All derivatives */ DBfloat u_pat, /* Patch (local) U parameter value */ DBfloat v_pat, /* Patch (local) V parameter value */ EVALS *p_xyz ) /* Coordinates and derivatives (ptr) */ /* Out: */ /* Data to p_xyz */ /*-----------------------------------------------------------------!*/ { /* Start of function */ /*!--------------- Internal variables ------------------------------*/ /* */ /* */ /*-----------------------------------------------------------------!*/ EVALS xyz_tra; /* Coordinates and derivatives transformed */ char errbuf[80]; /* String for error message fctn erpush */ short status; /* Error code from a called function */ /* ----------------- Theory ----------------------------------------*/ /* */ /* The coordinates and derivatives ........................ */ /* */ /*----------------------------------------------------------------- */ /*--------------end-of-declarations---------------------------------*/ /*! */ /* Algorithm */ /* ========= */ /* !*/ #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur227 Mid curve flag p_patl->p_flag %d\n", (int)p_patl->p_flag); fflush(dbgfil(SURPAC)); } #endif /*! */ /* 1. Check of input data and initializations */ /* __________________________________________ */ /* */ /* Initialize output coordinates and derivatives for DEBUG on. */ /* Call of initial. */ /* !*/ #ifdef DEBUG status=initial(p_patl,u_pat,v_pat,p_xyz); if (status<0) { sprintf(errbuf,"initial%%varkon_pat_rotloft (sur227)"); return(varkon_erpush("SU2973",errbuf)); } #endif /*! */ /* Retrieve coordinate tolerance. Call of varkon_ctol (sur751) */ /* !*/ ctol = varkon_ctol(); /*! */ /* 2. Calculate rotation system */ /* ____________________________ */ /* */ /* Call of r_csys. */ /* !*/ status= r_csys (p_patl); if (status<0) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur227 r_csys failed \n" ); fflush(dbgfil(SURPAC)); } #endif sprintf(errbuf,"r_csys%%varkon_pat_rotloft (sur227)"); return(varkon_erpush("SU2973",errbuf)); } /*! */ /* 2. Calculate curve derivatives in local system */ /* ______________________________________________ */ /* */ /* Call of cderiv. */ /* !*/ status= cderiv (p_patl, u_pat); if (status<0) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur227 cderiv failed \n" ); fflush(dbgfil(SURPAC)); } #endif sprintf(errbuf,"cderiv%%varkon_pat_rotloft (sur227)"); return(varkon_erpush("SU2973",errbuf)); } /*! */ /* 3. Calculate angle corresponding to input V value */ /* _________________________________________________ */ /* */ /* Call of vangle. */ /* !*/ status= vangle ( v_pat); if (status<0) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur227 vangle failed \n" ); fflush(dbgfil(SURPAC)); } #endif sprintf(errbuf,"vangle%%varkon_pat_rotloft (sur227)"); return(varkon_erpush("SU2973",errbuf)); } /*! */ /* 4. Calculate surface derivatives in local system */ /* ________________________________________________ */ /* */ /* Call of sderiv. */ /* !*/ status= sderiv (); if (status<0) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur227 sderiv failed \n" ); fflush(dbgfil(SURPAC)); } #endif sprintf(errbuf,"sderiv%%varkon_pat_rotloft (sur227)"); return(varkon_erpush("SU2973",errbuf)); } /*! */ /* 5. Transformation of derivatives */ /* ________________________________ */ /* */ /* Invertation of matrix and transformation of EVALS. */ /* Call of varkon_geo_612 and varkon_evals_transf (sur640). */ /* !*/ status=GEtform_inv (&rot_csys, &rot_csys_inv ); if (status<0) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "GEtform_inv failed \n" ); fflush(dbgfil(SURPAC)); } #endif sprintf(errbuf,"GEtform_inv%%varkon_pat_rotloft (sur227)"); return(varkon_erpush("SU2943",errbuf)); } xyz_s.e_case = 4; status=varkon_evals_transf (&xyz_s, &rot_csys_inv, &xyz_tra ); if (status<0) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "GEtform_inv failed \n" ); fflush(dbgfil(SURPAC)); } #endif sprintf(errbuf,"GEtform_inv%%varkon_pat_rotloft (sur227)"); return(varkon_erpush("SU2943",errbuf)); } /* Coordinates r(u) */ p_xyz->r_x= xyz_tra.r_x; p_xyz->r_y= xyz_tra.r_y; p_xyz->r_z= xyz_tra.r_z; /* Tangent dr/du */ p_xyz->u_x= xyz_tra.u_x; p_xyz->u_y= xyz_tra.u_y; p_xyz->u_z= xyz_tra.u_z; /* Tangent dr/dv */ p_xyz->v_x= xyz_tra.v_x; p_xyz->v_y= xyz_tra.v_y; p_xyz->v_z= xyz_tra.v_z; /* Second derivative d2r/du2 */ p_xyz->u2_x= xyz_tra.u2_x; p_xyz->u2_y= xyz_tra.u2_y; p_xyz->u2_z= xyz_tra.u2_z; /* Second derivative d2r/dv2 */ p_xyz->v2_x= xyz_tra.v2_x; p_xyz->v2_y= xyz_tra.v2_y; p_xyz->v2_z= xyz_tra.v2_z; /* Twist vector d2r/dudv */ p_xyz->uv_x= xyz_tra.uv_x; p_xyz->uv_y= xyz_tra.uv_y; p_xyz->uv_z= xyz_tra.uv_z; p_xyz->sp_x = poi_spine.x_gm; p_xyz->sp_y = poi_spine.y_gm; p_xyz->sp_z = poi_spine.z_gm; p_xyz->spt_x = tan_spine.x_gm; p_xyz->spt_y = tan_spine.y_gm; p_xyz->spt_z = tan_spine.z_gm; p_xyz->spt2_x= 0.0; p_xyz->spt2_y= 0.0; p_xyz->spt2_z= 0.0; #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur227 r_x %f r_y %f r_z %f \n", p_xyz->r_x,p_xyz->r_y,p_xyz->r_z); fprintf(dbgfil(SURPAC), "sur227 u_x %f u_y %f u_z %f \n", p_xyz->u_x,p_xyz->u_y,p_xyz->u_z); fprintf(dbgfil(SURPAC), "sur227 v_x %f v_y %f v_z %f \n", p_xyz->v_x,p_xyz->v_y,p_xyz->v_z); fprintf(dbgfil(SURPAC), "sur227 u2_x %f u2_y %f u2_z %f \n", p_xyz->u2_x,p_xyz->u2_y,p_xyz->u2_z); fprintf(dbgfil(SURPAC), "sur227 v2_x %f v2_y %f v2_z %f \n", p_xyz->v2_x,p_xyz->v2_y,p_xyz->v2_z); fprintf(dbgfil(SURPAC), "sur227 uv_x %f uv_y %f uv_z %f \n", p_xyz->uv_x,p_xyz->uv_y,p_xyz->uv_z); } if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur227 Exit *** varkon_pat_rotloft x= %8.2f y= %8.2f z= %8.2f \n", p_xyz->r_x,p_xyz->r_y,p_xyz->r_z); fflush(dbgfil(SURPAC)); /* To file from buffer */ } #endif return(SUCCED); } /* End of function */
DBstatus varkon_pat_sweeploft ( /*-------------- Argument declarations -----------------------------*/ /* */ /* In: */ GMPATL *p_patl, /* Pointer to the conic lofting patch */ DBint icase, /* Calculation case: */ /* Eq. 0: Only coordinates */ /* Eq. 1: Coordinates and dr/du derivative */ /* Eq. 2: Coordinates and dr/dv derivative */ /* Eq. : All derivatives */ DBfloat u_pat, /* Patch (local) U parameter value */ DBfloat v_pat, /* Patch (local) V parameter value */ EVALS *p_xyz ) /* Coordinates and derivatives (ptr) */ /* Out: */ /* Data to p_xyz */ /*-----------------------------------------------------------------!*/ { /* Start of function */ /*!--------------- Internal variables ------------------------------*/ /* */ DBTmat tra0_csys; /* Transformation system */ DBTmat tra1_csys; /* Transformation system eps */ DBTmat tra2_csys; /* Transformation system 2*eps */ DBfloat t_eps; /* Epsilon for parameter */ /* */ /*-----------------------------------------------------------------!*/ char errbuf[80]; /* String for error message fctn erpush */ short status; /* Error code from a called function */ /* ----------------- Theory ----------------------------------------*/ /* */ /* The coordinates and derivatives ........................ */ /* */ /*----------------------------------------------------------------- */ /*--------------end-of-declarations---------------------------------*/ /*! */ /* Algorithm */ /* ========= */ /* !*/ #ifdef DEBUG if ( dbglev(SURPAC) == 2 ) { fprintf(dbgfil(SURPAC), "sur229 Type of LFT_PAT p_patl->p_flag= %d\n", (int)p_patl->p_flag); fflush(dbgfil(SURPAC)); } #endif /*! */ /* 1. Check of input data and initializations */ /* __________________________________________ */ /* */ /* Initialize output coordinates and derivatives for DEBUG on. */ /* Call of initial. */ /* !*/ #ifdef DEBUG status=initial(p_patl,u_pat,v_pat,p_xyz); if (status<0) { sprintf(errbuf,"initial%%varkon_pat_sweeploft (sur229)"); return(varkon_erpush("SU2973",errbuf)); } #endif /*! */ /* Retrieve tolerances. */ /* !*/ ctol = varkon_ctol(); idpoint = varkon_idpoint(); comptol = varkon_comptol(); /*! */ /* 2. Calculate transformation matrices */ /* ____________________________________ */ /* */ /* Call of t_csys. */ /* !*/ t_eps = 0; status= t_csys (u_pat, p_patl, &t_eps, &tra0_csys ); if (status<0) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur229 t_csys failed 0\n" ); fflush(dbgfil(SURPAC)); } #endif sprintf(errbuf,"t_csys%%sur229"); return(varkon_erpush("SU2973",errbuf)); } V3MOME((char *)(&tra0_csys),(char *)(&tra_csys),sizeof(DBTmat)); status= t_csys (u_pat+t_eps, p_patl, &t_eps, &tra1_csys ); if (status<0) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur229 t_csys failed 1\n" ); fflush(dbgfil(SURPAC)); } #endif sprintf(errbuf,"t_csys%%sur229"); return(varkon_erpush("SU2973",errbuf)); } status= t_csys (u_pat+2.0*t_eps, p_patl, &t_eps, &tra2_csys ); if (status<0) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur229 t_csys failed 2\n" ); fflush(dbgfil(SURPAC)); } #endif sprintf(errbuf,"t_csys%%sur229"); return(varkon_erpush("SU2973",errbuf)); } /*! */ /* 3. Calculate U derivative transformation matrices. */ /* _________________________________________________ */ /* */ /* Call of dermat. */ /* !*/ status= dermat ( t_eps, &tra0_csys, &tra1_csys, &tra2_csys ); if (status<0) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur229 dermat failed\n" ); fflush(dbgfil(SURPAC)); } #endif sprintf(errbuf,"dermat%%sur229"); return(varkon_erpush("SU2973",errbuf)); } /*! */ /* 2. Calculate surface derivatives */ /* ________________________________ */ /* */ /* Call of sderiv. */ /* !*/ status= sderiv (p_patl, v_pat, p_xyz ); if (status<0) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur229 sderiv failed \n" ); fflush(dbgfil(SURPAC)); } #endif sprintf(errbuf,"sderiv%%sur229"); return(varkon_erpush("SU2973",errbuf)); } #ifdef DEBUG if ( dbglev(SURPAC) == 2 ) { fprintf(dbgfil(SURPAC), "sur229 r_x %f r_y %f r_z %f \n", p_xyz->r_x,p_xyz->r_y,p_xyz->r_z); fprintf(dbgfil(SURPAC), "sur229 u_x %f u_y %f u_z %f \n", p_xyz->u_x,p_xyz->u_y,p_xyz->u_z); fprintf(dbgfil(SURPAC), "sur229 v_x %f v_y %f v_z %f \n", p_xyz->v_x,p_xyz->v_y,p_xyz->v_z); fprintf(dbgfil(SURPAC), "sur229 u2_x %f u2_y %f u2_z %f \n", p_xyz->u2_x,p_xyz->u2_y,p_xyz->u2_z); fprintf(dbgfil(SURPAC), "sur229 v2_x %f v2_y %f v2_z %f \n", p_xyz->v2_x,p_xyz->v2_y,p_xyz->v2_z); fprintf(dbgfil(SURPAC), "sur229 uv_x %f uv_y %f uv_z %f \n", p_xyz->uv_x,p_xyz->uv_y,p_xyz->uv_z); } if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur229 Exit *** varkon_pat_sweeploft x= %8.2f y= %8.2f z= %8.2f \n", p_xyz->r_x,p_xyz->r_y,p_xyz->r_z); fflush(dbgfil(SURPAC)); /* To file from buffer */ } #endif return(SUCCED); } /* End of function */
void GLWidget::initializeGL() { //QOpenGLWidget::initializeGL(); //initializeOpenGLFunctions(); initial(); }
/* GCRT */ int rgcrt(char *filename, int *atomnum, ATOM * atom, CONTROLINFO cinfo, MOLINFO minfo) { FILE *fpin; int i, index; int nameindex; int numatom; int overflow_flag = 0; char tmpchar[10]; char line[MAXCHAR]; if ((fpin = fopen(filename, "r")) == NULL) { fprintf(stderr, "Cannot open file %s, exit\n", filename); exit(1); } initial(cinfo.maxatom, atom, minfo.resname); index = 0; numatom = 0; nameindex = -1; for (;;) { if (fgets(line, MAXCHAR, fpin) == NULL) { /* printf("\nFinished reading %s file.", cinfo.ifilename); */ break; } if (spaceline(line) == 1) { index++; continue; } if (index >= 2) index++; if (index <= 3) continue; if (index > 4 && spaceline(line) == 1) break; sscanf(line, "%s", tmpchar); if (nameindex == -1) { if (tmpchar[0] >= '0' && tmpchar[0] <= '9') nameindex = 0; else nameindex = 1; } if (overflow_flag == 0) { if (nameindex == 0) sscanf(line, "%d%lf%lf%lf", &atom[numatom].atomicnum, &atom[numatom].x, &atom[numatom].y, &atom[numatom].z); else sscanf(line, "%s%lf%lf%lf", atom[numatom].name, &atom[numatom].x, &atom[numatom].y, &atom[numatom].z); } numatom++; if (numatom >= cinfo.maxatom && overflow_flag == 0) { printf ("\nInfo: the atom number exceeds the MAXATOM, reallocate memory automatically"); overflow_flag = 1; } } *atomnum = numatom; if (nameindex == 0) { element(*atomnum, atom); for (i = 0; i < *atomnum; i++) strcpy(atom[i].name, atom[i].element); } if (nameindex == 1) atomicnum(*atomnum, atom); /* printf("\n atom number is %5d", *atomnum); */ fclose(fpin); return overflow_flag; }
void BackwardParabolicIBVP::gridMethod(DoubleMatrix &p, SweepMethodDirection direction) const { typedef void (*t_algorithm)(const double*, const double*, const double*, const double*, double*, unsigned int); t_algorithm algorithm = &tomasAlgorithm; if (direction == ForwardSweep) algorithm = &tomasAlgorithmL2R; if (direction == BackwardSweep) algorithm = &tomasAlgorithmR2L; Dimension time = mtimeDimension; Dimension dim1 = mspaceDimension.at(0); double ht = time.step(); unsigned int minM = time.min(); unsigned int maxM = time.max(); unsigned int M = maxM-minM; double hx = dim1.step(); unsigned int minN = dim1.min(); unsigned int maxN = dim1.max(); unsigned int N = maxN-minN; double h = ht/(hx*hx); p.clear(); p.resize(M+1, N+1); double *ka = (double*) malloc(sizeof(double)*(N-1)); double *kb = (double*) malloc(sizeof(double)*(N-1)); double *kc = (double*) malloc(sizeof(double)*(N-1)); double *kd = (double*) malloc(sizeof(double)*(N-1)); double *rx = (double*) malloc(sizeof(double)*(N-1)); /* initial condition */ SpaceNodePDE isn; for (unsigned int n=0; n<=N; n++) { isn.i = n+minN; isn.x = isn.i*hx; p[M][n] = initial(isn); } layerInfo(p, M); SpaceNodePDE lsn; lsn.i = minN; lsn.x = minN*hx; SpaceNodePDE rsn; rsn.i = maxN; rsn.x = maxN*hx; TimeNodePDE tn; for (unsigned int m=M-1; m!=UINT32_MAX; m--) { tn.i = m+minM; tn.t = tn.i*ht; for (unsigned int n=1; n<=N-1; n++) { isn.i = n+minN; isn.x = isn.i*hx; double alpha = -a(isn,tn)*h; double betta = 1.0 - 2.0*alpha; ka[n-1] = alpha; kb[n-1] = betta; kc[n-1] = alpha; kd[n-1] = p[m+1][n] - ht * f(isn, tn); } ka[0] = 0.0; kc[N-2] = 0.0; /* border conditions */ p[m][0] = boundary(lsn, tn); p[m][N] = boundary(rsn, tn); kd[0] += a(lsn,tn) * h * p[m][0]; kd[N-2] += a(rsn,tn) * h * p[m][N]; (*algorithm)(ka, kb, kc, kd, rx, N-1); for (unsigned int n=1; n<=N-1; n++) p[m][n] = rx[n-1]; layerInfo(p, m); } free(ka); free(kb); free(kc); free(kd); free(rx); }
/*Main program of the ABC algorithm*/ int main() { int iter,run; double mean; mean=0; srand(time(NULL)); int i,j,k,ii; po s[200]; FILE *f1; file=fopen("result\\out17.txt","w"); if((f1=fopen("input\\P10S2T03.dat","r"))==NULL) { exit(0); } fscanf(f1,"jobs %d\n",&J); fscanf(f1,"stage %d\n",&S); fscanf(f1,"machines %d",&sm[1]); for(i=2;i<=S-1;i++) fscanf(f1," %d",&sm[i]); fscanf(f1," %d\n",&sm[S]); fscanf(f1,"*Pro_req*\n"); for(i=1;i<=S;i++) { for(j=1;j<=J;j++) fscanf(f1,"%d ",&proreq[i][j]); fscanf(f1,"\n"); } fscanf(f1,"*Pro_time*\n"); for(i=1;i<=S;i++) { for(j=1;j<=J;j++) fscanf(f1,"%d ",&protime[i][j]); fscanf(f1,"\n"); } fclose(f1); double lower; lower=func_LB(J,S,sm,proreq,protime); fprintf(file,"lower=%lf\n",lower); for(i=1;i<=S;i++) { ub[i]=sm[i]+1; lb[i]=1; } double mmin=100000000.0; for(run=1;run<=runtime;run++) { initial(); MemorizeBestSource(); for (iter=1;iter<=maxCycle;iter++) //迭代次数 { SendEmployedBees();//雇佣蜂时期 CalculateProbabilities();//计算可能性 //SendOnlookerBees();//跟随蜂时期 MemorizeBestSource();//记录最好的蜂源 SendScoutBees();//如果到达尝试次数后,就到侦察蜂时期 } /* for(j=0;j<D;j++) { printf("GlobalParam[%d]: %f\n",j+1,GlobalParams[j]); }*/ fprintf(file,"%d. run: %f \n",run,GlobalMin); GlobalMins[run]=GlobalMin; mean=mean+GlobalMin; if(GlobalMin<mmin) mmin=GlobalMin; } double pd; pd=PD(mmin,lower); mean=mean/runtime; fprintf(file,"Means of %d runs: %f\n",runtime,mean); fprintf(file,"Mins of %d runs: %f\n",runtime,mmin); fprintf(file,"PD of this time: %f\n",pd); //fprintf(file,"maxspan=%d\n",max); //system("pause"); return 0; }
mog::Bullet::Bullet() { initial(); }
connection_state_ptr initial_state(access_ptr access) { connection_state_ptr initial(new connected_tcp(access)); return initial; }
GraphAndValues Masseuse::LoadPoseGraphAndLCC( const string& pose_graph_file, bool read_lcc) { FILE *fp = (FILE *)fopen(pose_graph_file.c_str(), "rb"); if (fp == NULL) { fprintf(stderr, "Could not open file %s\n", pose_graph_file.c_str()); } if (fread(&origin, sizeof(Eigen::Vector6d), 1, fp) != 1) { throw invalid_argument("LoadPoseGraphAndLCC: Cannot load the origin!"); } // std::cerr << "read origin: " << origin.transpose() << std::endl; unsigned numRelPoses = 0; unsigned numLCC = 0; if (fread(&numRelPoses, sizeof(unsigned), 1, fp) != 1) { printf("error! Cannot load num of relative poses.\n"); throw invalid_argument("LoadPoseGraphAndLCC: error loading file"); } if(read_lcc){ if (fread(&numLCC, sizeof(unsigned), 1, fp) != 1) { printf("error! Cannot load num of loop closure constraints.\n"); throw invalid_argument("LoadPoseGraphAndLCC: error loading file"); } } std::cerr << "Will load " << numRelPoses << " rel poses, " << numLCC << " loop closure constranits." << std::endl; relative_poses.clear(); // save all rel poses for (unsigned i = 0; i != numRelPoses; i++) { RelPose rPos; if (fread(&rPos.ref_id, sizeof(unsigned), 1, fp) != 1) { throw invalid_argument("LoadPoseGraphAndLCC: error loading file"); } if (fread(&rPos.live_id, sizeof(unsigned), 1, fp) != 1) { throw invalid_argument("LoadPoseGraphAndLCC: error loading file"); } if (fread(&rPos.rel_pose, sizeof(Eigen::Vector6d), 1, fp) != 1) { throw invalid_argument("LoadPoseGraphAndLCC: error loading file"); } if (fread(&rPos.cov, sizeof(Eigen::Matrix6d), 1, fp) != 1) { throw invalid_argument("LoadPoseGraphAndLCC: error loading file"); } relative_poses.push_back(rPos); } if(read_lcc){ loop_closure_constraints.clear(); // save all lcc here for (unsigned i = 0; i != numLCC; i++) { RelPose rPos; if (fread(&rPos.ref_id, sizeof(unsigned), 1, fp) != 1) { throw invalid_argument("LoadPoseGraphAndLCC: error loading file"); } if (fread(&rPos.live_id, sizeof(unsigned), 1, fp) != 1) { throw invalid_argument("LoadPoseGraphAndLCC: error loading file"); } if (fread(&rPos.rel_pose, sizeof(Eigen::Vector6d), 1, fp) != 1) { throw invalid_argument("LoadPoseGraphAndLCC: error loading file"); } if (fread(&rPos.cov, sizeof(Eigen::Matrix6d), 1, fp) != 1) { throw invalid_argument("LoadPoseGraphAndLCC: error loading file"); } loop_closure_constraints.push_back(rPos); } } fclose(fp); std::cerr << "Finished loading Pose Graph from " << pose_graph_file << std::endl; std::shared_ptr<Values> initial(new Values); std::shared_ptr<Graph> graph(new Graph); Pose3 prev_pose; unsigned numICPfailed = 0; for (size_t ii = 0; ii < relative_poses.size(); ++ii){ RelPose curr_pose = relative_poses[ii]; if(ii == 0){ // first relative pose, initialize graph at origin unsigned id = curr_pose.ref_id; Rot3 R(origin[3], origin[4], origin[5]); Point3 t = origin.head<3>(); Pose3 orig(R, t); (*initial)[id] = orig; prev_pose = orig; // std::cerr << "inserting origin: Rot: " << orig.rotationMatrix().eulerAngles // (0,1,2).transpose() << " Trans: " << orig.translation().transpose() << // " at index: " << id << // std::endl; } // Build the next vertex using the relative contstraint Rot3 R(curr_pose.rel_pose[3], curr_pose.rel_pose[4], curr_pose.rel_pose[5]); Point3 t = curr_pose.rel_pose.head<3>(); Pose3 rel(R, t); Pose3 new_pose = prev_pose*rel; (*initial)[curr_pose.live_id] = new_pose; // std::cerr << "inserting pose: Rot: " << new_pose.rotationMatrix().eulerAngles // (0,1,2).transpose() << " Trans: " << new_pose.translation().transpose() << // " at index: " << curr_pose.live_id << // std::endl; prev_pose = new_pose; // Also insert a factor for the binary pose constraint unsigned id1 = curr_pose.ref_id; unsigned id2 = curr_pose.live_id; Matrix m = curr_pose.cov; if(m.sum() == 0 || m.determinant() <= 0 || std::isnan(m.determinant()) /*|| m.determinant() > options.cov_det_thresh*/){ // std::cerr << "ICP failed for rel pose between " << id1 << " and " << id2 << // "Setting fixed covaraince..." << // std::endl; Eigen::Vector6d cov_vec; // TODO: Improve handling of cases where the frame-to-frame ICP failed cov_vec << 7e-8, 7e-8, 7e-8, 8e-11, 8e-11, 8e-11; m = cov_vec.asDiagonal(); numICPfailed++; } // std::cerr << "Adding binary constraint between id: " << id1 << " and " << // id2 << std::endl << "with cov: \n" << m << std::endl; // Create a new factor between poses if(options.use_identity_covariance){ m.setIdentity(); } m = m * options.rel_covariance_mult; Factor factor(id1, id2, rel, m); graph->push_back(factor); } std::cerr << std::setprecision(3) << std::fixed <<"ICP failed " << numICPfailed << " times " << "out of " << relative_poses.size() << " ( " << (double)numICPfailed/(double)relative_poses.size() * 100 << "% )" << std::endl; if( read_lcc ){ std::cerr << "Reading LLC." << std::endl; int discarded_lcc = 0; for(size_t ii = 0; ii < loop_closure_constraints.size(); ++ii){ RelPose curr_lcc = loop_closure_constraints[ii]; unsigned id1 = curr_lcc.ref_id; unsigned id2 = curr_lcc.live_id; Rot3 R(curr_lcc.rel_pose[3], curr_lcc.rel_pose[4], curr_lcc.rel_pose[5]); Point3 t = curr_lcc.rel_pose.head<3>(); Pose3 lcc(R, t); Matrix m = curr_lcc.cov; if(m.sum() == 0 || m.determinant() > options.cov_det_thresh || m.determinant() <= 0 || std::isnan(m.determinant())) { // ICP failed or something went wrong for this loop closure, ignoring // The determinant of the cov. matrix may also be larger than the // specified threshold. discarded_lcc++; continue; } // check if the lcc is between far away poses. If so, downweight it's // covariance. // const Pose3* lcc_0 = dynamic_cast<const Pose3*>(&initial->at(id1)); // const Pose3* lcc_1 = dynamic_cast<const Pose3*>(&initial->at(id2)); // Pose3 lcc_diff = lcc_0->compose(lcc).inverse().compose(*lcc_1); // std::cerr << "distance between poses for lcc: " << ii << // " between poses " << id1 << " and " << id2 << ": " // << lcc_diff.translation().norm() << std::endl; // Pose3 diff = (*lcc_0).inverse().compose(*lcc_1); // std::cerr << "distance between poses for lcc: " << ii << // " between poses " << id1 << " and " << id2 << ": " // << lcc.translation().norm() << std::endl; // Create a new factor between poses if(options.use_identity_covariance){ m.setIdentity(); } Factor lcc_factor(id1, id2, lcc, m); lcc_factor.isLCC = true; graph->push_back(lcc_factor); curr_lcc.ext_id = graph->size()-1; // std::cerr << std::scientific << // "Adding lcc between id: " << id1 << " and " << // id2 << std::endl << "with cov: \n" << lcc_factor.cov << std::endl; //m_addedLCC[keyFromId(id2)] = curr_lcc; /* // If we already have a constraint between poses i and j, only use the one // with the highest degree of certainty (lowest cov. determinant) if(m_addedLCC.count(keyFromId(id2)) == 0){ // LCC has not been added yet, just add graph->push_back(factor); curr_lcc.m_nExtId = graph->size()-1; m_addedLCC[keyFromId(id2)] = curr_lcc; }else{ // Check if the covariance of the new lcc for poses i and j // is smaller than what we are currently using EstPose old_lcc = m_addedLCC[keyFromId(id2)]; if(old_lcc.m_Cov.determinant() > curr_lcc.m_Cov.determinant()){ // new det is smaller, replace curr_lcc.m_nExtId = old_lcc.m_nExtId; graph->replace(old_lcc.m_nExtId, factor); m_addedLCC[keyFromId(id2)] = curr_lcc; // std::cerr << "determinant for new lcc between " << id1 << " and " << // id2 << " is: " << curr_lcc.m_Cov.determinant() << " < " // << old_lcc.m_Cov.determinant() << std::endl; }else{ // Determinant for new constraint is larger, skip it continue; } } */ } // //ZZZZZZZZZZZZZ Temp, add wrong LCC to test switchable constraints // unsigned id1 = 480; // unsigned id2 = 870; // Pose3& T2 = initial->at(id2); // Pose3& T1 = initial->at(id1); // Pose3 T12 = T1.inverse() * T2; // // Add random values to the translation // T12.translation()[0] += 5; // T12.translation()[1] -= 2; // T12.translation()[3] += 7; // // Rotate the pose by an arbitrary amount // Sophus::SO3d rot(0.5, 0.7, 0.1); // T12.rotationMatrix() *= rot.matrix(); // Factor wrong_lcc(id1, id2, T12, Eigen::Matrix6d::Identity()); // wrong_lcc.isLCC = true; // // now add the wrong LCC to the graph // graph->push_back(wrong_lcc); std::cerr << std::setprecision(3) << std::fixed <<"Did not use " << discarded_lcc << " LCC " << "out of " << numLCC << " ( " << (double)discarded_lcc/(double)numLCC * 100 << "% )" << std::endl; } return make_pair(graph, initial); }
/* MOL2 */ int rmol2(char *filename, int *atomnum, ATOM atom[], int *bondnum, BOND bond[], CONTROLINFO *cinfo, MOLINFO *minfo, int flag) { /*if flag =1, read in atom type, if flag ==0, do not read in atom type */ int i; int numatom; int numbond; int index = 0; int atomrecord = 0; int bondrecord = 0; int tmpint1; int tmpint2; int tmpint3; int tmpint4; int tmpint5; int mf1 = 1; int itype = 1; int overflow_flag = 0; int read_atomnum; int read_bondnum; int len; double tmpf1, tmpf2, tmpf3, tmpf4; char type[MAXCHAR]; char tmpchar1[MAXCHAR], tmpchar2[MAXCHAR], tmpchar3[MAXCHAR], tmpchar4[MAXCHAR], tmpchar5[MAXCHAR]; char tmpc1[MAXCHAR]; char line[MAXCHAR]; FILE *fpin; if ((fpin = fopen(filename, "r")) == NULL) { fprintf(stdout, "Cannot open file %s to read in rmol2(), exit\n", filename); exit(1); } initial((*cinfo).maxatom, atom, (*minfo).resname); numatom = 0; numbond = 0; for (;;) { if (fgets(line, MAXCHAR, fpin) == NULL) break; sscanf(line, "%s%s%s", tmpchar1, tmpchar2, tmpchar3); if (strcmp("@<TRIPOS>MOLECULE", tmpchar1) == 0) { index = 1; continue; } if (strcmp("@<TRIPOS>ATOM", tmpchar1) == 0) { atomrecord = 1; continue; } if (strcmp("@<TRIPOS>BOND", tmpchar1) == 0) { bondrecord = 1; atomrecord = 0; continue; } if (bondrecord == 1 && strncmp("@<TRIPOS>", tmpchar1, 9) == 0) { /* end of bonds */ bondrecord = 0; continue; } if (index == 1) { if((*cinfo).rnindex != 1) strcpy((*minfo).longresname, tmpchar1); index = 2; continue; } if (index == 2) { sscanf(line, "%d%d", &read_atomnum, &read_bondnum); if (read_atomnum > (*cinfo).maxatom || read_bondnum > (*cinfo).maxbond) { *atomnum = read_atomnum; *bondnum = read_bondnum; return 1; } index = -1; continue; } /* process the ATOM section: */ if (atomrecord) { strcpy(tmpchar5, "MOL"); sscanf(line, "%d%s%lf%lf%lf%s%d%s%lf", &tmpint1, tmpc1, &tmpf1, &tmpf2, &tmpf3, tmpchar4, &tmpint2, tmpchar5, &tmpf4); if( numatom==0 ) mf1 = tmpint1; /* atom number of first atom */ if (overflow_flag == 0) { if (strlen(tmpc1) > 5) { atom[numatom].name[0] = tmpc1[0]; atom[numatom].name[1] = tmpc1[1]; atom[numatom].name[2] = tmpc1[2]; atom[numatom].name[3] = tmpc1[3]; atom[numatom].name[4] = tmpc1[4]; atom[numatom].name[5] = '\0'; } else strcpy(atom[numatom].name, tmpc1); if (tmpc1[0] == '*') { for (i = 0; i < strlen(tmpchar4); i++) { if (tmpchar4[i] == '.') break; if (i > 3) break; atom[numatom].name[i] = tmpchar4[i]; } atom[numatom].name[i] = '\0'; } if (strlen(tmpc1) > 5) { atom[numatom].ambername[0] = tmpchar4[0]; atom[numatom].ambername[1] = tmpchar4[1]; atom[numatom].ambername[2] = tmpchar4[2]; atom[numatom].ambername[3] = tmpchar4[3]; atom[numatom].ambername[4] = tmpchar4[4]; atom[numatom].ambername[5] = '\0'; } else strcpy(atom[numatom].ambername, tmpchar4); atom[numatom].x = tmpf1; atom[numatom].y = tmpf2; atom[numatom].z = tmpf3; atom[numatom].charge = tmpf4; atom[numatom].resno = tmpint2; if (flag == 1){ if (strlen(tmpchar4) > 5) { atom[numatom].ambername[0] = tmpchar4[0]; atom[numatom].ambername[1] = tmpchar4[1]; atom[numatom].ambername[2] = tmpchar4[2]; atom[numatom].ambername[3] = tmpchar4[3]; atom[numatom].ambername[4] = tmpchar4[4]; atom[numatom].ambername[5] = '\0'; } else { strcpy(atom[numatom].ambername, tmpchar4); } } if ((*cinfo).rnindex == 1) strcpy(atom[numatom].aa, (*minfo).resname); else { if (strlen(tmpchar5) > 3) { atom[numatom].aa[0] = tmpchar5[0]; atom[numatom].aa[1] = tmpchar5[1]; atom[numatom].aa[2] = tmpchar5[2]; atom[numatom].aa[3] = '\0'; } else strcpy(atom[numatom].aa, tmpchar5); } } numatom++; if (numatom >= (*cinfo).maxatom && overflow_flag == 0) { printf ("\nThe atom number exceeds the MAXATOM, reallocate memory"); overflow_flag = 1; } } /* process the BOND section: */ if (bondrecord) { if (numbond >= read_bondnum) continue; sscanf(line, "%d%d%d%s", &tmpint3, &tmpint4, &tmpint5, type); if (overflow_flag == 0) { bond[numbond].jflag = -1; len = strlen(type); if(len >=2 && (type[len-1] == 'f' || type[len-1] == 'F')) { /* bond type is frozen during bond type assignment */ type[len-1] = '\0'; bond[numbond].jflag = 1; if(strncmp(type, "ar", 2) ==0 || strncmp(type, "AR", 2) == 0) { fprintf(stdout, "You cannot freeze this bond (%d-%d,%s) since it is unclear whether it is a single or double bond, you may change it to '7' (aromatic single) or '8' (aromatic double), exit\n", tmpint4-mf1 + 1, tmpint5-mf1 + 1, type); exit(1); } if(strncmp(type, "un", 2) ==0 || strncmp(type, "UN", 2) == 0) { fprintf(stdout, "You cannot freeze this bond (%d-%d,%s) since the bond type is unclear, exit\n", tmpint4-mf1 + 1, tmpint5-mf1 + 1, type); exit(1); } } atom[tmpint4 - mf1].con[atom[tmpint4 - mf1].connum++] = tmpint5 - mf1; atom[tmpint5 - mf1].con[atom[tmpint5 - mf1].connum++] = tmpint4 - mf1; if (strcmp(type, "1") == 0) itype = 1; else if (strcmp(type, "2") == 0) itype = 2; else if (strcmp(type, "3") == 0) itype = 3; else if (strcmp(type, "am") == 0) itype = 1; else if (strcmp(type, "7") == 0) itype = 1; else if (strcmp(type, "8") == 0) itype = 2; else if (strcmp(type, "ar") == 0) itype = 10; else if (strcmp(type, "SINGLE") == 0) itype = 1; else if (strcmp(type, "DOUBLE") == 0) itype = 2; else if (strcmp(type, "TRIPLE") == 0) itype = 3; else if (strcmp(type, "-1") == 0) itype = -1; else if (strcmp(type, "-2") == 0) itype = -2; else if (strcmp(type, "-3") == 0) itype = -3; else if (strcmp(type, "-am") == 0) itype = -1; else if (strcmp(type, "-ar") == 0) itype = -10; else if (strcmp(type, "-SINGLE") == 0) itype = -1; else if (strcmp(type, "-DOUBLE") == 0) itype = -2; else if (strcmp(type, "-TRIPLE") == 0) itype = -3; else { printf("\nUnknown bond type for BOND(%s-%s:%s), assuming it is a single bond", atom[tmpint4-mf1].name, atom[tmpint5-mf1].name, type); itype = 1; } bond[numbond].bondi = tmpint4 - mf1; bond[numbond].bondj = tmpint5 - mf1; bond[numbond].type = itype; } numbond++; if (numbond >= (*cinfo).maxbond && overflow_flag == 0) { printf ("\nThe bond number exceeds the MAXBOND, reallocate memory"); overflow_flag = 1; } } } fclose(fpin); *atomnum = numatom; *bondnum = numbond; /* if(overflow_flag == 0) { tmpf1 = 0; tmpf2 = 0; for(i=0;i<numatom;i++) { if(atom[i].charge > 0) tmpf1+=atom[i].charge; else tmpf2+=atom[i].charge; } printf("\nchargep is %9.4lf", tmpf1); printf("\nchargen is %9.4lf", tmpf2); } */ return overflow_flag; }
/* * Load a char and inventory into a new ch structure. */ bool load_char_obj( DESCRIPTOR_DATA *d, char *name ) { extern char *daPrompt; FILE *fp; CHAR_DATA *ch; char strsave [ MAX_INPUT_LENGTH ]; bool found; char sorry_player [] = "********************************************************\r\n" "** One or more of the critical fields in your player **\r\n" "** file were corrupted since you last played. Please **\r\n" "** contact an administrator or programmer to **\r\n" "** investigate the recovery of your characters. **\r\n" "********************************************************\r\n"; char sorry_object [] = "********************************************************\r\n" "** One or more of the critical fields in your player **\r\n" "** file were corrupted leading to the loss of one or **\r\n" "** more of your possessions. **\r\n" "********************************************************\r\n"; ch = new_character( TRUE ); d->character = ch; ch->desc = d; ch->name = str_dup( name ); ch->pcdata->prompt = str_dup( daPrompt ); ch->last_note = 0; ch->act = PLR_BLANK | PLR_COMBINE | PLR_PROMPT; ch->pcdata->pwd = str_dup( "" ); ch->pcdata->bamfin = str_dup( "" ); ch->pcdata->bamfout = str_dup( "" ); ch->pcdata->immskll = str_dup( "" ); ch->pcdata->title = str_dup( "" ); ch->pcdata->perm_str = 13; ch->pcdata->perm_int = 13; ch->pcdata->perm_wis = 13; ch->pcdata->perm_dex = 13; ch->pcdata->perm_con = 13; ch->pcdata->condition[COND_THIRST] = 48; ch->pcdata->condition[COND_FULL] = 48; ch->pcdata->pagelen = 20; ch->pcdata->switched = FALSE; found = FALSE; fclose( fpReserve ); /* parsed player file directories by Yaz of 4th Realm */ /* decompress if .gz file exists - Thx Alander */ sprintf( strsave, "%s%s%s%s%s", PLAYER_DIR, initial( ch->name ), "/", capitalize( name ), ".gz" ); if ( ( fp = fopen( strsave, "r" ) ) ) { char buf [ MAX_STRING_LENGTH ]; fclose( fp ); sprintf( buf, "gzip -dfq %s", strsave ); system( buf ); } sprintf( strsave, "%s%s%s%s", PLAYER_DIR, initial( ch->name ), "/", capitalize( name ) ); if ( ( fp = fopen( strsave, "r" ) ) ) { char buf[ MAX_STRING_LENGTH ]; int iNest; for ( iNest = 0; iNest < MAX_NEST; iNest++ ) rgObjNest[iNest] = NULL; found = TRUE; for ( ; ; ) { char *word; char letter; int status; letter = fread_letter( fp ); if ( letter == '*' ) { fread_to_eol( fp ); continue; } if ( letter != '#' ) { bug( "Load_char_obj: # not found.", 0 ); break; } word = fread_word( fp, &status ); if ( !str_cmp( word, "PLAYER" ) ) { if ( fread_char ( ch, fp ) ) { sprintf( buf, "Load_char_obj: %s section PLAYER corrupt.\r\n", name ); bug( buf, 0 ); write_to_buffer( d, sorry_player, 0 ); /* * In case you are curious, * it is ok to leave ch alone for close_socket * to free. * We want to now kick the bad character out as * what we are missing are MANDATORY fields. -Kahn */ SET_BIT( ch->act, PLR_DENY ); return TRUE; } } else if ( !str_cmp( word, "OBJECT" ) ) { if ( !fread_obj ( ch, fp ) ) { sprintf( buf, "Load_char_obj: %s section OBJECT corrupt.\r\n", name ); bug( buf, 0 ); write_to_buffer( d, sorry_object, 0 ); return FALSE; } } else if ( !str_cmp( word, "END" ) ) break; else { bug( "Load_char_obj: bad section.", 0 ); break; } } /* for */ fclose( fp ); } fpReserve = fopen( NULL_FILE, "r" ); return found; }
/* GZMAT */ int rgzmat(char *filename, int *atomnum, ATOM * atom, CONTROLINFO cinfo, MOLINFO minfo) { typedef struct { char name[MAXCHAR]; } STRNAME; FILE *fpin; int i, j, index, index0; int overflow_flag = 0; int findindex; int numatom; int coordinate_flag = 0; STRNAME *bondstr; STRNAME *anglestr; STRNAME *twiststr; char tmpchar1[MAXCHAR]; char tmpchar2[MAXCHAR]; char line[MAXCHAR]; if ((fpin = fopen(filename, "r")) == NULL) { fprintf(stdout, "Cannot open the input file %s to read in rgzmat(), exit\n", filename); exit(1); } bondstr = (STRNAME *) malloc(sizeof(STRNAME) * (cinfo.maxatom +10)); if (bondstr == NULL) { fprintf(stdout, "memory allocation error for *bondstr in rgzmat()\n"); exit(1); } anglestr = (STRNAME *) malloc(sizeof(STRNAME) * (cinfo.maxatom +10)); if (anglestr == NULL) { fprintf(stdout, "memory allocation error for *anglestr in rgzmat()\n"); exit(1); } twiststr = (STRNAME *) malloc(sizeof(STRNAME) * (cinfo.maxatom +10)); if (twiststr == NULL) { fprintf(stdout, "memory allocation error for *twiststr in rgzmat()\n"); exit(1); } initial(cinfo.maxatom, atom, minfo.resname); index = 0; index0 = 1; numatom = 0; for (;;) { if (fgets(line, MAXCHAR, fpin) == NULL) { /* printf("\nFinished reading %s file.", cinfo.ifilename); */ break; } if (spaceline(line) == 1) { if(coordinate_flag == 1) break; index++; continue; } if (index >= 2) index++; if (index <= 3) continue; if (index >= 4) { if (spaceline(line) == 1 || strncmp(line, "Vari", 4) == 0 || strncmp(line, "vari", 4) == 0) index0 = -1; if (strncmp(line, "Const", 5) == 0 || strncmp(line, "const", 5) == 0) index0 = -1; } if (index == 4) { if (overflow_flag == 0) sscanf(line, "%s", atom[numatom].name); numatom++; if (numatom >= cinfo.maxatom && overflow_flag == 0) { printf ("\nInfo: the atom number exceeds the MAXATOM, reallocate memory automatically"); overflow_flag = 1; } continue; } if (index == 5) { if (overflow_flag == 0) { sscanf(line, "%s%d%s", atom[numatom].name, &atom[numatom].bondatom, bondstr[numatom].name); if(atom[numatom].bondatom > numatom) { printf("\nError: bond atom ID is larger than ID of current atom (%d,%s), exit", numatom+1, atom[numatom].name); exit(1); } } numatom++; if (numatom >= cinfo.maxatom && overflow_flag == 0) { printf ("\nInfo: the atom number exceeds the MAXATOM, reallocate memory automatically"); overflow_flag = 1; } continue; } if (index == 6) { if (overflow_flag == 0) { sscanf(line, "%s%d%s%d%s", atom[numatom].name, &atom[numatom].bondatom, bondstr[numatom].name, &atom[numatom].angleatom, anglestr[numatom].name); if(atom[numatom].bondatom > numatom) { printf("\nError: bond atom ID is larger than ID of current atom (%d,%s), exit", numatom+1, atom[numatom].name); exit(1); } if(atom[numatom].angleatom > numatom) { printf("\nError: angle atom ID is larger than ID of current atom (%d,%s), exit", numatom+1, atom[numatom].name); exit(1); } } numatom++; if (numatom >= cinfo.maxatom && overflow_flag == 0) { printf ("\nInfo: the atom number exceeds the MAXATOM, reallocate memory automatically"); overflow_flag = 1; } continue; } if (index0 != -1) { if (overflow_flag == 0) { sscanf(line, "%s%d%s%d%s%d%s", atom[numatom].name, &atom[numatom].bondatom, bondstr[numatom].name, &atom[numatom].angleatom, anglestr[numatom].name, &atom[numatom].twistatom, twiststr[numatom].name); if(atom[numatom].bondatom > numatom) { printf("\nError: bond atom ID is larger than ID of current atom (%d,%s), exit", numatom+1, atom[numatom].name); exit(1); } if(atom[numatom].angleatom > numatom) { printf("\nError: angle atom ID is larger than ID of current atom (%d,%s), exit", numatom+1, atom[numatom].name); exit(1); } if(atom[numatom].twistatom > numatom) { printf("\nError: torsional atom ID is larger than ID of current atom (%d,%s), exit", numatom+1, atom[numatom].name); exit(1); } } numatom++; if (numatom >= cinfo.maxatom && overflow_flag == 0) { printf ("\nInfo: the atom number exceeds the MAXATOM, reallocate memory automatically"); overflow_flag = 1; } continue; } if (index0 == -1) { if (strchr(line, '=') == NULL) continue; coordinate_flag = 1; for(i=0;i<strlen(line);i++) if(line[i] == '=') line[i] = ' '; sscanf(line, "%s %s", tmpchar1, tmpchar2); for (i = 1; i < numatom; i++) { findindex = 1; for (j = 0; j < strlen(bondstr[i].name); j++) if (bondstr[i].name[j] != tmpchar1[j]) { findindex = 0; break; } if (findindex == 1) { strcpy(bondstr[i].name, tmpchar2); break; } } for (i = 2; i < numatom; i++) { findindex = 1; for (j = 0; j < strlen(anglestr[i].name); j++) if (anglestr[i].name[j] != tmpchar1[j]) { findindex = 0; break; } if (findindex == 1) { strcpy(anglestr[i].name, tmpchar2); break; } } for (i = 3; i < numatom; i++) { findindex = 1; for (j = 0; j < strlen(twiststr[i].name); j++) if (twiststr[i].name[j] != tmpchar1[j]) { findindex = 0; break; } if (findindex == 1) { strcpy(twiststr[i].name, tmpchar2); break; } } } } atom[1].bondatom--; atom[2].bondatom--; atom[2].angleatom--; for (i = 3; i < numatom; i++) { atom[i].bondatom--; atom[i].angleatom--; atom[i].twistatom--; } for (i = 1; i < numatom; i++) atom[i].bond = atof(bondstr[i].name); for (i = 2; i < numatom; i++) atom[i].angle = atof(anglestr[i].name); for (i = 3; i < numatom; i++) atom[i].twist = atof(twiststr[i].name); *atomnum = numatom; /* printf("\n atom number is %5d", *atomnum); */ fclose(fpin); free(bondstr); free(anglestr); free(twiststr); return overflow_flag; }
mitchell_moore( const seed_type s = 0 ) : next_( 0 ), next_p_( 31 ) { initial( s ); }
/* GZMAT */ int rjzmat(char *filename, int *atomnum, ATOM * atom, CONTROLINFO cinfo, MOLINFO minfo) { typedef struct { char str[30]; } STRNAME; FILE *fpin; int i, j, flag; int index = 0; int tmpint; int overflow_flag = 0; int findindex; int numatom; char tmpchar[30]; char tmpchar1[30]; char tmpchar2[30]; char tmpchar3[30]; char tmpchar4[30]; char tmpchar5[30]; char tmpchar6[30]; STRNAME *bondstr; STRNAME *anglestr; STRNAME *twiststr; double tmpf; char line[MAXCHAR]; bondstr = (STRNAME *) malloc(sizeof(STRNAME) * (cinfo.maxatom + 10)); if (bondstr == NULL) { fprintf(stderr, "memory allocation error for *bondstr in rjzmat()\n"); exit(0); } anglestr = (STRNAME *) malloc(sizeof(STRNAME) * (cinfo.maxatom + 10)); if (anglestr == NULL) { fprintf(stderr, "memory allocation error for *anglestr in rjzmat()\n"); exit(0); } twiststr = (STRNAME *) malloc(sizeof(STRNAME) * (cinfo.maxatom + 10)); if (twiststr == NULL) { fprintf(stderr, "memory allocation error for *twiststr in rjzmat()\n"); exit(0); } if ((fpin = fopen(filename, "r")) == NULL) { fprintf(stderr, "Cannot open file %s, exit\n", filename); exit(1); } initial(cinfo.maxatom, atom, minfo.resname); numatom = 0; flag = 0; for (;;) { if (fgets(line, MAXCHAR, fpin) == NULL) { /* printf("\nFinished reading %s file.", cinfo.ifilename); */ break; } strcpy(tmpchar, ""); tmpchar[0]='\0'; sscanf(line, "%s", tmpchar); if(strncmp(tmpchar, "&zmat", 5)==0) { flag =1; continue; } if(strncmp(tmpchar, "&zvar", 5)==0) { index =1; break; } if (flag == 1 && strcmp(tmpchar, "&") ==0) { flag = 0; continue; } if(strncmp(tmpchar, "molchg=", 7)==0) { tmpint = 0; for(i=7;i<= strlen(tmpchar);i++) tmpchar2[tmpint++] = tmpchar[i]; minfo.icharge = atoi(tmpchar2); continue; } if(strncmp(tmpchar, "multip=", 7)==0) { tmpint = 0; for(i=7;i<= strlen(tmpchar);i++) tmpchar2[tmpint++] = tmpchar[i]; minfo.multiplicity = atoi(tmpchar2); continue; } if (overflow_flag == 0 && flag == 1) { sscanf(line, "%s", atom[numatom].name); if (numatom >= cinfo.maxatom && overflow_flag == 0) { printf ("\nInfo: the atom number exceeds the MAXATOM, reallocate memory automatically"); overflow_flag = 1; } numatom++; continue; } } *atomnum = numatom; rewind(fpin); flag = 0; numatom = 0; for (;;) { if (fgets(line, MAXCHAR, fpin) == NULL) break; strcpy(tmpchar, ""); tmpchar[0]='\0'; sscanf(line, "%s", tmpchar); if(strncmp(tmpchar, "&zmat", 5)==0) { flag =1; continue; } if(strncmp(tmpchar, "&zvar", 5)==0) { flag =2; continue; } if(flag == 1 && strcmp(tmpchar, "&")==0) { flag = 0; if(index == 1) continue; else break; } if(flag == 2 && strcmp(tmpchar, "&")==0) break; if (overflow_flag == 0 && flag == 1) { strcpy(tmpchar1, ""); strcpy(tmpchar2, ""); strcpy(tmpchar3, ""); strcpy(tmpchar4, ""); tmpchar1[0]='\0'; tmpchar2[0]='\0'; tmpchar3[0]='\0'; tmpchar4[0]='\0'; sscanf(line, "%s%s%s%s%s%s%s", tmpchar1, tmpchar2, bondstr[numatom].str, tmpchar3, anglestr[numatom].str, tmpchar4, twiststr[numatom].str); if(numatom > 0) { findindex = 0; for(i=0;i<numatom;i++) { if(strcmp(atom[i].name, tmpchar2)==0){ atom[numatom].bondatom = i; findindex = 1; break; } } if(findindex == 0) { printf("\nThe bond atom (%s) does not appear before %s", tmpchar2, tmpchar1); exit(0); } } if(numatom > 1) { findindex = 0; for(i=0;i<numatom;i++) { if(strcmp(atom[i].name, tmpchar3)==0){ atom[numatom].angleatom = i; findindex = 1; break; } } if(findindex == 0) { printf("\nThe angle atom (%s) does not appear before %s", tmpchar3, tmpchar1); exit(0); } } if(numatom > 2) { findindex = 0; for(i=0;i<numatom;i++) { if(strcmp(atom[i].name, tmpchar4)==0){ atom[numatom].twistatom = i; findindex = 1; break; } } if(findindex == 0) { printf("\nThe torsional angle atom (%s) does not appear before %s", tmpchar4, tmpchar1); exit(0); } } numatom++; } if (flag == 2 && overflow_flag == 0) { for(i=0; i<strlen(line); i++) if(line[i]=='=') line[i]=' '; strcpy(tmpchar1, ""); tmpchar1[0]='\0'; strcpy(tmpchar2, ""); tmpchar2[0]='\0'; strcpy(tmpchar3, ""); tmpchar3[0]='\0'; strcpy(tmpchar4, ""); tmpchar4[0]='\0'; strcpy(tmpchar5, ""); tmpchar5[0]='\0'; strcpy(tmpchar6, ""); tmpchar6[0]='\0'; sscanf(line, "%s%s%s%s%s%s", tmpchar1, tmpchar2, tmpchar3, tmpchar4, tmpchar5, tmpchar6); for(i=0;i<*atomnum;i++) { if(strcmp(bondstr[i].str, tmpchar1)==0) strcpy(bondstr[i].str, tmpchar2); if(strcmp(anglestr[i].str, tmpchar3)==0) strcpy(anglestr[i].str, tmpchar4); if(strcmp(twiststr[i].str, tmpchar5)==0) strcpy(twiststr[i].str, tmpchar6); } } } for (i = 1; i < *atomnum; i++) atom[i].bond = atof(bondstr[i].str); for (i = 2; i < numatom; i++) atom[i].angle = atof(anglestr[i].str); for (i = 3; i < numatom; i++) atom[i].twist = atof(twiststr[i].str); /* printf("\n atom number is %5d", *atomnum); */ fclose(fpin); free(bondstr); free(anglestr); free(twiststr); return overflow_flag; }
int DBF::create ( const char *file, DBfield field[], int numfield ) { if ( _fd >= 0 ) close() ; if ( numfield > MAX_FIELDS ) { _errNo = DB_STRUC_ERR ; return DB_FAILURE ; } #if defined(UNIX) int FD = CREAT(strlwr(makeFileExt(file,".dbf"))) ; #else int FD = CREAT(file) ; #endif if ( FD < 0 ) { _errNo = DB_CREATE_ERR ; return DB_FAILURE ; } int i ; int RS = 1 ; for ( i = 0 ; i < numfield ; i++ ) { RS += field[i].length ; } time_t T = time(NULL) ; tm *t = localtime(&T) ; HEADER h ; _updYear = t->tm_year + 1900; _updMonth = t->tm_mon + 1; _updDay = t->tm_mday; memset(&h,0,sizeof(h)) ; h.signature = DBF_SIGNATURE ; h.date[0] = t->tm_year ; // since 1900 h.date[1] = _updMonth; h.date[2] = _updDay; h.headSize = sizeof(HEADER) + numfield * sizeof(FIELD) + 1 ; h.recSize = RS ; if ( WRITE(FD,&h,sizeof(h)) != sizeof(h) ) { CLOSE(FD) ; _errNo = DB_CREATE_ERR ; return DB_FAILURE ; } char *F ; int sz ; F = new char[sz=numfield*sizeof(FIELD)+1] ; if ( F == NULL ) { CLOSE(FD) ; _errNo = DB_NO_MEMORY ; return DB_FAILURE ; } memset(F,0,sz) ; FIELD *f = (FIELD*)F ; for ( i = 0 ; i < numfield ; i++, f++ ) { strcpy(f->name,field[i].name) ; strupr(f->name) ; f->type = field[i].type ; f->length = field[i].length ; f->decimal = field[i].decimal ; } f->name[0] = 0x0d ; i = WRITE(FD,F,sz) ; delete[] F ; if ( i != sz ) { CLOSE(FD) ; _errNo = DB_CREATE_ERR ; return DB_FAILURE ; } FLUSH(FD) ; _fd = FD ; return initial(&h) ; }
void boundary_trans( struct domain * theDomain , int dim ){ struct cell ** theCells = theDomain->theCells; int Nr = theDomain->Nr; int Nz = theDomain->Nz; int * Np = theDomain->Np; int Ng = theDomain->Ng; double * r_jph = theDomain->r_jph; double * z_kph = theDomain->z_kph; int * dim_rank = theDomain->dim_rank; int * dim_size = theDomain->dim_size; if( dim==1 && dim_rank[0] == dim_size[0]-1 ){ int j; for( j=Nr-1 ; j>Nr-1-Ng ; --j ){ int i,k; for( k=0 ; k<Nz ; ++k ){ int jk = j+Nr*k; for( i=0 ; i<Np[jk] ; ++i ){ struct cell * c = &(theCells[jk][i]); double phi = c->piph - .5*c->dphi; double x[3] = { .5*(r_jph[j]+r_jph[j-1]) , phi , .5*(z_kph[k]+z_kph[k-1]) }; initial( c->prim , x ); } } } } if( dim==2 && dim_rank[1] == 0 ){ int i,j,k; for( k=0 ; k<Ng ; ++k ){ for( j=0 ; j<Nr ; ++j ){ int jk = j+Nr*k; for( i=0 ; i<Np[jk] ; ++i ){ struct cell * c = &(theCells[jk][i]); double phi = c->piph - .5*c->dphi; double xp[3] = { r_jph[j] , c->piph , z_kph[k] }; double xm[3] = { r_jph[j-1] , c->piph-.5*c->dphi , z_kph[k-1] }; double r = get_moment_arm( xp , xm ); double x[3] = { r , phi , .5*(z_kph[k]+z_kph[k-1]) }; //double x[3] = { .5*(r_jph[j]+r_jph[j-1]) , phi , .5*(z_kph[k]+z_kph[k-1]) }; initial( c->prim , x ); } } } } if( dim==2 && dim_rank[1] == dim_size[1]-1 ){ int i,j,k; for( k=Nz-1 ; k>Nz-1-Ng ; --k ){ for( j=0 ; j<Nr ; ++j ){ int jk = j+Nr*k; for( i=0 ; i<Np[jk] ; ++i ){ struct cell * c = &(theCells[jk][i]); double phi = c->piph - .5*c->dphi; double xp[3] = { r_jph[j] , c->piph , z_kph[k] }; double xm[3] = { r_jph[j-1] , c->piph-.5*c->dphi , z_kph[k-1] }; double r = get_moment_arm( xp , xm ); double x[3] = { r , phi , .5*(z_kph[k]+z_kph[k-1]) }; //double x[3] = { .5*(r_jph[j]+r_jph[j-1]) , phi , .5*(z_kph[k]+z_kph[k-1]) }; initial( c->prim , x ); } } } } }
int main(int argc,char* argv[]) { char *str = new char[MAXSIZE],*p; int Port_BDS = atoi(argv[2]); int Port_FC = atoi(argv[3]); sockfd_BDS = Socket(); sockfd_FC = Socket(); struct sockaddr_in servself_addr,client_addr,servBDS_addr; struct hostent *host; int nread; socklen_t len; Bind(sockfd_FC,servself_addr,Port_FC); Listen(sockfd_FC,5); printf("The FS is listening\n"); bzero(&servBDS_addr,sizeof(servBDS_addr)); servBDS_addr.sin_family = AF_INET; host = gethostbyname(argv[1]); memcpy(&servBDS_addr.sin_addr.s_addr,host->h_addr,host->h_length); servBDS_addr.sin_port = htons(Port_BDS); connect(sockfd_BDS,(struct sockaddr*)&servBDS_addr,sizeof(servBDS_addr)); initial(); while (1) { len = sizeof(client_addr); client_sockfd = accept(sockfd_FC,(struct sockaddr *) &client_addr, &len); printf("Connect successfully\n"); bzero(SendToFC,sizeof(SendToFC)); strcat(SendToFC,CurrentInode.Name); strcat(SendToFC," $ "); Write(client_sockfd,SendToFC,strlen(SendToFC)); while (1) { bzero(ReceFromFC,sizeof(ReceFromFC)); int n = Read(client_sockfd,ReceFromFC,MAXSIZE); Write(STDOUT_FILENO,ReceFromFC,strlen(ReceFromFC)); // Show(CurrentInode,CurrentData); strcpy(str,ReceFromFC); p = str; str = strtok(str," \n"); if (0 == strcmp(str,"f")) Format(); else if (0 == strcmp(str,"mk")) /*Create a file*/ { str = strtok(NULL," \n"); Createfile(str,0); } else if (0 == strcmp(str,"mkdir")) /*Create a folder*/ { str = strtok(NULL," \n"); Createfile(str,1); } else if (0 == strcmp(str,"rm")) /*Remove a file*/ { str = strtok(NULL," \n"); Removefile(str,0); } else if (0 == strcmp(str,"cd")) /*Change path*/ { str = strtok(NULL," \n"); Changedir(str); HandleError("cdok!\n"); } else if (0 == strcmp(str,"rmdir")) { str = strtok(NULL," \n"); /*Remove a folder*/ Removefile(str,1); } else if (0 == strcmp(str,"ls")) { str = strtok(NULL," \n"); List(str); } else if (0 == strcmp(str,"cat")) /*Catch a file*/ { str = strtok(NULL," \n"); Catchfile(str); printf("Catch ok!\n"); } else if (0 == strcmp(str,"w")) { str = strtok(NULL,"\n"); WriteData(str); } else if (0 == strcmp(str,"a")) { str = strtok(NULL,"\n"); Append(str); } else if (0 == strcmp(str,"exit")) Exit(); else { HandleError("2:Unavailable command\n"); } bzero(SendToFC,sizeof(SendToFC)); strcat(SendToFC,CurrentInode.Name); strcat(SendToFC," $ "); Write(client_sockfd,SendToFC,strlen(SendToFC)); } Close(client_sockfd); } Close(sockfd_BDS); Close(sockfd_FC); }
void do_rename (CHAR_DATA* ch, char* argument) { char old_name[MAX_INPUT_LENGTH], new_name[MAX_INPUT_LENGTH], strsave [MAX_INPUT_LENGTH]; CHAR_DATA* victim; FILE* file; argument = one_argument(argument, old_name); /* find new/old name */ one_argument (argument, new_name); /* Trivial checks */ if (!old_name[0]) { send_to_char ("Rename who?\n\r",ch); return; } victim = get_char_world (ch, old_name); if (!victim) { send_to_char ("There is no such a person online.\n\r",ch); return; } if (IS_NPC(victim)) { send_to_char ("You cannot use Rename on NPCs.\n\r",ch); return; } /* allow rename self new_name,but otherwise only lower level */ if ( (victim != ch) && (get_trust (victim) >= get_trust (ch)) ) { send_to_char ("You failed.\n\r",ch); return; } if (!victim->desc || (victim->desc->connected != CON_PLAYING) ) { send_to_char ("This player has lost his link or is inside a pager or the like.\n\r",ch); return; } if (!new_name[0]) { send_to_char ("Rename to what new name?\n\r",ch); return; } /* Insert check for clan here!! */ /* if (victim->clan) { send_to_char ("This player is member of a clan, remove him from there first.\n\r",ch); return; } */ if (!check_parse_name(new_name)) { send_to_char ("The new name is illegal.\n\r",ch); return; } /* First, check if there is a player named that off-line */ #if !defined(machintosh) && !defined(MSDOS) sprintf( strsave, "%s%s%s%s", PLAYER_DIR, initial( new_name ), "/", capitalize( new_name ) ); #else sprintf( strsave, "%s%s", PLAYER_DIR, capitalize( new_name ) ); #endif fclose (fpReserve); /* close the reserve file */ file = fopen (strsave, "r"); /* attempt to to open pfile */ if (file) { send_to_char ("A player with that name already exists!\n\r",ch); fclose (file); fpReserve = fopen( NULL_FILE, "r" ); /* is this really necessary these days? */ return; } fpReserve = fopen( NULL_FILE, "r" ); /* reopen the extra file */ /* Check .gz file ! */ #if !defined(machintosh) && !defined(MSDOS) sprintf( strsave, "%s%s%s%s.gz", PLAYER_DIR, initial( new_name ), "/", capitalize( new_name ) ); #else sprintf( strsave, "%s%s.gz", PLAYER_DIR, capitalize( new_name ) ); #endif fclose (fpReserve); /* close the reserve file */ file = fopen (strsave, "r"); /* attempt to to open pfile */ if (file) { send_to_char ("A player with that name already exists in a compressed file!\n\r",ch); fclose (file); fpReserve = fopen( NULL_FILE, "r" ); return; } fpReserve = fopen( NULL_FILE, "r" ); /* reopen the extra file */ if (get_char_world(ch,new_name)) /* check for playing level-1 non-saved */ { send_to_char ("A player with the name you specified already exists!\n\r",ch); return; } /* Save the filename of the old name */ #if !defined(machintosh) && !defined(MSDOS) sprintf( strsave, "%s%s%s%s", PLAYER_DIR, initial( victim->name ), "/", capitalize( victim->name ) ); #else sprintf( strsave, "%s%s", PLAYER_DIR, capitalize( victim->name ) ); #endif /* Rename the character and save him to a new file */ /* NOTE: Players who are level 1 do NOT get saved under a new name */ free_string (victim->name); victim->name = str_dup (capitalize(new_name)); save_char_obj (victim); /* unlink the old file */ unlink (strsave); /* unlink does return a value.. but we do not care */ /* That's it! */ send_to_char ("Character renamed.\n\r",ch); victim->position = POS_STANDING; /* I am laaazy */ act ("$n has renamed you to $N!",ch,NULL,victim,TO_VICT); } /* do_rename */
static void crate_has_changed(struct selector *sel) { (void)listing_match(initial(sel), sel->view_listing, sel->search); scroll_set_entries(&sel->records, sel->view_listing->entries); retain_position(sel); }
void ColorMap::setRange(float minValue,float maxValue) { max = maxValue; min = minValue; initial(); }
// observe the raw infomation, but just like human ut will use some method to filter the noice // this is just for one robot void RobotTracker::observe(VisionRawInfo obs, double timestamp) { //如果有1秒没有来更新信号,自动复位,防止繁殖的程序内存不够 if(timestamp-time>0.5) { printf("Robot obvserve reset\r\n"); reset_on_observation = true; } // if there is no renew signal // if the observation has been reset if (reset_on_observation) { if (obs.conf <= 0.0) { return; } static Matrix observe_matrix(7,1), P(7); observe_matrix.e(0,0) = obs.pos.x; observe_matrix.e(1,0) = obs.pos.y; observe_matrix.e(2,0) = obs.angle; observe_matrix.e(3,0) = 0.0; observe_matrix.e(4,0) = 0.0; observe_matrix.e(5,0) = 0.0; observe_matrix.e(6,0) = 0.0; P.e(0,0) = DVAR(ROBOT_POSITION_VARIANCE); P.e(1,1) = DVAR(ROBOT_POSITION_VARIANCE); P.e(2,2) = DVAR(ROBOT_THETA_VARIANCE); P.e(3,3) = 0.0; // 0m/s if (type == ROBOT_TYPE_DIFF) { P.e(4,4) = 0.0; } else { P.e(4,4) = 0.0; // 0m/s } P.e(5,5) = 0.0; P.e(6,6) = 0.0; initial(obs.timestamp, observe_matrix, P); reset_on_observation = false; } else { // If this is a new observation. if (timestamp > time) { // Tick to current time. tick(timestamp - time); // Make observation if (obs.timestamp == timestamp) { double xtheta = xs[0].e(2,0); Matrix o(3,1); o.e(0,0) = obs.pos.x; o.e(1,0) = obs.pos.y; o.e(2,0) = anglemod(obs.angle - xtheta) + xtheta; update(o); } if (error_time_elapsed() > 10.0) { fprintf(stderr, "Kalman Error (pos, theta, vpos, vtheta): "); fprintf(stderr, "%f ", hypot(error_mean().e(0, 0), error_mean().e(1, 0))); fprintf(stderr, "%f ", error_mean().e(2, 0)); fprintf(stderr, "%f ", hypot(error_mean().e(3, 0), error_mean().e(4, 0))); fprintf(stderr, "%f\n", error_mean().e(5, 0)); error_reset(); } } } }
int Pserv13() { initial(); clear(); mvaddstr( 2, 0, "================================================================================"); mvaddstr(5, 0, " CI 服 务 申 请 "); mvaddstr( 8, 0, "================================================================================"); mvaddstr(10, 4, " 请选择您需要的使用期限: "); mvaddstr(12, 4, " [1] . 1个工作日; "); mvaddstr(13, 4, " [2] . 2个工作日; "); mvaddstr(14, 4, " [3] . 3个工作日; "); mvaddstr(15, 4, " [4] . 5个工作日(需邮件申请); "); mvaddstr(16, 4, " [5] . 10个工作日(需邮件申请); "); mvaddstr(17, 4, " [6] . 退出 "); int ch, opt=0; mvaddstr(12+opt, 1, "->"); do { ch=getch(); switch (ch) { case KEY_UP: if (opt!=0) { opt--; } else { opt+=5; } break; case KEY_DOWN: if (opt!=5) { opt++; } else { opt-=5; } break; case KEY_RIGHT: return opt; break; case KEY_LEFT: return -1; break; case '\r': return opt; break; default: break; } mvaddstr(12, 1, " "); mvaddstr(13, 1, " "); mvaddstr(14, 1, " "); mvaddstr(15, 1, " "); mvaddstr(16, 1, " "); mvaddstr(17, 1, " "); mvaddstr(12+opt, 1, "->"); } while (1); return -2; }
main(){ int X[V][2]={{0, 7}, {1, 0}, {1, 11}, {1, 19}, {2, 12}, {2, 13}, {3, 13}, {3, 17}, {4, 16}, {4, 18}, {5, 0}, {5, 5}, {5, 8}, {5, 10}, {5, 15}, {6, 1}, {6, 9}, {6, 11}, {7, 4}, {7, 13}, {8, 4}, {8, 14}, {8, 18}, {10, 7}, {11, 2}, {12, 0}, {12, 2}, {12, 3}, {13, 17}, {14, 17}, {15, 7}, {15, 12}, {15, 13}, {15, 15}, {16, 0}, {16, 2}, {16, 6}, {16, 9}, {17, 5}, {17, 17}, {18, 0}, {18, 6}, {18, 17}, {19, 1}, {19, 2}, {21, 9}, {21, 10}, {22, 1}, {22, 5}, {22, 11}, {22, 17}, {22, 18}, {23, 19}, {24, 2}, {24, 3}, {24, 13}, {25, 5}, {25, 11}, {26, 9}, {26, 16}, {27, 4}, {27, 11}, {27, 19}, {28, 0}, {28, 4}, {28, 11}, {29, 19}, {30, 4}, {31, 8}, {31, 10}, {31, 11}, {31, 18}, {32, 1}, {32, 8}, {33, 10}, {33, 14}, {33, 17}, {33, 19}, {34, 4}, {35, 2}, {36, 0}, {36, 6}, {37, 7}, {37, 9}, {38, 13}, {39, 13}, {39, 14}, {39, 15}, {39, 19}}; int i,j; double distance[V][V]={0.0}; double* ptrD=&distance[0][0]; for(i=0;i<V;i++) for(j=0;j<V;j++){ //printf("%d to %d is %lf\n",i,j,distance[i][j]); distance[i][j]=sqrt(pow(X[i][0]-X[j][0],2)+pow(X[i][1]-X[j][1],2)); printf("%d to %d is %lf\n",i,j,distance[i][j]); } int start=-1; double tourLength; double minLength=1000000.0; int* goodT=malloc(sizeof(int)*V); for(i=0;i<V;i++){ tourLength=0.0; int* tour=malloc(sizeof(int)*V); tour=initial(ptrD,i); for(j=0;j<V;j++) tourLength+=distance[j][*(tour+j)]; printf("Starting from vertex %d, the tour length is %lf\n",i,tourLength); if(tourLength<minLength){ minLength=tourLength; goodT=initial(ptrD,i); start=i; } free(tour); } printf("it starts from node %d\n",start); FILE* output; if((output=fopen("I3output.txt","w"))==NULL) printf("\nerror!Fail to open file!"); else printf("\nOpen I3output successfully!\n"); fprintf(output,"##This is the output of I1\n\n#Coordinates\n"); for(i=0;i<V;i++) fprintf(output,"%d %d %d\n",i,X[i][0],X[i][1]); fprintf(output,"\n\n#Tour\n"); i=0; do{ fprintf(output,"%d %d (%d) to %d %d (%d) distance %lf\n",X[i][0],X[i][1],i,X[*(goodT+i)][0],X[*(goodT+i)][1],*(goodT+i),distance[i][*(goodT+i)]); i=*(goodT+i); } while(i!=0); fprintf(output,"%d %d (%d)\n",X[0][0],X[0][1],i); fprintf(output,"%lf\n",minLength); //double originalLength=minLength; double updatedLength=minLength; int k,l; int moving; int stop; int first; int second; int update=1; int totalNodes; while(update==1){ update=0; for(i=0;i<V;i++) for(j=0;j<V;j++) if(i!=j&&j!=*(goodT+i)&&*(goodT+j)!=i&&j!=*(goodT+*(goodT+i))){ if(updatedLength>minLength-distance[i][*(goodT+i)]-distance[j][*(goodT+j)]+distance[*(goodT+i)][*(goodT+j)]+distance[i][j]){ updatedLength=minLength-distance[i][*(goodT+i)]-distance[j][*(goodT+j)]+distance[*(goodT+i)][*(goodT+j)]+distance[i][j]; moving=*(goodT+i); stop=j; first=i; second=j; update=1; l=*(goodT+second); printf("better tour is found (i=%d j=%d new length=%lf).\n",i,j,updatedLength); } } printf("%d connects to %d\n",second,*(goodT+second)); if(update==1){ totalNodes=1; k=moving; while(k!=stop){ totalNodes++; k=*(goodT+k);//printf("moving=%d stop=%d first=%d second=%d\n",moving,stop,first,second); } //printf("k = %d\n",totalNodes); int* segement=malloc(sizeof(int)*totalNodes); for(k=0;k<totalNodes;k++){ *(segement+k)=moving; moving=*(goodT+moving); }//printf("test\n"); for(k=totalNodes;k>1;k--) *(goodT+*(segement+k-1))=*(segement+k-2); free(segement); // if(*(goodT+k)==moving){ // *(goodT+moving)=k; // moving=k; // break; // } minLength=updatedLength; *(goodT+*(goodT+first))=l; //printf("%d connects to %d\n",second,*(goodT+second)); *(goodT+first)=second; //printf("update soluting...\n"); } } double finalD=0.0; fprintf(output,"\n\n#Improved Tour\n"); i=0; do{ fprintf(output,"%d %d (%d) to %d %d (%d) distance %lf\n",X[i][0],X[i][1],i,X[*(goodT+i)][0],X[*(goodT+i)][1],*(goodT+i),distance[i][*(goodT+i)]); i=*(goodT+i); finalD+=distance[i][*(goodT+i)]; } while(i!=0); fprintf(output,"%d %d (%d)\n\n",X[0][0],X[0][1],i); fprintf(output,"%lf %lf\n",minLength,finalD); fclose(output); free(goodT); }
int arms (double *xinit, int ninit, double *xl, double *xr, double (*myfunc)(double x, double *mydata), double *mydata, // double (*myfunc)(double x, void *mydata), void *mydata, double *convex, int npoint, int dometrop, double *xprev, double *xsamp, int nsamp, double *qcent, double *xcent, int ncent, int *neval) /* to perform derivative-free adaptive rejection sampling with metropolis step */ /* *xinit : starting values for x in ascending order */ /* ninit : number of starting values supplied */ /* *xl : left bound */ /* *xr : right bound */ /* *myfunc : function to evaluate log-density */ /* *mydata : data required by *myfunc */ /* *convex : adjustment for convexity */ /* npoint : maximum number of envelope points */ /* dometrop : whether metropolis step is required */ /* *xprev : previous value from markov chain */ /* *xsamp : to store sampled values */ /* nsamp : number of sampled values to be obtained */ /* *qcent : percentages for envelope centiles */ /* *xcent : to store requested centiles */ /* ncent : number of centiles requested */ /* *neval : on exit, the number of function evaluations performed */ { ENVELOPE *env; /* rejection envelope */ POINT pwork; /* a working point, not yet incorporated in envelope */ int msamp=0; /* the number of x-values currently sampled */ FUNBAG lpdf; /* to hold density function and its data */ METROPOLIS *metrop; /* to hold bits for metropolis step */ int i,err=0; /* check requested envelope centiles */ for(i=0; i<ncent; i++){ if((qcent[i] < 0.0) || (qcent[i] > 100.0)){ /* percentage requesting centile is out of range */ return 1005; } } /* incorporate density function and its data into FUNBAG lpdf */ lpdf.mydata = mydata; lpdf.myfunc = myfunc; /* set up space required for envelope */ env = (ENVELOPE *)malloc(sizeof(ENVELOPE)); if(env == NULL){ /* insufficient space */ return 1006; } /* start setting up metropolis struct */ metrop = (METROPOLIS *)malloc(sizeof(METROPOLIS)); if(metrop == NULL){ /* insufficient space */ return 1006; } metrop->on = dometrop; /* set up initial envelope */ err = initial(xinit,ninit,*xl,*xr,npoint,&lpdf,env,convex, neval,metrop); if(err) return err; /* finish setting up metropolis struct (can only do this after */ /* setting up env) */ if(metrop->on){ if((*xprev < *xl) || (*xprev > *xr)){ /* previous markov chain iterate out of range */ return 1007; } metrop->xprev = *xprev; metrop->yprev = perfunc(&lpdf,env,*xprev); } /* now do adaptive rejection */ do { /* sample a new point */ err=sample(env,&pwork); /* perform rejection (and perhaps metropolis) tests */ i = test(env,&pwork,&lpdf,metrop); if(i == 1){ /* point accepted */ xsamp[msamp++] = pwork.x; } else if (i != 0) { /* envelope error - violation without metropolis */ return 2000; } } while (msamp < nsamp); /* nsamp points now sampled */ /* calculate requested envelope centiles */ if(err==0) for (i=0; i<ncent; i++){ err=invert(qcent[i]/100.0,env,&pwork); xcent[i] = pwork.x; } /* free space */ free(env->p); free(env); free(metrop); return err; }
DBstatus varkon_sur_epts ( /*-------------- Argument declarations -----------------------------*/ /* */ /* In: */ DBSurf *p_sur, /* Surface (ptr) */ DBPatch *p_pat, /* Alloc. area for topol. patch data (ptr) */ IRUNON *p_comp, /* Computation data (ptr) */ PBOUND *p_pbtable, /* Patch boundary table (ptr) */ DBint pbn, /* Number of records in pbtable */ EPOINT *p_etable, /* Entry/exit point table (ptr) */ DBint *p_en ) /* Number of records in etable */ /* Out: */ /* Enter/exit points in EPOINT table and no records */ /*-----------------------------------------------------------------!*/ { /* Start of function */ /*!--------------- Internal variables ------------------------------*/ /* */ DBint ir; /* Loop index corresp. to PBOUND record */ DBint numrec; /* Record number */ DBint ctype; /* Case of computation */ BBOX pbox; /* Bounding box for the (PBOUND) patch */ BCONE pcone; /* Bounding cone for the (PBOUND) patch */ /* */ /*-----------------------------------------------------------------!*/ DBint i_r; /* Loop indec record */ EVALC ecrec; /* Record curve point and derivatives */ EVALS esrec; /* Record surface point and derivatives */ DBint sflag; /* Eq. -1: No solution Eq. 1: Solution */ DBint bcase; /* Eq. 1: u0 Eq. 2: u1 Eq. 3: v0 Eq. 4: v1 */ DBint all_b_anal[4]; /* Boundary point case for all boundaries */ /* Eq. 0: No points */ /* Eq. 1: Normal points */ /* Eq. 2: Curve coincides w. isoparameter */ short b_flag; /* Boundary point case */ char errbuf[80]; /* String for error message fctn erpush */ DBint ix1; /* Temporarely used loop index */ DBint n_select; /* Number of selected patches */ DBint status; /* Error code from a called function */ /*--------------end-of-declarations---------------------------------*/ /*! */ /* Algorithm */ /* ========= */ /* !*/ /*! */ /* 1. Check of input data and initializations */ /* __________________________________________ */ /* Initialize output coordinates and derivatives for DEBUG on. */ /* Call of initial, which also prints out the input data. */ /* !*/ b_flag = I_UNDEF; /* Printout of input data is in function initial */ #ifdef DEBUG status=initial(p_sur,p_pat,p_comp,p_pbtable,pbn,p_etable,p_en); if (status<0) { sprintf(errbuf,"initial%%varkon_sur_epts (sur920)"); return(varkon_erpush("SU2973",errbuf)); } #endif /* Initialize variabels xyz_ */ /* Calls of varkon_ini_evalc (sur776) and _ini_evals (sur770) */ /* !*/ for (i_r=1; i_r<= 9; i_r= i_r+1) { varkon_ini_evalc (&ecrec); curpt[i_r-1] = ecrec; varkon_ini_evals (&esrec); xyzpt[i_r-1] = esrec; } all_b_anal[0] = I_UNDEF; /* Boundary point case */ all_b_anal[1] = I_UNDEF; all_b_anal[2] = I_UNDEF; all_b_anal[3] = I_UNDEF; /*! */ /* Case of computation ctype from p_comp */ /* !*/ ctype = p_comp->ipl_un.ctype; /*! */ /* 2. Calculate all entry exit points */ /* __________________________________ */ /* */ /* !*/ /*! */ /* Initiate loop variables: */ numpts = 0; /* Loop all records in PBOUND table ir=0,1,....,pbn */ /* !*/ n_select = 0; /* Number of selected patches */ for ( ir=0; ir< pbn; ++ir ) /* Start loop PBOUND */ { n_patch = 0; /* No pts in one patch */ /*! */ /* Data from the PBOUND table: */ p_cr= p_pbtable + ir; /* Ptr to current record */ numrec=p_cr->rec_no; /* Record number */ u_s =p_cr->us; /* U start point */ v_s =p_cr->vs; /* V start point */ u_e =p_cr->ue; /* U end point */ v_e =p_cr->ve; /* V end point */ pbox =p_cr->pbox; /* BBOX */ pcone =p_cr->pcone; /* BCONE */ /* !*/ /*! */ /* Check if there is a solution for the bounding box or cone. */ /* Call of varkon_pat_chebound (sur914). */ /* Goto nosol if there is no solution in the patch. */ /* !*/ status=varkon_pat_chebound (p_sur,p_pat,p_comp,u_s,u_e,v_s,v_e,&pbox,&pcone,&sflag); if (status<0) { sprintf(errbuf,"varkon_pat_chebound(sur914)%%varkon_sur_epts"); return(varkon_erpush("SU2943",errbuf)); } if ( sflag == -99 ) /* Surface patch is not OK */ { p_cr->nu0 = 0; /* No solutions to PBOUND */ p_cr->nu1 = 0; p_cr->nv0 = 0; p_cr->nv1 = 0; goto nosol; } if ( sflag == -1 ) { p_cr->nu0 = 0; /* No solutions to PBOUND */ p_cr->nu1 = 0; p_cr->nv0 = 0; p_cr->nv1 = 0; goto nosol; } n_select = n_select + 1; /* Number of selected patches */ /*! */ /* Find solution points on curve segment U= u_s for V= v_s to v_e */ /* (u_s,v_s,u_e,v_e to the varkon_sur_num1 t_in variable) */ /* Call of boundary. */ /* !*/ t_in[0][0] = u_s; /* Start U */ t_in[0][1] = v_s; /* Start V */ t_in[1][0] = u_s; /* End U */ t_in[1][1] = v_e; /* End V */ bcase = 1; /* Boundary u= u_s */ status=boundary(p_sur,p_pat,p_comp,bcase); if (status<0) { sprintf(errbuf,"boundary u0%%varkon_sur_epts (sur920)"); return(varkon_erpush("SU2973",errbuf)); } all_b_anal[bcase-1] = b_anal; /* Boundary point case */ /*! */ /* Find solution points on curve segment U= u_e for V= v_s to v_e */ /* (u_s,v_s,u_e,v_e to the varkon_sur_num1 t_in variable) */ /* Call of boundary. */ /* !*/ t_in[0][0] = u_e; /* Start U */ t_in[0][1] = v_s; /* Start V */ t_in[1][0] = u_e; /* End U */ t_in[1][1] = v_e; /* End V */ bcase = 2; /* Boundary u= u_e */ status=boundary(p_sur,p_pat,p_comp,bcase); if (status<0) { sprintf(errbuf,"boundary u0%%varkon_sur_epts (sur920)"); return(varkon_erpush("SU2973",errbuf)); } all_b_anal[bcase-1] = b_anal; /* Boundary point case */ /*! */ /* No constant V for S_SILH calculation (goto novlin in this case) */ /* */ /* Find solution points on curve segment V= v_s for U= u_s to u_e */ /* (u_s,v_s,u_e,v_e to the varkon_sur_num1 t_in variable) */ /* Call of boundary. */ /* !*/ if ( ctype == S_SILH ) goto novlin; t_in[0][0] = u_s; /* Start U */ t_in[0][1] = v_s; /* Start V */ t_in[1][0] = u_e; /* End U */ t_in[1][1] = v_s; /* End V */ bcase = 3; /* Boundary v= v_s */ status=boundary(p_sur,p_pat,p_comp,bcase); if (status<0) { sprintf(errbuf,"boundary v_s%%varkon_sur_epts (sur920)"); return(varkon_erpush("SU2973",errbuf)); } all_b_anal[bcase-1] = b_anal; /* Boundary point case */ /*! */ /* Find solution points on curve segment V= v_e for U= u_s to u_e */ /* (u_s,v_s,u_e,v_e to the varkon_sur_num1 t_in variable) */ /* Call of boundary. */ /* !*/ t_in[0][0] = u_s; /* Start U */ t_in[0][1] = v_e; /* Start V */ t_in[1][0] = u_e; /* End U */ t_in[1][1] = v_e; /* End V */ bcase = 4; /* Boundary v= v_e */ status=boundary(p_sur,p_pat,p_comp,p_etable,bcase); if (status<0) { sprintf(errbuf,"boundary v_e%%varkon_sur_epts (sur920)"); return(varkon_erpush("SU2973",errbuf)); } all_b_anal[bcase-1] = b_anal; /* Boundary point case */ novlin:;/*!Label:novlin: No constant V lines !*/ nosol: /*!Label nosol: There is no solution in the patch !*/ /*! */ /* Printout of calculated entry/exit points For Debug On */ /* Call of pripts (if n_patch > 2 or = 1) */ /* !*/ #ifdef DEBUG if ( n_patch > 2 ) pripts(); if ( n_patch == 1 ) pripts(); #endif /*! */ /* Flag for no points in patch, normal points or two points for */ /* an iso-parametric segment (b_flag= 0, 1 and 2 resp.) */ /* !*/ if ( n_patch == 0 ) b_flag = 0; else if ( n_patch == 1 ) b_flag = 1; else if ( n_patch > 2 ) b_flag = 1; else if ( n_patch == 2 ) { if (all_b_anal[0] == 2 || /* */ all_b_anal[1] == 2 || /* */ all_b_anal[2] == 2 || /* */ all_b_anal[3] == 2 ) /* */ b_flag = 2; else /* */ b_flag = 1; } /*! */ /* Calculate all UV tangents */ /* Call of varkon_sur_uvtang (sur926). */ /* Tangents from curpt to u1_t,v1_t,u2_t,v2_t. */ /* !*/ if ( n_patch > 0 ) { status=varkon_sur_uvtang (n_patch,xyzpt,curpt,p_comp,b_flag); if (status<0) { sprintf(errbuf,"varkon_sur_uvtang(sur926)%%varkon_sur_epts"); return(varkon_erpush("SU2943",errbuf)); } u1_t=curpt[0].u_t; v1_t=curpt[0].v_t; u2_t=curpt[1].u_t; v2_t=curpt[1].v_t; } if ( n_patch == 1 ) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur920 Only one entry/exit pt u_s %f v_s %f u_e %f v_e %f\n", u_s ,v_s ,u_e ,v_e ); } #endif n_patch = 0; /* ???? 1994-04-10 Not handled !!! */ /* !! goto nosol; ???? 1994-04-10 Not handled !!! */ } if ( n_patch == 2 ) { /*! */ numpts = numpts+1; /* Patch with enter/exit pt*/ (p_etable+numpts-1)->rec_no=numpts; /* Record number */ (p_etable+numpts-1)->u1=u1; /* Point 1 */ (p_etable+numpts-1)->v1=v1; /* Point 1 */ (p_etable+numpts-1)->u2=u2; /* Point 2 */ (p_etable+numpts-1)->v2=v2; /* Point 2 */ (p_etable+numpts-1)->u1_t=u1_t; /* Tangent to point 1 */ (p_etable+numpts-1)->v1_t=v1_t; /* */ (p_etable+numpts-1)->u2_t=u2_t; /* Tangent to point 2 */ (p_etable+numpts-1)->v2_t=v2_t; /* */ (p_etable+numpts-1)->ptr1=0; /* Ptr to patch with eq. pt*/ (p_etable+numpts-1)->ptr2=0; /* Ptr to patch with eq. pt*/ (p_etable+numpts-1)->us=u_s; /* Patch limit start point */ (p_etable+numpts-1)->vs=v_s; /* */ (p_etable+numpts-1)->ue=u_e; /* Patch limit end point */ (p_etable+numpts-1)->ve=v_e; /* */ (p_etable+numpts-1)->b_flag= b_flag; /* Boundary flag */ (p_etable+numpts-1)->d_flag=3; /* Derivative flag */ /* Local curpt to EPOINT curpt for n_patch == 2 */ for (ix1 = 1; ix1 <= n_patch; ix1 = ix1+1) { (p_etable+numpts-1)->curpt[ix1-1]=curpt[ix1-1]; } /* !*/ } /* End n_patch == 2 */ /* Local curpt to EPOINT curpt for n_patch > 2 1996-09-26 */ if ( n_patch > 2 ) { #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur920 NOT_EXPECTED_ANY_MORE n_patch= %d numpts= %d\n", (int)n_patch, (int)numpts); } #endif /* Should be handled in sur900 1996-09-26 */ /* The case n_patch > 2 is not handled !!!!! */ #ifdef NOT_HANDLED_CASE for (ix1 = 1; ix1 <= n_patch; ix1 = ix1+1) { (p_etable+numpts-1)->curpt[ix1-1]=curpt[ix1-1]; } #endif } if ( numpts > EPMAX ) { sprintf(errbuf, "(EPMAX)%%varkon_sur_epts"); return(varkon_erpush("SU2993",errbuf)); } } /* End loop PBOUND */ /*! */ /* End all records in PBOUND ir=0,1,....,pbn */ /* !*/ /*! */ /* 3. Exit */ /* _______ */ /* */ /* Number of solutions to output variable */ *p_en = numpts; /* */ /* Exit with error if *p_en= 0 */ /* !*/ if ( *p_en == 0 ) { varkon_erinit(); sprintf(errbuf,"varkon_sur_epts%% "); return(varkon_erpush("SU2783",errbuf)); } #ifdef DEBUG if ( dbglev(SURPAC) == 1 ) { if (numpts > 0 ) { for (ix1 = 1; ix1 <= numpts ; ix1 = ix1+1) { fprintf(dbgfil(SURPAC), "sur920 %d p1 %15.10f %15.10f p2 %15.10f %15.10f\n", (int)ix1, (p_etable+ix1-1)->u1, (p_etable+ix1-1)->v1, (p_etable+ix1-1)->u2, (p_etable+ix1-1)->v2 ); } } } if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur920 Number of patches with possible solution n_select = %d\n", (int)n_select ); } if ( dbglev(SURPAC) == 1 ) { fprintf(dbgfil(SURPAC), "sur920 Exit *** varkon_sur_epts **No records in EPOINT*** = %d\n", (int)*p_en ); } #endif return(SUCCED); } /* End of function */