예제 #1
0
파일: mesh.c 프로젝트: EricPascolo/shyfem
int MarkOuterNodes( void )

{
	int ext;
	int loops;
	int external=0;
	float *xe, *ye;
	float xm,ym;
	Node_type *pn;
	Line_type *pl;

        ResetHashTable(HLI);
        while( (pl = VisitHashTableL(HLI)) != NULL ) {
	    if( !IsLtype(pl,L_EXTERNAL_REF) && !IsLtype(pl,L_INTERNAL_REF) )
			continue;

	    MakeCoordsFromLine(pl,&xe,&ye);

	    ResetHashTable(HNN);
	    while( (pn=VisitHashTableN(HNN)) != NULL ) {
		if( IsNtype(pn, N_EXTERNAL ) ) continue;
		if( IsNtype(pn, N_BOUNDARY ) ) continue;
		if( IsNtype(pn, N_ADDBOUND ) ) continue;
		xm = pn->coord.x;
		ym = pn->coord.y;
		loops = InClosedLine(pl->vertex,xe,ye,xm,ym);
		ext = 0;
		if( IsLtype(pl,L_EXTERNAL_REF) ) {
		    if( loops == 0 ) ext = 1;
		} else {
		    if( loops != 0 ) ext = 1;
		}
		if( ext ) {
		    SetNtype(pn, N_EXTERNAL );
                    external++;
		}
	    }

	    free(xe);
	    free(ye);
	}

	return external;
}
예제 #2
0
파일: meshck.c 프로젝트: EricPascolo/shyfem
void CheckCircumCircle( void )

{
	Elem_type *pe;

	ResetHashTable(HEL);
	while( (pe=VisitHashTableE(HEL)) != NULL ) {
		ControlCircumCircle(pe);
	}
}
예제 #3
0
int	initandparserfile(char *stringPath)
{
	FILE	*fp= NULL;
	char *pk = NULL;
	char stream[MAX_STREAM] = {0};
	char str_key[MAX_KEY] = {0};
	char	str_type[4] = {0};
	uint	offset = 0;
	HASH	s_hash;
	SParser	s_parse_tmp;

	printf("STRING_PATH=%s\n",stringPath);
	fp=fopen(stringPath,"r");

	if(fp == NULL)
	{
		printf("open STRING_PATH failed!\n");
		return FAILURE;
	}
	
	if (FAILURE == initHashTable(&s_parse_tmp)) {
		printf("initHashTable failed!\n");
		fclose(fp);
		return FAILURE;
	}
	ResetHashTable(&s_parse);//free memory at first
	s_parse = s_parse_tmp;
	
	fseek(fp, 0, SEEK_SET);
	while(fgets(stream, MAX_STREAM, fp) != NULL)
	{
		int	len = strlen(stream);
		pk = strstr(stream,"=");
		if ((stream[0] == ';') || (NULL == pk)) {
			offset += len;
			continue;
		}
		
		*pk = '\0';
		
		strncpy(str_key, stream, strlen(stream));
		s_hash.key = getkey(str_key);
		s_hash.ioffset = offset;
		offset += len;
		
		strcpy(str_attrname, str_key);
		insertToHash(&s_parse, s_hash);
		
		memset(stream, 0, MAX_STREAM);
		memset(str_key, 0, MAX_KEY);
	}
	fclose(fp);
	return SUCCESS;
}
예제 #4
0
파일: mesh.c 프로젝트: EricPascolo/shyfem
int MarkOuterElements( void )

