Click here to Skip to main content
15,922,650 members
Home / Discussions / C#
   

C#

 
Questionanother way Type 'short is short-shrifted, but not short-shifted Pin
BillWoodruff5-May-17 1:10
professionalBillWoodruff5-May-17 1:10 
AnswerRe: another way Type 'short is short-shrifted, but not short-shifted Pin
Jochen Arndt5-May-17 1:32
professionalJochen Arndt5-May-17 1:32 
AnswerRe: another way Type 'short is short-shrifted, but not short-shifted Pin
Pete O'Hanlon5-May-17 1:35
mvePete O'Hanlon5-May-17 1:35 
AnswerRe: another way Type 'short is short-shrifted, but not short-shifted Pin
harold aptroot5-May-17 3:05
harold aptroot5-May-17 3:05 
GeneralRe: another way Type 'short is short-shrifted, but not short-shifted Pin
BillWoodruff5-May-17 4:54
professionalBillWoodruff5-May-17 4:54 
GeneralRe: another way Type 'short is short-shrifted, but not short-shifted Pin
harold aptroot5-May-17 5:19
harold aptroot5-May-17 5:19 
GeneralRe: another way Type 'short is short-shrifted, but not short-shifted Pin
BillWoodruff5-May-17 7:44
professionalBillWoodruff5-May-17 7:44 
QuestionMessage Closed Pin
2-May-17 6:44
SHALCHAUHAN2-May-17 6:44 
AnswerRe: Regarding Website Pin
NotPolitcallyCorrect2-May-17 6:54
NotPolitcallyCorrect2-May-17 6:54 
AnswerRe: Regarding Website Pin
User 41802543-May-17 2:56
User 41802543-May-17 2:56 
QuestionLink DLL at runtime Pin
icristut2-May-17 1:36
icristut2-May-17 1:36 
AnswerRe: Link DLL at runtime Pin
Richard MacCutchan2-May-17 2:22
mveRichard MacCutchan2-May-17 2:22 
GeneralRe: Link DLL at runtime Pin
icristut2-May-17 2:29
icristut2-May-17 2:29 
GeneralRe: Link DLL at runtime Pin
Richard MacCutchan2-May-17 2:35
mveRichard MacCutchan2-May-17 2:35 
GeneralRe: Link DLL at runtime Pin
icristut2-May-17 4:29
icristut2-May-17 4:29 
GeneralRe: Link DLL at runtime Pin
Pete O'Hanlon2-May-17 4:38
mvePete O'Hanlon2-May-17 4:38 
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 

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.