;**************************************************************************** ; Author : Josh Grant, COAPS ; ; Description : This program takes the NSCAT dataset grids it and finds the ; weekly averge based on ; the week of each swath. Some of the data files contain ; swaths that are in one week and other swaths in the next ; week. All these exceptions are checked when finding the ; weekly average. Once a week is completed it is output to ; 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. ;**************************************************************************** ;@/usr/people/whalley/lidl/jday2date.pro ;@/usr/people/whalley/lidl/date2jday.pro @read_NSCAT_winds.pro PRO NSCATWRITEWEEK, grid_u, grid_v, totals, week, weeklyDirectory, miss stringFormat = STRCOMPRESS( '(i' + STRING( 2 ) + '.' $ + STRING( 2 ) + ')', /REMOVE_ALL ) IF ( week LT 15 ) THEN BEGIN file_name = weeklyDirectory + STRTRIM( 1996, 1 ) + $ STRING( week + 38, format = stringFormat ) + ".week.avg" ENDIF ELSE BEGIN file_name = weeklyDirectory + STRTRIM( 1997, 1 ) + $ STRING( week - 14, format = stringFormat ) + ".week.avg" ENDELSE FOR lon = 0, 359 DO BEGIN FOR lat = 0, 179 DO BEGIN IF ( totals( week, lon, lat ) NE 0 ) THEN BEGIN grid_u( week, lon, lat ) = grid_u( week, lon, lat ) / $ totals( week, lon, lat ) grid_v( week, lon, lat ) = grid_v( week, lon, lat ) / $ totals( week, lon, lat ) ENDIF ELSE BEGIN grid_u( week, lon, lat ) = miss grid_v( week, lon, lat ) = miss ENDELSE ENDFOR ENDFOR OPENW, output, file_name, /GET_LUN FOR lat = 0, 179 DO BEGIN printf, output, FORMAT = '(360F10.3)', grid_u( week, *, lat ) ENDFOR FOR lat = 0, 179 DO BEGIN printf, output, FORMAT = '(360F10.3)', grid_v( week, *, lat ) ENDFOR FREE_LUN, output print, "Finished " + file_name END nscatDirectory = "/Net/NSCAT/nscat/data/nc_W25/" weeklyDirectory = "/Net/NSCAT/people/grant/diverg_proj/grid2div/" + $ "data/winds/weekly/" tempFile = "temp2.div" miss = 99999.0 time = LONG(miss) lat = miss lon = miss dir = miss spd = miss grid_u = FLTARR( 42, 360, 180 ) grid_v = FLTARR( 42, 360, 180 ) totals = FLTARR( 42, 360, 180 ) ny = 0 nx = 0 grid_u( *, *, * ) = 0.0 grid_v( *, *, * ) = 0.0 totals( *, *, * ) = 0.0 index = 0 ptweek = 0 start = 259 periodstart = 259 endday = 366 FOR year = 1996, 1997 DO BEGIN IF ( year EQ 1997 ) THEN BEGIN start = 1 endday = 180 ENDIF FOR number = start, endday DO BEGIN stringFormat = STRCOMPRESS( '(i' + STRING( 3 ) + '.' $ + STRING( 3 ) + ')', /REMOVE_ALL ) file_name = nscatDirectory + 'NSCAT.' + STRTRIM( year, 1 ) + $ STRING( number, format = stringFormat ) + '.nc' error = read_NSCAT_winds( file_name, miss, time, lat, lon, $ dir, spd, nx, ny ) IF ( year EQ 1996 ) THEN index = number - periodstart IF ( year EQ 1997 ) THEN index = number + 366 - periodstart ; print, 'index = ' + STRTRIM(index, 1) IF ( error EQ 0 ) THEN BEGIN check = 0 IF ( index EQ 287 ) THEN ptweek = 40 ELSE ptweek = FIX( index / 7 ) min2date, time( 0 ), ptyear, ptmonth1, ptday1, pthour, ptmin min2date, time( ny - 1 ), ptyear, ptmonth2, ptday2, pthour, ptmin IF ( ptday1 NE ptday2 ) THEN check = 1 ; print, 'ptweek = ' + STRTRIM(ptweek, 1) FOR col = 0, nx - 1 DO BEGIN FOR row = 0, ny - 1 DO BEGIN IF ( spd( col, row ) NE miss AND $ dir( col, row ) NE miss ) THEN BEGIN grid_lat = FIX( lat( col, row ) + 90.5 ) grid_lon = FIX( lon( col, row ) + 0.5 ) IF ( check EQ 1 ) THEN BEGIN min2date, time( row ), ptyear, ptmonth, ptday, pthour, ptmin jday = DATE2JDAY( ptyear + 1900, ptmonth, ptday ) IF ( ptyear + 1900 EQ 1996 ) THEN jday = jday - periodstart $ ELSE jday = jday + 366 - periodstart ptweek = FIX( jday / 7 ) IF ( ptweek GT 40 ) THEN ptweek = 40 ENDIF IF ( grid_lon GT 359 ) THEN grid_lon = 359 IF ( grid_lat GT 179 ) THEN grid_lat = 179 rad = ( ACOS( -1 ) ) / 180.0 u = COS( ( 270.0 - dir( col, row ) ) * rad ) * spd( col, row ) v = SIN( ( 270.0 - dir( col, row ) ) * rad ) * spd( col, row ) grid_u( ptweek, grid_lon, grid_lat ) = $ grid_u( ptweek, grid_lon, grid_lat ) + u grid_v( ptweek, grid_lon, grid_lat ) = $ grid_v( ptweek, grid_lon, grid_lat ) + v totals( ptweek, grid_lon, grid_lat ) = $ totals( ptweek, grid_lon, grid_lat ) + 1.0 ENDIF ENDFOR ENDFOR print, "Finished " + file_name ENDIF IF ( ptweek NE 0 AND ptweek NE 41 ) THEN BEGIN print, 'ptweek = ' + STRTRIM(ptweek, 1) print, 'index MOD 7 = ' + STRTRIM(index MOD 7, 1) IF ( index MOD 7 EQ 2 ) THEN BEGIN ;print, 'index = ' + index NSCATWRITEWEEK, grid_u, grid_v, totals, ptweek - 1, $ weeklyDirectory, miss ENDIF ENDIF ENDFOR ENDFOR NSCATWRITEWEEK, grid_u, grid_v, totals, 40, weeklyDirectory, miss END