{
	int ext;
	int loops;
	int external=0;
	float *xe, *ye;
	float xm,ym;
	Elem_type *pe;
	Line_type *pl;

        ResetHashTable(HLI);
        while( (pl = VisitHashTableL(HLI)) != NULL ) {
	    if( !IsLtype(pl,L_EXTERNAL_REF) && !IsLtype(pl,L_INTERNAL_REF) )
			continue;

	    MakeCoordsFromLine(pl,&xe,&ye);

	    ResetHashTable(HEL);
	    while( (pe=VisitHashTableE(HEL)) != NULL ) {
		if( IsEtype(pe, E_EXTERNAL ) ) continue;
		MakeCM(pe,&xm,&ym);
		loops = InClosedLine(pl->vertex,xe,ye,xm,ym);
		ext = 0;
		if( IsLtype(pl,L_EXTERNAL_REF) ) {
		    if( loops == 0 ) ext = 1;
		} else {
		    if( loops != 0 ) ext = 1;
		}
		if( ext ) {
		    SetEtype(pe, E_EXTERNAL );
                    external++;
		}
	    }

	    free(xe);
	    free(ye);
	}

	return external;
}
예제 #5
0
파일: meshck.c 프로젝트: EricPascolo/shyfem
void CheckArea( void )

{
	Elem_type *pe;

	ResetHashTable(HEL);
	while( (pe=VisitHashTableE(HEL)) != NULL ) {
	    if( AreaElement(HNN,pe) <= 0. ) {
		Warning2("CheckArea: area is negative in element "
				,itos(pe->number));
	    }
	}
}
예제 #6
0
파일: meshck.c 프로젝트: EricPascolo/shyfem
void CheckBoundary( void )

{
	int i;
	Node_type *pn;
	Line_type *pl;

	ResetHashTable(HNN);
	while( (pn=VisitHashTableN(HNN)) != NULL ) {
		printf("%d %d ",pn->number,pn->type);
		printf("%f %f\n",pn->coord.x,pn->coord.y);
	}
	printf("\n");

	ResetHashTable(HLI);
	while( (pl=VisitHashTableL(HLI)) != NULL ) {
		printf("%d %d %d\n",pl->number,pl->type,pl->vertex);
		for(i=0;i<pl->vertex;i++) {
		    printf("%d\n",pl->index[i]);
		}
	}
}
예제 #7
0
파일: mesh.c 프로젝트: EricPascolo/shyfem
int MarkExternalElements( NodeList hull )

{
	int i,ncount;
	int external=0;
	int node;
	float *xe, *ye;
	float xm,ym;
	Elem_type *pe;
	Node_type *pn;

	ncount = hull->count;

	xe = (float *) malloc( ncount * sizeof(float) );
	ye = (float *) malloc( ncount * sizeof(float) );
	if( !xe || !ye )
		Error("MarkExternalElements: Cannot allocate coordinate list");

	for(i=0;i<ncount;i++) {
		node = hull->index[i];
		pn = RetrieveByNodeNumber(HNN,node);
		xe[i] = pn->coord.x;
		ye[i] = pn->coord.y;
	}

	ResetHashTable(HEL);
	while( (pe=VisitHashTableE(HEL)) != NULL ) {
		MakeCM(pe,&xm,&ym);
		if( !InConvex(ncount,xe,ye,xm,ym) ) {
			SetEtype(pe, E_EXTERNAL );
			external++;
		}
	}

	free(xe);
	free(ye);

	return external;
}
예제 #8
0
파일: meshck.c 프로젝트: EricPascolo/shyfem
void CheckCircumCircleProperty( void )

/*\
 *  New version of routine -> does a little bit too much.
\*/

