1 / 30

Reading Meteorological Data

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.

nia
Télécharger la présentation

Reading Meteorological Data

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Reading Meteorological Data ATS 315

  2. Stuff You’ll Need • strings • typecasting

  3. Strings • Strings are sets of characters. Maybe a word, for example. • char station[5];

  4. Strings • The “type” for strings is “char”. • char station[5];

  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];

  6. What We Use Strings For • The variables that contain information such as the names of the observing stations will be strings.

  7. Strings Are Tricky • Seems like this should work to assign a string…but “=“ doesn’t work for strings. main () { char station[5]; station = “KOMA”; }

  8. Strings Are Tricky • Rather, use the strcpy function (“string copy”). main () { char station[5]; strcpy(station,“KOMA”); }

  9. Strings Are Tricky • Use the %s format specifier to print strings… main () { char station[5]; strcpy(station,“KOMA”); printf (“%s\n”,station); }

  10. Strings Are Tricky • …or to scanf or fscanf a string. main () { char station[5]; scanf (“%s”,&station); }

  11. 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; }

  12. Typecasting • Notice the types of Temp and iTemp. main () { float Temp; int iTemp; iTemp = 47; Temp = (float) iTemp; }

  13. Typecasting • The integer “47” becomes the float “47.0000000” with this “typecast”. main () { float Temp; int iTemp; iTemp = 47; Temp = (float) iTemp; }

  14. Typecasting • The new “type” is in parentheses, just before what is to be converted. main () { float Temp; int iTemp; iTemp = 47; Temp = (float) iTemp; }

  15. 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;

  16. 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”);

  17. What do *_sao.wxp files look like? WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  18. What do *_sao.wxp files look like? • The first line will always read WXPSFC. • SkipToEndOfLine(fin); WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  19. 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); }

  20. 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. WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  21. What do *_sao.wxp files look like? • char timecode[15]; • fscanf (fin, “%[^\n]s\n”, &timecode); WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  22. What do *_sao.wxp files look like? • Each line after that is one decoded METAR from one station. • There are 1000s of observations. WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  23. What do *_sao.wxp files look like? • Each observation consists of a series of values, separated by spaces. WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  24. 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. WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  25. 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. WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  26. 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. WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  27. 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. WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  28. 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. WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  29. 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. WXPSFC 0900Z 12 FEB 04 K17Y 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 $

  30. 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); WXPSFC 0900Z 12 FEB 04 K17Y 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 $

More Related