Scrambler  1
bov2jpeg.f90
Go to the documentation of this file.
00001 !#########################################################################
00002 !               
00003 !    Copyright (C) 2003-2012 Department of Physics and Astronomy,
00004 !                            University of Rochester,
00005 !                            Rochester, NY
00006 !
00007 !    bov2jpeg.f90 is part of AstroBEAR.
00008 !
00009 !    AstroBEAR is free software: you can redistribute it and/or modify    
00010 !    it under the terms of the GNU General Public License as published by 
00011 !    the Free Software Foundation, either version 3 of the License, or    
00012 !    (at your option) any later version.
00013 !
00014 !    AstroBEAR is distributed in the hope that it will be useful, 
00015 !    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 !    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 !    GNU General Public License for more details.
00018 !
00019 !    You should have received a copy of the GNU General Public License
00020 !    along with AstroBEAR.  If not, see <http://www.gnu.org/licenses/>.
00021 !
00022 !#########################################################################
00023 program bov2jpeg
00024    USE IOPPM
00025    USE IOBOV
00026    USE Images
00027    IMPLICIT NONE
00028    TYPE(ImageDef) :: Image
00029    REAL(KIND=qPREC) :: minvalue, maxvalue, lower(2), upper(2), tnow, mymin, mymax
00030    REAL(KIND=qPREC), DIMENSION(:,:), POINTER :: data
00031    INTEGER :: N, nfiles, i, iErr
00032    CHARACTER(LEN=10) :: SCALE
00033    CHARACTER(LEN=60) :: BOVFILE, MINSTRING, MAXSTRING, PPMFILE
00034    CHARACTER(LEN=200) :: syscmd
00035    REAL(KIND=qPREC), PARAMETER :: UNSPECIFIED=1e30
00036    N=IARGC()
00037 
00038    IF (N < 1) THEN
00039       WRITE(*,*) 'usage: bov2jpeg file(s) [ [ log | linear ] [ minvalue [ maxvalue ]]] '
00040       STOP
00041    END IF
00042    nFiles=0
00043    scale='linear'
00044    DO i=1, N
00045       CALL GetARG(i,BOVFile)
00046       IF (TRIM(BOVFile) .eq. 'LINEAR') THEN
00047          SCALE='linear    '
00048          EXIT
00049       ELSEIF (TRIM(BOVFile) .eq. 'LOG') THEN
00050          SCALE='log       '
00051          EXIT
00052       ELSEIF (TRIM(BOVFile) .eq. 'linear') THEN
00053          SCALE='linear    '
00054          EXIT
00055       ELSEIF (TRIM(BOVFile) .eq. 'log') THEN
00056          SCALE='log       '
00057          EXIT
00058       ELSE
00059          nFiles=i
00060       END IF
00061    END DO
00062    write(*,*) 'found ', nfiles, ' files'
00063    write(*,*) 'SCALE= ', TRIM(SCALE)
00064 
00065    IF (N >= nFiles+2) THEN 
00066       CALL GETARG(nFiles+2,MINSTRING)
00067       READ(MINSTRING, *) minvalue
00068    ELSE
00069       minvalue=UNSPECIFIED !MINOVERALL !minval(data)
00070    END IF
00071 
00072    IF (N >= nFiles+3) THEN 
00073       CALL GETARG(nFiles+3,MAXSTRING)
00074       READ(MAXSTRING, *) maxvalue
00075    ELSE
00076       maxvalue=UNSPECIFIED !MAXOVERALL !maxval(data)
00077    END IF
00078    OPEN(UNIT=11, FILE='cmap.data', STATUS='old', IOSTAT=iErr)
00079    IF (iErr == 0) THEN
00080       READ(11,*) Image%npoints
00081       IF (Image%npoints > 10) write(*,*), 'error image only supports ', MaxCMapPoints, ' points'
00082       Image%npoints=min(Image%npoints, 10)
00083       DO i=1,Image%npoints
00084          READ(11,*) Image%cmap(i,:)
00085       END DO
00086       CLOSE(11)
00087    END IF
00088 
00089    DO i=1,nfiles
00090       CALL GetARG(i,BOVFile)
00091       CALL ReadBOV2DScalar(BOVFile, lower, upper, tnow, data)
00092       write(*,*) 'found data:', lower, upper, tnow, shape(data)
00093       IF (minvalue == UNSPECIFIED) THEN
00094          mymin=minval(data)
00095       ELSE
00096          mymin=minvalue
00097       END IF
00098       IF (maxvalue == UNSPECIFIED) THEN
00099          mymax=maxval(data)
00100       ELSE
00101          mymax=maxvalue
00102       END IF
00103 
00104       write(*,*) 'mymin=', mymin
00105       write(*,*) 'mymax=', mymax
00106       IF (TRIM(SCALE) .eq. 'log') THEN
00107          mymin=log(mymin)
00108          mymax=log(mymax)
00109          data=log(data)
00110       END IF
00111       n=len_trim(bovfile)
00112       WRITE(PPMFILE,'(A,A4)') BOVFILE(1:n-4), '.ppm'
00113       CALL WritePPM(PPMFILE, Image%cmap(1:Image%npoints,:),data, mymin, mymax)
00114       WRITE(syscmd, '(A8,A,A1,A,A11,A)') 'convert ', TRIM(PPMFILE), ' ', BOVFILE(1:n-4), '.jpg && rm ', TRIM(PPMFILE)
00115       !    write(*,*) 'calling ', syscmd
00116 
00117       CALL System(syscmd)
00118    END DO
00119 end program bov2jpeg
 All Classes Files Functions Variables