Click here to Skip to main content
15,887,453 members
Home / Discussions / C#
   

C#

 
GeneralRe: Link DLL at runtime Pin
icristut2-May-17 4:44
icristut2-May-17 4:44 
GeneralRe: Link DLL at runtime Pin
Dave Kreskowiak2-May-17 4:16
mveDave Kreskowiak2-May-17 4:16 
AnswerRe: Link DLL at runtime Pin
ZurdoDev2-May-17 4:38
professionalZurdoDev2-May-17 4:38 
GeneralRe: Link DLL at runtime Pin
icristut2-May-17 4:41
icristut2-May-17 4:41 
QuestionForm Designer Pin
Mangesh Sachane2-May-17 1:15
Mangesh Sachane2-May-17 1:15 
AnswerRe: Form Designer Pin
Pete O'Hanlon2-May-17 1:35
mvePete O'Hanlon2-May-17 1:35 
SuggestionRe: Form Designer Pin
Jochen Arndt2-May-17 1:38
professionalJochen Arndt2-May-17 1:38 
QuestionHelp to convert C into C# Pin
Vulaye1-May-17 22:52
Vulaye1-May-17 22:52 
Hi,

I come here because I need help to convert a C code into a C# code.

This is the C code which consists of eliminating aberrant values of a serie of data, then smoothing the data.

C#
int main(int argc, char *argv[])
{
  int   i, i1, n, low, high, filter=2, ntime=20 ;
  double time[20]={20.0,48.0,42.3,39.9,39.0,41.4,44.0,52.0,53.1,49.7,42.0,40.1,100.0,45.0,50.0,47.0,43.1,41.0,39.0,42.2};
  double average[20]={0.0},difference[20]={0.0},averagedif[20]={0.0}, localaverage ;
  double timeresult[20], smoothing[20]={0.0};
 
 
  /* 
   * Calculation of moving average (on 5 values) and difference
   */
  for ( i = 0 ; i < ntime ; i++ ) {
    low = i - filter ;
    high = i + filter ;
 
    if ( low < 0 ) low = 0 ;
    if ( high >= ntime ) high = ntime ;
 
    n = 0 ;
    for ( i1 = low ; i1 < high ; i1++ ) {
      average[i] = average[i] + time[i1] ;
      n = n + 1 ;
    }
    average[i] = average[i] / (double)n ;
    difference[i] = average[i] - time[i] ;
  }
 
  /* 
   * Calculation of average of the differences and replacement of aberrant peaks */
  for ( i = 0 ; i < ntime ; i++ ) {
    low = i - filter ;
    high = i + filter ;
 
    if ( low < 0 ) low = 0 ;
    if ( high >= ntime ) high = ntime ;
 
    n = 0 ;
    for ( i1 = low ; i1 < high ; i1++ ) {
      averagedif[i] = averagedif[i] + difference[i1] ;
      n = n + 1 ;
    }
    averagedif[i] = averagedif[i] / (double)n ;
 
    /* Test in function of the distance between difference and difference's average */
    if ( fabs(difference[i]) < fabs(averagedif[i]) )
      timeresult[i] = time[i] ;
    else {
      /* New calculation of average without the central point */
      /* Only if the differences on one hand and on the other hand are in the same direction */
      if ( i != 0 && i != (ntime-1) ) {
	if ( (difference[i]*difference[i-1] < 0.0) && (difference[i-1]*difference[i+1] > 0.0)) {
	  localaverage = 0.0 ;
	  n = 0 ;
	  for ( i1 = low ; i1 < high ; i1++ ) {
	    if ( i1 != i ) {
	     localaverage = localaverage + time[i1] ;
	      n = n + 1 ;
	    }
	  }
	  localaverage = localaverage / (double)n ;
	  timeresult[i] = localaverage ;
	}
	else
	  timeresult[i] = time[i] ;
      }
      else
      timeresult[i] = time[i] ;
    }
  }
 
 
  /* 
   * Calculation of the final smoothing (on 3 values) after eliminating aberrant peaks */
  for ( i = 0 ; i < ntime ; i++ ) {
    low = i - filter ;
    high = i + filter ;
 
    if ( low < 0 ) low = 0 ;
    if ( high >= ntime ) high = ntime ;
 
    n = 0 ;
    for ( i1 = low ; i1 < high ; i1++ ) {
      smoothing[i] = smoothing[i] + timeresult[i1] ;
      n = n + 1 ;
    }
    smoothing[i] = smoothing[i] / (double)n ;
  }
 
  /* Print */
  fprintf ( stdout, "\n T\taverage\tdifference\taveragedif\tT result\tSmoothing\n");
  for ( i = 0 ; i < ntime ; i++ )
    fprintf ( stdout, "\n %g\t%g\t%g\t%g\t%g\t%g",time[i],average[i],difference[i],averagedif[i],timeresult[i],smoothing[i]);
 
  /* Print in file */
  writefich ( time, 20, "Input.dat" );
  writefich ( timeresult, 20, "Output.dat" );
  writefich ( smoothing, 20, "Smoothing.dat" );
 
 
  return 1 ;
}


