PRO nc_put, fld, file_name, NCDF_DB = ncdf_db, X = x, Y = y, Z = z, T = t, GLOBAL = global @common @com_eg ; fld = structure ; fdl.data, fld.units, fld.short_name, fld.long_name, fld.missing_value, fld.direc ; fld.direc= data type (x,xy,xyzt,yt,etc...) ; X,Y,Z,T = structures containing attributes for each direction : ; x.name, x.units, x.long_name, x.data (+t.calendar and t.origin for time) ; Global = global attributes: conventions, title, origin IF debug_w THEN print, ' ' IF debug_w THEN print, ' ENTER nc_put...' dim = size(fld.data) dim_check = 0 type = fld.direc ; open netCDF file cdfid = ncdf_create(ncdf_db+file_name, /clobber) IF debug_w THEN print, ' type,cdfid = ', type, cdfid ncdf_control, cdfid, /fill ; grid jpi=1 jpj=1 jpk=1 xpos = strpos(type, 'x') ypos = strpos(type, 'y') zpos = strpos(type, 'z') tpos = strpos(type, 't') IF xpos NE -1 THEN BEGIN dim_check = dim_check+1 jpi = dim(xpos+1) ENDIF xid = ncdf_dimdef(cdfid, 'lon', jpi) IF ypos NE -1 THEN BEGIN dim_check = dim_check+1 jpj = dim(ypos+1) ENDIF yid = ncdf_dimdef(cdfid, 'lat', jpj) IF zpos NE -1 THEN BEGIN dim_check = dim_check+1 jpk = dim(zpos+1) ENDIF zid = ncdf_dimdef(cdfid, 'depth', jpk) IF tpos NE -1 THEN BEGIN dim_check = dim_check+1 ENDIF tid = ncdf_dimdef(cdfid, 'time', /UNLIMITED) IF dim_check NE dim(0) THEN BEGIN print, ' ERROR data size / type mismatch ', type, dim(0) ENDIF swx = 0 swy = 0 swz = 0 swt = 0 ; horizontal zonal axis ; IF strpos(type, 'x') NE -1 AND keyword_set(X) THEN BEGIN IF strpos (type, 'xy') NE -1 THEN BEGIN lonid = ncdf_vardef(cdfid,'lon', [xid, yid], /FLOAT) ENDIF ELSE lonid = ncdf_vardef(cdfid,'nav_lon', [xid], /FLOAT) NCDF_ATTPUT, cdfid, lonid, 'units', x.units NCDF_ATTPUT, cdfid, lonid, 'long_name', x.long_name NCDF_ATTPUT, cdfid, lonid, 'valid_min', min(x.data), /float NCDF_ATTPUT, cdfid, lonid, 'valid_max', max(x.data), /float swx = 1 ; ENDIF ; horizontal meridional axis ; IF strpos(type, 'y') NE -1 AND keyword_set(Y) THEN BEGIN IF strpos (type, 'xy') NE -1 THEN BEGIN latid = ncdf_vardef(cdfid,'lat', [xid, yid], /FLOAT) ENDIF ELSE latid = ncdf_vardef(cdfid,'nav_lat', [yid], /FLOAT) NCDF_ATTPUT, cdfid, latid, 'units', y.units NCDF_ATTPUT, cdfid, latid, 'long_name', y.long_name NCDF_ATTPUT, cdfid, latid, 'valid_min', min(y.data), /float NCDF_ATTPUT, cdfid, latid, 'valid_max', max(y.data), /float swy = 1 ; ENDIF ; vertical axis IF zpos NE -1 AND keyword_set(Z) THEN BEGIN vertid = ncdf_vardef(cdfid,z.name, [zid], /FLOAT) NCDF_ATTPUT, cdfid, vertid, 'units', z.units NCDF_ATTPUT, cdfid, vertid, 'long_name', z.long_name NCDF_ATTPUT, cdfid, vertid, 'valid_min', min(z.data), /float NCDF_ATTPUT, cdfid, vertid, 'valid_max', max(z.data), /float swz = 1 ENDIF ; time axis IF tpos NE -1 AND keyword_set(T) THEN BEGIN mid = NCDF_VARDEF(cdfid, 'time', [tid], /long) NCDF_ATTPUT, cdfid, mid, 'units', t.units NCDF_ATTPUT, cdfid, mid, 'calendar', t.calendar NCDF_ATTPUT, cdfid, mid, 'origin', t.origin NCDF_ATTPUT, cdfid, mid, 'long_name', t.long_name NCDF_ATTPUT, cdfid, mid, 'short_name', 'Time' NCDF_ATTPUT, cdfid, mid, 'valid_min', min(t.data), /long NCDF_ATTPUT, cdfid, mid, 'valid_max', max(t.data), /long time_data = t.data swt = 1 ENDIF ELSE BEGIN mid = NCDF_VARDEF(cdfid, 'time', [tid], /long) NCDF_ATTPUT, cdfid, mid, 'units', "days since 1991-03-01 00:00:00" time_data = 1. swt = 1 type = type+'t' CASE type OF 'xt': fld.data = reform(fld.data, jpi, 1) 'yt': fld.data = reform(fld.data, jpj, 1) 'zt': fld.data = reform(fld.data, jpk, 1) 'xyt': fld.data = reform(fld.data, jpi, jpj, 1) 'xzt': fld.data = reform(fld.data, jpi, jpk, 1) 'yzt': fld.data = reform(fld.data, jpj, jpk, 1) 'xyzt': fld.data = reform(fld.data, jpi, jpj, jpk, 1) ENDCASE ENDELSE IF debug_w THEN print, ' test 1 fld.short_name = ', fld.short_name IF debug_w THEN print, ' swx,y,z,t = ', swx, swy, swz, swt ; field attributes CASE type OF 'x': fldid = NCDF_VARDEF(cdfid,fld.short_name, [xid], /FLOAT) 'y': fldid = NCDF_VARDEF(cdfid,fld.short_name, [yid], /FLOAT) 'z': fldid = NCDF_VARDEF(cdfid,fld.short_name, [zid], /FLOAT) 't': fldid = NCDF_VARDEF(cdfid,fld.short_name, [tid], /FLOAT) 'xy': fldid = NCDF_VARDEF(cdfid,fld.short_name, [xid, yid], /FLOAT) 'xz': fldid = NCDF_VARDEF(cdfid,fld.short_name, [xid, zid], /FLOAT) 'yz': fldid = NCDF_VARDEF(cdfid,fld.short_name, [yid, zid], /FLOAT) 'xyz': fldid = NCDF_VARDEF(cdfid,fld.short_name, [xid, yid, zid], /FLOAT) 'xyt': fldid = NCDF_VARDEF(cdfid,fld.short_name, [xid, yid, tid], /FLOAT) 'xzt': fldid = NCDF_VARDEF(cdfid,fld.short_name, [xid, zid, tid], /FLOAT) 'yzt': fldid = NCDF_VARDEF(cdfid,fld.short_name, [xid, yid, zid, tid], /FLOAT) 'xyzt': fldid = NCDF_VARDEF(cdfid,fld.short_name, [xid, yid, zid, tid], /FLOAT) ELSE: ENDCASE CASE type OF 'xyzt': fld.data = reform(fld.data,jpi,jpj,jpk,jpt) ELSE: ENDCASE NCDF_ATTPUT, cdfid, fldid, 'units', fld.units NCDF_ATTPUT, cdfid, fldid, 'long_name', fld.long_name NCDF_ATTPUT, cdfid, fldid, 'short_name', fld.short_name NCDF_ATTPUT, cdfid, fldid, 'missing_value', fld.missing_value NCDF_ATTPUT, cdfid, fldid, 'valid_min', min(fld.data(where (fld.data NE fld.missing_value))), /float NCDF_ATTPUT, cdfid, fldid, 'valid_max', max(fld.data(where (fld.data NE fld.missing_value))), /float ; global attributes NCDF_ATTPUT, cdfid, /GLOBAL, 'Conventions', global.conventions NCDF_ATTPUT, cdfid, /GLOBAL, 'Title', global.title NCDF_ATTPUT, cdfid, /GLOBAL, 'Origin', global.origin NCDF_ATTPUT, cdfid, /GLOBAL, 'Software', global.software ; put file in data mode NCDF_CONTROL, cdfid, /ENDEF ; ; put grid data ; print, ' ' print, ' Writing '+fld.short_name+' to netCDF file ',ncdf_db+file_name ; stop IF swx EQ 1 THEN BEGIN print, ' writing lon, size =', size(x.data) NCDF_VARPUT, cdfid, lonid, x.data END IF swy EQ 1 THEN BEGIN print, ' writing lat, size =', size(y.data) NCDF_VARPUT, cdfid, latid, y.data END IF swz EQ 1 THEN BEGIN print, ' writing depth, size =', size(z.data) NCDF_VARPUT, cdfid, vertid, z.data END IF swt EQ 1 THEN BEGIN print, ' writing time, size=', size (time_data) NCDF_VARPUT, cdfid, mid, time_data END ; put field data print, ' Field legend = ',fld.long_name print, ' Field dimensions = ',size(fld.data) print, ' Field min/max/unit = ',min(fld.data(where (fld.data NE fld.missing_value))), max(fld.data(where (fld.data NE fld.missing_value))), ' ', fld.units print, ' Global attributes= Conventions: ', global.conventions print, ' Title: ', global.title print, ' Origin: ', global.origin ; stop NCDF_VARPUT, cdfid, fldid, fld.data ; close file NCDF_CLOSE, cdfid IF debug_w THEN print, ' ...EXIT nc_put' END