Program tcs_arit ! For arithmetical operations between fits images ! A.Bijaoui 11 Avril 1996 ! Adaptation OVN 01/04/06 & 04/11/09 Implicit None Character(Len=100) Option(50) Character(Len=80) Ife1,Ife2,Ifs,String,Mouch Character(Len=60) Comment Integer Lu,Nc,Nl,Bp,Nodef,Status,Np1,Np2,Ikeys,Nkeys,Err,Choice Integer Nc1,Nc2,Ncs,Nl1,Nl2,Nls,Nps Integer Nc21,Nc22,Nc23,Nl11,Nl12,Nl13,Nl21,Nl22,Nl23,Nc11,Nc12,Nc13 Integer Ils,Ics,Ncs1,Nls1,Il1,Il2,Ic1,Ic2 Real Xd,Yd,Dx,Dy,X Real,dimension(:,:),allocatable:: Im1,Im2,Ims Call Getline(Nkeys,Option) ! Parameter Initialization Nc11=1 ; Nc12=0 ; Nc13=1 Nl11=1 ; Nl12=0 ; Nl13=1 Nc21=1 ; Nc22=0 ; Nc23=1 Nl21=1 ; Nl22=0 ; Nl23=1 Ife1='dummy' Ife2='dummy' Ifs='dummy' Choice=2 ! Subtraction Mouch='mouch.lis' If(Nkeys.eq.0) then Write(*,*) 'Syntax : -i1 Image_in1 -i2 Image_in2 -o Image_Out' Write(*,*) ' -c11 Start_Column_1 -c12 End_Column_1 -c13 Column_Step_1' Write(*,*) ' -l11 Start_line_1 -l12 Last_line_1 -l13 Step_line_1' Write(*,*) ' -c21 Start_Column_2 -c22 End_Column_2 -c23 Column_Step_2' Write(*,*) ' -l21 Start_line_2 -l22 Last_line_2 -l23 Step_line_2' Write(*,*) ' -c Choice -l logfile' Write(*,*) 'Operation between two zones of images' Write(*,*) '-i1 Image_in1 First image (required)' Write(*,*) '-i2 Image_in2 Second image (required)' Write(*,*) '-o Image_out (required)' Write(*,*) '-c11 First column image 1 (def. 1)' Write(*,*) '-c12 Last column image 1 (def. number of columns)' Write(*,*) '-c13 step between two columns image 1 (def. 1)' Write(*,*) '-l11 First line image 1 (def. 1)' Write(*,*) '-l12 Last line image 1 (def. number of lines)' Write(*,*) '-l13 step between two lines image 1 (def. 1)' Write(*,*) '-c21 First column image 2 (def. 1)' Write(*,*) '-c22 Last column image 2 (def. number of columns)' Write(*,*) '-c23 step between two columns image 2 (def. 1)' Write(*,*) '-l21 First line image 2 (def. 1)' Write(*,*) '-l22 Last line image 2 (def. number of lines)' Write(*,*) '-l23 step between two lines image 2 (def. 1)' Write(*,*) '-c Arithmetique option (def. 2)' Write(*,*) ' 1 Addition' Write(*,*) ' 2 Subtraction' Write(*,*) ' 3 Multiplication' Write(*,*) ' 4 Ratio' Write(*,*) '-l logfile : name of the log file (def. mouch.lis)' Stop Endif do Ikeys=1,Nkeys,2 if(Option(Ikeys).eq.'-i1') Ife1 =Option(Ikeys+1) if(Option(Ikeys).eq.'-i2') Ife2 =Option(Ikeys+1) if(Option(Ikeys).eq.'-c11') Read(Option(Ikeys+1),*) Nc11 if(Option(Ikeys).eq.'-c12') Read(Option(Ikeys+1),*) Nc12 if(Option(Ikeys).eq.'-c13') Read(Option(Ikeys+1),*) Nc13 if(Option(Ikeys).eq.'-l11') Read(Option(Ikeys+1),*) Nl11 if(Option(Ikeys).eq.'-l12') Read(Option(Ikeys+1),*) Nl12 if(Option(Ikeys).eq.'-l13') Read(Option(Ikeys+1),*) Nl13 if(Option(Ikeys).eq.'-c21') Read(Option(Ikeys+1),*) Nc21 if(Option(Ikeys).eq.'-c22') Read(Option(Ikeys+1),*) Nc22 if(Option(Ikeys).eq.'-c23') Read(Option(Ikeys+1),*) Nc23 if(Option(Ikeys).eq.'-l21') Read(Option(Ikeys+1),*) Nl21 if(Option(Ikeys).eq.'-l22') Read(Option(Ikeys+1),*) Nl22 if(Option(Ikeys).eq.'-l23') Read(Option(Ikeys+1),*) Nl23 if(Option(Ikeys).eq.'-c') Read(Option(Ikeys+1),*) Choice if(Option(Ikeys).eq.'-o') Ifs =Option(Ikeys+1) if(Option(Ikeys).eq.'-l') Mouch =Option(Ikeys+1) enddo If(Ife1.eq."dummy") Stop "No first image (-i1)" If(Ife2.eq."dummy") Stop "No second image (-i2)" If(Ifs.eq."dummy") Stop "No file for the resulting image (-o)" Call Debut('OVN_arit',Mouch) Call WC('Operation between two zones of images') Call WC('First Image to process '// Ife1) Status=0 Lu=1 Call OFits(Lu,Ife1,Bp,String,Nc1,Nl1,Dx,Dy,Xd,Yd) If(BP.ne.-32) Stop 'This program processes only real data' Np1=Nc1*Nl1 Allocate(Im1(Nc1,Nl1),stat=err) ; If(err/=0) Stop "Allocation problem" Call FtgpvE(Lu,0,1,Np1,0,Im1,Nodef,Status) Call FTClos(Lu,Status) Write(String,'("Nc: ",I4," Nl: ",I4)') Nc1,Nl1 Call WC(string) If(Nc12==0) Nc12=Nc1 Write(String,'("From column: ",I4," to ",I4," Step ",I3)') Nc11,Nc12,Nc13 Call WC(string) If(Nl12==0) Nl12=Nl1 Write(String,'("From line : ",I4," to ",I4," Step ",I3)') Nl11,Nl12,Nl13 Call WC(string) Ncs=(Nc12-Nc11)/Nc13+1 Nls=(Nl12-Nl11)/Nl13+1 Call WC('Second Image to process '// Ife2) Call OFits(Lu,Ife2,Bp,String,Nc2,Nl2,Dx,Dy,Xd,Yd) If(BP.ne.-32) Stop 'This program processes only real data' Np2=Nc2*Nl2 Allocate(Im2(Nc2,Nl2),stat=err) ; If(err/=0) Stop "Allocation problem" Call FtgpvE(Lu,0,1,Np2,0,Im2,Nodef,Status) Call FTClos(Lu,Status) Write(String,'("Nc: ",I4," Nl: ",I4)') Nc2,Nl2 Call WC(string) If(Nc22==0) Nc22=Nc2 Write(String,'("From column: ",I4," to ",I4," Step ",I3)') Nc21,Nc22,Nc23 Call WC(string) If(Nl22==0) Nl22=Nl2 Write(String,'("From line : ",I4," to ",I4," Step ",I3)') Nl21,Nl22,Nl23 Call WC(string) Ncs1=(Nc22-Nc21)/Nc23+1 ; If(Ncs1.ne.Ncs) Stop "Incomptatiblity between the columns" Nls1=(Nl22-Nl21)/Nl23+1 ; If(Nls1.ne.Nls) Stop "Incomptatiblity between the lines" Allocate(Ims(Ncs,Nls),stat=err) ; If(err/=0) Stop "Allocation problem" Xd=Xd+(Nc21-1)*Dx Yd=Yd+(Nl21-1)*Dy Dx=Dx*Nc23 Dy=Dy*Nl23 If(Choice==1) Call WC('Addition') If(Choice==2) Call WC('Subtraction') If(Choice==3) Call WC('Multiplication') If(Choice==4) Call WC('Ratio') Do Ils=1,Nls Il1=Nl11+(Ils-1)*Nl13 Il2=Nl21+(Ils-1)*Nl23 Do Ics=1,Ncs Ic1=Nc11+(Ics-1)*Nc13 Ic2=Nc21+(Ics-1)*Nc23 X=0. If(Choice==1) X=Im1(Ic1,Il1)+Im2(Ic2,Il2) If(Choice==2) X=Im1(Ic1,Il1)-Im2(Ic2,Il2) If(Choice==3) X=Im1(Ic1,Il1)*Im2(Ic2,Il2) If(Choice==4) Then If(Im2(Ic2,Il2).ne.0.) Then X=Im1(Ic1,Il1)/Im2(Ic2,Il2) Else X=0. Endif Endif Ims(Ics,Ils)=X Enddo Enddo Call WC('Resulting Image '// Ifs) Comment='Operation between images with OVN_arit' Call CFits(Ifs,Lu,Comment,Ncs,Nls,Dx,Dy,Xd,Yd,BP) Call FtpprE(Lu,0,1,(Ncs*Nls),Ims,Status) Call FTClos(Lu,Status) CALL LAFIN('OVN_arit') END