read_sst.pro 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. PRO read_sst, Files, NumObs=NumObs, $
  2. Latitudes=Latitudes, Longitudes=Longitudes, $
  3. ObsSST=ObsSST, ModSST=ModSST, SSTQC=SSTQC, $
  4. Dates=Dates, rmdi=rmdi, Types=Types, iobs=iobs, jobs=jobs, $
  5. quiet=quiet
  6. ;------------------------------------------------------------
  7. ;IDL program to read in netcdf files of altimeter data.
  8. ;
  9. ;Author: D. J. Lea - Feb 2008
  10. ;
  11. ;------------------------------------------------------------
  12. rmdi = -99999.
  13. NumFiles=n_elements(Files)
  14. ;print,NumFiles
  15. ;RefDate = '1950-01-01'
  16. ;!DATE_SEPARATOR='-'
  17. RefDate=JULDAY(1,1,1950,0,0) ; should be at 0 UTC
  18. ifile2=0
  19. for ifile = 0, NumFiles-1 do begin
  20. ;------------------------------------------------------------
  21. ;1. Open the file containing the data
  22. ncid = ncdf_open(Files(ifile), /nowrite)
  23. if ncid lt 0 and not keyword_set(quiet) then print, 'Error opening file '+Files(ifile)
  24. if ncid ge 0 then begin
  25. if not keyword_set(quiet) then print, 'Opened file '+Files(ifile)+' successfully'
  26. ;------------------------------------------------------------
  27. ;2. Read in the dimensions in the file
  28. ncinfo = ncdf_inquire(ncid)
  29. if ncinfo.Ndims eq 1 then begin
  30. ncdf_diminq, ncid, 0, name, NData
  31. endif else if ncinfo.Ndims eq 2 then begin
  32. ncdf_diminq, ncid, 1, name, NData
  33. if (name eq "string8") then ncdf_diminq, ncid, 0, name, NData
  34. endif else if ncinfo.Ndims eq 3 then begin
  35. ncdf_diminq, ncid, 1, name, NLats
  36. ncdf_diminq, ncid, 2, name, NLons
  37. NData = NLats * NLons
  38. endif
  39. if not keyword_set(quiet) then print, 'Number of SST data points ',NData
  40. if (NData gt 0) then begin
  41. ;------------------------------------------------------------
  42. ;3. Allocate the data arrays and read in the data
  43. lons = dblarr(NData)
  44. lats = dblarr(NData)
  45. obsval = fltarr(NData)
  46. modval = fltarr(NData)
  47. bytQC = bytarr(NData)
  48. QC = fltarr(NData)
  49. obstyp = intarr(NData)
  50. Dats = dblarr(NData)
  51. dts = replicate(!dt_base, NData)
  52. iobsa = intarr(NData)
  53. jobsa = intarr(NData)
  54. varid = ncdf_varid(ncid, 'LONGITUDE')
  55. if varid ne -1 then ncdf_varget, ncid, varid, lons $
  56. else begin
  57. varid = ncdf_varid(ncid, 'lon')
  58. ncdf_varget, ncid, varid, lons
  59. endelse
  60. varid = ncdf_varid(ncid, 'LATITUDE')
  61. if varid ne -1 then ncdf_varget, ncid, varid, lats $
  62. else begin
  63. varid = ncdf_varid(ncid, 'lat')
  64. ncdf_varget, ncid, varid, lats
  65. endelse
  66. varid = ncdf_varid(ncid, 'JULD')
  67. if varid ne -1 then begin
  68. ncdf_varget, ncid, varid, Dats
  69. dts=RefDate + Dats
  70. endif else begin
  71. varid = ncdf_varid(ncid, 'time')
  72. ncdf_varget, ncid, varid, secs_from_base
  73. varid = ncdf_varid(ncid, 'sst_dtime')
  74. ncdf_varget, ncid, varid, dtime
  75. ncdf_attget, ncid, varid, 'scale_factor', scale_factor
  76. dtime=dtime*scale_factor
  77. ; RefDate = '1981-01-01'
  78. RefDate = JULDAY(1,1,1981,0,0) ; should be ref from 0 UTC
  79. dtime = dtime + secs_from_base
  80. dts = RefDate + dtime/86400.
  81. endelse
  82. varid = ncdf_varid(ncid, 'SST')
  83. if varid ne -1 then begin
  84. ncdf_varget, ncid, varid, obsval
  85. obsval=float(obsval) ;ensure obsval is a floating point array
  86. ncdf_attget, ncid, varid, '_FillValue', FillValue
  87. pts = where(obsval eq FillValue, count)
  88. if count gt 0 then obsval(pts) = rmdi
  89. endif else begin
  90. varid = ncdf_varid(ncid, 'sea_surface_temperature')
  91. ncdf_varget, ncid, varid, obsval
  92. obsval=float(obsval) ;ensure obsval is a floating point array
  93. ncdf_attget, ncid, varid, '_FillValue', FillValue
  94. ncdf_attget, ncid, varid, 'add_offset', Offset
  95. ncdf_attget, ncid, varid, 'scale_factor', Scale
  96. pts = where(obsval ne FillValue, count)
  97. if count gt 0 then obsval(pts) = Offset + (obsval(pts) *Scale)
  98. pts = where(obsval eq FillValue, count)
  99. if count gt 0 then obsval(pts) = rmdi
  100. endelse
  101. varid = ncdf_varid(ncid, 'SST_Hx')
  102. if varid ne -1 then begin
  103. ncdf_varget, ncid, varid, modval
  104. ncdf_attget, ncid, varid, '_FillValue', FillValue
  105. pts = where(modval eq FillValue, count)
  106. if count gt 0 then modval(pts) = rmdi
  107. endif
  108. varid = ncdf_varid(ncid, 'SST_QC')
  109. if varid ne -1 then begin
  110. ncdf_varget, ncid, varid, bytQC
  111. ncdf_attget, ncid, varid, '_FillValue', FillValue
  112. QC(*) = 0.
  113. pts = where(bytQC eq FillValue, count)
  114. if count gt 0 then QC(pts) = rmdi
  115. pts = where(bytQC ne 48, count)
  116. if count gt 0 then QC(pts) = bytQC(pts)-48
  117. endif else begin
  118. varid = ncdf_varid(ncid, 'confidence_flag')
  119. ncdf_varget, ncid, varid, bytQC
  120. QC = float(bytQC)
  121. endelse
  122. varid = ncdf_varid(ncid, 'SST_DATA_SOURCE')
  123. if varid ne -1 then ncdf_varget, ncid, varid, obstyp $
  124. else begin
  125. varid = ncdf_varid(ncid, 'data_source')
  126. if varid ne -1 then ncdf_varget, ncid, varid, obstyp
  127. endelse
  128. varid = ncdf_varid(ncid, 'callsign')
  129. if varid ne -1 then begin
  130. ncdf_varget, ncid, varid, callsign
  131. tmp=strtrim(string(obstyp),2)+' '+strtrim(string(callsign),2)
  132. obstyp=tmp
  133. endif else begin
  134. varid = ncdf_varid(ncid, 'SST_CALL_SIGN')
  135. if varid ne -1 then begin
  136. ncdf_varget, ncid, varid, callsign
  137. tmp=strtrim(string(obstyp),2)+' '+strtrim(string(callsign),2)
  138. obstyp=tmp
  139. endif
  140. endelse
  141. varid = ncdf_varid(ncid, 'IOBS')
  142. if (varid ne -1) then ncdf_varget, ncid, varid, iobsa
  143. varid = ncdf_varid(ncid, 'JOBS')
  144. if (varid ne -1) then ncdf_varget, ncid, varid, jobsa
  145. if ifile2 eq 0 then begin
  146. Latitudes = [float(lats)]
  147. Longitudes = [float(lons)]
  148. ObsSST = [obsval]
  149. ModSST = [modval]
  150. SSTQC = [QC]
  151. Dates = [dts]
  152. Types = [obstyp]
  153. iobs = [iobsa]
  154. jobs = [jobsa]
  155. endif else begin
  156. Latitudes = [Latitudes, float(lats)]
  157. Longitudes = [Longitudes, float(lons)]
  158. ObsSST = [ObsSST, obsval]
  159. ModSST = [ModSST, modval]
  160. SSTQC = [SSTQC, QC]
  161. Dates = [Dates, dts]
  162. Types = [Types, obstyp]
  163. iobs = [iobs, iobsa]
  164. jobs = [jobs, jobsa]
  165. endelse
  166. ifile2=ifile2+1
  167. endif
  168. ncdf_close, ncid
  169. endif
  170. endfor ; ifile
  171. NumObs = n_elements(Latitudes)
  172. END