program read_scf ! ! READ_SCF reads data files for the Survey of Consumer Finances (SCF) ! and writes out the user's choice of variables. The input file ! is vars.inp which has the number of variables to on line 1. ! In each line after that, the user needs to put the first column ! and length of the variable. This information is in the SCF ! `map' file. An example of vars.inp: ! 3 ! 56661 14 X42001 Revised weights ! 49017 14 X8022 Age (respondent) ! 49003 14 X8021 Sex (respondent) ! Ellen McGrattan, 7-27-06 ! Revised, ERM, 1-25-07 implicit none integer, parameter :: mv=5669 integer :: i,nv, io_stat character (len=9) :: vname character (len=58322) :: str integer, dimension(mv) :: ibeg,ilen open(unit=5, file='v2extract07.inp') open(unit=7, file='/media/IOMEGA_HDD/SCFdata/2007Survey/scf2007.ascii') open(unit=8, file='names07.m') read(5,*) nv do i=1,nv read(5,*) ibeg(i),ilen(i),vname write(8,'(a9,a10,i4,a2)') vname,'=scf07(:,',i,');' enddo io_stat=0 do while (io_stat>=0) read(7,'(a)',iostat=io_stat) str if (io_stat>=0) call writeout(9,58322,str,nv,ibeg(1:nv),ilen(1:nv)) enddo contains subroutine writeout(iunit,ns,string,n,nbeg,nlen) integer, intent(in) :: ns,n,iunit integer, dimension(n),intent(in) :: nbeg,nlen character (len=ns),intent(in) :: string integer :: i,j,k,l open(unit=iunit, file='scf07.dat') do i=1,n j = nbeg(i) k = nbeg(i)+nlen(i)-1 l = verify(string(j:k),"-0123456789 .") if ((j==-1).or.(l/=0).or.(string(j:k).eq.' . ')) then write(iunit,'(a)',advance='no') 'NaN' elseif (string(j:k).eq.' A ') then write(iunit,'(a)',advance='no') '50' elseif (string(j:k).eq.' B ') then write(iunit,'(a)',advance='no') '300' elseif (string(j:k).eq.' C ') then write(iunit,'(a)',advance='no') '750' elseif (string(j:k).eq.' D ') then write(iunit,'(a)',advance='no') '1750' elseif (string(j:k).eq.' E ') then write(iunit,'(a)',advance='no') '3750' elseif (string(j:k).eq.' F ') then write(iunit,'(a)',advance='no') '6250' elseif (string(j:k).eq.' G ') then write(iunit,'(a)',advance='no') '8750' elseif (string(j:k).eq.' H ') then write(iunit,'(a)',advance='no') '17500' elseif (string(j:k).eq.' I ') then write(iunit,'(a)',advance='no') '37500' elseif (string(j:k).eq.' J ') then write(iunit,'(a)',advance='no') '62500' elseif (string(j:k).eq.' K ') then write(iunit,'(a)',advance='no') '87500' elseif (string(j:k).eq.' L ') then write(iunit,'(a)',advance='no') '175000' elseif (string(j:k).eq.' M ') then write(iunit,'(a)',advance='no') '375000' elseif (string(j:k).eq.' N ') then write(iunit,'(a)',advance='no') '750000' elseif (string(j:k).eq.' O ') then write(iunit,'(a)',advance='no') '3000000' elseif (string(j:k).eq.' P ') then write(iunit,'(a)',advance='no') '7500000' elseif (string(j:k).eq.' Q ') then write(iunit,'(a)',advance='no') '17500000' elseif (string(j:k).eq.' R ') then write(iunit,'(a)',advance='no') '37500000' elseif (string(j:k).eq.' S ') then write(iunit,'(a)',advance='no') '75000000' elseif (string(j:k).eq.' T ') then write(iunit,'(a)',advance='no') '150000000' else write(iunit,'(a)',advance='no') string(j:k) endif write(iunit,'(a)',advance='no') ' ' enddo write(iunit,'(a)',advance='yes') ' ' end subroutine writeout end program read_scf