pro SarAutoLib ; this file contains all of the functions called by SarAuto.pro ; *********************************** ; NOTES: ; Note: Make fname dir under lake and year dir. Have all pics under ; that new dir. ; Ex: 2000/Superior/NSS.R1.GT.D00103.../*.jpg ; Ex: 2000/Superior/NSS.R1.GT.D00354.../*.jpg ; In Master.pl, when making SarAuto.pro, if directory already ; exists, ask them if they want to write over current contents... ; make sure LD_LIBRARY_PATH is set to: ; /usr/arch/graphics/lib/ ; setenv LD_LIBRARY_PATH /usr/arch/graphics/lib/ ; ; IDL Steps: ; .compile SarAutoLib ; .compile SarAuto ; SarAuto ; *********************************** forward_function envi_get_data forward_function ProcessImageFile forward_function IsValidFile forward_function ColorTable forward_function NonFiltered forward_function MakePicture end ; *************************************** FUNCTION IsValidFile, data_file_name a = bytarr(192) openr, input, data_file_name, /get_lun readu, input, a free_lun, input return, fix(string(a(188:191))) end ; *************************************** FUNCTION ProcessImageFile, fileName, dirToWrite, jpegToWrite, rotateOrder RC = STRARR(2) RC[0] = 0 RC[1] = 0 numSamp = 0 numLine = 0 if ((IsValidFile (fileName)) eq 0) then begin print, 'ERROR: File is not a valid RADARSAT file... print, ' Moving to holding directory...' return, RC endif else begin envi_open_file, fileName, r_fid=fid if (fid eq -1) then begin print, '*** ERROR: Envi could not open file: ' print, fileName print, '' return, RC endif else begin cmd = 'mkdir ' + dirToWrite SPAWN, cmd finalJpeg = dirToWrite + jpegToWrite envi_file_query, fid, ns=numSamp, nl=numLine, data_type=input_dt dims = [-1, 0, numSamp-1, 0, numLine-1] ; this calculates the number of rows and columns that the generated jpeg will have divisor = (numSamp / 1000) + 1 numCols = UINT(numSamp / divisor) numRows = UINT(numLine / divisor) nCols = STRING(numCols) nRows = STRING(numRows) rot = STRING(rotateOrder) foo = NonFiltered(dims, fid, nCols, nRows, rot, finalJpeg) envi_file_mng, id=fid, /remove RC[0] = numSamp RC[1] = numLine SPAWN, 'rm R_*.p?m' envi_file_mng, id=fid, /remove return, RC endelse endelse end ; ******************************************* ; FUNCTION: NonFiltered ; PURPOSE: To create images that ; aren't filtered such as ; a regular and gamma2 image ; PARAMATER: dims - ; fid - ; numSamp - ; numLine - ; rot - ; pname - ; RETURNS: 0 ; ******************************************* FUNCTION NonFiltered, dims, fid, numSamp, numLine, rot, pname PRINT, ' *** Making non-filtered images ***' text = 'Original Image' parms = [numSamp, numLine, pname, rot, 'reg', '', text] ; foo = MakePicture (dims, fid, parms) text = 'Gamma 2' parms = [numSamp, numLine, pname, rot, 'gamma', '2', text] ; foo = MakePicture (dims, fid, parms) text = 'Color Table: ' PRINT, '' PRINT, '*** Applying Color Table Process to Median 5x5 ***' textCT = text + 'Green / Red / Blue / White ' parms = [numSamp, numLine, pname, rot, 'colorTable', '2', textCT] ; foo = MakePicture(dims, fid, parms) textCT = text + 'Blue / Green / Red / Yellow ' parms = [numSamp, numLine, pname, rot, 'colorTable', '4', textCT] foo = MakePicture(dims, fid, parms) textCT = text + 'Rainbow ' parms = [numSamp, numLine, pname, rot, 'colorTable', '13', textCT] foo = MakePicture(dims, fid, parms) textCT = text + 'Stern Special ' parms = [numSamp, numLine, pname, rot, 'colorTable', '15', textCT] foo = MakePicture(dims, fid, parms) ; set the color table back to original LOADCT, 0 RETURN, 0 END ; ******************************************* ; FUNCTION: MakePicture ; PURPOSE: To create a jpeg image ; with all header info ; PARAMATER: dims - ; pos - ; fid - ; numSamp - ; numLine - ; pname - ; option - ; RETURNS: 0 ; ******************************************* FUNCTION MakePicture, dims, fid, parms pos = 0 numSamp = parms[0] numLine = parms[1] pname = parms[2] rot = parms[3] option = parms[4] value = parms[5] picText = parms[6] data = ENVI_GET_DATA(fid=fid, dims=dims, pos=pos) print, ' *** Creating Image ***' print, 'Rotating Image...' if (rot gt 0) then begin print, 'Image is ascending...' image = ROTATE(data, 7) endif else begin print, 'Image is decending...' image = ROTATE(data, 5) endelse tmp_name = pname + "_sartmp.jpg" ext = ".jpg" CASE option OF 'colorTable': BEGIN loadct, value TVLCT, red, green, blue, /GET CASE value OF '2': BEGIN ext='_GRBW.jpg' END '4': BEGIN ext='_BGRY.jpg' END '13': BEGIN ext='_RAINBOW.jpg' END '15': BEGIN ext='_STERN.jpg' END ENDCASE thisImage = image s = SIZE (thisImage) colorImage = BYTARR(3, s(1), s(2)) colorImage(0, *, *) = red(thisImage) colorImage(1, *, *) = green(thisImage) colorImage(2, *, *) = blue(thisImage) WRITE_JPEG, tmp_name, colorImage, TRUE=1, QUALITY=25, /ORDER END ELSE: BEGIN WRITE_JPEG, tmp_name, order=1, image, QUALITY=25 END ENDCASE PRINT, 'Resizing Image... (This could take a minute or so...)' cmd = 'djpeg ' + tmp_name + ' | pnmscale .75 > R_jpeg.pnm' ; cmd = 'djpeg ' + tmp_name + ' > R_jpeg.pnm' SPAWN, cmd cmd = "convert -geometry "" " + numSamp + " x " + numLine + " >"" R_jpeg.pnm R_jpeg1.pnm" SPAWN, cmd cmd = 'rm ' + tmp_name + ' R_jpeg.pnm' SPAWN, cmd CASE option OF 'gamma': BEGIN CASE value OF '2': BEGIN PRINT, 'Applying GAMMA value of 2 to image' SPAWN, 'mv R_jpeg1.pnm R_jpegGAMMA.pnm' SPAWN, 'pnmgamma 2 2 2 R_jpegGAMMA.pnm > R_jpeg1.pnm' ext = "_GAMMA2.jpg" END ENDCASE END ELSE: ; do nothing ENDCASE PRINT, 'Adding Header Information to Picture' cmd = 'pbmtext "VIEW: ' + picText + ' " > R_pictext.pnm' SPAWN, cmd cmd = 'pnmcat -white -tb -jleft R_TopTable.pbm R_jpeg1.pnm R_pictext.pnm R_BotTable.pbm > R_Master.pnm' SPAWN, cmd jpegName = pname + ext PRINT, 'Writing Jpeg: ', jpegName cmd = 'cjpeg -smooth 10 R_Master.pnm > ' + jpegName SPAWN, cmd ; leave the .pbm files cuz we'll need them for each view... ; delete them later... SPAWN, 'rm R_*.pnm' RETURN, 0 END