EIT Software Listings

 

anal
obsolete
response
util

 

Previous Routine
Next Routine

 

Listing of $SSW/soho/eit/idl/anal/cat_open.pro

 


;+
; NAME        :
;              CAT_OPEN
; PURPOSE     : Open and associate catalog to structure.
;
; CATEGORY    : EIT Catalog
;
; EXPLANATION :
;
; SYNTAX      :
;
; EXAMPLES    : none
;
; CALLED BY   :
;
; CALLS TO    : none
;
; ARGUMENTS   :	none
;
; KEYWORDS    :
;	FILE	: A string, the catalog file name
;	LONG	: When set, don't sort or remove duplicates in catalog
;
; OUTPUTS     :
;	Returns the associated catalog
;
;	LUN	: the logical unit that is associated with the cat file
;	N_REC	: the total number of cat entries in the catalog, including
;		  duplicates but excluding the header.
;	U_REC	: the number of cat entries to be used. If /LONG is set
;		  this is the same as N_REC
;	RECORDS : an long array of the records of the catalog in the selected
;		  order (or unordered).
;
; COMMON      : none
;
; RESTRICTIONS: none
;
; SIDE EFFECTS: none
;
; PROJECT     : SOHO - EIT
;
; HISTORY     : V1,  Elaine Einfalt (HSTX)
;             : V1.1 D.M. fecit, to account for different lengths of
;		   structures
;             : V1.2 JSN fixed byte padding, necessary for UNIX version
;                  6/12/96
;	      : V2.1 Einfalt reduced pad to make room for 24-char SCI_OBJ
;			     Since SCI_OBJ can be all 0B, it's a direct steal.
;             ; V2.2 JSN -fixed little_endian vs big_endian bug for Sun's
;                  20-jan-1998
;             : 11-nov-2002 F.Auchere Speeds up catalog reading.
; CONTACT     : eit@xanado.nascom.nasa.gov
;-

function CAT_OPEN,     file  = file,		 $		; input
		       long  = long,		 $		; input
		       lz    = lz,		 $		; input
		       lun   = cat_unit, 	 $		; output
		       n_rec = n_rec,		 $		; output
		       u_rec = u_rec,		 $		; output
		       records = records			; ouput

 if not(keyword_set(lz)) then begin
   ich = strpos(strupcase(file), '.CAT') & date = strmid(file, ich - 8, 8)
   ecs_date = strmid(date, 0, 4) + '/' + strmid(date, 4, 2) + '/' + $
   		strmid(date, 6, 2)
   cat_date = anytim2utc(ecs_date)
   date_19960327 = anytim2utc('1996/03/27')		; fix bad pad
   date_19960523 = anytim2utc('1996/05/23')		; added p1r,p1c/p2r,p2c

   ; Times are {MJD from 1995 jan 1, seconds from beginning of day} (except that
   ; the mjd's in the if statement below are real MJD's).

   ; Lines commented out incorrectly had a breaks at both 3/27 and 5/23
   ; but only need the one break since always have 8 new bytes for read
   ;
   ;if cat_date.mjd ge date_19960523.mjd then begin
   ;   pad = bytarr(42)
   ;endif else if cat_date.mjd ge date_19960327.mjd then begin
   ;   pad = bytarr(50)
   ;endif else begin
   ;   pad = bytarr(64)
   ;end
   if cat_date.mjd ge date_19960327.mjd then begin
      pad = bytarr(18)			; until SCI_OBJ this was 42
   endif else begin
      pad = bytarr(56)
   end
 endif else pad = bytarr(18)		; until SCI_OBJ this was 42

 cat_entry = 					$
       {nx:		0b,			$	; num pixel x / 32
	ny:		0b,			$	; num pixel y / 32
	nx_sum:		0b,			$	; x pixel summing
	ny_sum:		0b, 			$	; y pixel summing
	file_time:	{mjd:0, sec:0l}, 	$	; (see comment above)
	wave:		bytarr(4),		$	; sector+171
							;  (0=not used),
							;	1:171, 2:195,
							;	3:284, 3:304
	filter:		0b,			$	; filter
	obs_time:	{mjd:0, sec:0l},	$	; (see comment above)
	object:		0,			$	; feature planned
	program:	0L, 			$	; obs prog #
	exp_time:	0,			$	; exposure in 1/32 unit
	file_name:	bytarr(18),		$	; FITS file name
	image_of_seq:	0,			$	; (not used for LZ)
	n_leb_proc:	0b, 			$	; # of LEB proc steps
	leb_proc:	bytarr(8),		$	; LEB process steps
	temp:		intarr(2),		$	; data value CF and CCD
	n_wave:		0b,		 	$	; (only in LZ)
	n_repeat:	0, 			$	; (only in LZ)
	version:	0b, 			$	; nibbl for major,minor
        low_x:          0,                      $       ; low-x corner of image
        high_x:         0,                      $       ; high-x corner of image
        low_y:          0,                      $       ; low-y corner of image
        high_y:         0,                      $       ; high-y corner of image
	sci_obj:	bytarr(24),		$	; from iap
	pad:		pad}				; pad

