user-0 提问: c代码 转为 C#代码  急急~~~

回复:
user: user-1
content: 不要做A语言代码修改为B语言代码的无用功。 也不要做用A语言代码直接调用B语言代码库这样复杂、这样容易出错的傻事。 只需让A、B语言代码的输入输出重定向到文本文件，或修改A、B语言代码让其通过文本文件输入输出。 即可很方便地让A、B两种语言之间协调工作。 比如： A将请求数据写到文件a.txt，写完后改名为aa.txt B发现aa.txt存在时，读取其内容，调用相应功能，将结果写到文件b.txt，写完后删除aa.txt，改名为bb.txt A发现bb.txt存在时，读取其内容，读完后删除bb.txt 以上A可以替换为任何一种开发语言或开发环境，B可以替换为任何一种与A不同的开发语言或开发环境。 除非A或B不支持判断文件是否存在、文件读写和文件更名。 但是谁又能举出不支持判断文件是否存在、文件读写和文件更名的开发语言或开发环境呢？  共享临时文本文件这种进程之间的通讯方法相比其它方法的优点有很多，下面仅列出我现在能想到的： ·进程之间松耦合 ·进程可在同一台机器上，也可跨机，跨操作系统，跨硬件平台，甚至跨国。 ·方便调试和监视，只需让第三方或人工查看该临时文本文件即可。 ·方便在线开关服务，只需删除或创建该临时文本文件即可。 ·方便实现分布式和负载均衡。 ·方便队列化提供服务，而且几乎不可能发生队列满的情况（除非硬盘空间满） ·……

user: user-2
content: 可以用托管的方式打包给C#来调用，不需要转换吧

