;**************************************************************************** ; Author : Josh Grant, COAPS ; ; Description : This program takes a divergence file which is in the format ; previously specified for this project and grids each file. ; ; **Warning** : Due to poor planning on my part and lack of time the bulk of ; this program is not commented like it should be. ;**************************************************************************** PRO READFILE, filename, tempFile, data, times, ny, nx, err command = "/usr/sbin/gunzip -c " + filename + " > " + tempFile SPAWN, command, message OPENR, input, filename, /GET_LUN, ERROR = err IF ( err EQ 0 ) THEN BEGIN FREE_LUN, input OPENR, input, tempFile, /GET_LUN, ERROR = err print, "Reading " + filename line = FLTARR( 48 ) newLine = ' ' READF, input, ny, nx line = FLTARR( 48 ) singletime = '9999999 ' FOR pass = 0, 2 DO BEGIN FOR rows = 0, ny - 1 DO BEGIN READF, input, FORMAT = '(48F10.3)', line data( pass, *, rows ) = line ENDFOR READF, input, newLine ENDFOR FOR index = 0, ny - 1 DO BEGIN READU, input, singletime times( index ) = LONG(singletime) ENDFOR FREE_LUN, input print, "Done reading " + filename SPAWN, 'rm ' + tempFile ENDIF END dimensionsFile = "../others/dimensions.dat" base = "/Net/NSCAT/people/grant/diverg_proj/" swathsDirectory = base + "div2grid/data/daily_swath/" griddedDirectory = base + "div2grid/data/gridded/daily/" tempFile = "temp.div" miss = 99999.0 time = LON64ARR( 18000 ) data = FLTARR( 3, 48, 18000 ) gridded = FLTARR( 360, 180 ) totals = FLTARR( 360, 180 ) ny = 0 nx = 0 start = 294 endday = 366 FOR year = 1997, 1997 DO BEGIN IF ( year EQ 1997 ) THEN BEGIN start = 139 endday = 180 ENDIF FOR number = start, endday DO BEGIN stringFormat = STRCOMPRESS( '(i' + STRING( 3 ) + '.' $ + STRING( 3 ) + ')', /REMOVE_ALL ) file_name = swathsDirectory + STRTRIM( year, 1 ) + $ STRING( number, format = stringFormat ) + '.div.gz' gridded_name = griddedDirectory + STRTRIM( year, 1 ) + $ STRING( number, format = stringFormat ) + '.div.grid' READFILE, file_name, tempFile, data, time, ny, nx, error IF ( error EQ 0 ) THEN BEGIN gridded( *, * ) = miss totals( *, * ) = 0.0 FOR col = 0, nx - 1 DO BEGIN FOR row = 0, ny - 1 DO BEGIN IF ( data( 2, col, row ) NE miss ) THEN BEGIN gridded_lat = FIX( data( 0, col, row ) + 90.5 ) gridded_lon = FIX( data( 1, col, row ) + 0.5 ) IF ( gridded_lon GT 359 ) THEN gridded_lon = 359 IF ( gridded_lat GT 179 ) THEN gridded_lat = 179 IF ( gridded( gridded_lon, gridded_lat ) EQ miss ) THEN BEGIN gridded( gridded_lon, gridded_lat ) = data( 2, col, row ) totals( gridded_lon, gridded_lat ) = 1.0 ENDIF ELSE BEGIN gridded( gridded_lon, gridded_lat ) = $ gridded( gridded_lon, gridded_lat ) + data( 2, col, row ) totals( gridded_lon, gridded_lat ) = $ totals( gridded_lon, gridded_lat ) + 1.0 ENDELSE ENDIF ENDFOR ENDFOR FOR lon = 0, 359 DO BEGIN FOR lat = 0, 179 DO BEGIN IF ( totals( lon, lat ) NE 0 ) THEN BEGIN gridded( lon, lat ) = gridded( lon, lat ) / totals( lon, lat ) ENDIF ENDFOR ENDFOR OPENW, output, gridded_name, /GET_LUN printf, output, FORMAT = '(2I9)', time( 0 ), time( ny - 1 ) FOR lat = 0, 179 DO BEGIN printf, output, FORMAT = '(360F10.3)', gridded( *, lat ) ENDFOR FREE_LUN, output print, "Finished " + gridded_name ENDIF ENDFOR ENDFOR END