;1997/10/27 (einfalt) if !version.os eq 'vms' then begin

  print,'%CAT_OPEN, using ' + file
  if !version.os eq 'vms' and (is_gsfcvms() ne 3) then begin

      openr, cat_unit, file, /shared, /get_lun	     ; open catalog
      w = assoc(cat_unit,lonarr(32))   &   header = w(0)  ; read the cat header
      n_rec = header(0)				     ; get # recs in this cat

      cat = assoc(cat_unit, cat_entry)		     ; see above for structure
      entry = replicate(cat_entry, n_rec)

     for i = 1l, n_rec do entry(i-1) = cat(i)	    ; remember, don't do header

 endif else begin

; test for little_endian or big_endian
     test = 1
     byteorder, test, /ntohs
     lendian = test ne 1

     openr, cat_unit, file, /get_lun	     ; open catalog

     stat=fstat(cat_unit)
     nsz=stat.size/128
     cat=bytarr(128,nsz)
     readu,cat_unit,cat
     header = cat(*,0)
     n_rec=long(header,0)
     rev_swap,n_rec

     entry = replicate(cat_entry, n_rec)

     ; Note: When this particular catalog record structure is created in VMS,
     ;	     then the nested/imbedded structures, like file_time, are padded
     ;	     to a VMS byte boundary.  On the UNIX systems this padding is not
     ;	     there.  So what appears to be a 128 byte structure in VMS
     ;	     only uses 115 bytes on a UNIX system.


;===========================================================================
;
; Modified F. AUCHERE 02 JUILY 2002. Reads catalog on big endian machines
;
;===========================================================================

         if keyword_set(lz) then begin
             cat=cat(*,1:n_rec)
             top=115
         endif else begin
           if cat_date.mjd ge date_19960327.mjd then begin
             cat=cat(*,1:n_rec)
             top=115
; fixed unnecessary break -JSN 6/12/96
;         endif else if cat_date.mjd ge date_19960327.mjd then begin
;           rec=cat(*,i)
;           top=115
           endif else begin
             cat=cat(*,2*(1+lindgen(n_rec)))
             top=127
           end
         endelse

         if not lendian then begin
           entry.nx = reform(cat(0,*))
           entry.ny = reform(cat(1,*))
           entry.nx_sum = reform(cat(2,*))
           entry.ny_sum = reform(cat(3,*))
           entry.file_time.mjd = fix([cat(5,*),cat(4,*)],0,n_rec)
           entry.file_time.sec = long(reverse(cat(6:9,*)),0,n_rec)
           entry.wave = cat(10:13,*)
           entry.filter = reform(cat(14,*))
           entry.obs_time.mjd = fix([cat(16,*), cat(15,*)],0,n_rec)
           entry.obs_time.sec = long(reverse(cat(17:20,*)),0,n_rec)
           entry.object = fix([cat(22,*),cat(21,*)],0,n_rec)
           entry.program = long(reverse(cat(23:26,*)),0,n_rec)
           entry.exp_time = fix([cat(28,*),cat(27,*)],0,n_rec)
           entry.file_name = cat(29:46,*)
           entry.image_of_seq = fix([cat(48,*),cat(47,*)],0,n_rec)
           entry.n_leb_proc = reform(cat(49,*))
           entry.leb_proc = cat(50:57,*)
           entry.temp = reform([[fix([cat(59,*),cat(58,*)],0,n_rec)],[fix([cat(61,*),cat(60,*)],0,n_rec)]],2,n_rec)
           entry.n_wave = reform(cat(62,*))
           entry.n_repeat = fix([cat(64,*),cat(63,*)],0,n_rec)
           entry.version = reform(cat(65,*))
           entry.low_x = fix([cat(67,*),cat(66,*)],0,n_rec)
           entry.high_x = fix([cat(69,*),cat(68,*)],0,n_rec)
           entry.low_y= fix([cat(71,*),cat(70,*)],0,n_rec)
           entry.high_y = fix([cat(73,*),cat(72,*)],0,n_rec)
           entry.sci_obj = cat(74:97,*)
           entry.pad = cat(98:top,*)		; until SCI_OBJ this was 74
         endif else begin
