string _db_create_field_sql(string name, map<string, string> spec) { string sql; _db_process_field( spec ); sql = "`" + name + "` " + spec["mysql_type"]; if ( (spec["type"] == "varchar" || spec["type"] == "char" || spec["type"] == "text") && isset(spec["length"]) ) { sql += "(" + spec["length"] + ")"; } else if (isset(spec["precision"]) && isset(spec["scale"])) { sql += "(" + spec["precision"] + ", " + spec["scale"] + ")"; } if (!spec["unsigned"].empty()) { sql += " unsigned"; } if (spec["not null"] == _TRUE) { sql += " NOT NULL"; } if (!spec["auto_increment"].empty()) { sql += " auto_increment"; } if (inarray( spec, "default")) { if ( !is_numeric(spec["default"]) ) { spec["default"] = "\"" + spec["default"] + "\""; } sql += " DEFAULT " + spec["default"]; } if (spec["not null"].empty() && !isset(spec["default"])) { sql += " DEFAULT NULL"; } return sql; }
void FilterEnergyBase::v_Initialise( const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time) { m_index = -1; MultiRegions::ExpListSharedPtr areaField; ASSERTL0(pFields[0]->GetExpType() != MultiRegions::e3DH2D, "Homogeneous 2D expansion not supported" "for energy filter"); if (pFields[0]->GetExpType() == MultiRegions::e3DH1D) { m_homogeneous = true; } // Calculate area/volume of domain. if (m_homogeneous) { m_planes = pFields[0]->GetZIDs(); areaField = pFields[0]->GetPlane(0); } else { areaField = pFields[0]; } Array<OneD, NekDouble> inarray(areaField->GetNpoints(), 1.0); m_area = areaField->Integral(inarray); if (m_homogeneous) { m_area *= m_homogeneousLength; } // Output values at initial time. v_Update(pFields, time); }
/* * Put group information in user tables. */ void usergroup(const char *name, gid_t gid, char **mem) { struct login *lp; struct grp *gp; size_t sz; for (lp = l0; lp; lp = lp->l_next) { sz = strlen(name); if (lp->l_grp->g_gid == gid) { lp->l_grp->g_name = salloc(sz + 1); strcpy(lp->l_grp->g_name, name); } if (inarray(lp->l_name, mem)) { for (gp = lp->l_grp; gp->g_next; gp = gp->g_next); gp->g_next = (struct grp *)salloc(sizeof *gp); gp = gp->g_next; gp->g_next = NULL; gp->g_name = salloc(sz + 1); strcpy(gp->g_name, name); gp->g_gid = gid; } } }
int main() { int arr[50],index,num,i; printf("\nenter the size of array"); scanf("%d",&n); printf("enter array elements"); for(i=0;i<n;i++) { scanf("%d",&arr[i]); } printf("enter the number to be found"); scanf("%d",&num); index=inarray(arr,num); if(index==-1) { printf("number not found in array"); } else { printf("the num %d is found at %d index",num,index); } }
void EigenValuesAdvection::v_DoSolve() { int nvariables = 1; int i,dofs = GetNcoeffs(); //bool UseContCoeffs = false; Array<OneD, Array<OneD, NekDouble> > inarray(nvariables); Array<OneD, Array<OneD, NekDouble> > tmp(nvariables); Array<OneD, Array<OneD, NekDouble> > outarray(nvariables); Array<OneD, Array<OneD, NekDouble> > WeakAdv(nvariables); int npoints = GetNpoints(); int ncoeffs = GetNcoeffs(); switch (m_projectionType) { case MultiRegions::eDiscontinuous: { dofs = ncoeffs; break; } case MultiRegions::eGalerkin: case MultiRegions::eMixed_CG_Discontinuous: { //dofs = GetContNcoeffs(); //UseContCoeffs = true; break; } } cout << endl; cout << "Num Phys Points = " << npoints << endl; // phisical points cout << "Num Coeffs = " << ncoeffs << endl; // cout << "Num Cont Coeffs = " << dofs << endl; inarray[0] = Array<OneD, NekDouble>(npoints,0.0); outarray[0] = Array<OneD, NekDouble>(npoints,0.0); tmp[0] = Array<OneD, NekDouble>(npoints,0.0); WeakAdv[0] = Array<OneD, NekDouble>(ncoeffs,0.0); Array<OneD, NekDouble> MATRIX(npoints*npoints,0.0); for (int j = 0; j < npoints; j++) { inarray[0][j] = 1.0; /// Feeding the weak Advection oprator with a vector (inarray) /// Looping on inarray and changing the position of the only non-zero entry /// we simulate the multiplication by the identity matrix. /// The results stored in outarray is one of the columns of the weak advection oprators /// which are then stored in MATRIX for the futher eigenvalues calculation. switch (m_projectionType) { case MultiRegions::eDiscontinuous: { WeakDGAdvection(inarray, WeakAdv,true,true,1); m_fields[0]->MultiplyByElmtInvMass(WeakAdv[0],WeakAdv[0]); m_fields[0]->BwdTrans(WeakAdv[0],outarray[0]); Vmath::Neg(npoints,outarray[0],1); break; } case MultiRegions::eGalerkin: case MultiRegions::eMixed_CG_Discontinuous: { // Calculate -V\cdot Grad(u); for(i = 0; i < nvariables; ++i) { //Projection m_fields[i]->FwdTrans(inarray[i],WeakAdv[i]); m_fields[i]->BwdTrans_IterPerExp(WeakAdv[i],tmp[i]); //Advection operator AdvectionNonConservativeForm(m_velocity,tmp[i],outarray[i]); Vmath::Neg(npoints,outarray[i],1); //m_fields[i]->MultiplyByInvMassMatrix(WeakAdv[i],WeakAdv[i]); //Projection m_fields[i]->FwdTrans(outarray[i],WeakAdv[i]); m_fields[i]->BwdTrans_IterPerExp(WeakAdv[i],outarray[i]); } break; } } /// The result is stored in outarray (is the j-th columns of the weak advection operator). /// We now store it in MATRIX(j) Vmath::Vcopy(npoints,&(outarray[0][0]),1,&(MATRIX[j]),npoints); /// Set the j-th entry of inarray back to zero inarray[0][j] = 0.0; } //////////////////////////////////////////////////////////////////////////////// /// Calulating the eigenvalues of the weak advection operator stored in (MATRIX) /// using Lapack routines char jobvl = 'N'; char jobvr = 'N'; int info = 0, lwork = 3*npoints; NekDouble dum; Array<OneD, NekDouble> EIG_R(npoints); Array<OneD, NekDouble> EIG_I(npoints); Array<OneD, NekDouble> work(lwork); Lapack::Dgeev(jobvl,jobvr,npoints,MATRIX.get(),npoints,EIG_R.get(),EIG_I.get(),&dum,1,&dum,1,&work[0],lwork,info); //////////////////////////////////////////////////////// //Print Matrix FILE *mFile; mFile = fopen ("WeakAdvMatrix.txt","w"); for(int j = 0; j<npoints; j++) { for(int k = 0; k<npoints; k++) { fprintf(mFile,"%e ",MATRIX[j*npoints+k]); } fprintf(mFile,"\n"); } fclose (mFile); //////////////////////////////////////////////////////// //Output of the EigenValues FILE *pFile; pFile = fopen ("Eigenvalues.txt","w"); for(int j = 0; j<npoints; j++) { fprintf(pFile,"%e %e\n",EIG_R[j],EIG_I[j]); } fclose (pFile); cout << "\nEigenvalues : " << endl; for(int j = 0; j<npoints; j++) { cout << EIG_R[j] << "\t" << EIG_I[j] << endl; } cout << endl; }
static void addgroup(const char *grpname) { gid_t *grps; long lgid, ngrps_max; int dbmember, i, ngrps; gid_t egid; struct group *grp; char *ep, *pass, *cryptpw; char **p; egid = getegid(); /* Try it as a group name, then a group id. */ if ((grp = getgrnam(grpname)) == NULL) if ((lgid = strtol(grpname, &ep, 10)) <= 0 || *ep != '\0' || (grp = getgrgid((gid_t)lgid)) == NULL ) { warnx("%s: bad group name", grpname); return; } /* * If the user is not a member of the requested group and the group * has a password, prompt and check it. */ dbmember = 0; if (pwd->pw_gid == grp->gr_gid) dbmember = 1; for (p = grp->gr_mem; *p != NULL; p++) if (strcmp(*p, pwd->pw_name) == 0) { dbmember = 1; break; } if (!dbmember && *grp->gr_passwd != '\0' && getuid() != 0) { pass = getpass("Password:"******"Sorry\n"); return; } } ngrps_max = sysconf(_SC_NGROUPS_MAX) + 1; if ((grps = malloc(sizeof(gid_t) * ngrps_max)) == NULL) err(1, "malloc"); if ((ngrps = getgroups(ngrps_max, (gid_t *)grps)) < 0) { warn("getgroups"); goto end; } /* Remove requested gid from supp. list if it exists. */ if (grp->gr_gid != egid && inarray(grp->gr_gid, grps, ngrps)) { for (i = 0; i < ngrps; i++) if (grps[i] == grp->gr_gid) break; ngrps--; memmove(&grps[i], &grps[i + 1], (ngrps - i) * sizeof(gid_t)); PRIV_START; if (setgroups(ngrps, (const gid_t *)grps) < 0) { PRIV_END; warn("setgroups"); goto end; } PRIV_END; } PRIV_START; if (setgid(grp->gr_gid)) { PRIV_END; warn("setgid"); goto end; } PRIV_END; grps[0] = grp->gr_gid; /* Add old effective gid to supp. list if it does not exist. */ if (egid != grp->gr_gid && !inarray(egid, grps, ngrps)) { if (ngrps == ngrps_max) warnx("too many groups"); else { grps[ngrps++] = egid; PRIV_START; if (setgroups(ngrps, (const gid_t *)grps)) { PRIV_END; warn("setgroups"); goto end; } PRIV_END; } } end: free(grps); }
#include <stdlib.h> #include <ctype.h> /* Return the position of string in array, or -1 if not found */ int inarray(const char **array, int len, const char *string) { for (int i = 0; i < len; i++) { if (!strcmp(string, array[i])) { return i; } } return -1; } /* Remove string from array, adjust array length */ void delete(char **array, int *len, const char *string) { int pos = inarray( (const char **) array, *len, string ); int last = *len - 1; if (pos != last) { array[pos] = array[last]; } (*len)--; } void strtolower(char *ch) { for (; *ch; ch++) *ch = tolower(*ch); } int hamming(const char *op1, const char *op2) { int len = strlen(op1); int n = 0; for (int i = 0; i < len; i++) {
DWORD san2move(struct board_t *brd,char san[128]) { short c,d,idx,to,from,pcs,file,row,found,cap; short mvalid[MAXMOVES]; char buf[128]; char *str; DWORD promotion,mvs[MAXMOVES]; to=from=file=row=-1; cap=FALSE; pcs=PAWN; promotion=0; for(c=0;c<=127;c++) buf[c]=san[c]; buf[127]='\0'; str=buf; /* primo passaggio: cerchiamo di individuare subito gli arrocchi */ if(strncmp(buf,"O-O",strlen("O-O"))==0) { pcs=KING; from=((brd->color==WHITE)?(E1):(E8)); to=((brd->color==WHITE)?(G1):(G8)); goto third; } if(strncmp(buf,"O-O-O",strlen("O-O-O"))==0) { pcs=KING; from=((brd->color==WHITE)?(E1):(E8)); to=((brd->color==WHITE)?(C1):(C8)); goto third; } /* secondo passaggio: togliamo i caratteri inutili "x+#" e leggiamo la posizione SAN "normale" */ for(c=0;c<strlen(buf);c++) { if((buf[c]=='+')||(buf[c]=='#')||(buf[c]=='x')) { if(buf[c]=='x') cap=TRUE; for(d=c;d<strlen(buf);d++) buf[d]=buf[d+1]; } if((buf[c]=='=')&&(strlen(buf)==(c+2))) { promotion=promflags(buf[c+1]); buf[c]='\0'; } } if(strspn(buf,"123456789NBRQKabcdefgh")!=strlen(buf)) return 0; if((c=inarray(*san,"PNBRQK"))!=-1) { if(c==PAWN) return 0; pcs=c; *str++; } if((strlen(str)>=5)||(strlen(str)<=1)) return 0; if(strlen(str)==4) { if((from=findcoord(str))==-1) return 0; if((to=findcoord(str+2))==-1) return 0; } if(strlen(str)==3) { row=inarray(*str,"12345678"); file=inarray(*str,"abcdefgh"); if((to=findcoord(str+1))==-1) return 0; } if(strlen(str)==2) { if((to=findcoord(str))==-1) return 0; } third: /* terzo passaggio: generiamo tutte le mosse possibili ed escludiamo tutte quelle che non combaciano con i dati in nostro possesso */ idx=0; if(cap==TRUE) generate_captures(brd,mvs,&idx); else generate_moves(brd,mvs,&idx); for(c=0;c<idx;c++) { makemove(brd,mvs[c]); mvalid[c]=FALSE; if(is_in_check(brd,brd->color^1)==FALSE) { mvalid[c]=TRUE; if(((mvs[c]>>6)&0x3F)!=to) mvalid[c]=FALSE; else if(((mvs[c]>>12)&0x7)!=pcs) mvalid[c]=FALSE; else if((from!=-1)&&((mvs[c]&0x3F)!=from))