;******************************************************************************* ;*Usage: According to cognominal column between two txtfiles, the subrutine * ;*will extract the common part and obtain the common items for each txt file. * ;*finally, combine the two common files together and output to a new txt file. * * ;******************************************************************************* ;*Parameters: * ;* in_txt1: infile of ASCII format * ;* link_col1: specified column for searching key ;* item_num1:specified the number of items in txtfile * ;* in_txt2: infile of ASCII format * ;* link_col2: sepcified column for searching key ;* item_num2:specified the number of items in txtfile * ;* tile_label: if the in_txt file contain the tile.1 for yes, 0 for no * ;* split_character: specify the character for splitting each of columns $ * ;* such as ' ', ',' , '9B' * ;* out_txt: outfile of ASCII format, the same data structure as in_txt file, $ * ;* but, add the extracted fields from the ENVI image * * ;******************************************************************************* * pro ASCII_Link_2Txtfile,in_txt1,link_col1,item_num1,in_txt2,link_col2,item_num2,tile_label,split_character, $ out_txt
;*Query the in_txt1 file openr,lun_1,in_txt1,/get_lun ;*Query the in_txt1 file openr,lun_2,in_txt2,/get_lun ;Create outfile openw,lun_out,out_txt,/get_lun ;processing: ;Get items of in_txt file into memory temp1=' ';define two temporary string variable to contain each of items of the txt file temp2=' ' ;************************************** ;read the title line to jump,if it exists if tile_label eq 1 then begin readf,lun_1,temp1 readf,lun_2,temp2 printf,lun_out,temp1+temp2 endif ; to allocate the array to read the key-column and the txt-items in for each file txt1=strarr(item_num1) txt2=strarr(item_num2) link_key1=strarr(item_num1) link_key2=strarr(item_num2) for i=1,item_num1 do begin readf,lun_1,temp1;read the items of in_txt into memory records=strsplit(temp1,split_character,/extract) link_key1[i-1]=records[link_col1-1] txt1[i-1]=temp1 endfor for i=1,item_num2 do begin readf,lun_2,temp2;read the items of in_txt into memory records=strsplit(temp2,split_character,/extract) link_key2[i-1]=records[link_col2-1] txt2[i-1]=temp2 endfor for i=1,item_num1 do begin for j=1,item_num2 do begin ;index=where(link_key2=link_key1[i-1],count) if link_key1[i-1] eq link_key2[j-1] then begin