user: user-0
content: 以下为shiyanshuju9.c代码  部分2 /*******************************************************************  *  *  nNet_shiyanshuju9()  *  *  This is the main recall routine. It passes real world data  *  through Predict's data analysis and transformations, then  *  through the neural net, and then converts the output of the neural  *  net back to real world values. You can optionally obtain the network  *  outputs by passing a pointer (rpNetOut) to an array of size NOTPES.  *  ********************************************************************  */ #if defined(__STDC__) int nNet_shiyanshuju9(     Net_shiyanshuju9_In  *tpIn,           /* input structure */     Net_shiyanshuju9_Out *tpOut,          /* output structure */     float      *rpNetOut)       /* network outputs */ #else int nNet_shiyanshuju9( tpIn, tpOut, rpNetOut )     Net_shiyanshuju9_In  *tpIn;           /* input structure */     Net_shiyanshuju9_Out *tpOut;          /* output structure */     float      *rpNetOut;       /* network outputs */ #endif {     double       dX;                    /* current input value */     double       dW, dW1, dW2;          /* intermediate calculations */     double       dLast = 0.;            /* last continuous transform */     double       dMax;                  /* value of PE with highest output */     int          nType;                 /* -1 = missing, 0=valid, 1=NaN */     int          nOther;                /* other flag */     int          nX, nMax;              /* index of PE with highest output */     long         lV;                    /* long work value */     char        *cpEnd;                 /* end pointer */     char         caTmp[32];             /* work string */     float        raNetIn[NINPES];       /* neural net input data */     float        raNetOut[NOTPES];      /* neural net output data */      /* --- Convert Numeric Input to Floating Point Value --- */     if ( ISBADNUM( tpIn->f_IN_1 ) ) {        nType = 1; dX = (-261.8901);     } else {        nType = 0; dX = tpIn->f_IN_1;     }     if ( nType == 0 && (-225.3804) < (-106.3546) ) {        /* --- linear --- */        dW =  dX < (-225.3804)? (-225.3804):(dX < (-106.3546)? dX:(-106.3546));        raNetIn[0] = dLast = 0.9724129 * ( dW * 1.680308e-002 + 2.7870848 ) + (-2.7586956e-002);     } else {        raNetIn[0] = 0.;     }      /* --- Convert Numeric Input to Floating Point Value --- */     if ( ISBADNUM( tpIn->f_IN_2 ) ) {        nType = 1; dX = 25.6771;     } else {        nType = 0; dX = tpIn->f_IN_2;     }     if ( nType == 0 && 25.6771 < 30.8204 ) {        /* --- linear --- */        dW =  dX < 25.6771? 25.6771:(dX < 30.8204? dX:30.8204);        raNetIn[1] = dLast = 0.80638045 * ( dW * 0.38885534 + (-10.984676) ) + 0.19361891;     } else {        raNetIn[1] = 0.;     }      /* --- Convert Numeric Input to Floating Point Value --- */     if ( ISBADNUM( tpIn->f_IN_4 ) ) {        nType = 1; dX = 0.;     } else {        nType = 0; dX = tpIn->f_IN_4;     }     if ( nType == 0 && 12.7283 < 38.7375 ) {        /* --- linear --- */        dW =  dX < 12.7283? 12.7283:(dX < 38.7375? dX:38.7375);        raNetIn[2] = dLast = 0.9387166 * ( dW * 7.689587e-002 + (-1.9787537) ) + 6.1283372e-002;     } else {        raNetIn[2] = 0.;     }      /* --- Convert Numeric Input to Floating Point Value --- */     if ( ISBADNUM( tpIn->f_IN_7 ) ) {        nType = 1; dX = 0.;     } else {        nType = 0; dX = tpIn->f_IN_7;     }     if ( nType == 0 && 0. < 0.2677 ) {        /* --- linear --- */        dW =  dX < 0.? 0.:(dX < 0.2677? dX:0.2677);        raNetIn[3] = dLast = 0.6636413 * ( dW * 7.4710503 + (-1.) ) + 0.33635873;     } else {        raNetIn[3] = 0.;     }      /* --- Convert Numeric Input to Floating Point Value --- */     if ( ISBADNUM( tpIn->f_IN_10 ) ) {        nType = 1; dX = 299.817;     } else {        nType = 0; dX = tpIn->f_IN_10;     }     if ( nType == 0 && 299.817 < 998.3171 ) {        /* --- linear --- */        dW =  dX < 299.817? 299.817:(dX < 998.3171? dX:998.3171);        raNetIn[4] = dLast = 0.6708539 * ( dW * 2.8632781e-003 + (-1.8584594) ) + 0.32914603;     } else {        raNetIn[4] = 0.;     }      /*******************************************      *      * Neural Network Recall      *      *******************************************      */      if (tpOut != (Net_shiyanshuju9_Out *)0 || rpNetOut != (float *)0 )         PrdNet( raNetIn, raNetOut);                     /* run the network if required */      if ( rpNetOut != (float *)0 )                       /* copy raw outputs to user */         MEMCPY( (void *)rpNetOut, (void *)&raNetOut[0], sizeof(raNetOut) );      /* --- Convert Network Output to data Fields --- */      /*******************************************      *      * Output calculations      *      *******************************************      */     if (tpOut != (Net_shiyanshuju9_Out *)0         ) {        /* --- Output for <OUT_1> is continuous numeric value --- */        dX = 0;        /* --- x^0.5 --- */        dW = (raNetOut[0] - (-5.479496e-002)) / 0.17327541;        dX += (dW * dW - (-83.47722)) / 7.398113;           tpOut->f_OUT_1 = dX;         /* --- Output for <OUT_2> is continuous numeric value --- */        dX = 0;        /* --- x^2 --- */        dW = (raNetOut[1] - (-0.210087)) / 0.24005497;        dW = (dW < 0.1) ? 0.1:dW;  /* prevent domain errors */        dW = sqrt(dW);        dX += (dW - (-12.794007)) / 0.46550173;           tpOut->f_OUT_2 = dX;         /* --- Output for <OUT_3> is continuous numeric value --- */        dX = 0;        /* --- log(x) --- */        dW = exp((raNetOut[2] - (-9.637166e-002)) / 0.39988765);        dX += (dW - 74.95206) / (-5.785321);           tpOut->f_OUT_3 = dX;         /* --- Output for <OUT_4> is continuous numeric value --- */        dX = 0;        /* --- x^2 --- */        dW = (raNetOut[3] - (-0.4134845)) / 0.40517074;        dW = (dW < 0.1) ? 0.1:dW;  /* prevent domain errors */        dW = sqrt(dW);        dX += (dW - (-9.282644)) / 0.35905418;           tpOut->f_OUT_4 = dX;         /* --- Output for <OUT_5> is continuous numeric value --- */        dX = 0;        /* --- 1/x --- */        dW = (raNetOut[4] - 2.4429321) / (-9.077021);        dW = (dW < 0.11111111) ? 0.11111111:dW;  /* prevent domain errors */        dX += (1. / dW - (-34.681297)) / 9.605234;           tpOut->f_OUT_5 = dX;      }     return( 0 ); }

