Thread: Character formatting - SAC/fortran

Started: 2010-02-09 18:50:09
Last activity: 2010-02-09 18:50:09
Topics: SAC Help
Fiona Darbyshire
2010-02-09 18:50:09
I inherited a code for conversion of SAC to ASCII with extra information
going into the top of the ASCII file (ready for input to another program).
It's something I haven't used for quite some time and I've installed SAC
101.2 since the last time I used it. Something seems to have changed with
respect to some of the data formatting, so I recompiled the source code and
reran it. This solved one of my data formatting problems, but appears to
have created another. There appears to be some spurious white space in front
of station and component names which is creating an issue for the program
and its use as input to another code. I extracted the relevant piece of
fortran from the code; here it is:

character*4 kstnm
character*100 fin,fout
write(*,*)'Enter infile'
read(*,*)fin
call rsac1(fin,x,nlen,beg,del,NMAX,nerr)
call getkhv('KSTNM',kstnm,nerr)
write(*,*) KSTNM
open(unit=10,file='nmresult',status='unknown')
write(10,*),KSTNM
close(10)
stop
end

For a SAC file in which the station name is AKVQ, I get the following
result:
Standard output:
AKV

File nmresult (viewed in nedit):
AKV<nul>

(In each case there is a single space in front of the station or component
name)
If I change the character*4 statement for a larger number, I get the full
station name, but still with the space in front and the <nul> marker in the
file under nedit. The space and the nul cause problems for inputting the
station/component information to the next stage of the data analysis
procedure.
So my question is simply: why the space in front of the names, and is there
a way to eradicate it?

Thanks,

Fiona Darbyshire
Université du Québec à Montréal

10:19:46 v.f0c1234e