Example #1
0
extern eRunStatus node3_Run(	)
{
	Boolean bRunToFinish = true;
	int32 nReady = 1;
	node3_InitVIConstantList();
	{
		heap->e_State_in =node3_in_0_State_in_31;
		heap->l_While_____i = 0;
		do {
			{
				heap->b_Constant = true;
				heap->c_While_____SR_1 = node3_heap_lsr->c_While_____SR;
				heap->b_While_____SR_1 = node3_heap_lsr->b_While_____SR;
				{ /* Select */
					heap->e_State_in_CS = heap->e_State_in;
					switch ( heap->e_State_in_CS ) {
						/* begin case */
						case 0 : {
							/*********************************************************************************/
							/* mod0 \325\375\263\243\262\311\321\371 */
							/* mod1 \275\332\265\347\262\311\321\371 */
							/* mod2 \275\364\274\261\262\311\321\371 */
							/*********************************************************************************/
							{
								heap->n_sampleRate = 5.0000000000000000000E+0;
								heap->e_sampleRateMode = 1;
								heap->n_Range_1 = 3;
								heap->n_Range = 3;
								heap->n_DIO_Drive_Mode_3 = 3;
								heap->n_DIO_Drive_Mode_2 = 3;
								heap->n_DIO_Drive_Mode_1 = 3;
								heap->n_DIO_Drive_Mode = 3;
								heap->l_pow_1 = 100;
								heap->l_mod = 0;
								heap->l_bat = 3;
								heap->l_pow = 100;
								heap->l_sh1 = 35;
								heap->l_sh2 = 40;
								heap->b_Case_Structure_CT = false;
								if ((set_ai_power_Run( 	int32DataType, heap->l_pow_1	)) == eFail) CGenErr();
								{
									heap->by_IO_Channel_Number = 1;
/* Inline C node */
									{
										uInt8 channel = 0;
										uInt16 mode = 0;
										channel = heap->by_IO_Channel_Number;
										mode = heap->n_DIO_Drive_Mode;

										{
											#include "node3_inlineC__71.h"
										}

#undef log
#undef log2
#undef ln
									}
								}
								{
									heap->by_IO_Channel_Number_1 = 0;
/* Inline C node */
									{
										uInt8 channel = 0;
										uInt16 mode = 0;
										channel = heap->by_IO_Channel_Number_1;
										mode = heap->n_DIO_Drive_Mode_1;

										{
											#include "node3_inlineC__66.h"
										}

#undef log
#undef log2
#undef ln
									}
								}
								{
									heap->by_IO_Channel_Number_2 = 2;
/* Inline C node */
									{
										uInt8 channel = 0;
										uInt16 mode = 0;
										channel = heap->by_IO_Channel_Number_2;
										mode = heap->n_DIO_Drive_Mode_2;

										{
											#include "node3_inlineC__5B.h"
										}

#undef log
#undef log2
#undef ln
									}
								}
								{
									heap->by_IO_Channel_Number_3 = 3;
/* Inline C node */
									{
										uInt8 channel = 0;
										uInt16 mode = 0;
										channel = heap->by_IO_Channel_Number_3;
										mode = heap->n_DIO_Drive_Mode_3;

										{
											#include "node3_inlineC__50.h"
										}

#undef log
#undef log2
#undef ln
									}
								}
								{
									heap->i_IO_Channel_Number = 1;
/* Inline C node */
									{
										uInt16 range = 0;
										int16 channel = 0;
										range = heap->n_Range;
										channel = heap->i_IO_Channel_Number;

										{
											#include "node3_inlineC__45.h"
										}

#undef log
#undef log2
#undef ln
									}
								}
								{
									heap->i_IO_Channel_Number_1 = 0;
/* Inline C node */
									{
										uInt16 range = 0;
										int16 channel = 0;
										range = heap->n_Range_1;
										channel = heap->i_IO_Channel_Number_1;

										{
											#include "node3_inlineC__3A.h"
										}

#undef log
#undef log2
#undef ln
									}
								}
								{
									heap->XNodeTun82 = 0;
/* Inline C node */
									{
										int16 error = 0;
										uInt32 sampleIntervalMode = 0;
										float32 sampleInterval = 0.0;
										error = heap->XNodeTun82;
										sampleIntervalMode = heap->e_sampleRateMode;
										sampleInterval = heap->n_sampleRate;

										{
											#include "node3_inlineC__2F.h"
											heap->XNodeTunB2 = error;
										}

#undef log
#undef log2
#undef ln
									}
								}
/* Bundle by name */
								{
									cl_A0000* cl_001 = NULL;
									/* Cluster CopyOnModify */
									MemMove( &heap->c_Case_Structure_CT, &heap->c_While_____SR_1, sizeof( cl_A0000 ) );
									cl_001 = (cl_A0000*)&heap->c_Case_Structure_CT;
	cl_001->el_0 = heap->l_mod;
	cl_001->el_1 = heap->l_bat;
	cl_001->el_2 = heap->l_pow;
	cl_001->el_3 = heap->l_sh1;
	cl_001->el_4 = heap->l_sh2;
								}
							}
						} /* end case */
						break;
						/* begin case */
						case 1 : {
							{
								MemMove( &heap->c_While_____CT_2, &heap->c_While_____SR_1, sizeof( cl_A0000 ) );
								MemMove( &heap->c_While_____ST, &heap->c_While_____CT_2, sizeof( cl_A0000 ) );
								MemMove( &heap->c_While_____ST_1, &heap->c_While_____CT_2, sizeof( cl_A0000 ) );
								{
									MemMove( &heap->c_While_____ST_3, &heap->c_While_____ST_1, sizeof( cl_A0000 ) );
/* Unbundle by name */
									{
										cl_A0000* cl_002 = (cl_A0000*)&heap->c_While_____ST_3;
										heap->l________________mod = cl_002->el_0;
	}
									{ /* Select */
										heap->l________________mod_CS = heap->l________________mod;
										MemMove( &heap->c_While_____CT_3, &heap->c_While_____ST_3, sizeof( cl_A0000 ) );
										switch ( heap->l________________mod_CS ) {
											/* begin case */
											case 1 : {
												{
													heap->l_times_3 = 10;
													heap->l_times_2 = 10;
													heap->l_delta_1 = 5;
/* Unbundle by name */
													{
														cl_A0000* cl_003 = (cl_A0000*)&heap->c_While_____CT_3;
														heap->l________________sh1_1 = cl_003->el_3;
														heap->l________________sh2_1 = cl_003->el_4;
	}
													{
														extern Boolean sample_a0_out_0_A______1DC_init_;
														Boolean sample_a0_out_0_A______1DC = sample_a0_out_0_A______1DC_init_;
														extern float32 sample_a0_out_1_ai_426_init_;
														float32 sample_a0_out_1_ai_426 = sample_a0_out_1_ai_426_init_;
														heap->b_Case_Structure_CT = sample_a0_out_0_A______1DC_init_;
														heap->n_sample_a0_vi_ai_1 = sample_a0_out_1_ai_426_init_;
														if ((sample_a0_Run( 	int32DataType, heap->l________________sh1_1,
														int32DataType, heap->l_times_3,
														BooleanDataType, &heap->b_Case_Structure_CT,
														floatDataType, &heap->n_sample_a0_vi_ai_1	)) == eFail) CGenErr();
													}
													{
														static uInt32 id = 0;
														static NetworkVariableAttrs attrs = { 
															/* url */ _LVT("\\\\169.254.62.215\\Node1\\AI0"), 
															/* alias */ _LVT("VISN-WSN"), 
															/* buffering */ true, 
															/* buffer size limit */ 800 /* 0x320 */, 
															/* buffer value limit */ 50 /* 0x32 */
														};
														if (!NetworkVariableWrite(&id, attrs, NULL, &(heap->n_sample_a0_vi_ai_1), floatDataType, floatDataType, NULL)) {
															CGenErr();
														}
													}
	{
														extern float32 sample_a1_out_0_ai_426_init_;
														float32 sample_a1_out_0_ai_426 = sample_a1_out_0_ai_426_init_;
														heap->n_sample_a1_vi_ai_1 = sample_a1_out_0_ai_426_init_;
														if ((sample_a1_Run( 	int32DataType, heap->l_delta_1,
														int32DataType, heap->l________________sh2_1,
														int32DataType, heap->l_times_2,
														floatDataType, &heap->n_sample_a1_vi_ai_1	)) == eFail) CGenErr();
													}
													{
														static uInt32 id = 0;
														static NetworkVariableAttrs attrs = { 
															/* url */ _LVT("\\\\169.254.62.215\\Node1\\AI1"), 
															/* alias */ _LVT("VISN-WSN"), 
															/* buffering */ true, 
															/* buffer size limit */ 800 /* 0x320 */, 
															/* buffer value limit */ 50 /* 0x32 */
														};
														if (!NetworkVariableWrite(&id, attrs, NULL, &(heap->n_sample_a1_vi_ai_1), floatDataType, floatDataType, NULL)) {
															CGenErr();
														}
													}
	}
											} /* end case */
											break;
											/* begin case */
											case 2 : {
												{
													heap->l_times_4 = 1;
													heap->l_times_5 = 1;
													heap->l_delta_2 = 5;
/* Unbundle by name */
													{
														cl_A0000* cl_004 = (cl_A0000*)&heap->c_While_____CT_3;
														heap->l________________sh1_2 = cl_004->el_3;
														heap->l________________sh2_2 = cl_004->el_4;
	}
													{
														extern Boolean sample_a0_out_0_A______1DC_init_;
														Boolean sample_a0_out_0_A______1DC = sample_a0_out_0_A______1DC_init_;
														extern float32 sample_a0_out_1_ai_426_init_;
														float32 sample_a0_out_1_ai_426 = sample_a0_out_1_ai_426_init_;
														heap->b_Case_Structure_CT = sample_a0_out_0_A______1DC_init_;
														heap->n_sample_a0_vi_ai_2 = sample_a0_out_1_ai_426_init_;
														if ((sample_a0_Run( 	int32DataType, heap->l________________sh1_2,
														int32DataType, heap->l_times_4,
														BooleanDataType, &heap->b_Case_Structure_CT,
														floatDataType, &heap->n_sample_a0_vi_ai_2	)) == eFail) CGenErr();
													}
													{
														static uInt32 id = 0;
														static NetworkVariableAttrs attrs = { 
															/* url */ _LVT("\\\\169.254.62.215\\Node1\\AI0"), 
															/* alias */ _LVT("VISN-WSN"), 
															/* buffering */ true, 
															/* buffer size limit */ 800 /* 0x320 */, 
															/* buffer value limit */ 50 /* 0x32 */
														};
														if (!NetworkVariableWrite(&id, attrs, NULL, &(heap->n_sample_a0_vi_ai_2), floatDataType, floatDataType, NULL)) {
															CGenErr();
														}
													}
	{
														extern float32 sample_a1_out_0_ai_426_init_;
														float32 sample_a1_out_0_ai_426 = sample_a1_out_0_ai_426_init_;
														heap->n_sample_a1_vi_ai_2 = sample_a1_out_0_ai_426_init_;
														if ((sample_a1_Run( 	int32DataType, heap->l_delta_2,
														int32DataType, heap->l________________sh2_2,
														int32DataType, heap->l_times_5,
														floatDataType, &heap->n_sample_a1_vi_ai_2	)) == eFail) CGenErr();
													}
													{
														static uInt32 id = 0;
														static NetworkVariableAttrs attrs = { 
															/* url */ _LVT("\\\\169.254.62.215\\Node1\\AI1"), 
															/* alias */ _LVT("VISN-WSN"), 
															/* buffering */ true, 
															/* buffer size limit */ 800 /* 0x320 */, 
															/* buffer value limit */ 50 /* 0x32 */
														};
														if (!NetworkVariableWrite(&id, attrs, NULL, &(heap->n_sample_a1_vi_ai_2), floatDataType, floatDataType, NULL)) {
															CGenErr();
														}
													}
	}
											} /* end case */
											break;
											/* begin case */
											default : {
												{
													heap->l_times_1 = 3;
													heap->l_times = 3;
													heap->l_delta = 5;
/* Unbundle by name */
													{
														cl_A0000* cl_005 = (cl_A0000*)&heap->c_While_____CT_3;
														heap->l________________sh1 = cl_005->el_3;
														heap->l________________sh2 = cl_005->el_4;
	}
													{
														extern Boolean sample_a0_out_0_A______1DC_init_;
														Boolean sample_a0_out_0_A______1DC = sample_a0_out_0_A______1DC_init_;
														extern float32 sample_a0_out_1_ai_426_init_;
														float32 sample_a0_out_1_ai_426 = sample_a0_out_1_ai_426_init_;
														heap->b_Case_Structure_CT = sample_a0_out_0_A______1DC_init_;
														heap->n_sample_a0_vi_ai = sample_a0_out_1_ai_426_init_;
														if ((sample_a0_Run( 	int32DataType, heap->l________________sh1,
														int32DataType, heap->l_times_1,
														BooleanDataType, &heap->b_Case_Structure_CT,
														floatDataType, &heap->n_sample_a0_vi_ai	)) == eFail) CGenErr();
													}
													{
														static uInt32 id = 0;
														static NetworkVariableAttrs attrs = { 
															/* url */ _LVT("\\\\169.254.62.215\\Node1\\AI0"), 
															/* alias */ _LVT("VISN-WSN"), 
															/* buffering */ true, 
															/* buffer size limit */ 800 /* 0x320 */, 
															/* buffer value limit */ 50 /* 0x32 */
														};
														if (!NetworkVariableWrite(&id, attrs, NULL, &(heap->n_sample_a0_vi_ai), floatDataType, floatDataType, NULL)) {
															CGenErr();
														}
													}
	{
														extern float32 sample_a1_out_0_ai_426_init_;
														float32 sample_a1_out_0_ai_426 = sample_a1_out_0_ai_426_init_;
														heap->n_sample_a1_vi_ai = sample_a1_out_0_ai_426_init_;
														if ((sample_a1_Run( 	int32DataType, heap->l_delta,
														int32DataType, heap->l________________sh2,
														int32DataType, heap->l_times,
														floatDataType, &heap->n_sample_a1_vi_ai	)) == eFail) CGenErr();
													}
													{
														static uInt32 id = 0;
														static NetworkVariableAttrs attrs = { 
															/* url */ _LVT("\\\\169.254.62.215\\Node1\\AI1"), 
															/* alias */ _LVT("VISN-WSN"), 
															/* buffering */ true, 
															/* buffer size limit */ 800 /* 0x320 */, 
															/* buffer value limit */ 50 /* 0x32 */
														};
														if (!NetworkVariableWrite(&id, attrs, NULL, &(heap->n_sample_a1_vi_ai), floatDataType, floatDataType, NULL)) {
															CGenErr();
														}
													}
	}
											} /* end case */
											break;
										}
									} /* end switch */
									/**/
									/* 等于? */
									/**/
									heap->b________x___y_ =  (heap->b_Case_Structure_CT == heap->b_While_____SR_1);
									{ /* Select */
										heap->b________x___y__CS = heap->b________x___y_;
										/* begin case */
										if ( heap->b________x___y__CS ) {
											{
												MemMove( &heap->c_Case_Structure_CT, &heap->c_While_____ST, sizeof( cl_A0000 ) );
											}
										} /* end case */
										/* begin case */
										else {
											{
												{ /* Select */
													heap->b__________CS = heap->b_Case_Structure_CT;
													/* begin case */
													if ( heap->b__________CS ) {
														/*********************************************************************************/
														/* \275\370\310\353\276\257\261\250\304\243\312\275 */
														/*********************************************************************************/
														{
															heap->l_mod_2 = 2;
															heap->n_sampleInterval_1 = 1.0000000000000000000E+0;
															heap->b_bell_1 = true;
															{
																heap->n_Constant_1 = 0;
																{
																	heap->by_t_1 = 1;
																	heap->by_f_1 = 0;
																	/**/
																	/* 选择 */
																	/**/
																	if (heap->b_bell_1) {
																		heap->by______s__t_f_1 = heap->by_t_1;
	}
																	else {
																		heap->by______s__t_f_1 = heap->by_f_1;
	}
/* Inline C node */
																	{
																		uInt8 value = 0;
																		int8 unusedInput = 0;
																		value = heap->by______s__t_f_1;
																		unusedInput = heap->n_Constant_1;

																		{
																			#include "node3_inlineC__EA.h"
																		}

#undef log
#undef log2
#undef ln
																	}
																}
																{
/* Inline C node */
																	{
																		int8 unusedInput = 0;
																		unusedInput = heap->n_Constant_1;

																		{
																			#include "node3_inlineC__EC.h"
																		}

#undef log
#undef log2
#undef ln
																	}
																}
															}
															{
																heap->XNodeTun1B01 = 0;
/* Inline C node */
																{
																	int16 error = 0;
																	float32 sampleInterval = 0.0;
																	error = heap->XNodeTun1B01;
																	sampleInterval = heap->n_sampleInterval_1;

																	{
																		#include "node3_inlineC__D6.h"
																		heap->XNodeTun1B16 = error;
																	}

#undef log
#undef log2
#undef ln
																}
															}
/* Bundle by name */
															{
																cl_A0000* cl_006 = NULL;
																/* Cluster CopyOnModify */
																MemMove( &heap->c_Case_Structure_CT, &heap->c_While_____ST, sizeof( cl_A0000 ) );
																cl_006 = (cl_A0000*)&heap->c_Case_Structure_CT;
	cl_006->el_0 = heap->l_mod_2;
															}
														}
													} /* end case */
													/* begin case */
													else {
														{
															heap->n_sampleInterval = 5.0000000000000000000E+0;
															heap->l_mod_1 = 0;
															heap->b_bell = false;
															{
																heap->n_Constant = 0;
																{
																	heap->by_t = 1;
																	heap->by_f = 0;
																	/**/
																	/* 选择 */
																	/**/
																	if (heap->b_bell) {
																		heap->by______s__t_f = heap->by_t;
	}
																	else {
																		heap->by______s__t_f = heap->by_f;
	}
/* Inline C node */
																	{
																		uInt8 value = 0;
																		int8 unusedInput = 0;
																		value = heap->by______s__t_f;
																		unusedInput = heap->n_Constant;

																		{
																			#include "node3_inlineC__C8.h"
																		}

#undef log
#undef log2
#undef ln
																	}
																}
																{
/* Inline C node */
																	{
																		int8 unusedInput = 0;
																		unusedInput = heap->n_Constant;

																		{
																			#include "node3_inlineC__CA.h"
																		}

#undef log
#undef log2
#undef ln
																	}
																}
															}
															{
																heap->XNodeTun2A50 = 0;
/* Inline C node */
																{
																	int16 error = 0;
																	float32 sampleInterval = 0.0;
																	error = heap->XNodeTun2A50;
																	sampleInterval = heap->n_sampleInterval;

																	{
																		#include "node3_inlineC__B3.h"
																		heap->XNodeTun2A65 = error;
																	}

#undef log
#undef log2
#undef ln
																}
															}
/* Bundle by name */
															{
																cl_A0000* cl_007 = NULL;
																/* Cluster CopyOnModify */
																MemMove( &heap->c_Case_Structure_CT, &heap->c_While_____ST, sizeof( cl_A0000 ) );
																cl_007 = (cl_A0000*)&heap->c_Case_Structure_CT;
	cl_007->el_0 = heap->l_mod_1;
															}
														}
													} /* end case */
												} /* end switch */
											}
										} /* end case */
									} /* end switch */
								}
								/* FreeLoopInputs. */
		/* FreeLoopInputs. */
	}
						} /* end case */
						break;
						/* begin case */
						case 2 : {
							{
								/*********************************************************************************/
								/* \311\350\326\303\304\243\312\275\241\242\262\311\321\371\274\344\270\364\241\242\264\253\270\320\306\367\265\347\324\264\321\241\317\356\241\242\301\275\270\366\264\253\270\320\306\367\343\320\326\265 */
								/* mod0\316\252\327\324\266\250\322\345\304\243\312\275\243\254\270\337\313\331\317\324\312\276\304\243\312\275 */
								/* mod1\316\252\275\332\265\347\324\313\320\320\304\243\312\275 */
								/*********************************************************************************/
								/*********************************************************************************/
								/* setmod0-1 */
								/*********************************************************************************/
								/*********************************************************************************/
								/* redint */
								/*********************************************************************************/
								/*********************************************************************************/
								/* setpow10 */
								/*********************************************************************************/
								{
									{
										heap->XNodeTun144C = 0;
										heap->i_Constant = 0;
										heap->by_Constant = 0;
										heap->i_Constant_1 = 127;
/* Array initialize */
										{
											ArrDimSize i;
											ArrDimSize size=1;
											heap->a________________________ = PDAArrNew1D((ArrDimSize)heap->i_Constant_1, uCharDataType);
											size = (ArrDimSize)heap->i_Constant_1;
											if (size < 0) {
												size = 0;
											}
											if (IsNotZero(&heap->by_Constant, uCharDataType)) {
												MemSet(FirstElem(heap->a________________________), size, heap->by_Constant);
											}
	}
/* Inline C node */
										{
											int16 error = 0;
											PDAArrPtr receivedUserMessage_nodeTempArrayHandle = NULL;
											uInt8* receivedUserMessage = NULL;
											int16 receivedUserMessageLength = 0;
											error = heap->XNodeTun144C;
											receivedUserMessage_nodeTempArrayHandle=PDAArrCopyOnModify( heap->a________________________ );
											receivedUserMessage = (VoidHand)FirstElem(receivedUserMessage_nodeTempArrayHandle);
											receivedUserMessageLength = heap->i_Constant;

											{
												#include "node3_inlineC__105.h"
												heap->XNodeTun1450 = error;
												heap->a_____C_____________ = receivedUserMessage_nodeTempArrayHandle;
												heap->i_____C______________4 = receivedUserMessageLength;
											}

#undef log
#undef log2
#undef ln
										}
										/* Array Subset */
										{
											Boolean bEmpty = false;
											Boolean bNullInput=false;
											ArrDimSize start0;
											if (!heap->a_____C_____________) {heap->a_____C_____________ = PDAArrNewEmptyWithNDims( uCharDataType, (ArrDimSize)1 );bNullInput=true;}
											{
												ArrDimSize nDimSize0=0;
												start0 = (ArrDimSize)0;
												if (start0 < 0) {
													start0 = 0;
												}

												if (start0 >= PDAArrNthDim(heap->a_____C_____________, (ArrDimSize)0)) {
													start0 = PDAArrNthDim(heap->a_____C_____________, (ArrDimSize)0);
												}
												nDimSize0 = (ArrDimSize)heap->i_____C______________4;
												if (nDimSize0 <= 0) {
													nDimSize0 = 0;
												}
												if ((start0 + nDimSize0) > PDAArrNthDim(heap->a_____C_____________, (ArrDimSize)0)) {
													nDimSize0 = PDAArrNthDim(heap->a_____C_____________, (ArrDimSize)0) - start0;
												}
												if (!(heap->a________________ = PDAArrNew1D((ArrDimSize)nDimSize0, uCharDataType))){
													CGenErr();
												}
											}
											{
												ArrDimSize end0;
												if (start0 >= PDAArrNthDim(heap->a_____C_____________, (ArrDimSize)0)) {
													bEmpty = true;
												}
												end0 = start0 + (ArrDimSize)heap->i_____C______________4;
												if ((end0 < 0) || (end0 <= start0)) {
													bEmpty = true;	}
												if (end0 > PDAArrNthDim(heap->a_____C_____________, (ArrDimSize)0)) {
													end0 = PDAArrNthDim(heap->a_____C_____________, (ArrDimSize)0);
													PDAArrSetDim(heap->a________________, (ArrDimSize)0, (end0 - start0) );
												}
												if (!bEmpty) {
													MemMove(NthElem(heap->a________________, 0), NthElem(heap->a_____C_____________, start0), (end0-start0)*DataSize(uCharDataType));
												}
												else {
													MemHandleFree( heap->a________________ ); //  Uninitialized
													if (!(heap->a________________ = PDAArrNewEmptyWithNDims( uCharDataType, (ArrDimSize)1 ))) CGenErr();
												}
	if ((heap->a_____C_____________) && ((heap->a_____C_____________)->refcnt > 0)) {
													if (((heap->a_____C_____________)->refcnt == 1) && ((heap->a_____C_____________)->staticArray == false)) {
														(heap->a_____C_____________)->refcnt--;
														MemHandleFree( heap->a_____C_____________ );
														heap->a_____C_____________=NULL;
													}
													else
													 	PDAArrFree(heap->a_____C_____________);
												}
											}
											if (bNullInput) heap->a_____C_____________ = NULL;
										}
										/**/
										/* 字节数组至字符串转换 */
										/**/
										if (!PDAArrToString(heap->a________________, &(heap->XNodeTun1454))) {
											CGenErr();
										}
									}
									heap->s_____________________________X = heap->XNodeTun1454;
									PDAStrIncRefCnt(heap->s_____________________________X, (uInt16)2); /* XNode: tunnel list */
									{
										extern cl_A0000 set_red_state_out_0_set_24A_init_;
										cl_A0000 set_red_state_out_0_set_24A = set_red_state_out_0_set_24A_init_;
										heap->c_set_red_state_vi_set_ST_1 = set_red_state_out_0_set_24A;
										if ((set_red_state_Run( 	StringDataType, heap->s_____________________________X,
										0xA0000 | ClusterDataType, heap->c_While_____SR_1,
										0xA0000 | ClusterDataType, &heap->c_set_red_state_vi_set_ST_1	)) == eFail) CGenErr();
									}
									if ((message_dio_control_Run( 	StringDataType, heap->s_____________________________X	)) == eFail) CGenErr();
									heap->s_____________________________S = heap->s_____________________________X;
								}
								/* FreeLoopInputs. */
	{
									heap->s_____________________________S_1 = heap->s_____________________________S;
									PDAStrIncRefCnt(heap->s_____________________________S_1, (uInt16)1); /* SequenceTunnel */
									MemMove( &heap->c_set_red_state_vi_set_ST_5, &heap->c_set_red_state_vi_set_ST_1, sizeof( cl_A0000 ) );
/* Unbundle by name */
									{
										cl_A0000* cl_008 = (cl_A0000*)&heap->c_set_red_state_vi_set_ST_5;
										heap->l________________mod_1 = cl_008->el_0;
	}
									{ /* Select */
										heap->l________________mod_CS_1 = heap->l________________mod_1;
										MemMove( &heap->c_set_red_state_vi_set_CT, &heap->c_set_red_state_vi_set_ST_5, sizeof( cl_A0000 ) );
										/* begin case */
										if ( ( (heap->l________________mod_CS_1 == 1) ) ) {
											{
												heap->n_sampleInterval_3 = 6.0000000000000000000E+1;
												heap->l_pow_2 = 100;
												/* Free unwired input select tunnel. */
	if ((set_ai_power_Run( 	int32DataType, heap->l_pow_2	)) == eFail) CGenErr();
												{
													heap->XNodeTunE47 = 0;
/* Inline C node */
													{
														int16 error = 0;
														float32 sampleInterval = 0.0;
														error = heap->XNodeTunE47;
														sampleInterval = heap->n_sampleInterval_3;

														{
															#include "node3_inlineC__124.h"
															heap->XNodeTunE5C = error;
														}

#undef log
#undef log2
#undef ln
													}
												}
											}
										} /* end case */
										/* begin case */
										else {
											{
												heap->n_sampleInterval_2 = 5.0000000000000000000E+0;
												{
													heap->XNodeTunDD7 = 0;
/* Inline C node */
													{
														int16 error = 0;
														float32 sampleInterval = 0.0;
														error = heap->XNodeTunDD7;
														sampleInterval = heap->n_sampleInterval_2;

														{
															#include "node3_inlineC__118.h"
															heap->XNodeTunDF6 = error;
														}

#undef log
#undef log2
#undef ln
													}
												}
/* Unbundle by name */
												{
													cl_A0000* cl_009 = (cl_A0000*)&heap->c_set_red_state_vi_set_CT;
													heap->l________________pow = cl_009->el_2;
	}
												if ((set_ai_power_Run( 	int32DataType, heap->l________________pow	)) == eFail) CGenErr();
											}
										} /* end case */
									} /* end switch */
									MemMove( &heap->c_Case_Structure_CT, &heap->c_set_red_state_vi_set_ST_5, sizeof( cl_A0000 ) );
								}
								/* FreeLoopInputs. */
	if (heap->s_____________________________S && (((PDAStrPtr)heap->s_____________________________S)->refcnt > 0)) {
									if ((--((PDAStrPtr)heap->s_____________________________S)->refcnt == 0) && (!((PDAStrPtr)heap->s_____________________________S)->staticStr)) {
										MemHandleFree( heap->s_____________________________S );
										heap->s_____________________________S=NULL;
									}
								}
								/* FreeLoopInputs. */
	{
									node3_GlobalConstantsHeapPtr->i83B = PDAStrNewFromBuf(_LVT("received: "),(uInt32)10);
									heap->s_Constant = node3_GlobalConstantsHeapPtr->i83B;
									PDAStrIncRefCnt(heap->s_____________________________S_1, (uInt16)1); /* SequenceTunnel */
									{
										ControlDataItemPtr cdPtr = LVGetCurrentControlData();
										CreateArgListStatic(heap->Args82F_1, 2, 1 );
										argIn(heap->Args82F_1, 0).nType = StringDataType;
										argIn(heap->Args82F_1, 0).pValue = (void *)&heap->s_Constant;
										argIn(heap->Args82F_1, 1).nType = StringDataType;
										argIn(heap->Args82F_1, 1).pValue = (void *)&heap->s_____________________________S_1;
										argOut(heap->Args82F_1, 0).nType = StringDataType;
										argOut(heap->Args82F_1, 0).pValue = (void *)&heap->s________________________;
										if (!PDAStrConcat( (ArgList *)((ArgList **)heap->Args82F_1)[0], (ArgList *)((ArgList **)heap->Args82F_1)[1] )) {
											CGenErr();
										}
										if (gAppStop) {
											gAppStop=true;
											return eFinished;
										}
									}
									{
										heap->XNodeTun84A = 0;
										heap->s_________________________XT = heap->s________________________;
										PDAStrIncRefCnt(heap->s_________________________XT, (uInt16)1); /* FrameTunnel */
										/**/
										/* 字符串长度 */
										/**/
										heap->l________________ = (int32)PDAStrLen(heap->s_________________________XT);
										/**/
										/* 字符串至字节数组转换 */
										/**/
										if (!PDAStrToArray(heap->s_________________________XT, &(heap->a______________________________))) {
											CGenErr();
										}
/* Inline C node */
										{
											int16 error = 0;
											PDAArrPtr sendDebugMessage_nodeTempArrayHandle = NULL;
											uInt8* sendDebugMessage = NULL;
											int32 sendDebugMessageLength = 0;
											error = heap->XNodeTun84A;
											sendDebugMessage_nodeTempArrayHandle=PDAArrCopyOnModify( heap->a______________________________ );
											sendDebugMessage = (VoidHand)FirstElem(sendDebugMessage_nodeTempArrayHandle);
											sendDebugMessageLength = heap->l________________;

											{
												#include "node3_inlineC__130.h"
												heap->XNodeTun84E = error;
											}

											/* Free input array without corresponding output in inline C node */
	if ((sendDebugMessage_nodeTempArrayHandle) && ((sendDebugMessage_nodeTempArrayHandle)->refcnt > 0)) {
												if (((sendDebugMessage_nodeTempArrayHandle)->refcnt == 1) && ((sendDebugMessage_nodeTempArrayHandle)->staticArray == false)) {
													(sendDebugMessage_nodeTempArrayHandle)->refcnt--;
													MemHandleFree( sendDebugMessage_nodeTempArrayHandle );
													sendDebugMessage_nodeTempArrayHandle=NULL;
												}
												else
												 	PDAArrFree(sendDebugMessage_nodeTempArrayHandle);
											}
#undef log
#undef log2
#undef ln
										}
									}
								}
								/* FreeLoopInputs. */
	if (heap->s_____________________________S_1 && (((PDAStrPtr)heap->s_____________________________S_1)->refcnt > 0)) {
									if ((--((PDAStrPtr)heap->s_____________________________S_1)->refcnt == 0) && (!((PDAStrPtr)heap->s_____________________________S_1)->staticStr)) {
										MemHandleFree( heap->s_____________________________S_1 );
										heap->s_____________________________S_1=NULL;
									}
								}
								heap->b_Case_Structure_CT = heap->b_While_____SR_1;
							}
						} /* end case */
						break;
						/* begin case */
						case 3 : {
							{
								MemMove( &heap->c_Case_Structure_CT, &heap->c_While_____SR_1, sizeof( cl_A0000 ) );
								{
									heap->XNodeTun10B = 0;
									heap->e_Network_Status = 0;
/* Inline C node */
									{
										int16 error = 0;
										uInt32 networkStatus = 0;
										error = heap->XNodeTun10B;
										networkStatus = heap->e_Network_Status;

										{
											#include "node3_inlineC__13B.h"
											heap->XNodeTunC63 = error;
											heap->e_____C______________XT = networkStatus;
										}

#undef log
#undef log2
#undef ln
									}
								}
								{ /* Select */
									heap->e_____C______________CS = heap->e_____C______________XT;
									/* begin case */
									if ( ( (heap->e_____C______________CS == 1) ) ) {
										{
											node3_GlobalConstantsHeapPtr->i23A = PDAStrNewFromBuf(_LVT("Node connected ..."),(uInt32)18);
											heap->s_sendDebugMessage = node3_GlobalConstantsHeapPtr->i23A;
											{
												heap->XNodeTun24B = 0;
												heap->s_sendDebugMessage_XT = heap->s_sendDebugMessage;
												PDAStrIncRefCnt(heap->s_sendDebugMessage_XT, (uInt16)1); /* FrameTunnel */
												/**/
												/* 字符串长度 */
												/**/
												heap->l_________________1 = (int32)PDAStrLen(heap->s_sendDebugMessage_XT);
												/**/
												/* 字符串至字节数组转换 */
												/**/
												if (!PDAStrToArray(heap->s_sendDebugMessage_XT, &(heap->a_______________________________1))) {
													CGenErr();
												}
/* Inline C node */
												{
													int16 error = 0;
													PDAArrPtr sendDebugMessage_nodeTempArrayHandle = NULL;
													uInt8* sendDebugMessage = NULL;
													int32 sendDebugMessageLength = 0;
													error = heap->XNodeTun24B;
													sendDebugMessage_nodeTempArrayHandle=PDAArrCopyOnModify( heap->a_______________________________1 );
													sendDebugMessage = (VoidHand)FirstElem(sendDebugMessage_nodeTempArrayHandle);
													sendDebugMessageLength = heap->l_________________1;

													{
														#include "node3_inlineC__148.h"
														heap->XNodeTun251 = error;
													}

													/* Free input array without corresponding output in inline C node */
	if ((sendDebugMessage_nodeTempArrayHandle) && ((sendDebugMessage_nodeTempArrayHandle)->refcnt > 0)) {
														if (((sendDebugMessage_nodeTempArrayHandle)->refcnt == 1) && ((sendDebugMessage_nodeTempArrayHandle)->staticArray == false)) {
															(sendDebugMessage_nodeTempArrayHandle)->refcnt--;
															MemHandleFree( sendDebugMessage_nodeTempArrayHandle );
															sendDebugMessage_nodeTempArrayHandle=NULL;
														}
														else
														 	PDAArrFree(sendDebugMessage_nodeTempArrayHandle);
													}
#undef log
#undef log2
#undef ln
												}
											}
										}
									} /* end case */
									/* begin case */
									else {
										{
										}
									} /* end case */
								} /* end switch */
								heap->b_Case_Structure_CT = heap->b_While_____SR_1;
							}
						} /* end case */
						break;
						/* begin case */
						case 4 : {
							{
								MemMove( &heap->c_Case_Structure_CT, &heap->c_While_____SR_1, sizeof( cl_A0000 ) );
								heap->b_Case_Structure_CT = heap->b_While_____SR_1;
							}
						} /* end case */
						break;
					}
				} /* end switch */
				MemMove( &heap->c_Case_Structure_SR, &heap->c_Case_Structure_CT, sizeof( cl_A0000 ) );
				MemMove(&node3_heap_lsr->c_While_____SR, &heap->c_Case_Structure_SR, sizeof(cl_A0000));
				heap->b_Case_Structure_SR = heap->b_Case_Structure_CT;
				node3_heap_lsr->b_While_____SR = heap->b_Case_Structure_SR;
			}
			(heap->l_While_____i)++;
		}
		while(!heap->b_Constant && !gAppStop && !gLastError);
		node3_CleanupVIGlobalConstants();
		return eFinished;
	}
}
Example #2
0
int main(int argc, char** argv) {
    std::string sRef, sInFile, sOutFile, sLogFile;
    bool bVerbose;
    uint32_t win;
    uint32_t maxLineLength;

    try {
        TCLAP::CmdLine cmd("Command description message", ' ', "1.0");
        TCLAP::ValueArg<std::string> argReference("r","reference","Karma's reference sequence",true,"","string");
        TCLAP::ValueArg<std::string> argIn("i","in","Input VCF file",true,"","string");
        TCLAP::ValueArg<std::string> argOut("o","out","Output file",true,"","string");
        TCLAP::ValueArg<std::string> argLog("l","log","Log file - [out].log is default",false,"","string");
        TCLAP::SwitchArg switchVerbose("v","verbose","Turn on verbose mode",cmd,false);
        TCLAP::ValueArg<uint32_t> argWindow("w","win","Window size for HomPolymerRun (default:10)",false,10,"integer");
        TCLAP::ValueArg<uint32_t> argMaxLineLength("L","max-line-length","Maximun Line Length of the VCF file (default:1048576)",false,1048576,"integer");

        cmd.add(argReference);
        cmd.add(argIn);
        cmd.add(argOut);
        cmd.add(argLog);
        cmd.add(argWindow);
        cmd.add(argMaxLineLength);

        cmd.parse(argc, argv);

        sRef = argReference.getValue();
        sInFile = argIn.getValue();
        sOutFile = argOut.getValue();
        sLogFile = argLog.getValue();
        bVerbose = switchVerbose.getValue();
        win = argWindow.getValue();
        maxLineLength = argMaxLineLength.getValue();

        if ( sLogFile.empty() ) {
            sLogFile = sOutFile + ".log";
        }
        Logger::gLogger = new Logger(sLogFile.c_str(), bVerbose);

        //    Logger::gLogger->writeLog("Arguments in effect: \n%s",cmd.toString().c_str());
        Logger::gLogger->writeLog("Arguments in effect: \n");
        std::ostringstream oss;
        std::list<TCLAP::Arg*> argList = cmd.getArgList();
        for(std::list<TCLAP::Arg*>::iterator i=argList.begin(); i != argList.end(); ++i) {
            oss << "\t" << (*i)->toString() << std::endl;
        }
        Logger::gLogger->writeLog("%s", oss.str().c_str());
    }
    catch (TCLAP::ArgException &e) {
        std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
        abort();
    }

    GenomeSequence genomeSequence( sRef );

    char* buf = new char[maxLineLength];
    char* leftSequence = new char[win+1];
    char* rightSequence = new char[win+1];

    std::vector<std::string> vChromosomes;
    std::vector<uint32_t> vCoordinates;
    std::vector<char> vRefBases;
    std::vector<std::string> vLeftSequences;
    std::vector<std::string> vRightSequences;

    std::map<std::string,uint32_t> mLeftCounts;
    std::map<std::string,uint32_t> mRightCounts;
    std::vector<uint32_t> vHomPolRuns;

    Logger::gLogger->writeLog("Reading input VCF file %s..",sInFile.c_str());

    std::ifstream ifsVcf(sInFile.c_str());
    if ( ! ifsVcf.is_open() ) {
        Logger::gLogger->error("Error opening file %s",sInFile.c_str());
    }

    while( !ifsVcf.getline(buf, maxLineLength).eof() ) {
        if ( buf[0] == '#' ) {
            // comment line
        }
        else {
            CStringTokenizer t(buf, buf + ifsVcf.gcount(), "\t ");

            t.GetNext();
            std::string sChrom = t.token().c_str();

            t.GetNext();
            uint32_t nPos = static_cast<uint32_t>(atoi(t.token().c_str()));

            genomeIndex_t markerIndex = genomeSequence.getGenomePosition(sChrom.c_str(), nPos);
            bool leftA = true, leftT = true, rightA = true, rightT = true;
            uint32_t leftRun = 0, rightRun = 0;

            if ( markerIndex < win ) {
                Logger::gLogger->error("Marker %s:%u is way too close to the end of genome given window size %u",sChrom.c_str(),nPos,win);
            }

            for(uint32_t i=0; i < win; ++i) {
                rightSequence[i] = genomeSequence[markerIndex+i+1];
                leftSequence[win-i-1] = genomeSequence[markerIndex-i-1];

                switch(rightSequence[i]) {
                case 'A':
                    if ( rightA ) {
                        rightRun = i+1;
                    }
                    rightT = false;
                    break;
                case 'T':
                    if ( rightT ) {
                        rightRun = i+1;
                    }
                    rightA = false;
                    break;
                default:
                    rightT = rightA = false;
                }

                switch(leftSequence[win-i-1]) {
                case 'A':
                    if ( leftA ) {
                        leftRun = i+1;
                    }
                    leftT = false;
                    break;
                case 'T':
                    if ( leftT ) {
                        leftRun = i+1;
                    }
                    leftA = false;
                    break;
                default:
                    leftT = leftA = false;
                }
            }

            leftSequence[win] = rightSequence[win] = '\0';

            //fprintf(fpOut,"%s\t%u\t%d\t%s\t%c\t%s\n",sChrom.c_str(), nPos, (rightRun > leftRun) ? rightRun : leftRun, leftSequence, genomeSequence[markerIndex], rightSequence);

            vChromosomes.push_back(sChrom);
            vCoordinates.push_back(nPos);
            vRefBases.push_back(genomeSequence[markerIndex]);
            vLeftSequences.push_back(leftSequence);
            vRightSequences.push_back(rightSequence);
            ++(mLeftCounts[leftSequence]);
            ++(mRightCounts[rightSequence]);
            vHomPolRuns.push_back( (rightRun > leftRun) ? rightRun : leftRun );
        }
    }

    Logger::gLogger->writeLog("Writing output file %s",sOutFile.c_str());
    FILE* fpOut = fopen(sOutFile.c_str(),"w");

    for(uint32_t i=0; i < vChromosomes.size(); ++i) {
        uint32_t leftCount = mLeftCounts[vLeftSequences[i]];
        uint32_t rightCount = mRightCounts[vRightSequences[i]];
        fprintf(fpOut,"%s\t%u\t%u\t%u\t%.5lf\t%s\t%c\t%s\n",vChromosomes[i].c_str(),vCoordinates[i],vHomPolRuns[i], (leftCount > rightCount) ? leftCount : rightCount, static_cast<double>((leftCount > rightCount) ? leftCount : rightCount)/static_cast<double>(vChromosomes.size()), vLeftSequences[i].c_str(), vRefBases[i], vRightSequences[i].c_str());
    }

    delete[] buf;
    delete[] leftSequence;
    delete[] rightSequence;
}