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, 5-7-09 implicit none integer, parameter :: mv=5669 integer :: i,nv, io_stat character (len=9) :: vname character (len=35024) :: str integer, dimension(mv) :: ibeg,ilen open(unit=5, file='v2extract89.inp') open(unit=7, file='/media/IOMEGA_HDD/SCFData/1989Survey/scf89.ascii') open(unit=8, file='names89.m') read(5,*) nv do i=1,nv read(5,*) ibeg(i),ilen(i),vname write(8,'(a9,a10,i4,a2)') vname,'=scf89(:,',i,');' enddo io_stat=0 do while (io_stat>=0) read(7,'(a)',iostat=io_stat) str if (io_stat>=0) call writeout(9,35024,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='scf89.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' 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