NADCON5-ng  0.0.2
NADCON5 Next Generation Documentation
xyz2b.f
Go to the documentation of this file.
1 c> \ingroup core
2 c> \if MANPAGE
3 c> \page xyz2b
4 c> \endif
5 c>
6 c> Part of the NADCON5 \ref core , Converts GMT `*.grd` to a `*.b` NADCON style grid file
7 c>
8 c> Turn gmt/netcdf grd dump into my grid file (real number version)
9 c> assumes grd dump is longitude/latitude/real (binary s.p.)
10 c>
11 c>
12 c> ### Program arguments
13 c> Arguments are newline terminated and read from standard input
14 c>
15 c> When run from the command line, the program prints a prompt for each argument
16 c>
17 c> They are enumerated here
18 c> \param infile Input File Name
19 c> \param outfile Output File Name
20 c>
21 c> ### Program Inputs:
22 c>
23 c> - `lin` Input File (`*.grd`)
24 c>
25 c> ### Program Outputs:
26 c>
27 c> - `lout` Output File (`*.b`)
28 c>
29  program xyz2b
30 
31 *** turn gmt/netcdf grd dump into my grid file (real number version)
32 *** assumes grd dump is longitude/latitude/real (binary s.p.)
33 
34  implicit double precision(a-h,o-z)
35  parameter(len=5401*5401)
36  parameter(gran=3600.d0)
37  character*88 fname
38  logical makpos
39  integer h(len)
40  real*4 z(len),glo,gla,val
41  equivalence(h(1),z(1))
42 
43  lin=1
44  lout=2
45 
46 **** write(*,1)
47 ****1 format(' program xyz2b --> Enter input file name: ',$)
48 **** read(*,'(a)') fname
49 
50  read(5,'(a)') fname
51 
52 *** next line is non-standard (binary input)
53 c open(lin,file='temp',status='old',form='binary')
54  open(lin,file=fname,status='old',form='binary')
55 
56 **** write(*,2)
57 ****2 format(' grid output --> Enter file name: ',$)
58 **** read(*,'(a)') fname
59 
60  read(5,'(a)') fname
61 
62 c open(lout,file='xyz2b.b',status='new',form='unformatted')
63  open(lout,file=fname,status='new',form='unformatted')
64 
65 **** write(*,'(a,$)') 'Integer data? '
66 **** read (*,'(a)') yesno
67 
68 *** real number version
69 
70  yesno='n'
71  if(yesno.eq.'y'.or.yesno.eq.'Y') then
72  ikind=0
73  else
74  ikind=1
75  endif
76 
77  glamx=-9999.d0
78  glamn= 9999.d0
79  glomx=-9999.d0
80  glomn= 9999.d0
81  dgla =-9999.d0
82  dglo =-9999.d0
83 
84 *** loop over data -- get grid parameters
85 
86  n=0
87  read(lin) glo,gla,val
88  n=1
89  if(makpos(glo)) continue
90 
91  if(gla.gt.glamx) glamx=gla
92  if(gla.lt.glamn) glamn=gla
93  if(glo.gt.glomx) glomx=glo
94  if(glo.lt.glomn) glomn=glo
95 
96  glax=gla
97  glox=glo
98 
99  100 read(lin,end=777) glo,gla,val
100  n=n+1
101  if(makpos(glo)) continue
102 
103  if(gla.gt.glamx) glamx=gla
104  if(gla.lt.glamn) glamn=gla
105  if(glo.gt.glomx) glomx=glo
106  if(glo.lt.glomn) glomn=glo
107 
108  dla=dabs(gla-glax)
109  dlo=dabs(glo-glox)
110  if(dla.gt.dgla.and.dla.lt.(glamx-glamn)/2.d0 ) dgla=dla
111  if(dlo.gt.dglo.and.dlo.lt.(glomx-glomn)/2.d0 ) dglo=dlo
112 
113  glax=gla
114  glox=glo
115  go to 100
116  777 rewind lin
117 
118 *** adjust granularity of input and report header
119 
120  glamn=idnint(gran*glamn)/gran
121  glamx=idnint(gran*glamx)/gran
122  glomn=idnint(gran*glomn)/gran
123  glomx=idnint(gran*glomx)/gran
124  dgla =idnint(gran*dgla )/gran
125  dglo =idnint(gran*dglo )/gran
126  nla=idnint((glamx-glamn)/dgla)+1
127  nlo=idnint((glomx-glomn)/dglo)+1
128  dgla=(glamx-glamn)/dble(nla-1)
129  dglo=(glomx-glomn)/dble(nlo-1)
130 
131  write(*,*)
132  write(*,*) ' kind=',ikind
133  write(*,*) ' LAT min=',glamn
134  write(*,*) ' del=',dgla,' # lat=',nla
135  write(*,*) ' max=',glamn+(nla-1)*dgla
136  write(*,*) ' LON min=',glomn
137  write(*,*) ' del=',dglo,' # lon=',nlo
138  write(*,*) ' max=',glomn+(nlo-1)*dglo
139 
140 *** initialize the grid
141 
142  if(nla*nlo.gt.len) stop 12345
143  if(ikind.eq.0) then
144  do 3 i=1,nla*nlo
145  3 h(i)=0
146  else
147  do 4 i=1,nla*nlo
148  4 z(i)=9999999999.0
149  endif
150 
151 *** read the text (3rd column is alway real*4 float)
152 
153  icount=0
154  iclip=0
155  10 read(lin,end=7777) glo,gla,val
156  icount=icount+1
157  if(makpos(glo)) continue
158  if(ikind.eq.0) then
159  ival=nint(val)
160  call put1(ival,gla,glo,h,nla,nlo,glamn,dgla,glomn,dglo,iclip)
161  else
162  call put2( val,gla,glo,z,nla,nlo,glamn,dgla,glomn,dglo,iclip)
163  endif
164  go to 10
165  7777 continue
166 
167 *** write the grid
168 
169  write(lout) glamn,glomn,dgla,dglo,nla,nlo,ikind
170  if(ikind.eq.0) then
171  call w1(lout,h,nla,nlo,glamn,dgla,glomn,dglo)
172  else
173  call w2(lout,z,nla,nlo,glamn,dgla,glomn,dglo)
174  endif
175 
176  write(*,*) ' all, icount, iclip = ',nla*nlo,icount,iclip
177 
178  stop
179  end
180  subroutine put1(ival,gla,glo,h,nla,nlo,glamn,dgla,glomn,dglo,iclp)
182 *** load value into grid
183 
184  implicit double precision(a-h,o-z)
185  real*4 val,gla,glo
186  integer h(nla,nlo)
187 
188  i=idnint((gla-glamn)/dgla)+1
189  if(i.lt.1.or.i.gt.nla) then
190  iclp=iclp+1
191  return
192  endif
193  j=idnint((glo-glomn)/dglo)+1
194  if(j.lt.1.or.j.gt.nlo) then
195  iclp=iclp+1
196  return
197  endif
198  h(i,j)=ival
199 
200  return
201  end
202  subroutine put2(val,gla,glo,z,nla,nlo,glamn,dgla,glomn,dglo,iclip)
204 *** load value into grid
205 
206  implicit double precision(a-h,o-z)
207  real*4 z(nla,nlo),val,gla,glo
208 
209  i=idnint((gla-glamn)/dgla)+1
210  if(i.lt.1.or.i.gt.nla) then
211  iclip=iclip+1
212  return
213  endif
214  j=idnint((glo-glomn)/dglo)+1
215  if(j.lt.1.or.j.gt.nlo) then
216  iclip=iclip+1
217  return
218  endif
219  z(i,j)=val
220 
221  return
222  end
223  subroutine w1(lout,h,nla,nlo,glamn,dgla,glomn,dglo)
225 *** write records south to north (elements are west to east)
226 
227  implicit double precision(a-h,o-z)
228  integer h(nla,nlo)
229 
230  do 1 i=1,nla
231  1 write(lout) (h(i,j),j=1,nlo)
232 
233  return
234  end
235  subroutine w2(lout,z,nla,nlo,glamn,dgla,glomn,dglo)
237 *** write records south to north (elements are west to east)
238 
239  implicit double precision(a-h,o-z)
240  real*4 z(nla,nlo)
241 
242  do 1 i=1,nla
243  1 write(lout) (z(i,j),j=1,nlo)
244 
245  return
246  end
247  logical function makpos(glon)
249 *** insure longitude is positive (single precision)
250 
251  makpos=.false.
252 
253  1 if(glon.lt.0.d0) then
254  glon=glon+360.d0
255  makpos=.true.
256  go to 1
257  endif
258 
259  2 if(glon.ge.360.d0) then
260  glon=glon-360.d0
261  go to 2
262  endif
263 
264  return
265  end
subroutine w1(lout, h, nla, nlo, glamn, dgla, glomn, dglo)
Definition: xyz2b.f:224
subroutine put2(val, gla, glo, z, nla, nlo, glamn, dgla, glomn, dglo, iclip)
Definition: xyz2b.f:203
logical function makpos(glon)
Definition: xyz2b.f:248
subroutine w2(lout, z, nla, nlo, glamn, dgla, glomn, dglo)
Definition: xyz2b.f:236
subroutine put1(ival, gla, glo, h, nla, nlo, glamn, dgla, glomn, dglo, iclp)
Definition: xyz2b.f:181
program xyz2b
Part of the NADCON5 NADCON5 Core Library , Converts GMT *.grd to a *.b NADCON style grid file...
Definition: xyz2b.f:29