Guest User

Untitled

a guest
Oct 2nd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 KB | None | 0 0
  1. program read_unidata2
  2.  
  3. use wjc_units_conv_mod
  4. use wjc_wind_spd_dir_to_u_v_mod
  5.  
  6. implicit none
  7.  
  8. ! File Control
  9.  
  10. integer, parameter :: MAXREC = 100
  11.  
  12. character (len=180) :: directory
  13. character (len=180) :: filename
  14. character (len=180) :: csv_filename
  15.  
  16. integer :: ios
  17.  
  18.  
  19. ! Station Harvesting Variables
  20.  
  21. character (len= 4) :: target_station
  22.  
  23. ! Unidata SFLIST Input Variables
  24.  
  25. integer :: yyyy
  26. integer :: mm
  27. integer :: dd
  28. integer :: hh
  29. integer :: mn
  30.  
  31. real, parameter :: FILL_VALUE = -9999.0
  32.  
  33. character (len= 4), dimension(MAXREC) :: station_code = "____"
  34.  
  35. real, dimension(MAXREC) :: longitude = FILL_VALUE
  36. real, dimension(MAXREC) :: latitude = FILL_VALUE
  37. real, dimension(MAXREC) :: elevation = FILL_VALUE
  38.  
  39. real, dimension(MAXREC) :: tmpf = FILL_VALUE
  40. real, dimension(MAXREC) :: dwpf = FILL_VALUE
  41. real, dimension(MAXREC) :: drct = FILL_VALUE
  42. real, dimension(MAXREC) :: sknt = FILL_VALUE
  43. real, dimension(MAXREC) :: pmsl = FILL_VALUE
  44.  
  45. ! Derived Variables
  46.  
  47. real, dimension(MAXREC) :: uwnd = FILL_VALUE
  48. real, dimension(MAXREC) :: vwnd = FILL_VALUE
  49. real, dimension(MAXREC) :: rh = FILL_VALUE
  50.  
  51.  
  52. ! Modified Date-Time for Excel/CSV/R compatability
  53.  
  54. character (len=16), dimension(MAXREC) :: excel_date = "________________"
  55.  
  56. !!!!! Record Counts
  57.  
  58. integer :: i ! index for record count
  59. integer :: number_of_records ! counter for number of records
  60.  
  61. !!!!! Functions
  62.  
  63. ! real :: wjc_degf_to_k_func
  64.  
  65.  
  66. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  67.  
  68. directory = "/academic/atm_519/data/UNIDATA_ASCII_2014/"
  69. filename = "sflist_2018-09-14.txt"
  70.  
  71. write(*,'(A)', advance="no") "Enter Target Station :"
  72.  
  73. read(*,*) target_station
  74.  
  75. open(unit = 1, &
  76. file = trim(directory) // trim(filename), &
  77. status = "old", &
  78. form = "formatted", &
  79. iostat = ios)
  80.  
  81. print*, ios
  82.  
  83. !reading headers
  84.  
  85. read(1,*)
  86. read(1,*)
  87. read(1,*)
  88. read(1,*)
  89.  
  90. ! read station line
  91.  
  92. i = 1
  93.  
  94. read(1, 1000, iostat=ios) station_code(i), &
  95. yyyy, &
  96. mm, &
  97. dd, &
  98. hh, &
  99. mn, &
  100. longitude(i), &
  101. latitude(i), &
  102. elevation(i), &
  103. tmpf(i), &
  104. dwpf(i), &
  105. drct(i), &
  106. sknt(i), &
  107. pmsl(i)
  108.  
  109. 1000 format(3x, a4, 4x, 3(i2), x, 2(i2), x, 6(f9.2), /, 23x, 2(f9.2))
  110.  
  111.  
  112. do while (ios .eq. 0)
  113.  
  114.  
  115. if (trim(adjustL(station_code(i))) .eq. trim(target_station)) then
  116.  
  117. write(excel_date(i), 2000) (2000+yyyy), mm, dd, hh, mn
  118.  
  119. tmpf(i) = wjc_degf_to_k_func( tmpf(i) , &
  120. FILL_VALUE )
  121.  
  122. dwpf(i) = wjc_degf_to_k_func( dwpf(i), &
  123. FILL_VALUE )
  124.  
  125. 2000 format(i4.4, "-", i2.2, "-", i2.2, " ", i2.2, ":", i2.2)
  126.  
  127. write(*,*) "Record for ", target_station, &
  128. " found at ", excel_date(i)
  129.  
  130. i = i + 1
  131.  
  132. end if
  133. !! read for next time step
  134.  
  135. read(1, 1000, iostat=ios) station_code(i), &
  136. yyyy, &
  137. mm, &
  138. dd, &
  139. hh, &
  140. mn, &
  141. longitude(i), &
  142. latitude(i), &
  143. elevation(i), &
  144. tmpf(i), &
  145. dwpf(i), &
  146. drct(i), &
  147. sknt(i), &
  148. pmsl(i)
  149.  
  150.  
  151.  
  152. end do
  153.  
  154. number_of_records = i - 1
  155.  
  156. write(*,*) "Total Records for Station ", target_station, &
  157. ": ", number_of_records
  158.  
  159. close(unit = 1)
  160.  
  161.  
  162.  
  163. call wjc_wind_spd_dir_to_u_v_sub_1d(sknt, &
  164. drct, &
  165. uwnd, &
  166. vwnd, &
  167. FILL_VALUE )
  168.  
  169.  
  170.  
  171.  
  172. ! Write the CSV File
  173.  
  174. write(csv_filename, 3000) trim(target_station), excel_date(1)(1:10)
  175.  
  176. 3000 format(A, "_", A10, ".csv")
  177.  
  178. write(*,*) "writing CSV output to file ", trim(csv_filename)
  179.  
  180. open(unit = 2, &
  181. file = "./" // trim(csv_filename), &
  182. form = "formatted")
  183.  
  184. write(2,*) "st_id,time,lon,lat,elev,temp,dwpt,drct,uwnd,vwnd,sknt,pmsl"
  185.  
  186.  
  187. do i = 1, number_of_records
  188.  
  189. write(2,4000) station_code(i), &
  190. excel_date(i), &
  191. longitude(i), &
  192. latitude(i), &
  193. elevation(i), &
  194. tmpf(i), &
  195. dwpf(i), &
  196. drct(i), &
  197. sknt(i), &
  198. uwnd(i), &
  199. vwnd(i), &
  200. pmsl(i)
  201.  
  202. 4000 format( A4, ",", A16, 14(",", F9.2) )
  203.  
  204. end do
  205.  
  206. close(unit = 2)
  207.  
  208.  
  209. end program read_unidata2
  210.  
  211.  
  212. !
  213. !--- Sample Read Line From Unidata SFLIST Command
  214. !
  215. !12312341234121212112121123456789123456789123456789123456789123456789123456789
  216. ! STN YYMMDD/HHMM SLON SLAT SELV TMPF DWPF DRCT
  217. !12345678901234567890123123456789123456789
  218. ! SKNT PMSL
  219. ! 2G4 141001/0000 -79.34 39.58 894.00 51.80 -9999.00 210.00
  220. ! 4.00 -9999.00
Add Comment
Please, Sign In to add comment