Tuesday, January 29, 2008

EATS1011 Lecture 8

Clouds

  • Clouds to fall but then they fall into warmer air and evaporate
  • CCN: 100%
    • Cloud condensation Nuclei (CCN)
  • Newton's first law
    • The droplet of radius r
    • The droplet's going down
    • And friction of particles in the air
    • Eventually balance out
    • Friction force
      • 6πR(eta) V
        • Eta is viscosity (missing symbol)
    • Gravitational force
      • M*g
        • M ass of the droplet
        • G ravity
        • = 4/3πR3
    • These two forces equal each other out
    • Get formulas from website
    • This only applies to 'small' droples (< 100microns)
    • Terminal Velocity




    • VT = 6x103 R(m) m/s (R> 100 mm)
  • Condenstation -> growth
    • 1/R
  • 1) collision and coalescence
    • Warm
  • 2) bergeon process
    • Mixed phase clouds
      • (liquid water + ice)
    • The difference in vapour pressure drives the growth of the droplets
  • Size spectrum
    • 1 micron -> 5 microns -> 10 microns – 15 microns – 50 microns
    • The small ones fall slower than the large ones
    • The large one sweep up the smaller ones under them
      • Until the droplet gets even bigger and falls faster
      • If there are enough small particles you can see how we get very large droplets

Thursday, January 24, 2008

CSE 2031 Lecture 6

Arrays and pointers

  • An array name by itself is
    • An address
    • A pointer value
  • A pointer is
    • A variable taking addresses as values
  • An array name is
    • A particular fixed address
    • Like a constant pointer
  • When an array is declared, the compiler allocates
    • A base address
      • The address of element 0
  • And sufficient memory allocation for the rest of the elements

Array indexing and pointer arithmetic

#define MAXSIZE 1024

int A[MAXSIZE], *p;

/*

*space allocated for A

* but p – has not been given a value , even if it did here wouldn't necessarily be any space allocated *where it pointed

*/

Equivalent Statements

  • P = A;
  • P = A+I;
  • P = &A[0];
  • P=&A[i];
  • P[0]
    • is the same as saying *p
  • p[3]
    • is the same as saying *(p+3)

Summing the Array

  • 4 forms
  • 1

    sum =0;

    int i;

    for (i=0; i<maxSize; i++)

    sum += A[i];


     

  • 2

sum = 0;

for(p=A; p<&A[MAXSIZE];p++)

sum+= *p;

  • 3

sum = 0;

