C+ C NAME: C bReadNic C PURPOSE: C Read image from prototype SMEI camera C CATEGORY: C I/O C CALLING SEQUENCE: logical function bReadNic(iAct0, cFile, N, nX, nY, nB, Img, cTrailer) C INPUTS: C iAct0 integer open code passed to href=bOpenFile= C Usually set to zero. If cFile is known C to exist (e.g. a return value from C href=iSearch=) then file access can be C made more efficient by using the value C OPN__REOPEN (defined in openfile.h). C cFile character*(*) file name C N integer size of Img C OUTPUTS: C bReadNic logical .TRUE. : success C .FALSE.: failure C nX integer horizontal size of image C nY integer vertical size of image C nB integer # bytes per number on input file C 2 for integer*2 C 4 for integer*4 C -4 for real*4 C Img(nX*nY) real image data C cTrailer character*(*) trailer info from image file C CALLS: C bOpenFile, iFreeLun, Say C SEE ALSO: C bWriteNic C RESTRICTIONS: C Reading of *.nic.gz files depends on availability of gzip C (windows) or gunzip (Linux). C SIDE EFFECTS: C Linux : bOpenFile is passed OPN__RECLBYTE+OPN__READONLY C Other OS: bOpenFile is passed OPN__BINARY +OPN__READONLY C INCLUDE: include 'openfile.h' include 'dirspec.h' C PROCEDURE: C On Linux the file is opened as a direct, unformatted file with C a record length of 2 bytes. The file is read in packets of 2 byte. C This also works on Windows, but a much faster method opens C the file as a sequential, unformatted file and, after reading the C the array dimensions from the header reads the entire image with C a single read (this does not work on Linux). C MODIFICATION HISTORY: C AUG-2000, Paul Hick (UCSD/CASS) C MAR-2003, Paul Hick (UCSD/CASS) C Added capability to process *.nic.gz files (the file is C decompressed into a temporary file in $temp; the temporary C file is read and deleted). C JUL-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C Added argument nB. C Modified to enable reading of integer*4 and real*4 data. C The output now is real*4 instead of integer*4. C- integer iAct0 character cFile*(*) integer N integer nX integer nY integer nB real Img(N) character cTrailer*(*) character cSay*8 /'bReadNic'/ parameter (ndat = 1280*600) integer*2 idat integer*2 iidat(ndat) integer jdat integer jjdat(ndat) equivalence (jjdat,iidat) character cStr*512 integer*2 iStr(256) equivalence (cStr, iStr) logical bOpenFile if (cOpSys .eq. OS__UNIX .or. cOpSys .eq. OS__LINUX) then iAct = iAct0+OPN__RECLBYTE+OPN__READONLY !+OPN__STOP+OPN__NOPARSE+OPN__TRYINPUT iRecl = 2 ! If cFileSpec is a .gz. file then it will be unzipped into a temporary file ! in $temp. The temporary file is deleted by the iFreeLun call below, bReadNic = bOpenFile(iAct,iU, cFile, iRecl) if (bReadNic) then read (iU, rec=1) idat nX = idat read (iU, rec=2) idat nY = idat read (iU, rec=3) idat nB = idat iR = 3 do i=1,nX*nY iR = iR+1 if (i .gt. N) call Say(cSay,'E','Image','array not big enough') if (nB .eq. 2) then read (iU, rec=iR) idat ! Unsigned integer*2 Img(i) = idat if (Img(i) .lt. 0) Img(i) = Img(i)+65536.0 else if (nB .eq. 4) then read (iU, rec=iR) jdat ! Integer*4 Img(i) = jdat else if (nB .eq. -4) then read (iU, rec=iR) Img(i)! Real*4 end if end do cStr = ' ' j = 0 i = 0 do while (i .lt. 256 .and. j .eq. 0) i = i +1 iR = iR+1 read (iU, rec=iR, iostat=j) iStr(i) end do iU = iFreeLun(iU) cTrailer = cStr else nX = 0 nY = 0 nB = 0 cTrailer = ' ' end if else iAct = iAct0+OPN__BINARY+OPN__READONLY !+OPN__STOP+OPN__NOPARSE+OPN__TRYINPUT bReadNic = bOpenFile(iAct,iU, cFile, iRecl) if (bReadNic) then read (iU) idat nX = idat read (iU) idat nY = idat read (iU) idat nB = idat if (nX*nY .gt. N) call Say(cSay,'E','Image','array not big enough') if (nB .eq. 2) then read (iU) (iidat(i),i=1,nX*nY) do i=1,nX*nY Img(i) = iidat(i) if (Img(i) .lt. 0) Img(i) = Img(i)+65536.0 end do else if (nB .eq. 4) then read (iU) (jjdat(i),i=1,nX*nY) do i=1,nX*nY Img(i) = jjdat(i) end do else if (nB .eq. -4) then read (iU) (Img(i),i=1,nX*nY) end if !------ ! The trailer may not be present so check the return status. read (iU, iostat=j) cStr if (j .ne. 0) cStr = ' ' iU = iFreeLun(iU) cTrailer = cStr end if end if return end