;===========================================================================
;
; Reads catalog on little endian machines
;
;===========================================================================
           entry.nx = reform(cat(0,*))
           entry.ny = reform(cat(1,*))
           entry.nx_sum = reform(cat(2,*))
           entry.ny_sum = reform(cat(3,*))
           entry.file_time.mjd = fix(cat(4:5,*),0,n_rec)
           entry.file_time.sec = long(cat(6:9,*),0,n_rec)
           entry.wave = cat(10:13,*)
           entry.filter = reform(cat(14,*))
           entry.obs_time.mjd = fix(cat(15:16,*),0,n_rec)
           entry.obs_time.sec = long(cat(17:20,*),0,n_rec)
           entry.object = fix(cat(21:22,*),0,n_rec)
           entry.program = long(cat(23:26,*),0,n_rec)
           entry.exp_time = fix(cat(27:28,*),0,n_rec)
           entry.file_name = cat(29:46,*)
           entry.image_of_seq = fix(cat(47:48,*),0,n_rec)
           entry.n_leb_proc = reform(cat(49,*))
           entry.leb_proc = cat(50:57,*)
           entry.temp = reform([[fix(cat(58:59,*),0,n_rec)],[fix(cat(60:61,*),0,n_rec)]],2,n_rec)
           entry.n_wave = reform(cat(62,*))
           entry.n_repeat = fix(cat(63:64,*),0,n_rec)
           entry.version = reform(cat(65,*))
           entry.low_x = fix(cat(66:67,*),0,n_rec)
           entry.high_x = fix(cat(68:69,*),0,n_rec)
           entry.low_y= fix(cat(70:71,*),0,n_rec)
           entry.high_y = fix(cat(72:73,*),0,n_rec)
           entry.sci_obj = cat(74:97,*)
           entry.pad = cat(98:top,*)		; until SCI_OBJ this was 74
         endelse
   ;endfor
 endelse

 obs_time = { mjd : entry.obs_time.mjd + 49718, $
	      time: entry.obs_time.sec * 1000L}
 tai_arr  = utc2tai(anytim2utc(obs_time))

 if not(keyword_set(long)) then begin		; long format will not sort
						; or remove duplicates.
    ordered = sort(tai_arr)			; Sorted but may have duplicates
    uni = uniq(tai_arr(ordered))		; get rid of duplicates

    records = ordered(uni) + 1			; ordered and unique indices,
                           			; offset because 1st record
						; is the header

 endif else records = lindgen(n_rec)+1		; use original order

 u_rec = n_elements(records)			; # of record to consider

 free_lun, cat_unit

 return, entry

end


Web curator: Frédéric Auchère
Responsible NASA official: Joseph B. Gurman, Facility Scientist, Solar Data Analysis Center
joseph.b.gurman@gsfc.nasa.gov
+1 301 286-4767
NASA Goddard Space Flight Center
Solar Physics Branch / Code 682

Last revised: - Wed May 9 21:44:57 2007- F. Auchère