X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 20 Mar 2014 03:13 PM by  anon
Help on time array loop
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
20 Mar 2014 03:13 PM
    My code following my message here is messing up on creating a time series for my 3hr daily rainfall trmm net-cdf data that i am reading into IDL. It is only looping the years from 1998-2013 and the first 6 months 1-6. Basically I am trying to create my time array during each loop so it corresponds to the net-cdf file time. For an example a file name is: 3B42.19980101.00.7 this represents January 1, 1998 00Z time for the file. I know its my time array and how its taking in each variable, but I am completely stuck on what the problem is. Please help me figure this out!! Thank you for your time pro january_files LatMax = 3 & LatMin = -3 LonMax = 36 & LonMin = 30 days_leap_year = [31,29,31,30,31,30,31,31,30,31,30,31] days_normal_year = [31,28,31,30,31,30,31,31,30,31,30,31] days_month = [] num_hours = 8 num_days = 31 num_months = 12 data_years= [1998,2013] num_years = data_years[1] - data_years[0] + 1 hours = 03 days = 1 month = 1 map_limits = [LonMin, LonMax, LatMin, LatMax] time_array = STRARR(num_years, num_months, num_days, num_hours) for iyears=0, num_years - 1 do begin year = iyears + data_years[0] IF year EQ 2000 OR 2004 OR 2008 OR 2012 THEN $ days_month = days_leap_year ELSE days_month = days_normal_year foreach element, days_month, index do num_days = element for imonths=0, num_months -1 do begin for idays=0, num_days -1 do begin for ihours=0, num_hours -1 do begin time_array[iyears,imonths,idays, ihours] = '/media/TOSHIBA EXT/1998_files/3B42.' + $ STRING(year, FORMAT ='(i04)') + STRING(imonths+1, FORMAT ='(i02)') + $ STRING(idays+1, FORMAT = '(i02)') + '.' + STRING(hours, FORMAT = '(i02)') + '.7.nc' exist = FILE_TEST(time_array[iyears,imonths,idays, ihours]) IF exist then begin lun_rainfall = NCDF_OPEN(time_array[iyears,imonths,idays, ihours]) NCDF_VARGET, lun_rainfall, 'longitude', longitude NCDF_VARGET, lun_rainfall, 'latitude', latitude indices_lon = WHERE(longitude GE LonMin AND longitude LE LonMax) use_lon = longitude[indices_lon] num_lon = N_ELEMENTS(use_lon) indices_lat = WHERE(latitude GE LatMin AND latitude LE LatMax) use_lat = latitude[indices_lat] num_lat = N_ELEMENTS(use_lat) dimen_count = [num_lon, num_lat, 1] dimen_offset = [MIN(indices_lon), MIN(indices_lat), 0] ncdf_varget, lun_rainfall, 'pcp', rainfall, count = dimen_count, offset = dimen_offset NCDF_CLOSE, lun_rainfall endif hours = hours + 03 if hours eq 24 then hours = 00 & days = days + 1 if days gt num_days then days = 1 endfor endfor endfor endfor print, rainfall WINDOW, 3, XSIZE=900, YSIZE=900 DEVICE, DECOMPOSED=0 LOADCT, 39 !P.COLOR=2 !P.BACKGROUND=255 ERASE, 255 MAP_SET ,0,0,0, /CYLINDRICAL, LIMIT=[LatMin, LonMin, LatMax, LonMax], $ /ISOTROPIC, /NOBORDER, NOERASE CONTOUR, rainfall, LONGITUDE, LATITUDE, /OVERPLOT XCHAR=1 YCHAR=1 MAP_CONTINENTS, /COASTS, /COUNTRIES, COLOR=0, THICK=1, /HIRES AXIS, XAXIS=0, XRANGE=[LonMin, LonMax], XSTYLE=1, COLOR=0, CHARSIZE=XCHAR, XTHICK=3, CHARTHICK=4, $ XTICKINTERVAL=1, XMINOR=4 AXIS, YAXIS=0, YRANGE=[LonMin, LonMax], YSTYLE=1, COLOR=0, CHARSIZE=YCHAR, YTHICK=3, CHARTHICK=4, $ YTICKINTERVAL=1, YMINOR=4 AXIS, XAXIS=1, XRANGE=[LonMin, LonMax], XSTYLE=1, COLOR=0, CHARSIZE=0.01, XTHICK=3, CHARTHICK=2, $ XTICKINTERVAL=1, XMINOR=4 AXIS, YAXIS=1, YRANGE=[LonMin, LonMax], YSTYLE=1, COLOR=0, CHARSIZE=0.01, YTHICK=3, CHARTHICK=2, $ YTICKINTERVAL=1, YMINOR=4 STOP END

    Deleted User



    New Member


    Posts:
    New Member


    --
    23 Mar 2014 08:50 AM
    Hi, For anything to do with dates, I work in utc and then convert to yymmdd (or yyyymmdd hh:mm:ss) when done. Get the routines utc2yymmdd.pro and yymmdd2utc.pro from http://hesperia.gsfc.nasa...nrl/idl/nrlgen/time/ Also get anytim2utc.pro from http://hesperia.gsfc.nasa.gov/ssw/gen/idl/time/ [and maybe glance at some of those other time routines as well - they're handy!] Example: IDL> start_date = '980101' IDL> utc = yymmdd2utc( start_date ) In IDL, utc will be a structure containing mjd [modified julian date] and time [in seconds, I believe]. Now you can increment utc.mjd by 1 for each day in your time series i.e. while (yymmdd NE '131231') do begin utc.mjd++ yymmdd=utc2yymmdd( utc ) ; Do stuff here... endwhile If you care about hours/minutes as well, use anytim2utc: IDL> utc = anytime2utc('yyyy-mm-dd hh:mm:ss') Some combination of those should at least simplify your problem, if not solve it. You'll no longer have to worry about leap years, etc, as mjd takes care of that for you. Hope this helps!
    You are not authorized to post a reply.