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
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
• In square brackets, you need to specify how long the string is capable of being.
• Usually overestimate, just to be sure.
• char station[5];
What We Use Strings For
• The variables that contain information such as the names of the observing stations will be strings.
Strings Are Tricky
• Seems like this should work to assign a string…but “=“ doesn’t work for strings.
main () {
char station[5];
station = “KOMA”;
}
Strings Are Tricky
• Rather, use the strcpy function (“string copy”).
main () {
char station[5];
strcpy(station,“KOMA”);
}
Strings Are Tricky
• Use the %s format specifier to print strings…
main () {
char station[5];
strcpy(station,“KOMA”);
printf (“%s\n”,station);
}
Strings Are Tricky
• …or to scanf or fscanf a string.
main () {
char station[5];
scanf (“%s”,&station);
}
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;
}
Typecasting
• Notice the types of Temp and iTemp.
main () {
float Temp;
int iTemp;
iTemp = 47;
Temp = (float) iTemp;
}
Typecasting
• The integer “47” becomes the float “47.0000000” with this “typecast”.
main () {
float Temp;
int iTemp;
iTemp = 47;
Temp = (float) iTemp;
}
Typecasting
• The new “type” is in parentheses, just before what is to be converted.
main () {
float Temp;
int iTemp;
iTemp = 47;
Temp = (float) iTemp;
}
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;
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”);
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 $
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 $
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);
}
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 $
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 $
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 $
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 $
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 $
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 $
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 $
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 $
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 $
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 $
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 $