For(i=0;i<MAXSIZE;i++

sum += *(A+i);

  • 4

Sum = 0;

P=A;

For(i=0 i<MAXSIZE;i++)

Sum += p[i]; /*no dereferencing*/

  • Practice adding pointers and casting them
  • When you minus the two you get how many blocks of allocated memory exist between them
  • If you cast them and minus them you get the mem address casted to ints then you get the difference between that

Arrays as function parameters

  • In a function header
    • An array isn't declared w/ a fixed size in a function header
    • Int A[] is equivalent to int *A
      • This ONLY applies to a function parameter
    • Otherwise Int A[] is is NOT equivalent to int *A
      • Int *A; creates a pointer variable
      • Int A[] creates a constant pointer and no storage

Pointers and strings

  • Strings are arrays of char and are ended with \0
    • \0 is a null character
  • "ABC"
    • Type is char*
    • Value is address of the 'A'
  • Char word[] = "xyz"
    • Is the same as char word[] = {'x','y','z','\0'};
  • Char *p = "xyz";
    • Word is an array of length 4.
    • P is a pointer and points (for now) to an array with 4 elements
    • P can change reference
    • *p doesn't allocate new space

Dynamic Memory Allocation

  • Memory allocated while the program is running
  • Stack
    • When there is a function call there are parameters and local variables
    • Space set aside to hold the values for returns when functions are called
      • Stacks grow during recursion
      • Goes from the top down
      • LIFO
    • A stack grows and shrinks automatically
  • Heap
    • Declares space and the space remains allocated

Malloc

  • Void *malloc ( size_T n) /* memory allocation*/
    • Returns pointer to n bytes
    • Parameter is an integer type
      • Signed or unsigned
    • Sets aside an amount of space
    • Set aside contiguously , like an array
    • What is returned is a pointer to the space allocated
    • If space cannot be allocated a null pointer is returned
    • The storage is uninitialized
      • Not necessarily emptied space
    • Returns NULL if it can't be done
  • Void *calloc (size_t n, size_t element_size)
    • Allocate enough space for this many elements that take 'so much space'

Algorithm assessment

  • Is the algorithm running in constant time?
    • Runs the same amount of time no matter when 'n' is
    • O(1)
      • No loops or constant time loops
  • Linear time
    • Does the problem run exactly proportional to the size of 'n'?
    • Dominant single loop dependant linearly on n
  • Logarithmic
    • The algorithm divides the size of the problem by a constant
      • Runs in O(log n)
        • Dominant single lop is a divide by 2 on each iteration

Assertions

  • Boolean expressions or predicates that evaluate to true or false
  • In a program they express constraints on the state that must be true at that point
  • Associate with
    • Individual program statements
    • Functions
    • Classes
  • Specify clearly, precisely and succinctly
    • What is expected and guaranteed by each component
      • Class function and statement
    • The essence of documentation
    • Essential for debugging
    • Aids in fault tolerance
  • Result
    • Result of a query but only in ensure assertions
  • Current
    • @ Current object
  • Void
    • Not attached
  • Name
    • Value of the variable name before a routine starts
  • Name'
    • Value of the name after a routine terminates
    • Alternate name 'old name' instead of Name'
  • **study textual notation**
    • From online notes, cannot type all this

Tuesday, January 22, 2008

CSE 2031 Lecture 5

void makeDouble(int* x)

{

    *x = 2* *x;

}


 

* modifies a pointer

This in English is makeDouble takes an integers pointer

Then the integers pointer is modified.

An '&' sign is a pointer. int I, *p; /* means that there is an integer I and an integer memory reference *p;

An expression has a type and value.

*(r=&j) *= *p

**p dereferences p


 

Pointer to void

  • Why do pointers have types?
    • So we can dereference them

Eats 1011 Lecture 6

ITCZ - intertropical Convergence Zone

ERBE – Earth Radiation Budget Experiment

  • Designed to study the radiative energy
  • Measures radiation coming from the atmosphere

Tropics

  • Solar heating is greater than IR cooling

Polar Regions

  • Solar heating is less than IR cooling

Heat transfers between the two to stop the earth from getting really hot in some areas and really cold in others


 

Water Vapour in the Atmosphere

  • Mixing ratio
    • Troposphere is between 10-2 to 10-5 by volume or mass with most in the lower troposphere
    • Global average ~2.5*10-3
    • Stratosphere 4*10-6 by volume
  • Latent Heat
    • Energy is required/released for a phase change
    • Heat storage when liquid converts to vapour
    • Heat release when vapour turns to water
      • Lv – vaporization – 2.5 * 106 J/Kg
      • Lf – fusion / freezing – 3.3*105
      • Ls – sublimation – Lu + Lf – 2.8*106
        • Energy required / released when 1Kg of material changes state
  • To calculate the amount of energy required for evaporation
    • Need mass of water

      • 2cm = 0.02m rain (over each m2)
      • Density water, pw = 1000kg/m3
      • Mass = 20kg/m2





      • Mean water mixing ratio ~
        • Mass water =
      • Removal rate is estimated from the globally average rainfall ~ 1m / year
      • This is equivalent to about
      • Mass over 1m2 ~ /m2
      • = 1000 kg/m2
      • Turnover time

tresidence = (25kg/m2) / (1000 kg/m2 * year)

Sunday, January 20, 2008

Delete me

Thursday, January 17, 2008

CSE 2031 Lecture 4

Strings

  • strlen(s)
    • returns length
  • strcmp(s,t)
  • returns positive if s>t, negative if s<t, and 0 if they are equal.
  • strcat(s,t)
    • concatenates t onto s
      • changes string s
    • looks or \o and contatenates at that spot

#include <stdio.h>

Int main(void)

{

char s1[] = {'H','e','l','l','o','\o'};

char s2[4];

printf("Address of s1 is %p\n", s1);

printf("address of s2 is %p\n", s2);

printf("Enter a line: ");

fgets(s2, sizeof(s2), stdin);/* bolded represent extras for using fgets*/

printf("%s\n", s2);

printf("%s\n", s1);

return 0;

}


 

  • Fgets is the new one that works better, if you use just gets you will run into problems with memory over runs
  • Where s1 in this example can be overwritten by s2 if the user input is long enough
  • Look up input and output in textbook
  • With fgets it will only take in the amount of characters assigned after the first comma
  • However if less than the specified amount is passed and the enter key is pushed, the new line character will count as 1 char

Pointers

int n = 5;

int *p;

p = &n

printf("%d\n", *p);

printf("%d\n", n);


 


 

  • *p = 7;
    • Changes whatever value P was addressing to 7

If n = 5, and you said this before printing, it would print 7