{
	int i,node;
	Elem_type *pe, *pvis;

	ResetHashTable(HEL);
	while( (pe=VisitHashTableE(HEL)) != NULL ) {
	    if( IsEtype(pe, E_EXTERNAL ) ) continue;
	    if( !InElemCircumCircle(pe,pe,1.01) ) {
		Error2("CheckCircumCircleProperty: Violation (0)"
					,itos(pe->number));
	    }
	    for(i=0;i<3;i++) {
		pvis = RetrieveByElemNumber(HEL,pe->neibor[i]);
		node = pe->index[(i+2)%3];
		while( (pvis=GoAround(pvis,node,RIGHT)) != NULL ) {
		    if( pvis == NULL || pvis == pe ) break;
		    if( InElemCircumCircle(pvis,pe,0.99) ) {
			Error2("CheckCircumCircleProperty: Violation (1)"
					,itos(pe->number));
		    }
		}
		pvis = RetrieveByElemNumber(HEL,pe->neibor[i]);
		node = pe->index[(i+1)%3];
		while( (pvis=GoAround(pvis,node,LEFT)) != NULL ) {
		    if( pvis == NULL || pvis == pe ) break;
		    if( InElemCircumCircle(pvis,pe,0.99) ) {
			Error2("CheckCircumCircleProperty: Violation (2)"
					,itos(pe->number));
		    }
		}
	    }
	}
}
예제 #9
0
파일: parsers.c 프로젝트: smx-smx/dsl-n55u
/* Paul modify 2013/2/7 */
int	initandparserfile(void)
{
	//FILE *fp = NULL;
	char *pk = NULL;
	char	str_path[PATH_LENGTH] = {0};
	char stream[MAX_STREAM] = {0};
	char str_key[MAX_KEY] = {0};
	char	str_type[4] = {0};
	int	nIndex = 0;
	uint	offset = 0;
	HASH	s_hash;
	SParser	s_parse_tmp;

	//Andy Chiu, 2015/03/03. retry for cfg_manager restart scoket issue.
	int res = 0, i;
	for(i = 0; i < 5; ++i)
	{
		res = tcapi_get("LanguageSwitch_Entry", "Type", str_type);
		if(!res && strlen(str_type) > 0 )
			break;
		
		tcdbg_printf("[%s, %d]get lang failed!\n", __FUNCTION__, __LINE__);
		sleep(1);
	}
	
	if (strlen(str_type))
		nIndex = atoi(str_type);

	if(nIndex == 0)
	{
		for(i = 0; i < 5; ++i)
		{
			memset(str_type, 0, sizeof(str_type));
			res = tcapi_get("WebCurSet_Entry", "detected_lang_type", str_type);
			if(!res && strlen(str_type) > 0 )
				break;
			tcdbg_printf("[%s, %d]get lang failed!\n", __FUNCTION__, __LINE__);
			sleep(1);
		}
		if (strlen(str_type))
			nIndex = atoi(str_type);
	}

	init_flag = nIndex;
	closefp();//close file pointer at first
	
	if(nIndex == 1) //English
		sprintf(str_path, STRING_PATH, "EN");
	else if(nIndex == 2) //Brazil
		sprintf(str_path, STRING_PATH, "BR");
	else if(nIndex == 3) //Simplified Chinese
		sprintf(str_path, STRING_PATH, "CN");
	else if(nIndex == 4) //Cesky
		sprintf(str_path, STRING_PATH, "CZ");
	else if(nIndex == 5) //Dansk
		sprintf(str_path, STRING_PATH, "DA");
	else if(nIndex == 6) //Deutsch
		sprintf(str_path, STRING_PATH, "DE");
	else if(nIndex == 7) //Espanol
		sprintf(str_path, STRING_PATH, "ES");
	else if(nIndex == 8) //Finsk
		sprintf(str_path, STRING_PATH, "FI");
	else if(nIndex == 9) //Francais
		sprintf(str_path, STRING_PATH, "FR");
	else if(nIndex == 10) //Italiano
		sprintf(str_path, STRING_PATH, "IT");
	else if(nIndex == 11) //Malay
		sprintf(str_path, STRING_PATH, "MS");
	else if(nIndex == 12) //Norsk
		sprintf(str_path, STRING_PATH, "NO");
	else if(nIndex == 13) //Polski
		sprintf(str_path, STRING_PATH, "PL");
	else if(nIndex == 14) //Russian
		sprintf(str_path, STRING_PATH, "RU");
	else if(nIndex == 15) //Svensk
		sprintf(str_path, STRING_PATH, "SV");
	else if(nIndex == 16) //Thai
		sprintf(str_path, STRING_PATH, "TH");
	else if(nIndex == 17) //Turkey
		sprintf(str_path, STRING_PATH, "TR");
	else if(nIndex == 18) //Traditional Chinese
		sprintf(str_path, STRING_PATH, "TW");
	else if(nIndex == 19) //Ukraine
		sprintf(str_path, STRING_PATH, "UK");
	else
		sprintf(str_path, STRING_PATH, "EN");
		
	fpl=fopen(str_path,"r");
	if(fpl == NULL)
	{
		tcdbg_printf("\r\n%s:can't open %s\r\n",__FUNCTION__, str_path);
		return FAILURE;
	}
	
	if (FAILURE == initHashTable(&s_parse_tmp)) {
		tcdbg_printf("\r\n%s:alloc memory\n", __FUNCTION__);
		return FAILURE;
	}
	ResetHashTable(&s_parse);//free memory at first
	s_parse = s_parse_tmp;
	
	fseek(fpl, 0, SEEK_SET);
	while(fgets(stream, MAX_STREAM, fpl) != NULL)
	{
		int	len = strlen(stream);
		pk = strstr(stream,"=");
		if ((stream[0] == ';') || (NULL == pk)) {
			offset += len;
			continue;
		}
		
		*pk = '\0';
		
		strncpy(str_key, stream, strlen(stream));
		s_hash.key = getkey(str_key);
		s_hash.ioffset = offset;
		offset += len;
		
		strcpy(str_attrname, str_key);
		insertToHash(&s_parse, s_hash);
		
		memset(stream, 0, MAX_STREAM);
		memset(str_key, 0, MAX_KEY);
	}
	//fclose(fp);
	return SUCCESS;
}
예제 #10
0
파일: meshfi.c 프로젝트: marcobj/shyfem
void WriteFile( char *file , NodeList list , int all )

