CACK_OOPS_!@#$%^&*()*&^%$#@!_SPOO_KCAC RICE.FOR C+ C NAME: C rice C PURPOSE: C Compress/decompress *.nic files C CATEGORY: C I/O C CALLING SEQUENCE: program rice C rice file1 [file2 ...] [/directory[=directory]] C rice /help (displays help) C (on Linux use a '-' instead of '/') C INPUTS: C file1 file2 file specifications for files to be processed. Only C files with type .nic or .ice are accepted. The file C name can contain wildcards. Directories are optional. C C If no files are specified then the user is prompted for C a single file specification C /directory=directory C output directory for compressed/decompressed files C Specifying /directory (without an '=directory') will C put output files in the same directory as the input C files. C C If no directory is specified then the user is prompted C to specify a directory. The default directory presented C will be the directory of the first input file. C CALLS: C ForeignArg, AskChar, iSearch, Say, lowercase, iSetFileSpec C iGetFileSpec, LocFirst, LocFirstLen, iCheckDirectory, bCompressNic C bUncompressNic, cInt2Str C INCLUDE: include 'dirspec.h' include 'openfile.h' include 'filparts.h' C RESTRICTIONS: C This program is only intended to compress/decompress *.nic files from C the SMEI camera. If a *.ice file is decompressed which is not a C compressed *.nic file then the decompressed file will contain garbage. C PROCEDURE: C > On NT this program will usually be executed by clicking on the program C icon, i.e. without any command line arguments. When prompted for C File(s) to be processed C specify a file name and type (the directory is optional). C The name may include a wild card; the type must be .nic or .ice C C > In NT it is possible to select up to 100 files, and 'drag and drop' them C on the program icon (the value 100 is defined as a parameter nVar=100) C C > When prompted for C Output directory C specify a destination directory for the output files. The default C (selected by hitting return) is the same directory as the input file(s). C C > .nic files are compressed to .ice files C > .ice files are decompressed to .nic files. C C > Files implied by the file1, file2, etc. arguments are accumulated in C an array of file names. Currently a maximum of 2000 files are processed. C MODIFICATION HISTORY: C DEC-2000, Kevin Nguyen, Paul Hick (UCSD; pphick@ucsd.edu) C- parameter (nVar = 100) parameter (nFile = 2000) character cSay*4 /'rice'/ character cVar(nVar)*80 character cArg*200 character cDir*120 character cFile*120 character cType*10 character cFiles(nFile)*120 character cInt2Str*14 integer Str2Str logical bCompressNic logical bUncompressNic iVar = nVar call ForeignArg(' ',iVar,cVar,cArg) if (LocFirst(cSwitch//'help',cArg) .ne. 0) then call Say(cSay,'I','Usage', & 'When prompted for#'// & ' File(s) to be processed#'// & 'specify a file name and type (the directory is optional).#'// & 'The name may include a wild card; the type must be .nic or .ice#'// & '.nic files are compressed to .ice files#'// & '.ice files are decompressed to .nic files.#'// & 'A maximum of 2000 files can be processed.#'// & '.#'// & 'When prompted for#'// & ' Output directory#'// & 'specify a destination directory for the output files.#'// & 'The default (selected by hitting return) is the same#'// & 'directory as the input file(s)#'// & '.#'// & 'At the command line use this syntax to bypass the prompts:#'// & ' '//cSay//' file1 [file2 ...] '//cSwitch//'dir=dir#'// & '.') call Say(cSay,'I','Stop','Exit') end if !------ ! If iVar=0 no file name specification was entered on the command line. ! In this case prompt user for file name specification. if (iVar .eq. 0) then call AskChar('File(s) to be processed',cVar(1)) iVar = 1 end if !------- ! Loop over all file name specifications and accumulate the files in the ! Files arrays. Note that only the first 2000 files will be processed. iFile = 0 do I=1,iVar is = 1 do while (iSearch(is, cVar(I), cFile) .eq. 1) is = 0 if (iFile .lt. nFile) then iFile = iFile+1 cFiles(iFile) = cFile else if (iFile .eq. nFile) then call Say(cSay,'I',cInt2Str(nFile),'Max. number of files processed') end if end do end do if (iFile .eq. 0) call Say(cSay,'S','Stop','No files found') !------- ! If the switch /dir=dir_name is not present, then prompt for a ! directory. If it is present, then extract 'dir_name' and make sure ! it is an existing directory. I = LocFirst(cSwitch//'dir',cArg) if (I .eq. 0) then I = iSetFileSpec(cFiles(1)) I = iGetFileSpec(0,FIL__DIRECTORY,cDir) call AskChar('Output directory$dir',cDir) ! cDir will include trailing backslash else I = I+len(cSwitch) I1 = LocFirst('=',cArg(I:)) if (I1 .eq. 0) then ! Output to input directory cDir = ' ' else ! Output to dir specified on command line I2 = LocFirstLen(cSwitch,cArg(I:)) cDir = cArg(I-1+I1+1:I-1+I2-1) if (iCheckDirectory(cDir) .eq. 0) call Say(cSay,'E',cDir,'directory does not exist') I1 = iGetFileSpec(0,FIL__DIRECTORY,cDir)! Adds backslash if it's not there yet end if end if do I=1,iFile I1 = iSetFileSpec(cFiles(I)) I1 = iGetFileSpec(FIL__TYPE,FIL__TYPE,cType) call lowercase(cType) if (cType .eq. '.nic') then if ( bCompressNic(OPN__TRYINPUT, cFiles(I), cDir)) continue else if (cType .eq. '.ice') then if (bUncompressNic(OPN__TRYINPUT, cFiles(I), cDir)) continue else call Say(cSay,'I',cFiles(I),'file ignored') end if end do I = 0 I = I+Str2Str('processed' , cArg(I+1:))+1 I = I+Int2Str(iFile , cArg(I+1:))+1 I = I+Str2Str('files#done' , cArg(I+1:)) call Say(cSay,'S','Stop',cArg) end CACK_OOPS_!@#$%^&*()*&^%$#@!_SPOO_KCAC BCOMPRESSNIC.FOR C+ C NAME: C bCompressNic C PURPOSE: C Read *.nic file, compress the image array and write to *.ice file C CATEGORY: C I/O C CALLING SEQUENCE: logical function bCompressNic(iAct, cFile, cDir) C INPUTS: C iAct integer open specified (passed to bReadNic) C If cFile is known to be a valid *.nic file use C iAct = OPN__TRYINPUT C cFile character*(*) file name (with .nic file type) C cDir character*(*) output directory; C if cDir = ' ' then the compressed file C is put in the same directory as the input file C OUTPUTS: C bCompressNic logical .TRUE. : file compressed successfully C .FALSE.: error compressing file C (compressed file) C CALLS: C bReadNic, iSetFileSpec, iGetFileSpec, iPutFileSpec, ice_write C Int2Str, Str2Str, itrim C RESTRICTIONS: C cDir must include a trailing backslash, i.e. C:\temp\ instead of just C:\temp C INCLUDE: include 'openfile.h' include 'filparts.h' C PROCEDURE: C > If cDir = ' ', then the compressed file is written into the same directory as C the original image file. C > The compressed file is written only if the compression factor is less than 0.9. C > The file name of the compressed file is the same as the original file C with the file type changed to .ice. C > The trailer information in the compressed file contains three items C separated by a carriage return, line feed pair: C - 2 integer*4 values containing the dimensions of the image file (e.g. '1280 600') C (the product nX*nY is also recorded in the header of the .ice file) C - file name and type of the input file (e.g. tmo_001.nic) C - the trailer of the original image file C MODIFICATION HISTORY: C AUG-2000, Paul Hick (UCSD; pphick@ucsd.edu) C- integer iAct character cFile*(*) character cDir *(*) parameter (nOrig = 1280*600) real rOrigA(nOrig) integer iOrigA(nOrig) integer iPack (nOrig) character cOut * 120 character cInfo* 512 character cStr *1024 character CR /13/ character LF /10/ logical bReadNic integer Str2Str cInfo = '' bCompressNic = bReadNic(iAct, cFile, nOrig, nX, nY, nB, rOrigA, cInfo) do I=1,nX*nY iOrigA(I) = nint(rOrigA(I)) end do if (bCompressNic) then I = iSetFileSpec(cFile) I = 0 ! nB added with ice version 'ice 0002' I = I+Int2Str(nB, cStr(I+1:))+1 ! # bytes/number I = I+Int2Str( 2, cStr(I+1:))+1 ! # dimensions I = I+Int2Str(nX, cStr(I+1:))+1 ! Horizontal dimension I = I+Int2Str(nY, cStr(I+1:))+1 ! Vertical dimension I = I+iGetFileSpec(FIL__NAME,FIL__TYPE,cStr(I+1:)) ! File name and type I = I+Str2Str(CR//LF, cStr(I+1:)) I = I+Str2Str(cInfo , cStr(I+1:)) ! Image file trailer if (itrim(cDir) .ne. 0) I = iPutFileSpec(0, FIL__DIRECTORY, cDir) I = iPutFileSpec(FIL__TYPE, FIL__TYPE, '.ice') ! Change file type to .ice I = iGetFileSpec(0, FIL__TYPE, cOut) bCompressNic = ice_write(OPN__REOPEN, cOut, nB, 0.9, nX*nY, iOrigA, nOrig, iPack, cStr) .eq. 1 end if return end CACK_OOPS_!@#$%^&*()*&^%$#@!_SPOO_KCAC BUNCOMPRESSNIC.FOR C+ C NAME: C bUncompressNic C PURPOSE: C Read compressed *.nic file, and decompress it to *.nic file C CATEGORY: C I/O C CALLING SEQUENCE: logical function bUncompressNic(iAct, cFile, cDir) C INPUTS: C iAct integer open specified (passed to bOpenFile) C If cFile is known to be a valid *.ice file use C iAct = OPN__TRYINPUT C cFile character*(*) file name (with .ice file type) C cDir character*(*) output directory; C if cDir = ' ' then the decompressed file C is put in the same directory as the input file C OUTPUTS: C bUncompressNic logical .TRUE. : file decompressed successfully C .FALSE.: error decompressing file C (decompressed file) C CALLS: C iSetFileSpec, iGetFileSpec, iPutFileSpec, ice_read, itrim, bWriteNic C INCLUDE: include 'dirspec.h' include 'openfile.h' include 'filparts.h' C RESTRICTIONS: C Writing the decompressed file will currently only work on Windows. C PROCEDURE: C > If cDir = ' ', then the decompressed file is written into the same directory C as the original image file. C > The file name of the compressed file is the same as the original file C with the file type changed to .nic. C > The decompressed file should be byte for byte identical to the original file (i.e. the C DOS 'fc /b' command or the Unix 'diff' command should not detect any differences. C MODIFICATION HISTORY: C DEC-2000, Kevin Nguyen, Paul Hick (UCSD; pphick@ucsd.edu) C- integer iAct character cFile*(*) character cDir*(*) parameter (nOrig = 1280*600) real rOrigA(nOrig) integer iOrigA(nOrig) integer iPack (nOrig) character CR /13/ character LF /10/ character cInfo*1024 character cFmt *10 character cVers*8 logical bWriteNic iOrig = nOrig bUncompressNic = ice_read(iAct, cFile, iOrig, iOrigA, nOrig, iPack, cInfo, cVers) .eq. 1 do I=0,iOrig rOrigA(I) = float(iOrigA(I)) end do if (bUncompressNic) then !------- ! g77 does not allow specification of format '(I)'. It requires an ! explicity length qualifier, e.g. '(I2)'. nB = 2 if (cVers .ne. 'ice 0001') then I = index(cInfo, ' ') J = Int2Str(I-1,cFmt) cFmt = '(I'//cFmt(:itrim(cFmt))//')' read (cInfo(:I-1), cFmt) nB ! # bytes/number cInfo = cInfo(I+1:) ! Skip past nB end if I = index(cInfo, ' ') J = Int2Str(I-1,cFmt) cFmt = '(I'//cFmt(:itrim(cFmt))//')' read (cInfo(:I-1), cFmt) J ! Always 2 cInfo = cInfo(I+1:) ! Skip past J I = index(cInfo, ' ') J = Int2Str(I-1,cFmt) cFmt = '(I'//cFmt(:itrim(cFmt))//')' read (cInfo(:I-1), cFmt) nX ! 1280 for full image cInfo = cInfo(I+1:) ! Skip past nX I = index(cInfo, ' ') J = Int2Str(I-1,cFmt) cFmt = '(I'//cFmt(:itrim(cFmt))//')' read (cInfo(:I-1), cFmt) nY ! 600 for full image cInfo = cInfo(I+1:) ! Skip past nY I = index(cInfo, CR//LF) ! Skip past original file name cInfo = cInfo(I+2:) bUncompressNic = bWriteNic(cFile,cDir,nX,nY,nB,rOrigA,cInfo) end if return end