Thread: Im stuck.

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    3

    Im stuck.

    I'm still a rookie with C and I'm calculating some thermodynamic parameters for meteorology and want to show the freezing levels. I can get it too show all heights that are 0 degrees C or lower... but I want it to only show the 1 or 2 levels that the temp changes from positive to zero or lower. Data file example would be

    height temp
    100 10
    1000 -2
    1500 5
    2000 -7
    2500 -15


    I would want it to say there is a freezing level at 1000 and 2000 meters. Any help would be great!
    Last edited by Wx_Kev; 12-04-2012 at 01:03 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Posting your code so far would help as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    3
    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main()
    {
    
     float P, h, T, DpT;  // P=pressure, h=height, T=temperature, DpT=dewpoint temp
     int i;                // counter for loop
     int j;                 // counter for loop
     float K, km;          // K=Temp in Kelvin, km=height in kilometers, LR=Lapse Rate
     float esw;                // saturation vapor pressure over water
     float esi;                  // saturation vapor pressure over ice
     float height[500];           // array of heights in kilometers
     float tempC[500];          // array of temp in celcius
     float tempK[500];             // array of temp in kelvin
     float pressure[500];         // array of pressures
     float dewpt[500];          // array of dewpoint temps
     float BP = 373;             // Boil point at 1 atm
     float TP = 273.16;            // Triple point
     float estw = 1013.25;         // saturation vapor pressure at the steam-point pressure
     float esi0 = 6.1173;            // saturation vapor pressure at the ice-point pressure
     float part1, part2, part3, part4, part5, part6;     // parts of Goff-Gratch formula
    
     const int header_length = 0;
     char buff[256];
     j = 0;
    
    FILE *input;
    
      input = fopen("KLM_ama.txt","r"); //input data file
    
       if(input == NULL)              //input check
         {
           printf("check your file name!\n");
           return(0);
         }
    
       for(i=0; i<header_length; i++)
         {
            fgets(buff,265,input);
         }
    
       while(fgets(buff,256,input))
         {
           fscanf(input,"%f %f %f %f", &P,&h,&T,&DpT);
    
            tempC[j] = T;
            pressure[j] = P;
            dewpt[j] = DpT;
    
            K = tempC[j] + 273;                   // Convert to Kelvin
            km = h/1000;                          // Convert height to kilometer
    
            tempK[j] = K;
            height[j] = km;
    
       //   printf("%5.0f %5.2f %f \n",pressure[j],height[j],tempK[j]);
            j++;
         }
    
       for(j=0; j<200; j++)
         {
           if(tempK[j]>223 && tempK[j]<375)      // calculation over water
            {
             part1 = -7.90298*((BP/tempK[j])-1)+5.02808*log10(BP/tempK[j]);
    
             part2 = 0.00000013816*((pow(10,11.344*(1-(tempK[j]/BP))))-1);
    
             part3 = 0.0081328*((pow(10,-3.49149*((BP/tempK[j])-1)))-1);
    
             esw = (pow(10,part1-part2+part3+log10(estw)));
    
          //   printf("Saturation vapor pressure over water is %5.2f hPa at %5.0f mb \n", esw, pressure[j]);
            }
    
           if(tempK[j]<273 && tempK[j]>173)     // calculation over ice
            {
             part4 = -9.09718*((TP/tempK[j])-1);
    
             part5 = 3.56654*log10(TP/tempK[j]);
    
             part6 = .876793*(1-(tempK[j]/TP));
    
             esi = (pow(10,part4-part5+part6+log10(esi0)));
    
           //  printf("Saturation vapor pressure over ice is %5.3f hPa at %5.0f mb \n", esi, pressure[j]);
    
            }
          }
    
      for(j=0; j<1; j++) // calculation of LCL
         {
          float LCL;
          LCL = ((tempC[j]-dewpt[j])/2.5)*304.8;
    
          printf("LCL hieght is %5.2f meters\n", LCL);
         }
    
       for(j=0; j<200; j++) // calculation of freezing levels
        {
          if(tempC[j]<0)
          {
           printf("freezing levels at: %5.2f hpa\n", pressure[j]);
          }
        }
    
    }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
    // loop over heights
    for ( h = 1 ; h < n ; h++ ) {
      if ( (temp[h-1] < 0 && temp[h] >= 0)  || 
           (temp[h-1] >= 0 && temp[h] < 0) ) {
        // transition
      }
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Dec 2012
    Posts
    3
    Thanks a bunch!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stuck
    By shukiren in forum C Programming
    Replies: 22
    Last Post: 09-27-2011, 07:46 PM
  2. very stuck please help!
    By dac in forum C++ Programming
    Replies: 25
    Last Post: 05-07-2006, 02:45 AM
  3. im stuck, cant fix..HELP
    By swgh in forum C++ Programming
    Replies: 3
    Last Post: 05-03-2005, 08:59 AM
  4. please help, i'm really stuck
    By sweetly in forum C++ Programming
    Replies: 5
    Last Post: 09-30-2003, 03:57 AM
  5. HELP! New To C++ and stuck
    By flatline911 in forum C++ Programming
    Replies: 5
    Last Post: 07-01-2003, 09:45 AM