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_seaice.pro in branches/dev_2802_OBStools/NEMOGCM/TOOLS/OBSTOOLS/dataplot – NEMO

source: branches/dev_2802_OBStools/NEMOGCM/TOOLS/OBSTOOLS/dataplot/read_seaice.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.2 KB
Line 
1PRO  read_seaice, Files, NumObs=NumObs, $
2               Latitudes=Latitudes, Longitudes=Longitudes, $
3               Obs=Obs, modarr=modarr, qc=qcarr, $
4               Dates=Dates, rmdi=rmdi, iobs=outiobs, jobs=outjobs, $
5               nodates=nodates, quiet=quiet
6;------------------------------------------------------------
7;IDL program to read in netcdf files of sea ice data.
8;
9;Author:   D. J. Lea       Feb 2008
10;
11;------------------------------------------------------------
12rmdi = -99999.
13NumFiles=n_elements(Files)
14;RefDate = '1950-01-01'
15;!DATE_SEPARATOR='-'
16RefDate=JULDAY(1,1,1950,0,0)     ; should be at 0 UTC
17
18; could read in from file
19
20ifile2=0
21for ifile = 0, NumFiles-1 do begin
22;------------------------------------------------------------
23;1. Open the file containing the data
24  ncid = ncdf_open(Files(ifile), /nowrite)
25  if ncid lt 0 and not keyword_set(quiet) then print, 'Error opening file '+Files(ifile)
26  if ncid ge 0 then begin
27  if not keyword_set(quiet) then print, 'Opened file '+Files(ifile)+' successfully'
28
29;------------------------------------------------------------
30;2. Read in the dimensions in the file
31  ncinfo = ncdf_inquire(ncid)
32  ncdf_diminq, ncid, 0, name, NData
33  if Ndata gt 0 then begin
34
35;------------------------------------------------------------
36;3. Allocate the data arrays and read in the data
37  lons   = dblarr(NData)
38  lats   = dblarr(NData)
39  obsval = fltarr(NData)
40  modval = fltarr(NData)
41  bytQC  = bytarr(NData) 
42  QC     = fltarr(NData)
43  Dats   = dblarr(NData)
44  dts    = replicate(!dt_base, NData)
45  iobs = intarr(NData)
46  jobs = intarr(NData)
47
48; output attribute and variable info
49;  ncattinfo, id
50 
51  varid = ncdf_varid(ncid, 'lon')
52;  if not keyword_set(quiet) then print,varid
53  if (varid eq -1) then varid = ncdf_varid(ncid, 'LONGITUDE')
54  ncdf_varget, ncid, varid, lons
55 
56  varid = ncdf_varid(ncid, 'lat')
57;  if not keyword_set(quiet) then print,varid
58  if (varid eq -1) then varid = ncdf_varid(ncid, 'LATITUDE')
59  ncdf_varget, ncid, varid, lats
60
61  if (keyword_set(nodates) eq 0) then begin
62; if not keyword_set(quiet) then print,'reading time'
63; varid = ncdf_varid(ncid, 'time')
64; varid = ncdf_varid(ncid, 'SeaIce_dtime')
65; if not keyword_set(quiet) then print,varid
66; if (varid ne -1) then begin
67;  ncdf_varget, ncid, varid, time
68;  if not keyword_set(quiet) then print,'sec_to_dt 1'
69;        dts= sec_to_dt(time, Base=RefDate, date_fmt=5)
70; endif
71; if not keyword_set(quiet) then print,time
72
73;;  varid = ncdf_varid(ncid, 'SeaIce_dtime')
74;;    if not keyword_set(quiet) then print,varid
75;  if (varid eq -1) then varid = ncdf_varid(ncid, 'JULD')
76;  if (varid ne -1) then begin
77;     ncdf_varget, ncid, varid, Dats
78;  if not keyword_set(quiet) then print,'sec_to_dt 2'
79;        dts = sec_to_dt(Dats*24.*60.*60., Base=RefDate, date_fmt=5)
80;  endif
81
82  varid = ncdf_varid(ncid, 'JULD')
83  if varid ne -1 then begin
84    ncdf_varget, ncid, varid, Dats
85;    dts = sec_to_dt(Dats*24.*60.*60., Base=RefDate, date_fmt=5)
86    dts = Dats+RefDate
87  endif else begin
88    varid = ncdf_varid(ncid, 'time')
89    ncdf_varget, ncid, varid, secs_from_base
90    varid = ncdf_varid(ncid, 'SeaIce_dtime')
91    ncdf_varget, ncid, varid, dtime
92    ncdf_attget, ncid, varid, 'scale_factor', scale_factor   
93    if not keyword_set(quiet) then print,'dtime(0): ',dtime(0), scale_factor
94    dtime=dtime*scale_factor
95;    RefDate = '1981-01-01'
96    RefDate = JULDAY(1,1,1981,0,0)  ; should be ref from 0 UTC
97    dtime = dtime + secs_from_base
98;    dts = sec_to_dt(dtime, Base=RefDate, date_fmt=5)
99    dts = RefDate + dtime/86400.
100  endelse
101
102  endif
103
104  if not keyword_set(quiet) then print,'reading sea ice data'   
105  varid = ncdf_varid(ncid, 'sea_ice_concentration')
106    if not keyword_set(quiet) then print,varid
107    if (varid eq -1) then begin
108       varid2 = ncdf_varid(ncid, 'SEAICE')
109         if (varid2 ne -1) then ncdf_varget, ncid, varid2, obsval
110    endif
111    if (varid ne -1) then ncdf_varget, ncid, varid, obsval
112    if not keyword_set(quiet) then print,'scale_factor'
113  scale_factor=1. 
114  if (varid ne -1) then ncdf_attget, ncid, varid, 'scale_factor', scale_factor
115
116  if not keyword_set(quiet) then print,'_FillValue'
117  FillValue=99999
118     
119;  ncdf_attget, ncid, varid, '_FillValue', FillValue
120  if not keyword_set(quiet) then print,FillValue 
121
122  pts = where(obsval eq FillValue, count)
123
124  if not keyword_set(quiet) then print,'scale_factor ',scale_factor 
125  obsval=obsval*scale_factor
126 
127  if count gt 0 then obsval(pts) = rmdi
128
129
130  if not keyword_set(quiet) then print,'reading sea ice model values'
131  varid = ncdf_varid(ncid, 'SEAICE_Hx')
132  if (varid ne -1) then ncdf_varget, ncid, varid, modval
133
134  varid = ncdf_varid(ncid, 'IOBS')
135  if (varid ne -1) then ncdf_varget, ncid, varid, iobs
136 
137  varid = ncdf_varid(ncid, 'JOBS')
138  if (varid ne -1) then ncdf_varget, ncid, varid, jobs
139 
140
141  scale_factor=1
142  pts = where(modval eq FillValue or modval eq -9999, count)
143 
144  modval=modval*scale_factor
145 
146  if count gt 0 then modval(pts) = rmdi
147
148   if not keyword_set(quiet) then print,'sea ice qc'
149
150  varid = ncdf_varid(ncid, 'SEAICE_QC')       
151  if (varid ne -1) then begin
152   if not keyword_set(quiet) then print,'bytQC'
153   ncdf_varget, ncid, varid, bytQC
154   ncdf_attget, ncid, varid, '_FillValue', FillValue
155   QC(*) = 0.
156   pts = where(bytQC eq FillValue, count)
157   if count gt 0 then QC(pts) = rmdi
158   pts = where(bytQC ne 48, count)
159   if count gt 0 then QC(pts) = 1. 
160  endif else begin
161   varid = ncdf_varid(ncid, 'confidence_flag')
162   ncdf_varget, ncid, varid, QC
163  endelse
164 
165  if ifile2 eq 0 then begin
166    Latitudes = [float(lats)]
167    Longitudes = [float(lons)]
168    Obs = [obsval]
169    Modarr = [modval]
170    QCarr = [QC]
171    Dates = [dts]
172    if (n_elements(iobs) gt 0) then outiobs = [iobs]
173    if (n_elements(jobs) gt 0) then outjobs = [jobs]
174  endif else begin
175    Latitudes = [Latitudes, float(lats)]
176    Longitudes = [Longitudes, float(lons)]
177    Obs = [Obs, obsval]
178    Modarr = [Modarr, modval]   
179    QCarr = [QCarr, QC]
180    Dates = [Dates, dts]
181    if (n_elements(iobs) gt 0) then outiobs = [outiobs, iobs]
182    if (n_elements(jobs) gt 0) then outjobs = [outjobs, jobs]
183  endelse     
184
185ifile2=ifile2+1
186endif
187
188  if not keyword_set(quiet) then print,'closing file'
189
190  ncdf_close, ncid
191
192endif
193endfor ; ifile 
194 
195NumObs = n_elements(Latitudes)
196
197if (n_elements(Modarr) ne NumObs) then Modarr=replicate(rmdi,NumObs)
198
199END
Note: See TracBrowser for help on using the repository browser.