{
	int i,j;
	int count;
	int linetype;
	FILE *fp;
	Node_type *pn;
	Elem_type *pe;
	Line_type *pl;

	if( file == NULL ) {
	    fp=fopen("new.grd","w");
	} else {
	    fp=fopen(file,"w");
	}

	/* comments */

        fprintf(fp,"\n");
        fprintf(fp,"0 (mesh) automatic generated grid\n");
        fprintf(fp,"\n");

	/* nodes */

	ResetHashTable(HNN);
	while( (pn=VisitHashTableN(HNN)) != NULL ) {
		if( !all && IsNtype(pn, N_EXTERNAL ) ) continue;
                fprintf(fp,"1 %d %d %f %f"
                        ,pn->number
                        ,(int) pn->type
                        ,pn->coord.x
                        ,pn->coord.y
                        );
                if( pn->depth != NULLDEPTH )
                        fprintf(fp," %f\n",pn->depth);
                else
                        fprintf(fp,"\n");

	}

        fprintf(fp,"\n");

	/* elements */

        for(i=1;i<=NTotElems;i++) {
          if( (pe=RetrieveByElemNumber(HEL,i)) != NULL ) {
		if( !all && IsEtype(pe, E_EXTERNAL ) ) continue;
                fprintf(fp,"2 %d %d %d"
                        ,pe->number
                        ,(int) pe->type
                        ,pe->vertex
                        );

                for(j=0;j<pe->vertex;j++) {
                        if( j%10 == 0 && pe->vertex > 3 )
                                fprintf(fp,"\n");
                        fprintf(fp," %d",pe->index[j]);
                }
        	fprintf(fp,"\n");
	  }
	}

        fprintf(fp,"\n");

	/* lines */


        for(i=1;i<=NTotLines;i++) {
          if( (pl=RetrieveByLineNumber(HLI,i)) != NULL ) {
	    if( IsLtype(pl,L_EXTERNAL_REF) || IsLtype(pl,L_INTERNAL_REF) 
			|| IsLtype(pl,L_FAULT_REF)
			|| EqualsLtype(pl,L_NONE) ) {
		if( IsLtype(pl,L_EXTERNAL_REF) ) {
		  linetype = L_EXTERNAL;
		} else if( IsLtype(pl,L_INTERNAL_REF) ) {
		  linetype = L_INTERNAL;
		} else if( IsLtype(pl,L_FAULT_REF) ) {
		  linetype = L_FAULT;
		} else {
		  linetype = 0;
		}
                fprintf(fp,"3 %d %d %d"
                        ,pl->number
                        ,linetype
                        ,pl->vertex
                        );

                for(j=0;j<pl->vertex;j++) {
                        if( j%10 == 0 )
                                fprintf(fp,"\n");
                        fprintf(fp," %d",pl->index[j]);
                }
                fprintf(fp,"\n");
	    }
          }
        }

        fprintf(fp,"\n");

	/* list */

	if( list ) {
		count = list->count;
        	fprintf(fp,"3 1 1 %d",count+1);
        	for(j=0;j<=count;j++) {
                	if( j%10 == 0 ) fprintf(fp,"\n");
                	fprintf(fp," %d",list->index[j%count]);
        	}
        	fprintf(fp,"\n");
	}

	fclose(fp);
}
예제 #11
0
파일: meshck.c 프로젝트: EricPascolo/shyfem
int CheckInput( void )

