C+ C NAME: C bWriteNic C PURPOSE: C Writes a binary .nic file in the exact format the SMEI camera C software produces. C CATEGORY: C I/O C CALLING SEQUENCE: logical function bWriteNic(cFile, cDir, nX, nY, nB, Orig, cTrailer) C INPUTS: C cFile character*(*) file name C (the file type will be replaced by .nic) C cDir character*(*) output directory C if not left blank this directory overrides C the directory specification in cFile C nX integer row length C nY integer column height C nB integer # bytes per number in output file C 2 for integer*2 C 4 for integer*4 C -4 for real*4 C Orig(nX*nY) integer image data C cTrailer character*512 trailer C OUTPUTS: C (output to .nic file) C CALLS: C itrim, iSetFileSpec, iPutFileSpec, iGetFileSpec, bOpenFile, iFreeLun C SEE ALSO: C bReadNic C INCLUDE: include 'dirspec.h' include 'filparts.h' include 'openfile.h' C RESTRICTIONS: C Has only been tested on NT and Linux C PROCEDURE: C WIN: Output file is opened as a sequential access file C (iAct = OPN__REOPEN+OPN__NEW+OPN__BINARY in bOpenFile call) C The file is written with a single write: C read (iU) .... C C Linux: The WIN method produces a file in Linux which has 8 bytes C attached to the end. To avoid this we open a direct access file C (iAct = OPN__REOPEN+OPN__NEW+OPN__RECLBYTE in bOpenFile call) C with a record length in bytes equal to the total size of the file C The file is written with a single write: C read (iU,rec=1) .... C C The second method (for Linux) will also work for WIN. C MODIFICATION HISTORY: C FEB-2001, Paul Hick (UCSD/CASS) C JUL-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C Modified to enable reading of integer*4 and real*4 data. C The input array is now real*4 instead of integer*4. C- character cFile*(*) character cDir *(*) integer nX integer nY integer nB real Orig(*) character cTrailer*512 character cSay*9 /'bWriteNic'/ character cOut*120 integer*2 iX integer*2 iY integer*2 iB integer*2 Orig2(1280*600) integer Orig4(1280*600) logical bOpenFile nXY = nX*nY if (nB .ne. 4 .and. nB .ne. -4 .and. nB .ne. 2) nB = 2 if (nB .eq. 2) then do I=1,nXY ! Copy int*4 into int*2 Orig2(I) = nint(Orig(I)) end do else if (nB .eq. 4) then do I=1,nXY ! Copy int*4 into int*2 Orig4(I) = nint(Orig(I)) end do end if I = iSetFileSpec(cFile) if (itrim(cDir) .ne. 0) I = iPutFileSpec(0, FIL__DIRECTORY, cDir) I = iPutFileSpec(FIL__TYPE, FIL__TYPE, '.nic')! Replace .ice by .nic I = iGetFileSpec(0, 0, cOut) iX = nX iY = nY iB = nB if (cOpSys .eq. OS__UNIX .or. cOpSys .eq. OS__LINUX) then iRecl = 3*2+nXY*abs(nB)+len(cTrailer) bWriteNic = bOpenFile(OPN__REOPEN+OPN__NEW+OPN__RECLBYTE, iU, cOut, iRecl) if (bWriteNic) then if (nB .eq. 2) then write (iU,rec=1) iX,iY,iB,(Orig2(I),I=1,nXY),cTrailer else if (nB .eq. 4) then write (iU,rec=1) iX,iY,iB,(Orig4(I),I=1,nXY),cTrailer else if (nB .eq. -4) then write (iU,rec=1) iX,iY,iB,(Orig (I),I=1,nXY),cTrailer end if iU = iFreeLun(iU) end if else iRecl = 0 ! Write binary image file bWriteNic = bOpenFile(OPN__REOPEN+OPN__NEW+OPN__BINARY, iU, cOut, iRecl) if (bWriteNic) then if (nB .eq. 2) then write (iU) iX,iY,iB,(Orig2(I),I=1,nXY),cTrailer else if (nB .eq. 4) then write (iU) iX,iY,iB,(Orig4(I),I=1,nXY),cTrailer else if (nB .eq. -4) then write (iU) iX,iY,iB,(Orig (I),I=1,nXY),cTrailer end if iU = iFreeLun(iU) end if end if return end