; Given an AR NOAA number, selects all MDI images that contain that AR pro sel_AR, noaa, srt_dt, subsq, edpt, errdat, dims, loud=loud, long_cut=long_cut if n_elements(loud) eq 0 then loud=0 ; longitudinal cutoff if n_elements(long_cut) eq 0 then long_cut=60 errdat=0 dims=fltarr(6,100) ; read AR number if not call variable if n_elements(noaa) eq 0 then begin print, "Enter noaa AR number:" read, noaa endif ; check latest NARs to make sure AR is contained in MDI data sub=0 repeat begin today=systime() tmjd = date2mjd(2007,8,19) tdy=strmid(today,8,2)+'/'+strmid(today,4,3)+'/'+strmid(today,20,4) jd = tmjd - sub mjd2date,jd,tdyr,tdmth,tddy today=STRCOMPRESS(tdyr, /remove_all)+'/'+STRCOMPRESS(tdmth,/remove_all)+'/'+STRCOMPRESS(tddy,/remove_all) if loud then nar=get_nar(today) else nar=get_nar(today, /quiet) tst=0 if (n_tags(nar) eq 0) then sub=sub+7 else begin q=where(nar.noaa) & if q(0) eq -1 then begin & sub=sub+1 & tst=1 & endif & endelse endrep until (n_tags(nar) ne 0) and tst eq 0 if (noaa gt max(nar.noaa) and noaa lt 7956) then begin & print, "AR not contained in MDI data. Skipping region." & errdat=1 & goto, fin & endif ;if (noaa gt 9999) then begin & print, "invalid AR number" & errdat=1 & goto, fin & endif if loud then print, "year" ; find correct year if noaa ge 7956 then begin & yr=1996 & mth=4 & endif else begin & yr=2002 & mth=6 & endelse stp=0 repeat begin dy=1 & if yr eq 1999 then dy=2 repeat begin if mth lt 10 then mnth='0'+strcompress(string(mth),/remove_all) else mnth=strcompress(string(mth),/remove_all) if dy lt 10 then day='0'+strcompress(string(dy),/remove_all) else day=strcompress(string(dy),/remove_all) dt=string(yr)+'-'+mnth+'-'+day if loud then nar=get_nar(dt) else nar=get_nar(dt, /quiet) tst=0 if (n_tags(nar) eq 0) then dy=dy+7 else begin q=where(nar.noaa) & if q(0) eq -1 then begin & dy=dy+1 & tst=1 & endif & endelse if dy gt 31 then begin & mth=mth+1 & dy=dy-31 & endif if mth gt 12 then begin & yr=yr+1 & mth=mth-12 & endif endrep until (n_tags(nar) ne 0) and (tst eq 0) k=where(nar.noaa ge 7956) & j=where(nar.noaa lt 7956) if noaa ge 7956 then begin if k(0) ne -1 then nar=nar(where(nar.noaa ge 7956)) else nar.noaa=0 endif else begin if j(0) ne -1 then nar=nar(where(nar.noaa lt 7956)) else nar.noaa=0 endelse if (max(nar.noaa) lt noaa) then yr=yr+1 else if (min(nar.noaa) gt noaa) then begin & yr=yr-1 & stp=1 & endif else stp=1 if noaa ge 7956 and yr gt 2002 then begin & yr=2002 & stp=1 & endif if yr ge 2000+fix(tdyr) then begin & yr=2000+fix(tdyr)-1 & stp=1 & endif endrep until stp eq 1 if loud then print, "month" ; find correct month stp=0 repeat begin dy=1 repeat begin if mth lt 10 then mnth='0'+strcompress(string(mth),/remove_all) else mnth=strcompress(string(mth),/remove_all) if dy lt 10 then day='0'+strcompress(string(dy),/remove_all) else day=strcompress(string(dy),/remove_all) dt=string(yr)+'-'+mnth+'-'+day if loud then nar=get_nar(dt) else nar=get_nar(dt, /quiet) tst=0 if (n_tags(nar) eq 0) then dy=dy+7 else begin q=where(nar.noaa) & if q(0) eq -1 then begin & dy=dy+1 & tst=1 & endif & endelse if dy gt 31 then begin & mth=mth+1 & dy=dy-31 & endif if mth gt 12 then begin & yr=yr+1 & mth=mth-12 & endif endrep until (n_tags(nar) ne 0) and tst eq 0 k=where(nar.noaa ge 7956) & j=where(nar.noaa lt 7956) if noaa ge 7956 then begin if k(0) ne -1 then nar=nar(where(nar.noaa ge 7956)) else nar.noaa=0 endif else begin if j(0) ne -1 then nar=nar(where(nar.noaa lt 7956)) else nar.noaa=0 endelse if (max(nar.noaa) lt noaa) then mth=mth+1 else begin & mth=mth-1 & stp=1 & endelse endrep until stp eq 1 if mth gt 12 then begin & mth=mth-12 & yr=yr+1 & endif if loud then print, "day" ;find correct day stp=0 & dy=1 repeat begin repeat begin if mth lt 10 then mnth='0'+strcompress(string(mth),/remove_all) else mnth=strcompress(string(mth),/remove_all) if dy lt 10 then day='0'+strcompress(string(dy),/remove_all) else day=strcompress(string(dy),/remove_all) dt=string(yr)+'-'+mnth+'-'+day if loud then nar=get_nar(dt) else nar=get_nar(dt, /quiet) if n_tags(nar) ne 0 then begin k=where(nar.noaa ge 7956) & j=where(nar.noaa lt 7956) if noaa ge 7956 then begin if k(0) ne -1 then nar=nar(where(nar.noaa ge 7956)) else nar.noaa=0 endif else begin if j(0) ne -1 then nar=nar(where(nar.noaa lt 7956)) else nar.noaa=0 endelse endif if (n_tags(nar) eq 0) then dy=dy+1 if (n_tags(nar) ne 0) then if min(nar.noaa) gt noaa then begin & if loud then print, "AR data not found in NOAA database" & errdat=1 & goto, fin & endif endrep until (n_tags(nar) ne 0) if (max(nar.noaa) lt noaa) then dy=dy+1 else begin ntst=where(nar.noaa eq noaa) if ntst(0) eq -1 then dy=dy+1 else begin tmp=nar(ntst) tmp=tmp(where(tmp.location(0) eq max(tmp.location(0)))) if n_elements(tmp) gt 1 then tmp=tmp(0) if tmp.location(0) gt (-1*long_cut) then stp=1 else dy=dy+1 endelse endelse if dy gt 31 then begin & mth=mth+1 & dy=dy-31 & endif if mth gt 12 then begin & yr=yr+1 & mth=mth-12 & endif endrep until stp eq 1 if loud then begin if mth lt 10 then mnth='0'+strcompress(string(mth),/remove_all) else mnth=strcompress(string(mth),/remove_all) if dy lt 10 then day='0'+strcompress(string(dy),/remove_all) else day=strcompress(string(dy),/remove_all) dt=string(yr)+'-'+mnth+'-'+day print, "date:", dt print, "noaa:", noaa endif repeat begin if mth lt 10 then mnth='0'+strcompress(string(mth),/remove_all) else mnth=strcompress(string(mth),/remove_all) if dy lt 10 then day='0'+strcompress(string(dy-1),/remove_all) else day=strcompress(string(dy-1),/remove_all) dt2=strcompress(string(yr),/remove_all)+'-'+mnth+'-'+day if loud then nar=get_nar(dt2) else nar=get_nar(dt2, /quiet) q=-1 & if n_tags(nar) ne 0 then begin q=where(nar.noaa eq noaa) if q(0) ne -1 then dy=dy-1 endif else dy=dy+1 endrep until q(0) eq -1 if mth lt 10 then mnth='0'+strcompress(string(mth),/remove_all) else mnth=strcompress(string(mth),/remove_all) if dy lt 10 then day='0'+strcompress(string(dy),/remove_all) else day=strcompress(string(dy),/remove_all) dt2=string(yr)+'-'+mnth+'-'+day if loud then nar=get_nar(dt2) else nar=get_nar(dt2, /quiet) nar=nar(where(nar.noaa eq noaa)) & nar=nar(where(nar.location(0) eq max(nar.location(0)))) if n_elements(nar) gt 1 then nar=nar(0) if loud then begin if mth lt 10 then mnth='0'+strcompress(string(mth),/remove_all) else mnth=strcompress(string(mth),/remove_all) if dy lt 10 then day='0'+strcompress(string(dy),/remove_all) else day=strcompress(string(dy),/remove_all) dt=string(yr)+'-'+mnth+'-'+day print, "start date:", dt endif ; find the number of subsequent mdi's containing the AR num=0 & tmpdy=dy & tmp=0 & subsq=intarr(10) & swch=0 & ctr=0 if nar.location(0) lt -long_cut then begin & swch=1 & ctr=1 & endif repeat begin if mth lt 10 then mnth='0'+strcompress(string(mth),/remove_all) else mnth=strcompress(string(mth),/remove_all) if tmpdy lt 10 then day='0'+strcompress(string(tmpdy),/remove_all) else day=strcompress(string(tmpdy),/remove_all) dt=string(yr)+'-'+mnth+'-'+day if loud then nar=get_nar(dt) else nar=get_nar(dt,/quiet) if n_tags(nar) ne 0 then begin q=where(nar.noaa eq noaa) if q(0) ne -1 then begin ntmp=nar(where(nar.noaa eq noaa)) min=min(ntmp.location(0)) & max=max(ntmp.location(0)) if loud then print, "location(0) min", min, "location(0) max", max if min le (long_cut) and max ge -(long_cut) then begin if swch eq 1 then begin & swch=0 & subsq(ctr)=tmp & if loud then print, "storing"+string(tmp)+"to"+string(ctr)+"of subsq" & ctr=ctr+1 & tmp=0 & endif num=num+1 & tmpdy=tmpdy+1 & end_dt=dt if loud then print, "AR found" if n_elements(srt_date) eq 0 then srt_date=dt tmp=1 & if min lt -(long_cut) then begin & tmp=2 & ntmp=ntmp(where(ntmp.location(0) eq max)) & endif else ntmp=ntmp(where(ntmp.location(0) eq min)) if n_elements(ntmp) gt 1 then ntmp=ntmp(0) q=max(where(dims(0,*))) & q=q+1 dims(0,q)=ntmp.long_ext dims(1,q)=ntmp.area if ntmp.location(1) ne 0 then dims(2,q)=ntmp.location(1) else dims(2,q)=.00001 if ntmp.longitude ne 0 then dims(3,q)=ntmp.longitude else dims(3,q)=.00001 dims(4,q)=tmp endif else begin if swch eq 0 then begin & swch=1 & subsq(ctr)=num & if loud then print, "storing"+string(num)+"to"+string(ctr)+"of subsq" & ctr=ctr+1 & num=0 & endif if max(ntmp.location(0)) lt -(long_cut) then dy=dy+1 tmp=tmp+1 & tmpdy=tmpdy+1 if loud then print, "AR found outside long cut" endelse endif else begin if swch eq 0 then begin & swch=1 & subsq(ctr)=num & if loud then print, "storing"+string(num)+"to"+string(ctr)+"of subsq" & ctr=ctr+1 & num=0 & endif tmp=tmp+1 & tmpdy=tmpdy+1 if loud then print, "AR not found" endelse endif else begin if swch eq 0 then begin & swch=1 & subsq(ctr)=num & if loud then print, "storing"+string(num)+"to"+string(ctr)+"of subsq" & ctr=ctr+1 & num=0 & endif tmp=tmp+1 & tmpdy=tmpdy+1 if loud then print, "No AR data" endelse endrep until tmp gt 14 if n_elements(end_dt) eq 0 then begin & if loud then print, "AR data not found in NOAA database" & errdat=1 & goto, fin & endif edpt=intarr(2) if loud then nar=get_nar(end_dt) else nar=get_nar(end_dt,/quiet) nar=nar(where(nar.noaa eq noaa)) if n_elements(nar) gt 1 then begin ntmp=nar(where(nar.location(0) eq max(nar.location(0)))) q=max(where(dims(0,*))) & q=q+1 dims(0,q)=ntmp.long_ext dims(1,q)=ntmp.area dims(2,q)=ntmp.location(1) dims(3,q)=ntmp.longitude dims(4,q)=2 endif else begin q=max(where(dims(0,*))) & q=q+1 dims(0,q)=nar.long_ext dims(1,q)=nar.area dims(2,q)=nar.location(1) dims(3,q)=nar.longitude dims(4,q)=1 endelse nar=nar(0) & lonlat=nar.location idx=-1 & tm=0 repeat begin idx=idx+1 lng = lonlat(0)+diff_rot((float(tm)/1440), lonlat(1), /synodic) tm=tm+96 endrep until (idx eq 14) or lng gt long_cut edpt(1)=idx if loud then nar=get_nar(srt_date) else nar=get_nar(srt_date,/quiet) nar=nar(where(nar.noaa eq noaa)) & nar=nar(where(nar.location(0) eq max(nar.location(0)))) & lonlat=nar.location idx=15 & tm=0 repeat begin idx=idx-1 lng = lonlat(0)+diff_rot((float(tm)/1440), lonlat(1), /synodic) tm=tm-96 endrep until (idx eq 0) or lng lt -(long_cut) edpt(0)=idx if loud then begin if mth lt 10 then mnth='0'+strcompress(string(mth),/remove_all) else mnth=strcompress(string(mth),/remove_all) if dy lt 10 then day='0'+strcompress(string(dy),/remove_all) else day=strcompress(string(dy),/remove_all) dt=string(yr)+'-'+mnth+'-'+day print, "start date:", dt print, subsq print, noaa endif srt_dt=intarr(3) & srt_dt(0)=yr & srt_dt(1)=mth & srt_dt(2)=dy fin: end