This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 5th, 2013  |  syntax: Objective C  |  size: 5.69 KB  |  views: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. - (void)updateConversionLabel:(UITextField *)textField
  2. {
  3.    
  4.    
  5.    
  6.    
  7.     //Float for å få textfieldsene til nummer
  8.     double temprature = [tempratureText.text doubleValue] / 100;
  9.     double methane    = [methaneText.text    doubleValue] / 100;
  10.     double ethane     = [ethaneText.text     doubleValue] / 100;
  11.     double propane    = [propaneText.text    doubleValue] / 100;
  12.     double nbutane    = [nbutaneText.text    doubleValue] / 100;
  13.     double ibutane    = [ibutaneText.text    doubleValue] / 100;
  14.     double npentane   = [npentaneText.text   doubleValue] / 100;
  15.     double ipentane   = [ipentaneText.text   doubleValue] / 100;
  16.     double nhexane    = [nhexaneText.text    doubleValue] / 100;
  17.     double nitrogen   = [nitrogenText.text   doubleValue] / 100;
  18.     double oxygen     = [oxygenText.text     doubleValue] / 100;
  19.    
  20.     double negTemp = 0 - temprature;
  21.    
  22.    
  23.     //Floats og formatters for underflow, overflow
  24.    
  25.    
  26.     double sum = (methane + ethane + propane + nbutane + ibutane + npentane + ipentane + nhexane + nitrogen + oxygen) * 100;
  27.    
  28.     double overflowPart = -100.0 + sum;
  29.     double underflowPart = 100.0 - sum;
  30.    
  31.     NSNumber          *underFlow = [[NSNumber alloc]initWithDouble:underflowPart];
  32.     NSNumberFormatter *underFlowResult = [[NSNumberFormatter alloc] init];
  33.      underFlowResult.numberStyle = NSNumberFormatterDecimalStyle;
  34.     [underFlowResult setNumberStyle:NSNumberFormatterDecimalStyle];
  35.     [underFlowResult setMaximumFractionDigits:4];
  36.    
  37.    
  38.     NSString          *formattedUnderFlow = [underFlowResult stringFromNumber:(NSNumber*)underFlow];
  39.    
  40.    
  41.     NSNumber          *overFlow = [[NSNumber alloc]initWithDouble:overflowPart];
  42.     NSNumberFormatter *overFlowResult = [[NSNumberFormatter alloc] init];
  43.      overFlowResult.numberStyle = NSNumberFormatterDecimalStyle;
  44.     [overFlowResult setNumberStyle:NSNumberFormatterDecimalStyle];
  45.     [overFlowResult setMaximumFractionDigits:4];
  46.    
  47.     NSString          *formattedOverFlow = [overFlowResult stringFromNumber:(NSNumber*)overFlow];
  48.  
  49.  
  50.     //Floats for variabler til ligningen
  51.    
  52.     double result = 5;
  53.    
  54.    
  55.    
  56.     //Ligningen for å regne ut Vi DETTE ER Vi
  57.     double V_Methane  = 0.00013587            *negTemp + 0.0600344222;
  58.     double V_Ethane   = 0.0000846133          *negTemp + 0.0615095778;
  59.     double V_Prophane = 0.00009079333         *negTemp + 0.0770448222;
  60.     double V_nButan   = 0.00009612            *negTemp + 0.0922712;
  61.     double V_iButan   = 0.000100973           *negTemp + 0.09452962;
  62.     double V_nPentan  = 0.0001053867          *negTemp + 0.1084497556;
  63.     double V_iPentan  = 0.00010883            *negTemp + 0.1091473556;
  64.     double V_nHexan   = 0.0001108667          *negTemp + 0.1226542222;
  65.     double V_Nitrogen = 0.0000165914718614718 *negTemp * negTemp + 0.00605352099567096
  66.                                               *negTemp + 0.590940545454541;
  67.     double V_Oxygen   = 0.000193              *negTemp + 0.0625020;
  68.  
  69.     //Ligningen for å regne ut density
  70.    
  71.    
  72.    
  73.    
  74.    
  75.    
  76.     double Mi[10] = {16.0426,30.064,44.0962,558.123,558.123,72.1498,72.1498,86.1766,28.0134,31.9988};
  77.     double Vi[10] = {V_Methane, V_Ethane,V_Prophane,V_nButan,V_iButan,V_nPentan,V_iPentan,V_nHexan,V_Nitrogen,V_Oxygen};
  78.     double fraction[10] = {methane, ethane, propane, nbutane, ibutane,npentane,ipentane,nhexane,nitrogen,oxygen};
  79.    
  80.    
  81.     //double resultTest[3];
  82.     //for (int i=0; i<3; ++i) resultTest[i] = static[i] * dynamic[i];
  83.     double miTimesFrac[10];
  84.     for (int i=0; i<10; ++i) miTimesFrac[i] = Mi[i] * fraction[i];
  85.    
  86.     double miTimesVi[10];
  87.     for (int i=0; i<10; ++i) miTimesVi[i] = Mi[i] * Vi[i];
  88.    
  89.     double TMiTimesVi = 0.0;
  90.     double TMiTimesFrac= 0.0;
  91.     for(unsigned int i=0; i<10; i++)
  92.     {
  93.         TMiTimesFrac+=miTimesFrac[i];
  94.         TMiTimesVi+=miTimesVi[i];
  95.         NSLog(@"Mi * Frac %f, Mi * Vi = %f",TMiTimesFrac, TMiTimesVi);
  96.        
  97.     }
  98.    
  99.  
  100.    
  101.    
  102.  
  103.    
  104.    
  105.    
  106.        
  107.     for (int i=0; i<10; ++i) NSLog(@"%f ", miTimesFrac[i]);
  108.    
  109.  
  110.    
  111.    
  112.    
  113.    
  114.  
  115.    
  116.     //=RESULT=
  117.    
  118.    
  119.    
  120.    
  121.    
  122.    
  123.     /*----------STREK FORDI DET ER CHILL OG JEG ER FERDIG MED FLOATER----------*/
  124.    
  125.     NSString *resultTilGlobal = [[NSString alloc]initWithFormat:@"%.4f",result];
  126.     NSString *resultString    = [[NSString alloc]initWithFormat:@"D = %f",result];
  127.     NSString *overflowString  = [[NSString alloc]initWithFormat:@"Total %@ greater than 100 %%", formattedOverFlow];
  128.     NSString *underflowString = [[NSString alloc]initWithFormat:@"Total %@ less than 100 %%",    formattedUnderFlow];
  129.    
  130.    
  131.     /*----------STREK FORDI DET ER CHILL OG JEG ER FERDIG MED STRINGS----------*/
  132.    
  133.     [[NSUserDefaults standardUserDefaults] setObject:resultTilGlobal
  134.                                               forKey:@"globalMathString"];
  135.    
  136.     /*----------STREK FORDI DET ER CHILL OG JEG ER FERDIG MED DATA MANAGMENT----------*/
  137.  
  138.     if (underflowPart == 100.0)
  139.     {
  140.         outputText.text = @"Start by entering values above";
  141.     }
  142.     if (sum == 100.0)
  143.     {
  144.         outputText.text = resultString;
  145.     }
  146.    
  147.     if (sum > 100.0)
  148.     {
  149.         outputText.text = overflowString;
  150.     }
  151.        
  152.     if (sum < 100.0)
  153.     {
  154.         outputText.text = underflowString;
  155.     }
  156.      
  157.     if (negTemp == 0 && methane == 0 && ethane == 0 && propane == 0 && nbutane == 0 && ibutane == 0 && oxygen == 0 && npentane == 0 && ipentane == 0 && nhexane == 0 && nitrogen == 0)
  158.     {
  159.         outputText.text = @"Start by entering values above";
  160.     }
  161.     /*----------STREK FORDI DET ER CHILL OG JEG ER FERDIG MED 'if'----------*/
  162.    
  163.    
  164.    
  165. }
clone this paste RAW Paste Data