user: user-0
content: 以下为shiyanshuju9.c代码  部分1  #include <stdio.h>       /* file i/o */ #include <stdlib.h>      /* strtod(), strtol(), gcvt() */ #include <math.h>        /* exp(), log(), tanh(), etc. */ #include <string.h>      /* strcmp(), strcpy(), memcpy(), memset() */ #include <ctype.h>       /* iscntrl() */  #define NINPES 5 #define NOTPES 5 #define NOUTWT 30  /************************************  ************************************  *    Network Initialization  ************************************  ************************************  */  #if defined(PII_FC) static void *vpDPNetPtr = {0};     /* network pointer for DPack */  #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #if defined(__STDC__) || defined(PROTOTYPE) extern int PII_FC( void *, float *, float * ); #else extern int PII_FC(); #endif #ifdef __cplusplus } #endif /* __cplusplus */  /* --- Call Professional II/PLUS FlashCode or Designer Pack --- */ /* Also, see function below to set the network pointer.  * Use: FlashCode  *    1) Generate FlashCode using Professional II/PLUS.  *    2) Compile this module with -DPII_FC=NN_Recall (substitute root name)  *    3) Compile the Flash Code function.  *    4) Link together.  The FlashCode from PII will be called instead of  *       the NeuralWorks Predict Network.  * Use: Designer Pack  *    1) Generate "C" Code using Designer Pack.  *    2) Compile this module using -DPII_FC=DPackRecall (substitute root name)  *    3) After opening a network with DPack, call vPRFCROOT_SetDPHandle( (void *)handle )  *    4) Link together.  The DPack network will be called instead of the  *       NeuralWorks Predict Network.  */ #if defined(__STDC__) static void PrdNet(float *rpXIn, float *rpXOut) #else static void PrdNet( rpXIn, rpXOut ) float *rpXIn, *rpXOut; #endif {     (void)PII_FC( vpDPNetPtr, rpXIn, rpXOut );     return; }  #else /* Output weights */ static float raWt2Out[NOUTWT] = {    /* 0 */ (float)-6.9772303e-003,    /* 1 */ (float)-0.22497514,    /* 2 */ (float)0.98650813,    /* 3 */ (float)0.23666802,    /* 4 */ (float)0.79942703,    /* 5 */ (float)1.5066184,    /* 6 */ (float)-6.233854e-002,    /* 7 */ (float)2.3891075e-002,    /* 8 */ (float)1.918594,    /* 9 */ (float)-1.0658346,    /* 10 */ (float)0.8399428,    /* 11 */ (float)-2.2225966,    /* 12 */ (float)0.13121328,    /* 13 */ (float)-0.15465668,    /* 14 */ (float)-1.1468887,    /* 15 */ (float)-0.59482586,    /* 16 */ (float)-0.7353769,    /* 17 */ (float)3.7726889,    /* 18 */ (float)-5.0419986e-002,    /* 19 */ (float)0.15658432,    /* 20 */ (float)1.0938865,    /* 21 */ (float)-1.9184152,    /* 22 */ (float)1.1970326,    /* 23 */ (float)-0.6883255,    /* 24 */ (float)8.570853e-003,    /* 25 */ (float)-0.10618572,    /* 26 */ (float)-2.0398974,    /* 27 */ (float)-1.0895295,    /* 28 */ (float)-1.2608963,    /* 29 */ (float)5.4203014, };  /* Output layer scale */ static float raOScale[NOTPES] = {    /* 0 */ (float)0.9548405,    /* 1 */ (float)1.004153,    /* 2 */ (float)1.0021739,    /* 3 */ (float)0.99405915,    /* 4 */ (float)0.9990998, }; /* Output layer offset */ static float raOOffst[NOTPES] = {    /* 0 */ (float)3.686923e-002,    /* 1 */ (float)1.0166546e-002,    /* 2 */ (float)-4.751115e-003,    /* 3 */ (float)6.515321e-003,    /* 4 */ (float)2.905434e-003, };   /************************************  ************************************  *    Network Recall  ************************************  ************************************  */  #if defined(__STDC__) || defined(PROTOTYPE) static void PrdNet( float *, float * ); #endif  #if defined(__STDC__) static void PrdNet(float *rpXIn, float *rpXOut) #else static void PrdNet( rpXIn, rpXOut ) float *rpXIn, *rpXOut; #endif {    float     *rpX1, *rpW1;    float     *rpWB, *rpI;    float     *rpSc, *rpOf;    int        nX, nY;    float      rS, rX;     /* Output layer calculations */    for (nX = 0,         rpSc = &raOScale[0],         rpOf = &raOOffst[0],         rpX1 = rpXOut,         rpW1 = &raWt2Out[0];         nX < NOTPES;         rpSc++, rpOf++,         nX++, rpX1++) {       rS = *rpW1++;  /* bias */       for (nY=NINPES,   /* input -> output */            rpI = rpXIn;            nY > 0;            nY--, rpI++, rpW1++) {          rS += (*rpI)*(*rpW1);       }       rS = 1.0 / (1.0 + exp(-rS));   /* sigmoid */       *rpX1 = (*rpSc) * rS + (*rpOf);  /* post scaling */    }     return; } #endif /* PII_FC */  /* --- Data Transformations --- */   #include "shiyanshuju9.h"     /* definitions of input & output structures */  #if !defined(STRCMP)                    /* allow user to make alternate definitions */ #define STRCMP(s1,s2) strcmp(s1,s2) #endif  #if !defined(STRCPY) #define STRCPY(d,s)   strcpy(d,s) #endif  #if !defined(MEMCPY) #define MEMCPY(d,s,n) memcpy(d,s,n) #endif  #if !defined(_WINDOWS) && !defined(WINDOWS) && !defined(IsDBCSLeadByte) #define NoDBCS                  1 #define IsDBCSLeadByte(x)       0 #endif  /* --- Math Exception Detection --- */  #if defined(VAXULT) || defined(VMS) #define NAN_MASK         0x00007f80                     /* VAX IEEE Numbers */ #define NAN_VALUE        (NAN_MASK|0x00014000) #else #define NAN_MASK         0x7f800000                     /* Standard IEEE Numbers */ #define NAN_VALUE        (NAN_MASK|0x00400001) #endif #define ULREP(x)         (*((unsigned long *)&(x))) #define ISNAN(x)         ((ULREP(x)&NAN_MASK)==NAN_MASK)        /* NaN test for float */  #if defined(__SC__) #include <fltpnt.h> #define isinf(x)        (fpclassify(x)==FP_INFINITE) #define issubnormal(x)  (fpclassify(x)==FP_SUBNORMAL) #endif  #if defined(__sgi) #include <ieeefp.h> #define isinf(x)        (fpclass(x)==FP_NINF    || fpclass(x)==FP_PINF) #define issubnormal(x)  (fpclass(x)==FP_NDENORM || fpclass(x)==FP_PDENORM) #endif  #if defined(RS6) #include <fp.h> #define isinf(x)        (IS_INF(x)) #define issubnormal(x)  (IS_DENORM(x)) #endif  #if defined(HP700) #define issubnormal(x)  (fpclassify(x)==FP_MINUS_DENORM || fpclassify(x)==FP_PLUS_DENORM) #endif  #if defined(isinf) && defined(issubnormal) #define ISBADNUM(x) (ISNAN(x) || isinf(x) || issubnormal(x)) #else #define ISBADNUM(x)  ISNAN(x) #endif  #define ZTINY   (1.e-5) /*********************************************************************  *  * nNet_shiyanshuju9DimGet(nWhich)  *  * Use this routine to get various array dimensions  *  *   nWhich can take on the following values  *  *    0:  Number of input fields  *    1:  Number of output fields  *    2:  Number of active input transforms (i.e. neural net inputs)  *    3:  Number of active output transforms (i.e. neural net outputs)  *  *********************************************************************  */ #if defined(__STDC__) int nNet_shiyanshuju9DimGet(     int        nWhich)         /* Which dimension to get */ #else int nNet_shiyanshuju9DimGet( nWhich )     int        nWhich;         /* Which dimension to get */ #endif {    switch(nWhich) {      case 0:   return(26);      case 1:   return(5);      case 2:   return(NINPES);      case 3:   return(NOTPES);    }    return(0); }