Do you have some suggestions to help me to convert this C code into C# ?

Thanks in advance !

Wink | ;)
AnswerRe: Help to convert C into C# Pin
Jochen Arndt1-May-17 23:19
professionalJochen Arndt1-May-17 23:19 
AnswerRe: Help to convert C into C# Pin
OriginalGriff1-May-17 23:35
mveOriginalGriff1-May-17 23:35 
GeneralRe: Help to convert C into C# Pin
Vulaye1-May-17 23:43
Vulaye1-May-17 23:43 
GeneralRe: Help to convert C into C# Pin
OriginalGriff2-May-17 0:24
mveOriginalGriff2-May-17 0:24 
QuestionA way to overlay a transparent image on the screen that does not respond to the mouse. Pin
bions1-May-17 7:06
bions1-May-17 7:06 
GeneralRe: A way to overlay a transparent image on the screen that does not respond to the mouse. Pin
Richard MacCutchan1-May-17 7:26
mveRichard MacCutchan1-May-17 7:26 
GeneralRe: A way to overlay a transparent image on the screen that does not respond to the mouse. Pin
bions1-May-17 10:24
bions1-May-17 10:24 
GeneralRe: A way to overlay a transparent image on the screen that does not respond to the mouse. Pin
Dave Kreskowiak1-May-17 14:06
mveDave Kreskowiak1-May-17 14:06 
GeneralRe: A way to overlay a transparent image on the screen that does not respond to the mouse. Pin
Richard MacCutchan1-May-17 20:43
mveRichard MacCutchan1-May-17 20:43 
QuestionCrystal Report installation File missing Error and Run time file loading error Pin
Member 1253182629-Apr-17 9:47
Member 1253182629-Apr-17 9:47 
AnswerRe: Crystal Report installation File missing Error and Run time file loading error Pin
CHill6029-Apr-17 9:55
mveCHill6029-Apr-17 9:55 
AnswerRe: Crystal Report installation File missing Error and Run time file loading error Pin
OriginalGriff29-Apr-17 21:33
mveOriginalGriff29-Apr-17 21:33 
GeneralRe: Crystal Report installation File missing Error and Run time file loading error Pin
Richard Andrew x6430-Apr-17 9:26
professionalRichard Andrew x6430-Apr-17 9:26 
QuestionHow to fill DataGridView Cells on cellvaluechanged in MYSQL in C#? Pin
TatsuSheva28-Apr-17 23:33
TatsuSheva28-Apr-17 23:33 
SuggestionRe: How to fill DataGridView Cells on cellvaluechanged in MYSQL in C#? Pin
CHill6029-Apr-17 2:32
mveCHill6029-Apr-17 2:32 
AnswerRe: How to fill DataGridView Cells on cellvaluechanged in MYSQL in C#? Pin
User 418025429-Apr-17 3:01
User 418025429-Apr-17 3:01 
QuestionHOW I CAN MOVE LIGHT POINT FROM POINT TO POINT IN TIME Pin
Member 1315403828-Apr-17 21:16
Member 1315403828-Apr-17 21:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.