New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
read_sst.pro in branches/dev_2802_OBStools/NEMOGCM/TOOLS/OBSTOOLS/dataplot – NEMO

source: branches/dev_2802_OBStools/NEMOGCM/TOOLS/OBSTOOLS/dataplot/read_sst.pro @ 3002

Last change on this file since 3002 was 3002, checked in by djlea, 13 years ago

Update documentation for obstools and dataplot. Removal of dataplot code not needed. Addition of headers to some dataplot code. Addition of .exe to command example in obstools.

File size: 6.1 KB
Line 
1PRO  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;------------------------------------------------------------
12rmdi = -99999.
13NumFiles=n_elements(Files)
14;print,NumFiles
15;RefDate = '1950-01-01'
16;!DATE_SEPARATOR='-'
17RefDate=JULDAY(1,1,1950,0,0)    ; should be at 0 UTC
18ifile2=0
19for 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;------------------------------------------------------------
28;2. Read in the dimensions in the file
29  ncinfo = ncdf_inquire(ncid)
30
31  if ncinfo.Ndims eq 1 then begin
32    ncdf_diminq, ncid, 0, name, NData
33  endif else if ncinfo.Ndims eq 2 then begin
34    ncdf_diminq, ncid, 1, name, NData
35    if (name eq "string8") then  ncdf_diminq, ncid, 0, name, NData
36  endif else if ncinfo.Ndims eq 3 then begin
37    ncdf_diminq, ncid, 1, name, NLats
38    ncdf_diminq, ncid, 2, name, NLons
39    NData = NLats * NLons
40  endif
41   
42  if not keyword_set(quiet) then print, 'Number of SST data points ',NData
43 
44  if (NData gt 0) then begin
45;------------------------------------------------------------
46;3. Allocate the data arrays and read in the data
47  lons   = dblarr(NData)
48  lats   = dblarr(NData)
49  obsval = fltarr(NData)
50  modval = fltarr(NData)
51  bytQC  = bytarr(NData)
52  QC     = fltarr(NData)
53  obstyp = intarr(NData) 
54  Dats   = dblarr(NData)
55  dts    = replicate(!dt_base, NData)
56  iobsa = intarr(NData)
57  jobsa = intarr(NData)
58 
59  varid = ncdf_varid(ncid, 'LONGITUDE')
60  if varid ne -1 then ncdf_varget, ncid, varid, lons $
61  else begin
62    varid = ncdf_varid(ncid, 'lon')
63    ncdf_varget, ncid, varid, lons
64  endelse
65 
66  varid = ncdf_varid(ncid, 'LATITUDE')
67  if varid ne -1 then ncdf_varget, ncid, varid, lats $
68  else begin
69    varid = ncdf_varid(ncid, 'lat')
70    ncdf_varget, ncid, varid, lats
71  endelse
72 
73  varid = ncdf_varid(ncid, 'JULD')
74  if varid ne -1 then begin
75    ncdf_varget, ncid, varid, Dats
76;    dts = sec_to_dt(Dats*24.*60.*60., Base=RefDate, date_fmt=5)
77    dts=RefDate + Dats
78   
79  endif else begin
80    varid = ncdf_varid(ncid, 'time')
81    ncdf_varget, ncid, varid, secs_from_base
82    varid = ncdf_varid(ncid, 'sst_dtime')
83    ncdf_varget, ncid, varid, dtime
84    ncdf_attget, ncid, varid, 'scale_factor', scale_factor
85    dtime=dtime*scale_factor
86;    RefDate = '1981-01-01'
87    RefDate = JULDAY(1,1,1981,0,0)  ; should be ref from 0 UTC
88    dtime = dtime + secs_from_base
89;    dts = sec_to_dt(dtime, Base=RefDate, date_fmt=5)
90    dts = RefDate + dtime/86400.
91  endelse
92       
93  varid = ncdf_varid(ncid, 'SST')
94  if varid ne -1 then begin
95    ncdf_varget, ncid, varid, obsval
96    obsval=float(obsval)        ;ensure obsval is a floating point array
97    ncdf_attget, ncid, varid, '_FillValue', FillValue
98    pts = where(obsval eq FillValue, count)
99    if count gt 0 then obsval(pts) = rmdi
100  endif else begin
101    varid = ncdf_varid(ncid, 'sea_surface_temperature')
102    ncdf_varget, ncid, varid, obsval
103    obsval=float(obsval)   ;ensure obsval is a floating point array
104    ncdf_attget, ncid, varid, '_FillValue', FillValue
105    ncdf_attget, ncid, varid, 'add_offset', Offset
106    ncdf_attget, ncid, varid, 'scale_factor', Scale
107    pts = where(obsval ne FillValue, count)
108    if count gt 0 then obsval(pts) = Offset + (obsval(pts) *Scale)
109    pts = where(obsval eq FillValue, count)
110    if count gt 0 then obsval(pts) = rmdi
111  endelse
112
113  varid = ncdf_varid(ncid, 'SST_Hx')
114  if varid ne -1 then begin
115    ncdf_varget, ncid, varid, modval
116    ncdf_attget, ncid, varid, '_FillValue', FillValue
117    pts = where(modval eq FillValue, count)
118    if count gt 0 then modval(pts) = rmdi
119  endif
120     
121  varid = ncdf_varid(ncid, 'SST_QC')
122  if varid ne -1 then begin
123    ncdf_varget, ncid, varid, bytQC
124    ncdf_attget, ncid, varid, '_FillValue', FillValue
125    QC(*) = 0.
126    pts = where(bytQC eq FillValue, count)
127    if count gt 0 then QC(pts) = rmdi
128    pts = where(bytQC ne 48, count)
129    if count gt 0 then QC(pts) = bytQC(pts)-48
130  endif else begin
131    varid = ncdf_varid(ncid, 'confidence_flag')
132    ncdf_varget, ncid, varid, bytQC
133    QC = float(bytQC)
134  endelse
135     
136  varid = ncdf_varid(ncid, 'SST_DATA_SOURCE')
137  if varid ne -1 then ncdf_varget, ncid, varid, obstyp $
138  else begin
139    varid = ncdf_varid(ncid, 'data_source')
140    if varid ne -1 then ncdf_varget, ncid, varid, obstyp
141  endelse
142
143  varid = ncdf_varid(ncid, 'callsign')
144  if varid ne -1 then begin
145   ncdf_varget, ncid, varid, callsign
146        tmp=strtrim(string(obstyp),2)+' '+strtrim(string(callsign),2)
147        obstyp=tmp
148  endif else begin
149   varid = ncdf_varid(ncid, 'SST_CALL_SIGN')
150   if varid ne -1 then begin
151      ncdf_varget, ncid, varid, callsign
152        tmp=strtrim(string(obstyp),2)+' '+strtrim(string(callsign),2)
153        obstyp=tmp
154   endif
155  endelse
156
157  varid = ncdf_varid(ncid, 'IOBS')
158  if (varid ne -1) then ncdf_varget, ncid, varid, iobsa
159 
160  varid = ncdf_varid(ncid, 'JOBS')
161  if (varid ne -1) then ncdf_varget, ncid, varid, jobsa
162     
163  if ifile2 eq 0 then begin
164    Latitudes = [float(lats)]
165    Longitudes = [float(lons)]
166    ObsSST = [obsval]
167    ModSST = [modval]
168    SSTQC = [QC]
169    Dates = [dts]
170    Types = [obstyp]
171    iobs = [iobsa]
172    jobs = [jobsa]
173  endif else begin
174    Latitudes = [Latitudes, float(lats)]
175    Longitudes = [Longitudes, float(lons)]
176    ObsSST = [ObsSST, obsval]
177    ModSST = [ModSST, modval]
178    SSTQC = [SSTQC, QC]
179    Dates = [Dates, dts]   
180    Types = [Types, obstyp]
181    iobs = [iobs, iobsa]
182    jobs = [jobs, jobsa]       
183  endelse     
184
185  ifile2=ifile2+1
186  endif
187  ncdf_close, ncid
188
189  endif
190
191endfor ; ifile 
192 
193NumObs = n_elements(Latitudes)
194
195END
Note: See TracBrowser for help on using the repository browser.