30
Reading Meteorological Data ATS 315

Reading Meteorological Data

  • Upload
    nia

  • View
    34

  • Download
    4

Embed Size (px)

DESCRIPTION

Reading Meteorological Data. ATS 315. Stuff You’ll Need. strings typecasting. Strings. Strings are sets of characters. Maybe a word, for example. char station[5];. Strings. The “type” for strings is “char”. char station[5];. Strings. - PowerPoint PPT Presentation

Citation preview

Page 1: Reading Meteorological Data

Reading Meteorological Data

ATS 315

Page 2: Reading Meteorological Data

Stuff You’ll Need

• strings

• typecasting

Page 3: Reading Meteorological Data

Strings

• Strings are sets of characters. Maybe a word, for example.

• char station[5];

Page 4: Reading Meteorological Data

Strings

• The “type” for strings is “char”.

• char station[5];

Page 5: Reading Meteorological Data

Strings

• In square brackets, you need to specify how long the string is capable of being.

• Usually overestimate, just to be sure.

• char station[5];

Page 6: Reading Meteorological Data

What We Use Strings For

• The variables that contain information such as the names of the observing stations will be strings.

Page 7: Reading Meteorological Data

Strings Are Tricky

• Seems like this should work to assign a string…but “=“ doesn’t work for strings.

main () {

char station[5];

station = “KOMA”;

}

Page 8: Reading Meteorological Data

Strings Are Tricky

• Rather, use the strcpy function (“string copy”).

main () {

char station[5];

strcpy(station,“KOMA”);

}

Page 9: Reading Meteorological Data

Strings Are Tricky

• Use the %s format specifier to print strings…

main () {

char station[5];

strcpy(station,“KOMA”);

printf (“%s\n”,station);

}

Page 10: Reading Meteorological Data

Strings Are Tricky

• …or to scanf or fscanf a string.

main () {

char station[5];

scanf (“%s”,&station);

}

Page 11: Reading Meteorological Data

Typecasting

• How you convert between two variable types.

• Normally used to convert int to float.

main () {

float Temp;

int iTemp;

iTemp = 47;

Temp = (float) iTemp;

}

Page 12: Reading Meteorological Data

Typecasting

• Notice the types of Temp and iTemp.

main () {

float Temp;

int iTemp;

iTemp = 47;

Temp = (float) iTemp;

}

Page 13: Reading Meteorological Data

Typecasting

• The integer “47” becomes the float “47.0000000” with this “typecast”.

main () {

float Temp;

int iTemp;

iTemp = 47;

Temp = (float) iTemp;

}

Page 14: Reading Meteorological Data

Typecasting

• The new “type” is in parentheses, just before what is to be converted.

main () {

float Temp;

int iTemp;

iTemp = 47;

Temp = (float) iTemp;

}

Page 15: Reading Meteorological Data

What We Use Typecasting For

• The temperature codes in METAR are in tenths of a degree Fahrenheit.

• 224 needs to be converted to 22.4

• temp = ((float) tempcode) / 10.0;

Page 16: Reading Meteorological Data

Where are the observation files?

• The most recent surface observations are kept in a file called /var/data/ldm/convert/current_sao.wxp

fin = fopen (“/var/data/ldm/convert/current_sao.wxp”,”r”);

Page 17: Reading Meteorological Data

What do *_sao.wxp files look like?

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 18: Reading Meteorological Data

What do *_sao.wxp files look like?

• The first line will always read WXPSFC.

• SkipToEndOfLine(fin);

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 19: Reading Meteorological Data

SkipToEndOfLine(fin);

void SkipToEndOfLine (FILE *f) {

fscanf (f,"%*[^\n]\n");

}

main () {FILE *fin;fin = fopen (“/var/data/ldm/convert/current_sao.wxp”,”r”);SkipToEndOfLine(fin);fclose(fin);

}

Page 20: Reading Meteorological Data

What do *_sao.wxp files look like?

• The second line will always be the time the observations were taken.

• This mixture of numbers and letters is a string.

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 21: Reading Meteorological Data

What do *_sao.wxp files look like?

• char timecode[15];

• fscanf (fin, “%[^\n]s\n”, &timecode);

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 22: Reading Meteorological Data

What do *_sao.wxp files look like?

• Each line after that is one decoded METAR from one station.

• There are 1000s of observations.

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 23: Reading Meteorological Data

What do *_sao.wxp files look like?

• Each observation consists of a series of values, separated by spaces.

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 24: Reading Meteorological Data

What do *_sao.wxp files look like?

• The first value is a string—the station identifier.

• Usually declared to be at least 5 characters long.

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 25: Reading Meteorological Data

What do *_sao.wxp files look like?

• Second value: integer that codes up the temperature in tenths of a degree FAHRENHEIT.

• Needs to be typecast to a float, then divided by 10.

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 26: Reading Meteorological Data

What do *_sao.wxp files look like?

• Third value: integer that codes up the dewpoint in tenths of a degree FAHRENHEIT.

• Needs to be typecast to a float, then divided by 10.

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 27: Reading Meteorological Data

What do *_sao.wxp files look like?

• Fourth value: integer that codes up the wind direction and speed.

• Use the function provided in the handout to decode.

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 28: Reading Meteorological Data

What do *_sao.wxp files look like?

• Fifth value: integer that codes up the altimeter setting.

• Read it in, but we aren’t going to use it for anything in this class.

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 29: Reading Meteorological Data

What do *_sao.wxp files look like?

• Sixth value: integer that codes up the mean sea level pressure.

• Decode it like you would in a station model.• If the code is -99, make your variable pres

something negative.

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $

Page 30: Reading Meteorological Data

What do *_sao.wxp files look like?

• The rest of the line contains visibilities, comments, etc… stuff that we aren’t going to work with in this course.

• SkipToEndOfLine(fin);

WXPSFC0900Z 12 FEB 04K17Y 86 50 3204 31 -99 10.0 -99C - @0848 #AO2 $KEDE 428 356 0000 22 -99 10.0 -99M - @0845 #AO2 $MPTO 752 716 0000 980 -99 -99 20F - @0900 $MMMD 734 734 0000 992 133 7.0 -99C - @0846 #50000 977 $MMUN 752 716 1406 996 155 7.0 20F,250S - @0845 #57006 8/508 956 $KMRN 374 338 0000 17 -99 5.0 13B,24O !RA @0847 #AO2 P0003 $