⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nec2cpp.cpp

📁 矩量法仿真电磁辐射和散射的源代码(c++)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			/* take action according to card id mnemonic */			switch( ain_num )			{			case 0: /* "fr" card, frequency parameters */				s_context.fr_card(itmp1, itmp2, tmp1, tmp2);				continue;					case 1: /* "ld" card, loading parameters */				s_context.ld_card(itmp1, itmp2, itmp3, itmp4, tmp1, tmp2, tmp3);				continue;					case 2: /* "gn" card, ground parameters under the antenna */				s_context.gn_card(itmp1, itmp2, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);				continue; 					case 3: /* "ex" card, excitation parameters */				s_context.ex_card((enum excitation_type)itmp1, itmp2, itmp3, itmp4, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);				continue; /* continue card input loop */					case 4: /* "nt" card, network parameters */				s_context.nt_card(itmp1, itmp2, itmp3, itmp4, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);				continue; /* continue card input loop */					case 5: /* "tl" card, network parameters */				if (parameter_count < 10)				{					nec_error_mode em(s_output);					s_output.endl();					s_output.line("nec2++: Missing parameters in \"TL\" card. Blank parameters should be specified as zero." );					exit(0);				}				s_context.tl_card(itmp1, itmp2, itmp3, itmp4, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);				continue; /* continue card input loop */					case 6: /* "xq" execute card - calc. including radiated fields */				s_context.xq_card(itmp1);				continue;					case 7: /* "gd" card, ground representation */				s_context.gd_card(tmp1, tmp2, tmp3, tmp4);				continue; /* continue card input loop */					case 8: /* "rp" card, standard observation angle parameters */				{					// pull out the XNDA parameters here...										int XNDA = itmp4;					int X = XNDA / 1000;					int N = (XNDA / 100) % 10;					int D = (XNDA / 10) % 10;					int A = XNDA % 10;										s_context.rp_card(itmp1, itmp2, itmp3, X, N, D, A, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);				}				continue; /* was break; followed by special code */					case 9: /* "nx" card, do next job */				next_job = true;				continue; /* continue card input loop */					case 10: /* "pt" card, print control for current */				s_context.pt_card(itmp1, itmp2, itmp3, itmp4);				continue; /* continue card input loop */					case 11: /* "kh" card, matrix integration limit */				s_context.kh_card(tmp1);				continue; /* continue card input loop */					case 12:  /* "ne" card, near field calculation parameters */				s_context.ne_card(itmp1, itmp2, itmp3, itmp4, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);				continue;						case 13:  /* "nh" card, near field calculation parameters */				s_context.nh_card(itmp1, itmp2, itmp3, itmp4, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);				continue;					case 14: /* "pq" card, print control for charge */				s_context.pq_card(itmp1, itmp2, itmp3, itmp4);				continue; /* continue card input loop */					case 15: /* "ek" card,  extended thin wire kernel option */				if (-1 == itmp1)					s_context.set_extended_thin_wire_kernel(false);				else					s_context.set_extended_thin_wire_kernel(true);				continue; /* continue card input loop */					case 16: /* "cp" card, maximum coupling between antennas */				s_context.cp_card(itmp1, itmp2, itmp3, itmp4);				continue; /* continue card input loop */					case 17: /* "pl" card, plot flags */				{					std::string ploutput_filename(input_filename);					ploutput_filename += ".plt";					try					{						s_context.pl_card(ploutput_filename.c_str(), itmp1, itmp2, itmp3, itmp4);					}					catch(...)					{						char mesg[88] = "nec2++: ";											strcat( mesg, ploutput_filename.c_str() );						perror( mesg );						exit(-1);					}				}				continue; /* continue card input loop */					case 19: /* "wg" card, not supported */				throw new nec_exception("\"WG\" card, not supported.");					default:				if ( ain_num != 18 ) // EN card				{					throw new nec_exception("FAULTY DATA CARD LABEL AFTER GEOMETRY SECTION.");				}							/******************************************************				*** normal exit of nec2++ when all jobs complete ok ***				******************************************************/				s_context.all_jobs_completed();								/* time the process */				secnds( &tmp1 );				tmp1 -= ex_timer;				fprintf( output_fp, "\n\n  TOTAL RUN TIME: %d msec", (int)tmp1 );								if( input_fp != NULL )					fclose( input_fp );				if( output_fp != NULL )					fclose(output_fp);									return(0);			} /* switch( ain_num ) */					/*				End of the main input section. 							far_field_flag is true if last card was XQ or RP								This is no longer used, but I am leaving it in here while I iron this out				properly. simulate() should be called by the xq card and the rp card.			*/			ASSERT(false == ((ain_num == 6) || (ain_num == 8)));			s_context.simulate(false);		} /* while( ! next_job ) */		} /* while(true)  */	return(0);} /* end of nec_main() *//*-----------------------------------------------------------------------*//*!\brief Read a line and fill in the parameter values. \return The number of parameters read*/int readmn(FILE* input_fp, FILE* output_fp, 	char *gm, int *i1, int *i2, int *i3, int *i4,	nec_float *f1, nec_float *f2, nec_float *f3,	nec_float *f4, nec_float *f5, nec_float *f6 ){	int parameter_count = 0;	char line_buf[134];	int line_idx;	int n_integer_params = 4, n_float_params = 6;	int integer_array[4] = { 0, 0, 0, 0 };	nec_float real_array[6] = { 0., 0., 0., 0., 0., 0. };		/* read a line from input file */	int eof = load_line( line_buf, input_fp );		/* get line length */	int line_length = (int) strlen(line_buf );		/* abort if card's mnemonic too short or missing */	if ( line_length < 2 )	{		if (EOF == eof)		{			// insert an EN card if we get to an end of file			strncpy( gm, "EN", 2 );			return 0;		}		else		{			fprintf( output_fp,				"\n  COMMAND DATA CARD ERROR:"				"\n  CARD'S MNEMONIC CODE TOO SHORT OR MISSING." );			exit(-1);		}	}		/* extract card's mnemonic code */	strncpy( gm, line_buf, 2 );	gm[2] = '\0';		/* Exit if "XT" command read (for testing) */	if ( strcmp( gm, "XT" ) == 0 )	{		fprintf( stderr,			"\nnec2++: Exiting after an \"XT\" command in read_geometry_card()\n" );		fprintf( output_fp,			"\n\n  nec2++: Exiting after an \"XT\" command in read_geometry_card()" );		exit(0);	}		/* Return if only mnemonic on card */	if ( line_length == 2 )	{		*i1 = *i2 = *i3 = *i4 = 0;		*f1 = *f2 = *f3 = *f4 = *f5 = *f6 = 0.0;		return 0;	}		/* read integers from line */	line_idx = 1;	for (int i = 0; i < n_integer_params; i++ )	{		/* Find first numerical character */		while( ((line_buf[++line_idx] <  '0')  ||			(line_buf[  line_idx] >  '9')) &&			(line_buf[  line_idx] != '+')  &&			(line_buf[  line_idx] != '-') )		if ( (line_buf[line_idx] == '\0') )		{			*i1= integer_array[0];			*i2= integer_array[1];			*i3= integer_array[2];			*i4= integer_array[3];			*f1= real_array[0];			*f2= real_array[1];			*f3= real_array[2];			*f4= real_array[3];			*f5= real_array[4];			*f6= real_array[5];			return parameter_count;		}				/* read an integer from line */		integer_array[i] = atoi( &line_buf[line_idx] );		parameter_count++;				/* traverse numerical field to next ' ' or ',' or '\0' */		line_idx--;		while( (line_buf[++line_idx] != ' ') &&			(line_buf[  line_idx] != ',') &&			(line_buf[  line_idx] != '\0') )		{			/* test for non-numerical characters */			if ( ((line_buf[line_idx] <  '0')  ||				(line_buf[line_idx] >  '9')) &&				(line_buf[line_idx] != '+')  &&				(line_buf[line_idx] != '-') )			{				fprintf( output_fp,				"\n  COMMAND DATA CARD \"%s\" ERROR:"				"\n  NON-NUMERICAL CHARACTER '%c' IN INTEGER FIELD AT CHAR. %d\n",				gm, line_buf[line_idx], (line_idx+1) );				exit(-1);			}				} /* while( (line_buff[++line_idx] ... */				/* Return on end of line */		if ( line_buf[line_idx] == '\0' )		{			*i1= integer_array[0];			*i2= integer_array[1];			*i3= integer_array[2];			*i4= integer_array[3];			*f1= real_array[0];			*f2= real_array[1];			*f3= real_array[2];			*f4= real_array[3];			*f5= real_array[4];			*f6= real_array[5];			return parameter_count;		}			} /* for( i = 0; i < n_integer_params; i++ ) */		/* read nec_floats from line */	for (int i = 0; i < n_float_params; i++ )	{		/* Find first numerical character */		while( ((line_buf[++line_idx] <  '0')  ||			(line_buf[  line_idx] >  '9')) &&			(line_buf[  line_idx] != '+')  &&			(line_buf[  line_idx] != '-')  &&			(line_buf[  line_idx] != '.') )		if ( (line_buf[line_idx] == '\0') )		{			*i1= integer_array[0];			*i2= integer_array[1];			*i3= integer_array[2];			*i4= integer_array[3];			*f1= real_array[0];			*f2= real_array[1];			*f3= real_array[2];			*f4= real_array[3];			*f5= real_array[4];			*f6= real_array[5];			return parameter_count;		}				/* read a nec_float from line */		real_array[i] = atof( &line_buf[line_idx] );		parameter_count++;				/* traverse numerical field to next ' ' or ',' */		line_idx--;		while( (line_buf[++line_idx] != ' ') &&			(line_buf[  line_idx] != ',') &&			(line_buf[  line_idx] != '\0') )		{			/* test for non-numerical characters */			if ( ((line_buf[line_idx] <  '0')  ||				(line_buf[line_idx] >  '9')) &&				(line_buf[line_idx] != '.')  &&				(line_buf[line_idx] != '+')  &&				(line_buf[line_idx] != '-')  &&				(line_buf[line_idx] != 'E')  &&				(line_buf[line_idx] != 'e') )			{				fprintf( output_fp,				"\n  COMMAND DATA CARD \"%s\" ERROR:"				"\n  NON-NUMERICAL CHARACTER '%c' IN FLOAT FIELD AT CHAR. %d\n",				gm, line_buf[line_idx], (line_idx+1) );				exit(-1);			}				} /* while( (line_buff[++line_idx] ... */				/* Return on end of line */		if ( line_buf[line_idx] == '\0' )		{			*i1= integer_array[0];			*i2= integer_array[1];			*i3= integer_array[2];			*i4= integer_array[3];			*f1= real_array[0];			*f2= real_array[1];			*f3= real_array[2];			*f4= real_array[3];			*f5= real_array[4];			*f6= real_array[5];			return parameter_count;		}			} /* for( i = 0; i < n_float_params; i++ ) */		*i1= integer_array[0];	*i2= integer_array[1];	*i3= integer_array[2];	*i4= integer_array[3];	*f1= real_array[0];	*f2= real_array[1];	*f3= real_array[2];	*f4= real_array[3];	*f5= real_array[4];	*f6= real_array[5];		return parameter_count;}/*-----------------------------------------------------------------------*/#ifndef _WIN32static void sig_handler(int signal ){	switch( signal )	{		case SIGINT :			fprintf(stderr, "nec2++: exiting via user interrupt" );			exit( signal );			case SIGSEGV :			fprintf(stderr, "nec2++: segmentation fault" );			exit( signal );			case SIGFPE :			fprintf(stderr, "nec2++: floating point exception" );			exit( signal );			case SIGABRT :			fprintf(stderr, "nec2++: abort signal received" );			exit( signal );			case SIGTERM :			fprintf(stderr, "nec2++: termination request received" );			exit( signal );	}}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -