pro uf_to_bscan,uf_input,bscan_output ;======================================================== ; This PV-WAVE or IDL program was written by Shane Mayor ; in April 1996 to convert UF files to BSCAN files. ; ; This version is from Shane's collection (probably an ; original) and made available on the Web 2/18/97. ; ; Reads UF files conforming to the description by ; Barnes, BAMS, Nov 1980, Vol 61, No 11, pp. 1401-1404. ; ; Writes BSCAN files conforming to the description set by ; Shane Mayor. For more info on BSCAN format contact ; Shane at 303-497-2008 or shane@ucar.edu. BSCAN files ; are relatively simple, fixed-record length, real*4, ; binary data files with 30 word headers. Each field ; requires a separate BSCAN file. ; ; The UF_TO_BSCAN command line requires TWO arguments: ; 1) uf_input....... name of UF input file ; 2) bscan_output... name of BSCAN output file ; Because one file for each field will be created, ; the two character UF field descriptor will be appended ; to the user-supplied BSCAN output file name. ; ; The program will prompt the user for some information. ; ; CURRENT PROGRAM LIMITATIONS: ; 1) can only handle UF files with 10 fields maximum ; 2) records must contain only one ray per record ; 3) cannot handle changing field lengths in UF file ; ;======================================================== ; Check to see if the UF file exists err = findfile(uf_input,count=count) if (count eq 0) then begin print,'UF input file: ',uf_input,' cannot be found.' return endif ; Define some things bscan_flag = -999. uf_rec_num = 0L header = fltarr(30) ; Open the UF file for reading openr,uf_lun,uf_input,/get_lun ; Read UF records until end-of-file while (not eof(uf_lun)) do begin read_uf_rec,uf_lun,rec_len,byt_buf words = rec_len/2 int_buf = fix(byt_buf,0,words) str_buf = strarr(words) count=0 for i=0,rec_len-1,2 do begin str_buf(count)=string(byt_buf(i:i+1)) count=count+1 endfor pos1 = int_buf(4) fields_per_ray = int_buf(pos1-1) records_per_ray = int_buf(pos1) fields_this_rec = int_buf(pos1+1) if (fields_per_ray ne fields_this_rec) then begin print,'Warning: fields_per_ray NE fields_per_rec.' print,'UF_TO_BSCAN stopping.' print,'UF record number ',uf_rec_num stop endif else begin field_name = strarr(fields_per_ray) field_header_pos = intarr(fields_per_ray) field_start_data = intarr(fields_per_ray) field_end_data = intarr(fields_per_ray) field_length = intarr(fields_per_ray) for i=0,(fields_per_ray-1) do begin field_name(i) = str_buf(pos1+2+(i*2)) field_header_pos(i) = int_buf(pos1+3+(i*2))-1 field_start_data(i) = int_buf(field_header_pos(i)) endfor for i=0,(fields_per_ray-1) do begin if (i lt (fields_per_ray-1)) then begin field_end_data(i) = int_buf(field_header_pos(i+1)) endif else begin field_end_data(i) = words-1 endelse field_length(i) = field_end_data(i)-field_start_data(i)+1 endfor lat = float(int_buf(18))+float(int_buf(19))+(float(int_buf(20))/64.)/60. lon = float(int_buf(21))+float(int_buf(22))+(float(int_buf(23))/64.)/60. ; FIRST RECORD if (uf_rec_num eq 0) then begin print,' ' print,'RADAR/LIDAR NAME: ',strtrim(str_buf(10:13),2) print,'SITE NAME: ',strtrim(str_buf(14:17),2) print,'TIME ZONE: ',strtrim(str_buf(31),2) print,'SITE LAT: ',lat print,'SITE LON: ',lon print,'TAPE GEN: ',strtrim(str_buf(40:43),2) print,'GEN DATE: ',strtrim(int_buf(37:39),2) get_site_id: site_id = 0. print,' ' print,'Please enter site/platform ID for BSCAN output. This value' print,'will reside in BSCAN file header element 22 (out of 0-29).' print,'(If unknown, enter 9.0000 for stationary platform or 8.0000' print,'for moving platform. The fractional part of these numbers' print,'is used for specific site or platform identifications.' read,site_id if ((site_id lt 8.000000) or (site_id ge 10.000000)) then begin print,'Sorry, site/platform IDs can only begin with 8 or 9.' print,'Please enter 9 for ground-based or 8 for moving platform.' goto,get_site_id endif print,' ' print,'Thank you.' print,' ' get_first_data_id: first_data_id = 0. print,'Please enter BSCAN data ID of first UF field. This value' print,'will reside in BSCAN file header element 16 (out of 0-29).' print,'Each additional data field will claim the next data id.' print,'Here are some examples of what to answer here:' print,'0 ...... NAILS data from NCAR signal processor' print,'20 ..... Excimer UV-DIAL' print,'40 ..... Yan''s Ozone DIAL' print,'60 ..... SABL' print,'80 ..... Grund''s 2-micron Doppler lidar' print,'100 .... Multiple Antenna Profiling Radar (MAPR)' print,'120 .... Regular ISS 915-MHz radar profiler' print,'140 .... NOAA-ETL 3 cm Doppler radar' print,'160 .... NOAA-ETL mini-MOPA Doppler lidar' print,'180 .... NCAR/NOAA NAILS data from Lassen Processor' print,'200 .... NOAA-ETL k-band Doppler radar' print,'If unknown, please enter: ',strtrim(bscan_flag,2) read,first_data_id if ((first_data_id lt 0.000000) and (first_data_id ne bscan_flag)) then begin print,'Sorry, data ID must be greater than 0. if not ',bscan_flag print,'Please enter correct data ID or ',bscan_flag,' if unknown.' goto,get_first_data_id endif print,' ' print,'Thank you.' print,' ' ; Dimension some variables by number of fields struc = strarr(fields_per_ray) output_luns = intarr(fields_per_ray) data_id = findgen(fields_per_ray) data_id = data_id + first_data_id prf = fltarr(fields_per_ray) z0 = fltarr(fields_per_ray) dz = fltarr(fields_per_ray) scale_factor = fltarr(fields_per_ray) polarization = fltarr(fields_per_ray) wavelength = fltarr(fields_per_ray) h_beam_width = fltarr(fields_per_ray) v_beam_width = fltarr(fields_per_ray) bandwidth = fltarr(fields_per_ray) last_field_name = field_name last_field_header_pos = field_header_pos for i=0,(fields_per_ray-1) do begin openw,temp_lun,bscan_output+'.'+field_name(i),/get_lun print,'Opening: ',bscan_output+'.'+field_name(i)+$ ' as LUN ',strtrim(temp_lun,2),' for data ID ',$ strtrim(data_id(i),2) output_luns(i) = temp_lun case i of 0: begin stuc_0 = assoc(output_luns(i),fltarr(30+field_length(i))) data_0 = fltarr(field_length(i)) rec_0 = fltarr(field_length(i)+30) end 1: begin stuc_1 = assoc(output_luns(i),fltarr(30+field_length(i))) data_1 = fltarr(field_length(i)) rec_1 = fltarr(field_length(i)+30) end 2: begin stuc_2 = assoc(output_luns(i),fltarr(30+field_length(i))) data_2 = fltarr(field_length(i)) rec_2 = fltarr(field_length(i)+30) end 3: begin stuc_3 = assoc(output_luns(i),fltarr(30+field_length(i))) data_3 = fltarr(field_length(i)) rec_3 = fltarr(field_length(i)+30) end 4: begin stuc_4 = assoc(output_luns(i),fltarr(30+field_length(i))) data_4 = fltarr(field_length(i)) rec_4 = fltarr(field_length(i)+30) end 5: begin stuc_5 = assoc(output_luns(i),fltarr(30+field_length(i))) data_5 = fltarr(field_length(i)) rec_5 = fltarr(field_length(i)+30) end 6: begin stuc_6 = assoc(output_luns(i),fltarr(30+field_length(i))) data_6 = fltarr(field_length(i)) rec_6 = fltarr(field_length(i)+30) end 7: begin stuc_7 = assoc(output_luns(i),fltarr(30+field_length(i))) data_7 = fltarr(field_length(i)) rec_7 = fltarr(field_length(i)+30) end 8: begin stuc_8 = assoc(output_luns(i),fltarr(30+field_length(i))) data_8 = fltarr(field_length(i)) rec_8 = fltarr(field_length(i)+30) end 9: begin stuc_9 = assoc(output_luns(i),fltarr(30+field_length(i))) data_9 = fltarr(field_length(i)) rec_9 = fltarr(field_length(i)+30) end else: begin print,'Sorry UT_TO_BSCAN cannot open that many files.' stop end endcase endfor print,' ' print,'UF_TO_BSCAN will report every 100 records converted.' print,' ' endif ; FILL OUT THE BSCAN RECORD HEADER ; WITH COMMON VARIABLES. header(0)=int_buf(28) header(1)=int_buf(29) header(2)=int_buf(30) header(3)=int_buf(24) header(4)=bscan_flag header(5)=bscan_flag header(6)=int_buf(32)/64. header(7)=int_buf(33)/64. header(8)=bscan_flag header(9)=bscan_flag header(10)=bscan_flag header(11)=int_buf(26) header(12)=int_buf(27) header(13)=1900.+int_buf(25) header(14)=bscan_flag header(15)=bscan_flag header(16)=bscan_flag header(17)=bscan_flag header(18)=lat header(19)=lon header(20)=bscan_flag header(21)=bscan_flag header(22)=site_id header(23)=30. header(24)=float(int_buf(44)) header(25)=bscan_flag header(26)=bscan_flag header(27)=bscan_flag header(28)=bscan_flag header(29)=bscan_flag ; FOR ALL UF RECORDS for i=0,(fields_per_ray-1) do begin prf(i) = 1./(float(int_buf(field_header_pos(i)+17))*1.e-6) z0(i) = float(int_buf(field_header_pos(i)+2))/1000. dz(i) = float(int_buf(field_header_pos(i)+4)) scale_factor(i) = float(int_buf(field_header_pos(i)+1)) wavelength(i) = float(int_buf(field_header_pos(i)+11))/64. polarization(i) = float(int_buf(field_header_pos(i)+10)) h_beam_width(i) = float(int_buf(field_header_pos(i)+7)) v_beam_width(i) = float(int_buf(field_header_pos(i)+8)) bandwidth(i) = float(int_buf(field_header_pos(i)+9)) header(14) = prf(i) header(16) = data_id(i) header(20) = z0(i) header(21) = dz(i) header(28) = field_length(i) case i of 0: begin data_0(*) = float(int_buf(field_start_data(i):field_end_data(i)))/scale_factor(i) rec_0(0:29) = header(*) rec_0(30:field_length(i)+30-1)=data_0(*) stuc_0(uf_rec_num) = rec_0 end 1: begin data_1(*) = float(int_buf(field_start_data(i):field_end_data(i)))/scale_factor(i) rec_1(0:29) = header(*) rec_1(30:field_length(i)+30-1)=data_1(*) stuc_1(uf_rec_num) = rec_1 end 2: begin data_2(*) = float(int_buf(field_start_data(i):field_end_data(i)))/scale_factor(i) rec_2(0:29) = header(*) rec_2(30:field_length(i)+30-1)=data_2(*) stuc_2(uf_rec_num) = rec_2 end 3: begin data_3(*) = float(int_buf(field_start_data(i):field_end_data(i)))/scale_factor(i) rec_3(0:29) = header(*) rec_3(30:field_length(i)+30-1)=data_3(*) stuc_3(uf_rec_num) = rec_3 end 4: begin data_4(*) = float(int_buf(field_start_data(i):field_end_data(i)))/scale_factor(i) rec_4(0:29) = header(*) rec_4(30:field_length(i)+30-1)=data_4(*) stuc_4(uf_rec_num) = rec_4 end 5: begin data_5(*) = float(int_buf(field_start_data(i):field_end_data(i)))/scale_factor(i) rec_5(0:29) = header(*) rec_5(30:field_length(i)+30-1)=data_5(*) stuc_5(uf_rec_num) = rec_5 end 6: begin data_6(*) = float(int_buf(field_start_data(i):field_end_data(i)))/scale_factor(i) rec_6(0:29) = header(*) rec_6(30:field_length(i)+30-1)=data_6(*) stuc_6(uf_rec_num) = rec_6 end 7: begin data_7(*) = float(int_buf(field_start_data(i):field_end_data(i)))/scale_factor(i) rec_7(0:29) = header(*) rec_7(30:field_length(i)+30-1)=data_7(*) stuc_7(uf_rec_num) = rec_7 end 8: begin data_8(*) = float(int_buf(field_start_data(i):field_end_data(i)))/scale_factor(i) rec_8(0:29) = header(*) rec_8(30:field_length(i)+30-1)=data_8(*) stuc_8(uf_rec_num) = rec_8 end 9: begin data_9(*) = float(int_buf(field_start_data(i):field_end_data(i)))/scale_factor(i) rec_9(0:29) = header(*) rec_9(30:field_length(i)+30-1)=data_9(*) stuc_9(uf_rec_num) = rec_9 end else: begin print,'Sorry UT_TO_BSCAN cannot open that many files.' stop end endcase endfor last_field_name = field_name last_field_header_pos = field_header_pos endelse if ((uf_rec_num mod 100) eq 0) then begin print,'RECORD ',strtrim(uf_rec_num,2)+' on '+$ strtrim(fix(header(11)),2)+'-'+$ strtrim(fix(header(12)),2)+'-'+$ strtrim(fix(header(13)),2)+' at '+$ strtrim(fix(header(0)),2)+':'+$ strtrim(fix(header(1)),2)+':'+$ strtrim(fix(header(2)),2) endif ; for i = 0,(fields_per_ray-1) do begin ; print,field_name(i),field_header_pos(i),field_start_data(i),field_end_data(i),field_length(i) ; print,field_name(i),wavelength(i) ; endfor ; stop uf_rec_num = uf_rec_num + 1L endwhile print,'EOF on UF detected.' print,'Closing UF file. close,uf_lun free_lun,uf_lun print,' ' for i=0,(fields_per_ray-1) do begin print,'Closing: ',bscan_output+'.'+field_name(i)+$ ' as LUN ',strtrim(temp_lun,2),' for data ID ',$ strtrim(data_id(i),2) close,output_luns(i) free_lun,output_luns(i) endfor print,'Done.' return end