;------------------------------------------------------------- ;+ ; NAME: ; MONTHNAMES ; PURPOSE: ; Returns a string array of month names. ; CATEGORY: ; CALLING SEQUENCE: ; mnam = mnthnmes() ; INPUTS: ; KEYWORD PARAMETERS: ; OUTPUTS: ; mnam = string array of 13 items: out ; ['Error','January',...'December'] ; COMMON BLOCKS: ; NOTES: ; MODIFICATION HISTORY: ; R. Sterner, 18 Sep, 1989 ; ; Copyright (C) 1989, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. Other limitations apply as described in the file disclaimer.txt. ;- ;------------------------------------------------------------- function mnthnmes, help=hlp if keyword_set(hlp) then begin print,' Returns a string array of month names.' print,' mnam = mnthnmes()' print,' mnam = string array of 13 items: out' print," ['Error','January',...'December']" return, -1 endif mn = ['Error','January','February','March','April','May',$ 'June','July','August','September','October',$ 'November','December'] return, mn end ;------------------------------------------------------------- ;+ ; NAME: ; YMD2JD ; PURPOSE: ; From Year, Month, and Day compute Julian Day number. ; CATEGORY: ; CALLING SEQUENCE: ; jd = ymd2jd(y,m,d) ; INPUTS: ; y = Year (like 1987). in ; m = month (like 7 for July). in ; d = month day (like 23). in ; KEYWORD PARAMETERS: ; OUTPUTS: ; jd = Julian Day number (like 2447000). out ; COMMON BLOCKS: ; NOTES: ; MODIFICATION HISTORY: ; R. Sterner, 23 June, 1985 --- converted from FORTRAN. ; Johns Hopkins University Applied Physics Laboratory. ; RES 18 Sep, 1989 --- converted to SUN ; ; Copyright (C) 1985, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. Other limitations apply as described in the file disclaimer.txt. ;- ;------------------------------------------------------------- function ymd2jd, iy, im, id, help=hlp if (n_params(0) LT 3) or keyword_set(hlp) then begin print,' From Year, Month, and Day compute Julian Day number.' print,' jd = ymd2jd(y,m,d)' print,' y = Year (like 1987). in' print,' m = month (like 7 for July). in' print,' d = month day (like 23). in' print,' jd = Julian Day number (like 2447000). out' return, -1 endif y = long(iy) m = long(im) d = long(id) jd = 367*y-7*(y+(m+9)/12)/4-3*((y+(m-9)/7)/100+1)/4 $ +275*m/9+d+1721029 return, jd end ;------------------------------------------------------------- ;+ ; NAME: ; WEEKDAY ; PURPOSE: ; Compute weekday given year, month, day. ; CATEGORY: ; CALLING SEQUENCE: ; wd = weekday(y,m,d,[nwd]) ; INPUTS: ; y, m, d = Year, month, day (Like 1988, 10, 31). in ; KEYWORD PARAMETERS: ; OUTPUTS: ; wd = Returned name of weekday. out ; nwd = optional Weekday number. out ; COMMON BLOCKS: ; NOTES: ; MODIFICATION HISTORY: ; R. Sterner. 31 Oct, 1988. ; Johns Hopkins University Applied Physics Laboratory. ; RES 18 Sep, 1989 --- converted to SUN ; ; Copyright (C) 1988, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. Other limitations apply as described in the file disclaimer.txt. ;- ;------------------------------------------------------------- FUNCTION WEEKDAY, Y, M, D, NWD, help=hlp IF (N_PARAMS(0) LT 3) or keyword_set(hlp) THEN BEGIN PRINT,' Compute weekday given year, month, day.' PRINT,' wd = weekday(y,m,d,[nwd])' PRINT,' y, m, d = Year, month, day (Like 1988, 10, 31). in' PRINT,' wd = Returned name of weekday. out' PRINT,' nwd = optional Weekday number. out' RETURN, -1 ENDIF NAMES = ['','Sunday','Monday','Tuesday',$ 'Wednesday','Thursday','Friday','Saturday'] NWD = ((YMD2JD(Y,M,D) + 1) MOD 7) + 1 RETURN, NAMES(NWD) END ;------------------------------------------------------------- ;+ ; NAME: ; STREP ; PURPOSE: ; Edit a string by position. Precede, Follow, Replace, Delete. ; CATEGORY: ; CALLING SEQUENCE: ; newstring = strep(string,cmd,p,ss,[iflg]) ; INPUTS: ; string = string to edit. in ; cmd = edit command: in ; 'P' = precede position p with substring ss. ; 'F' = follow position p with substring ss. ; 'R' = replace text starting at position p ; with text from substring ss. ; 'D' = delete N characters starting at ; position p. The calling sequence for ; this command is slightly different: ; IFLG = STREP(string,'D',p,n,[iflg]) ; Where n = number of characters to delete. ; p = character position to use. in ; 0 = first char. Any number larger ; than the string length = last char. ; ss = substring to use. For 'D' command in ; n is used instead of ss. ; KEYWORD PARAMETERS: ; OUTPUTS: ; iflg = 0 for a successful edit, out ; iflg = -1 for an error and no change to string. ; newstring = edited string. out ; COMMON BLOCKS: ; NOTES: ; MODIFICATION HISTORY: ; Written by R. Sterner, 27 Dec, 1984. ; Converted to SUN 13 Aug, 1989 --- R. Sterner. ; Johns Hopkins University Applied Physics Laboratory. ; ; Copyright (C) 1984, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. Other limitations apply as described in the file disclaimer.txt. ;- ;------------------------------------------------------------- function strep,s,cmd,ip,ss,iflg, help=hlp if (n_params(0) lt 4) or keyword_set(hlp) then begin print,' Edit a string by position. Precede, Follow, Replace, Delete.' print,' newstring = strep(string,cmd,p,ss,[iflg]) print,' string = string to edit. in' print,' cmd = edit command: in' print," 'P' = precede position p with substring ss. print," 'F' = follow position p with substring ss. print," 'R' = replace text starting at position p print,' with text from substring ss. print," 'D' = delete N characters starting at print,' position p. The calling sequence for print,' this command is slightly different: print," IFLG = STREP(string,'D',p,n,[iflg]) print,' Where n = number of characters to delete. print,' p = character position to use. in' print,' 0 = first char. Any number larger print,' than the string length = last char. print," ss = substring to use. For 'D' command in" print,' n is used instead of ss. print,' iflg = 0 for a successful edit, out' print,' iflg = -1 for an error and no change to string. print,' newstring = edited string. out' return, -1 endif N = STRLEN(S) - 1 IF N LT 0 THEN $ IF CMD EQ 'D' THEN RETURN, '' ELSE RETURN, SS P = IP>00) EQ SSL-3) THEN SSTYP = 2 if (pdot gt 0) and (pdot eq ssl-3) then sstyp = 2 if (pdot eq 0) and (ssl gt 3) then sstyp = 3 if (pdot gt 0) and (pdot lt ssl-3) then sstyp = 4 if (pdot eq 0) and (ssl eq 3) then sstyp = 5 ned = 0 ; Number of occurrences actually changed. case sstyp of 1: begin s = old e = '' end 2: begin s = strsub(old,0,ssl-4) e = '' end 3: begin s = '' e = strsub(old,3,ssl-1) end 4: begin s = strsub(old,0,pdot-1) e = strsub(old,pdot+3,ssl-1) end 5: begin s = '' e = '' end else: print, ' Error in STRESS: Error in sstyp' endcase ;--------------- Find substring # N start --------------- pos = -1 nfor = n>1 loop: for i = 1, nfor do begin pos = pos + 1 case sstyp of 1: pos = strpos(rstr,s,pos) 2: pos = strpos(rstr,s,pos) 4: pos = strpos(rstr,s,pos) 3: pos = strpos(rstr,e,pos) 5: pos = 0 endcase if pos lt 0 then goto, done endfor ;---------- Find substring # N END ---------------- case sstyp of 1: begin pos1 = pos pos2 = pos + strlen(s) - 1 end 2: begin pos1 = pos pos2 = strlen(rstr) - 1 end 3: begin pos1 = 0 pos2 = pos + strlen(e) - 1 end 4: begin pos1 = pos pos2 = strpos(rstr,e,pos+1) if (pos2 lt 0) then goto, done pos2 = pos2 + strlen(e) - 1 end 5: begin pos1 = 0 pos2 = strlen(rstr) - 1 end endcase ;------------ edit string -------------- case cmd of 'P': begin rstr = strep(rstr,cmd,pos1,new) pos = pos + strlen(new) end 'F': begin rstr = strep(rstr,cmd,pos2,new) pos = pos + strlen(new) end 'R': begin rstr = strep(rstr,'D',pos1,pos2-pos1+1) if (pos1 gt 0) then $ rstr = strep(rstr,'F',pos1-1,new) if (pos1 eq 0) then $ rstr = strep(rstr,'P',0,new) pos = pos + strlen(new) - 1 end 'D': begin rstr = strep(rstr,cmd,pos1,pos2-pos1+1) pos = pos - 1 end else: begin print, 'Error in STRESS: unknown command.' return,rstr end endcase ned = ned + 1 if sstyp eq 5 then return,rstr if n eq 0 then goto, loop done: ;--- if old_in an array then do the first element then call recursively ;--- and accumulate the results if (n_elements(old_in) gt 1) then begin ;call again until done all old = old_in(1:*) if (n_elements(new_in) gt 1) then new = new_in(1:*) tmp = 0 rstr = stress(rstr,cmdx,n,old,new,tmp) ned = ned+tmp endif return, rstr end ;------------------------------------------------------------- ;+ ; NAME: ; YMD2DATE ; PURPOSE: ; Convert from year, month, day numbers to date string. ; CATEGORY: ; CALLING SEQUENCE: ; date = ymd2date(Y,M,D) ; INPUTS: ; y = year number (like 1986). in ; m = month number (1 - 12). in ; d = day of month number (1 - 31). in ; KEYWORD PARAMETERS: ; Keywords: ; FORMAT = format string. Allows output date to be customized. ; The following substitutions take place in the format string: ; Y$ = 4 digit year. ; y$ = 2 digit year. ; N$ = full month name. ; n$ = 3 letter month name. ; d$ = day of month number. ; W$ = full weekday name. ; w$ = 3 letter week day name. ; OUTPUTS: ; date = returned date string (like 24-May-1986). out ; COMMON BLOCKS: ; NOTES: ; Notes: ; The default format string is 'd$-n$-Y$' giving 24-Sep-1989 ; Example: FORMAT='w$ N$ d$, Y$' would give 'Mon ; MODIFICATION HISTORY: ; R. Sterner. 16 Jul, 1986. ; RES 18 Sep, 1989 --- converted to SUN ; R. Sterner, 28 Feb, 1991 --- modified format. ; R. Sterner, 16 Dec, 1991 --- added space to 1 digit day. ; Johns Hopkins University Applied Physics Laboratory. ; ; Copyright (C) 1986, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. Other limitations apply as described in the file disclaimer.txt. ;- ;------------------------------------------------------------- function ymd2date, y, m, d, help=hlp, format=frmt if (n_params(0) lt 3) or keyword_set(hlp) then begin print,' Convert from year, month, day numbers to date string.' print,' date = ymd2date(Y,M,D)' print,' y = year number (like 1986). in' print,' m = month number (1 - 12). in' print,' d = day of month number (1 - 31). in' print,' date = returned date string (like 24-May-1986). out' print,' Keywords:' print,' FORMAT = format string. Allows output date to be '+$ 'customized.' print,' The following substitutions take place in the '+$ 'format string:' print,' Y$ = 4 digit year.' print,' y$ = 2 digit year.' print,' N$ = full month name.' print,' n$ = 3 letter month name.' print,' d$ = day of month number.' print,' W$ = full weekday name.' print,' w$ = 3 letter week day name.' print,' Notes:' print," The default format string is 'd$-n$-Y$' giving 24-Sep-1989" print," Example: FORMAT='w$ N$ d$, Y$' would give 'Mon "+$ "September 18, 1989'" return, -1 endif ;---- error check ----- w = where(y lt 0, cnt) if cnt gt 0 then begin print,'Error in ymd2date: invalid year: ',y(w) return, -1 endif ;----- Handle 2 digit years ------ w = where(y lt 50, cnt) ; Y < 50 assumed 2xxx. if cnt gt 0 then y(w) = y(w) + 2000 w = where(y lt 100, cnt) ; 50 < Y < 100 assumed 19xx. if cnt gt 0 then y(w) = y(w) + 1900 w = where((m lt 1) or (m gt 12),cnt) if cnt gt 0 then begin print,'Error in ymd2date: invalid month: ',m(w) return, -1 endif w = where((d lt 1) or (d gt 31), cnt) if cnt gt 0 then begin print,'Error in ymd2date: invalid month day: ', d(w) return, -1 endif ;----- format string ------ fmt = 'd$-n$-Y$' if keyword_set(frmt) then fmt = frmt l_y = n_elements(y)-1 l_m = n_elements(m)-1 l_d = n_elements(d)-1 l_dates = l_y>l_m>l_d date_arr = strarr(l_dates+1) ;----- Loop through all dates --------- for i = 0, l_dates do begin ;----- Get all the allowed parts ----- yu = strtrim(y(i