source: trunk/SRC/ReadWrite/readoldopadistcoast.pro @ 134

Last change on this file since 134 was 130, checked in by pinsard, 18 years ago

improvements of ReadWrite/?*.pro header

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