source: trunk/SRC/ReadWrite/readoldopadistcoast.pro

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1;+
2;
3; @file_comments
4; read the old binary direct access file that contains the
5; distance to the coast in OPA.
6;
7; based on the OPA subroutines dtacof and parctl
8;
9; @categories
10; For OPA
11;
12; @param UNIT
13;
14; @param PARAMS
15;
16; @param NUM
17;
18; @returns
19; a structure that contains two elements: tdistcoast (the
20; distance for the t-points) and fdistcoast (the distance for the
21; f-points).
22;
23; @history
24; Sebastien Masson (smasson\@lodyc.jussieu.fr)
25;                      June, 2002
26; @version
27; $Id$
28;
29;-
30FUNCTION read3fromopa, unit, params, num
31;
32  compile_opt idl2, strictarrsubs
33;
34   offset=params.reclen*params.jpk*(num-1L)
35   a=assoc(unit,dblarr(params.jpiglo,params.jpjglo,params.jpk,/nozero),offset)
36   b = a[0]
37   return, b
38end
39;
40;+
41;
42; @file_comments
43;
44; @categories
45; For OPA
46;
47; @param FILENAME {in}{required}
48; Filename (with the whole path if necessary)
49;
50; @param JPIGLO {in}{required}
51;
52; @param JPJGLO {in}{required}
53;
54; @param JPK {in}{required}
55; Dimensions of the opa grid
56;
57; @keyword IBLOC {default=4096L}
58; Ibloc size
59;
60; @keyword JPBYT {default=8L}
61; Jpbyt size
62;
63; @keyword NUMREC {default=19L*jpk}
64; Number of records in the file.
65;
66; @history
67; Sebastien Masson (smasson\@lodyc.jussieu.fr)
68;                      June, 2002
69;
70; @version
71; $Id$
72;
73;-
74FUNCTION readoldopadistcoast, filename, jpiglo, jpjglo, jpk $
75                            , IBLOC=ibloc, JPBYT=jpbyt, NUMREC=numrec
76;
77  compile_opt idl2, strictarrsubs
78;
79   iname_file = findfile(filename)
80   if iname_file[0] EQ '' then begin
81      ras = report( 'Bad file name')
82      return, -1
83   ENDIF ELSE iname_file = iname_file[0]
84; open the file
85   openr,numcost , iname_file, /get_lun, /swap_if_little_endian
86; check the size of the file
87   fileparameters = fstat(numcost)
88; default parameter definition for ORCA2
89   IF keyword_set(ibloc) THEN ibloc = long(ibloc) ELSE ibloc = 4096L
90   jpiglo = long(jpiglo)
91   jpjglo = long(jpjglo)
92   jpk = long(jpk)
93   IF keyword_set(jpbyt) THEN jpbyt = long(jpbyt) ELSE jpbyt = 8L
94; record length computation
95   reclen = ibloc*((jpiglo*jpjglo*jpbyt-1 )/ibloc+1)
96; number of records
97   IF keyword_set(numrec) THEN numrec = long(numrec) ELSE numrec = 3L*jpk
98; difference between the record length and the size of the contained
99; array.
100   toomuch = reclen-jpiglo*jpjglo*jpbyt
101; expected size computation
102   size = numrec*reclen-toomuch
103   if size NE fileparameters.size then begin
104      ras = report(['The size of the file is not the expected one!', $
105      'Check your file or the values of ibloc, jpiglo,', $
106      'jpjglo, jpk, jpbyt, numrec in this program'])
107      return, -1
108   endif
109; first record: six 64-bit integer to read.
110; default definition
111   iimlu = long64(999)
112   ijmlu = long64(999)
113   ikmlu = long64(999)
114; read
115   readu, numcost, iimlu, ijmlu, ikmlu
116   if iimlu NE jpiglo then begin
117      ras = report( 'iimlu = '+strtrim(iimlu, 1)+' differs from jpiglo ='+strtrim(jpiglo, 1))
118      return, -1
119   endif
120   if ijmlu NE jpjglo then begin
121      ras = report( 'ijmlu = '+strtrim(ijmlu, 1)+' differs from jpjglo ='+strtrim(jpjglo, 1))
122      return, -1
123   endif
124   if ikmlu NE jpk then begin
125      ras = report( 'ikmlu = '+strtrim(ikmlu, 1)+' differs from jpk ='+strtrim(jpk, 1))
126      return, -1
127   endif
128; other records
129   params = {jpiglo:jpiglo, jpjglo:jpjglo, jpk:jpk, reclen:reclen}
130   tdistcoast = read3fromopa(numcost, params, 2)
131   fdistcoast = read3fromopa(numcost, params, 3)
132;
133   close, numcost
134   free_lun, numcost
135
136   return, {tdistcoast:tdistcoast, fdistcoast:fdistcoast}
137end
Note: See TracBrowser for help on using the repository browser.