/*\
 *  here we should also check for :
 *  - counter-clockwise line turning
 *  - no nodes out of external line
 *  - internal lines are really internal of external line
 *  - lines closed
 *  ...
\*/

{
	int i;
	int ntot=0;
	int next=0;
	int nint=0;
	int nbound=0;
	int turn;
	int ndim;
	int error;
        Node_type *pn;
        Elem_type *pe;
        Line_type *pl;
	StackTable backg;
	float *xe, *ye;
	float area;
	float areamax = 0.;
        Line_type *plmax = NULL;	/* biggest line */
        Line_type *plext = NULL;	/* external line */

/* set all nodes to NONE */

       	ResetHashTable(HNN);
	while( (pn=VisitHashTableN(HNN)) != NULL ) {
		SetNtype(pn, N_NONE );
	}

/* look for lines */

        ResetHashTable(HLI);
        while( (pl=VisitHashTableL(HLI)) != NULL ) {

	    area = ABS( AreaLine(HNN,pl) );
	    if( area > areamax ) {
		areamax = area;
		plmax = pl;
	    }

	    if( pl->type == L_EXTERNAL ) {	/* HACK *//* FIXME */
		plext = pl;
		SetLtype(pl, L_EXTERNAL );
	    } else if( pl->type == L_INTERNAL ) {
		SetLtype(pl, L_INTERNAL );
	    } else if( pl->type == L_FAULT ) {
		SetLtype(pl, L_FAULT );
	    } else if( pl->type == L_NONE ) {
		if( IsLineClosed(pl) ) {
		    SetLtype(pl, L_INTERNAL );
		} else {
		    SetLtype(pl, L_FAULT );
		}
	    } else {
		  Error2("Unknown line type in line ",itos(pl->number));
	    }

	    ntot++;
	    if( IsLtype(pl, L_EXTERNAL ) ) next++;
	    if( IsLtype(pl, L_INTERNAL ) ) nint++;
        }

/* look for boundary lines */

	if( next > 1 ) {
		Error("More than one line marked external");
	} else if( ntot == 0 ) {
		Warning("No line found: using hull as boundary");
       		ResetHashTable(HNN);
		while( (pn=VisitHashTableN(HNN)) != NULL ) {
			SetNtype(pn, N_BOUNDARY );
		}
	} else if( next == 0 ) {
		Warning("No external line found... using biggest one");
		Warning2("  external line is ",itos(plmax->number));
		plext = plmax;
		SetLtype(plmax, L_EXTERNAL );
		next++;
	}

/* check if external line is closed and all other lines are inside */

	if( plext != NULL ) {
	  if( ! IsLineClosed(plext) ) {
    	    Error2("External line is not closed: ",itos(plext->number));
          }
          ResetHashTable(HLI);
          while( (pl=VisitHashTableL(HLI)) != NULL ) {
	      if( pl == plext ) continue;
	      if( ! IsLineInLine(plext,pl) ) {
	      	Error2("Line not inside external line: ",itos(pl->number));
	      }
	  }
	}

/* check lines and set node type */

	error = 0;
        ResetHashTable(HLI);
        while( (pl=VisitHashTableL(HLI)) != NULL ) {
	    if( IsLtype(pl, L_EXTERNAL ) || IsLtype(pl, L_INTERNAL ) ) {

		/* check for closed line */ /* FIXME */ /* -> close line */

		if( ! IsLineClosed(pl) ) {
	    	    Error2("Line is not closed: ",itos(pl->number));
	        }

		ndim = pl->vertex;
		MakeCoordsFromLine(pl,&xe,&ye);

		/* check for not unique coordinates */

	        for(i=1;i<ndim;i++) {
		  if( pl->index[i-1] == pl->index[i] ) {
		    printf("*** Line %d: identical node %d\n"
				,pl->number,pl->index[i]);
		    error++;
	          } else if( xe[i-1] == xe[i] && ye[i-1] == ye[i] ) {
		    printf("*** Line %d: Identical coordinates - ",pl->number);
		    printf("nodes %d and %d\n",pl->index[i-1],pl->index[i]);
		    error++;
		  }
		}
		
		/* check for counter-clockwise turning */

		turn = TurnClosedLine(pl->vertex,xe,ye);
		if( turn == 1 ) {
			/* ok */;
		} else if( turn == -1 ) {
			printf("Line %d in clockwise sense -> inverting\n"
				,pl->number);
			InvertIndex(pl->index,pl->vertex);
		} else {
			printf("*** Line %d: turning number %d\n",
				pl->number,turn);
			printf("  (the line might turn on itself)\n");
			error++;
		}
		free(xe); free(ye);

		/* set node type for nodes on boundary */

		for(i=0;i<pl->vertex;i++) {
			pn = RetrieveByNodeNumber(HNN,pl->index[i]);
			SetNtype(pn, N_BOUNDARY );
		}
	    }
        }

	if( error ) {
		Error("Errors found in lines");
	}

	/* look for background grid */

	if( OpBackGround >= 0 ) {
	    backg = MakeStackTable();
	    BCK = MakeListTable();
       	    ResetHashTable(HEL);
	    while( (pe=VisitHashTableE(HEL)) != NULL ) {
		if( pe->type == OpBackGround ) {
		    Push(backg,(void *)pe);
		} else {
		    SetEtype(pe, E_EXTERNAL ); /* tentativly... */
		}
	    }
	    while( (pe=(Elem_type *)Pop(backg)) != NULL ) {
		DeleteHashByNumber(HEL,pe->number);
		InsertListTable(BCK,(void *)pe);
		for(i=0;i<3;i++) {
		    pn = RetrieveByNodeNumber(HNN,pe->index[i]);
		    SetNtype(pn, N_EXTERNAL );
		    if( pn->depth == NULLDEPTH ) {
			Error2("Null resolution in background grid at node : ",
					itos(pn->number));
		    }
		}
	    }
	    FreeStackTable(backg);
	}

	/* count all nodes of boundary type */

       	ResetHashTable(HNN);
	while( (pn=VisitHashTableN(HNN)) != NULL ) {
		if( IsNtype(pn, N_BOUNDARY ) ) nbound++;
	}

	return nbound;
}