/[MITgcm]/MITgcm/utils/scripts/joinds
ViewVC logotype

Contents of /MITgcm/utils/scripts/joinds

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Wed May 26 23:19:47 1999 UTC (24 years, 11 months ago) by adcroft
Branch: MAIN
CVS Tags: checkpoint46n_post, checkpoint51k_post, checkpoint62v, checkpoint47e_post, checkpoint57m_post, checkpoint52l_pre, checkpoint44e_post, checkpoint62u, hrcube4, hrcube5, checkpoint46l_post, checkpoint57g_pre, checkpoint46g_pre, checkpoint47c_post, release1_p13_pre, checkpoint62t, checkpoint50c_post, checkpoint57s_post, checkpoint58b_post, checkpoint57b_post, checkpoint46f_post, checkpoint52d_pre, checkpoint57g_post, checkpoint48e_post, checkpoint56b_post, checkpoint50c_pre, checkpoint57y_post, checkpoint44f_post, checkpoint46b_post, checkpoint52j_pre, checkpoint43a-release1mods, checkpoint51o_pre, checkpoint65z, checkpoint65x, checkpoint65y, checkpoint54d_post, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint54e_post, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, ecco_c50_e32, ecco_c50_e33, ecco_c50_e30, ecco_c50_e31, release1_p13, checkpoint40pre3, checkpoint62c, checkpoint40pre1, checkpoint51l_post, checkpoint40pre7, checkpoint40pre6, checkpoint48i_post, checkpoint57r_post, checkpoint40pre9, checkpoint40pre8, checkpoint46l_pre, checkpoint57d_post, checkpoint57i_post, checkpoint52l_post, checkpoint52k_post, chkpt44d_post, checkpoint59, checkpoint58, checkpoint55, checkpoint54, checkpoint57, checkpoint56, checkpoint51, checkpoint50, checkpoint53, checkpoint52, release1_p8, release1_p9, checkpoint50d_post, release1_p1, release1_p2, release1_p3, release1_p4, release1_p5, release1_p6, release1_p7, checkpoint58f_post, checkpoint52f_post, checkpoint57n_post, checkpoint58d_post, checkpoint62s, checkpoint58a_post, checkpoint62r, checkpoint62q, checkpoint50b_pre, checkpoint44e_pre, checkpoint62p, checkpoint57z_post, checkpoint54f_post, checkpoint51f_post, checkpoint62a, release1_b1, checkpoint62g, checkpoint62f, checkpoint62e, checkpoint62d, checkpoint62k, checkpoint62j, checkpoint62i, checkpoint62h, checkpoint62o, checkpoint62n, checkpoint62m, checkpoint62l, ecco_c51_e34d, ecco_c51_e34e, ecco_c51_e34f, ecco_c51_e34g, checkpoint62w, ecco_c51_e34a, ecco_c51_e34b, ecco_c51_e34c, checkpoint62z, checkpoint62y, checkpoint62x, checkpoint58y_post, checkpoint48b_post, checkpoint43, checkpoint51d_post, checkpoint48c_pre, checkpoint47d_pre, checkpoint51t_post, checkpoint58t_post, checkpoint38, checkpoint51n_post, release1_chkpt44d_post, checkpoint55i_post, checkpoint58m_post, checkpoint57l_post, checkpoint52i_pre, hrcube_1, hrcube_2, hrcube_3, checkpoint51s_post, checkpoint47a_post, checkpoint57t_post, checkpoint55c_post, checkpoint48d_pre, checkpoint51j_post, checkpoint47i_post, checkpoint63g, checkpoint52e_pre, checkpoint57v_post, branch-atmos-merge-shapiro, checkpoint57f_post, checkpoint52e_post, checkpoint51n_pre, checkpoint47d_post, icebear5, icebear4, icebear3, icebear2, checkpoint53d_post, checkpoint46d_pre, checkpoint40pre2, checkpoint64, checkpoint65, checkpoint60, checkpoint61, checkpoint62, checkpoint63, checkpoint57a_post, checkpoint48d_post, release1-branch_tutorials, checkpoint57h_pre, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint48f_post, checkpoint45d_post, checkpoint52b_pre, checkpoint54b_post, checkpoint46j_pre, checkpoint58w_post, checkpoint57h_post, checkpoint51l_pre, checkpoint52m_post, checkpoint57y_pre, chkpt44a_post, checkpoint55g_post, checkpoint44h_pre, checkpoint48h_post, checkpoint51q_post, checkpoint40pre4, ecco_c50_e29, checkpoint51b_pre, checkpoint46a_post, checkpoint47g_post, checkpoint52b_post, checkpoint52c_post, checkpoint46j_post, checkpoint28, checkpoint29, checkpoint51h_pre, checkpoint23, checkpoint24, checkpoint25, checkpoint46k_post, checkpoint27, ecco_c50_e28, chkpt44c_pre, checkpoint58o_post, checkpoint48a_post, checkpoint45a_post, checkpoint57c_post, checkpoint50f_post, checkpoint50a_post, checkpoint50f_pre, checkpoint58p_post, checkpoint58q_post, branch-atmos-merge-freeze, branch-atmos-merge-start, checkpoint52f_pre, checkpoint55d_post, ecco_c44_e19, ecco_c44_e18, ecco_c44_e17, ecco_c44_e16, release1_p12, checkpoint58e_post, release1_p10, release1_p11, release1_p16, release1_p17, release1_p14, release1_p15, checkpoint47j_post, pre38tag1, checkpoint54a_pre, checkpoint63p, checkpoint63q, checkpoint63r, checkpoint63s, checkpoint63l, checkpoint63m, checkpoint63n, checkpoint63o, checkpoint63h, checkpoint63i, checkpoint63j, checkpoint63k, checkpoint63d, checkpoint63e, checkpoint63f, ecco_c50_e33a, checkpoint53c_post, checkpoint63a, checkpoint63b, checkpoint63c, checkpoint55d_pre, checkpoint57c_pre, checkpoint58r_post, checkpoint55j_post, branch-exfmods-tag, checkpoint44g_post, branchpoint-genmake2, checkpoint26, checkpoint54a_post, checkpoint46e_pre, checkpoint55h_post, checkpoint58n_post, checkpoint51r_post, checkpoint48c_post, checkpoint45b_post, checkpoint46b_pre, checkpoint51i_post, checkpoint57e_post, release1-branch-end, c37_adj, release1_final_v1, checkpoint55b_post, checkpoint51b_post, checkpoint51c_post, checkpoint46c_pre, checkpoint53a_post, checkpoint46, checkpoint65o, checkpoint47b_post, checkpoint44b_post, checkpoint59q, checkpoint59p, checkpoint59r, checkpoint59e, checkpoint59d, checkpoint59g, checkpoint59f, checkpoint59a, checkpoint55f_post, checkpoint59c, checkpoint59b, checkpoint59m, checkpoint59l, checkpoint59o, checkpoint59n, checkpoint59i, checkpoint59h, checkpoint59k, ecco_c51_e34, checkpoint46h_pre, checkpoint52d_post, checkpoint53g_post, checkpoint46m_post, checkpoint57p_post, checkpint57u_post, checkpoint46a_pre, checkpoint50g_post, checkpoint45c_post, checkpoint57q_post, ecco_ice2, ecco_ice1, checkpoint44h_post, pre38-close, eckpoint57e_pre, checkpoint46g_post, release1_p12_pre, checkpoint58k_post, checkpoint39, checkpoint52a_pre, checkpoint33, checkpoint32, checkpoint31, checkpoint30, checkpoint37, checkpoint36, checkpoint35, checkpoint34, checkpoint62b, ecco_c44_e22, checkpoint58v_post, checkpoint50h_post, checkpoint52i_post, checkpoint50e_pre, checkpoint50i_post, ecco_c44_e25, checkpoint51i_pre, checkpoint52h_pre, checkpoint56a_post, checkpoint64y, checkpoint64x, checkpoint58l_post, checkpoint64z, checkpoint53f_post, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, checkpoint40pre5, checkpoint57h_done, checkpoint52j_post, checkpoint47f_post, checkpoint50e_post, chkpt44a_pre, checkpoint46i_post, ecco_c44_e23, ecco_c44_e20, ecco_c44_e21, ecco_c44_e26, ecco_c44_e27, ecco_c44_e24, checkpoint57j_post, checkpoint57f_pre, checkpoint61f, checkpoint46c_post, checkpoint58g_post, ecco-branch-mod1, ecco-branch-mod2, ecco-branch-mod3, ecco-branch-mod4, ecco-branch-mod5, branch-netcdf, checkpoint50d_pre, checkpoint58x_post, branch-atmos-merge-zonalfilt, checkpoint61n, checkpoint52n_post, checkpoint53b_pre, checkpoint46e_post, checkpoint59j, release1_beta1, checkpoint58h_post, checkpoint56c_post, checkpoint58j_post, checkpoint51e_post, checkpoint44b_pre, checkpoint42, checkpoint57a_pre, checkpoint40, checkpoint41, checkpoint55a_post, checkpoint47, checkpoint44, checkpoint45, checkpoint48, checkpoint49, checkpoint57o_post, checkpoint46h_post, checkpoint51o_post, checkpoint61q, checkpoint57k_post, checkpoint51f_pre, chkpt44c_post, checkpoint48g_post, checkpoint53b_post, checkpoint47h_post, checkpoint52a_post, checkpoint57w_post, checkpoint61e, checkpoint44f_pre, branch-atmos-merge-phase5, branch-atmos-merge-phase4, branch-atmos-merge-phase7, branch-atmos-merge-phase6, branch-atmos-merge-phase1, checkpoint58i_post, branch-atmos-merge-phase3, branch-atmos-merge-phase2, checkpoint51g_post, ecco_c52_e35, checkpoint57x_post, checkpoint46d_post, checkpoint50b_post, checkpoint58c_post, checkpoint58u_post, release1-branch_branchpoint, checkpoint51m_post, checkpoint53d_pre, checkpoint58s_post, checkpoint55e_post, checkpoint61g, checkpoint61d, checkpoint54c_post, checkpoint61b, checkpoint61c, checkpoint61a, checkpoint51a_post, checkpoint61o, checkpoint61l, checkpoint61m, checkpoint61j, checkpoint61k, checkpoint61h, checkpoint61i, checkpoint61v, checkpoint61w, checkpoint61t, checkpoint61u, checkpoint61r, checkpoint61s, checkpoint61p, checkpoint51p_post, checkpoint61z, checkpoint61x, checkpoint61y, checkpoint51u_post, HEAD
Branch point for: c24_e25_ice, branch-exfmods-curt, release1_final, release1-branch, branch-genmake2, release1, branch-nonh, tg2-branch, ecco-branch, release1_50yr, netcdf-sm0, icebear, checkpoint51n_branch, branch-atmos-merge, pre38, release1_coupled
Added matlab and scripts directories:
 o matlab contains rdmeta.m and rdmds.m, scripts for reading model
   output directly into Matlab
 o scripts contains joinds, Zhangfan's post-processing script for
   joining processor-based model output
   and joinmds, a place-holder (ie. hack) post-processing script that
   joins tiled-based model output

1 #!/usr/local/bin/perl -w
2
3 # MITgcmUV dataset joining utility.
4 # Tested with perl 4.0 and newer.
5 # Tested on Linux 2.0.27/I486, Irix 6.2/{IP22,IP25}
6 # Zhangfan XING, xing@pacific.jpl.nasa.gov
7 #
8 # LOGS:
9 # 980707, version 0.0.1, basically works
10 # 980721, version 0.2.0, proper handling of data file's header and terminator
11 # for diff bytesex.
12
13 #------
14 # usage
15 #------
16 sub usage {
17 print STDERR
18 "\nUsage:$0 [-Ddir0 -Ddir1 ...] " .
19 "prefix suffix [(little-endian|big-endian)]\n";
20 print STDERR "\nMITgcmUV dataset joining utility, version 0.2.0\n";
21 print STDERR
22 "Check http://escher.jpl.nasa.gov:2000/tools/ for newer version.\n";
23 print STDERR "Report problem to xing\@pacific.jpl.nasa.gov\n\n";
24 exit 1;
25 }
26
27 #------------------------------
28 # product of a list of integers
29 #------------------------------
30 sub listprod {
31 local ($product) = 1;
32 local ($x);
33 foreach $x (@_) {
34 $product *= $x;
35 }
36 $product;
37 }
38
39 #----------------
40 # @list1 + @list2
41 #----------------
42 sub lists_add {
43 local (*l1,*l2) = @_;
44 ($#l1 == $#l2) || return undef;
45
46 local (@l);
47 for (local($i)=0;$i<=$#l1;$i++) {
48 $l[$i]=$l1[$i]+$l2[$i];
49 }
50 @l;
51 }
52
53 #-------------
54 # pos to index
55 # 0-based.
56 #-------------
57 sub pos2index {
58
59 local ($pos,@dim) = @_;
60 local ($rightmost) = pop(@dim);
61
62 local (@index,$d);
63 foreach $d (@dim) {
64 push(@index,$pos%$d);
65 $pos = int($pos/$d);
66 }
67
68 # self-guarding
69 unless ($rightmost > $pos) {
70 return undef;
71 }
72
73 push(@index,$pos);
74 @index;
75 }
76
77 #-------------
78 # index to pos
79 # 0-based.
80 #-------------
81 sub index2pos {
82 local (*index,*dim) = @_;
83
84 return undef unless ($#index == $#dim);
85
86 local ($pos) = $index[$#index];
87 for (local($i)=$#dim;$i>0;$i--) {
88 $pos = $pos * $dim[$i-1] + $index[$i-1];
89 }
90 $pos;
91 }
92
93 #-------------------------
94 # check machine's bytesex.
95 # returns "little-endian" or "big-endian"
96 # or dies if unable to figure out
97 #-------------------------
98 sub mach_bytesex {
99
100 local ($foo) = pack("s2",1,2);
101 if ($foo eq "\1\0\2\0") {
102 return "little-endian";
103 } elsif ($foo eq "\0\1\0\2") {
104 return "big-endian";
105 } else {
106 die "Your machine has a strange bytesex.\n".
107 "Email your platform info to xing\@pacific.jpl.nasa.gov\n";
108 }
109 }
110
111 #--------------------------------------------------
112 # check bytesex of a fortran unformatted data file
113 # current machine's bytesex is used as a reference.
114 # returns: one of "little-endian", "big-endian", "undecidable" and "unknown"
115 #--------------------------------------------------
116 sub file_bytesex {
117
118 # only if this platform's bytesex is either big- or little-endian
119 # otherwise dies. Hope this won't happen.
120 local($mach_bytesex) = &mach_bytesex();
121
122 local ($file) = shift;
123 local (*FILE);
124
125 open(FILE,$file) || die "$file: $!\n";
126
127 local(@fstat) = stat(FILE);
128 local ($size) = $fstat[7] - 8; # total data size in bytes
129
130 local($hdr,$tmr) = ("","");
131 read(FILE,$hdr,4);
132 seek(FILE,-4,2);
133 read(FILE,$tmr,4);
134 close(FILE);
135
136 # this part checks for self-consistency of Fortran unformatted file
137 ($hdr eq $tmr) || die "$file: not a Fortran unformatted data file.\n";
138
139 local ($ori) = unpack("I",$hdr);
140 local ($rev) = unpack("I",join("",reverse(split(//,$hdr))));
141
142 ($ori != $size && $rev != $size) &&
143 return "unknown";
144
145 ($ori == $size && $rev == $size) &&
146 return "undecidable";
147
148 local ($opposite) = ($mach_bytesex eq "little-endian") ?
149 "big-endian" : "little-endian";
150
151 return ($ori == $size) ? $mach_bytesex : $opposite;
152
153 }
154
155 #--------------------------------
156 # check meta info for one dataset
157 #--------------------------------
158
159 sub check_meta {
160
161 local ($ds,$dir) = @_;
162 local ($fmeta) = "$dir/$ds.meta";
163
164 #~~~~~~~~~~~~~~~~
165 # check meta info
166 #~~~~~~~~~~~~~~~~
167
168 undef $/; # read to the end of file
169 open(MFILE,"<$fmeta") || die "$fmeta: $!\n";
170 $_=<MFILE>;
171 close(MFILE);
172 $/ = "\n"; # never mess up
173
174 s/\([^)]*\)//g; #rm (.*)
175 s/\/\/[^\n]*\n//g; #rm comment lines
176 s/\/\*.*\*\///g; #rm inline comments
177 s/\s+//g; #rm white spaces
178 /id=\[(.+)\];nDims=\[(.+)\];dimList=\[(.+)\];format=\['(.+)'\];/
179 || die "$fmeta: meta file format error\n";
180 local ($id_,$nDims_,$dimList_,$format_) = ($1,$2,$3,$4);
181
182 # check Identifier
183 (defined $id) || ($id = $id_);
184 ($id eq $id_) ||
185 die "$fmeta: id $id_ inconsistent with other dataset\n";
186
187 # check Number of dimensions
188 (defined $nDims) || ($nDims = $nDims_);
189 ($nDims eq $nDims_) ||
190 die "$fmeta: nDims $nDims_ inconsistent with other dataset\n";
191
192 # check Field format
193 (defined $format) || ($format = $format_);
194 ($format eq $format_) ||
195 die "$fmeta: format $format_ inconsistent with other dataset\n";
196
197 # check dimList
198 # calc dimesions and leading index of this subset
199 local (@dimList_) = split(/,/,$dimList_);
200
201 ($nDims_*3 == $#dimList_+1) ||
202 die "$fmeta: nDims and dimList conflicting\n";
203
204 local (@Dim,@dim,@Index0) = ();
205 for (local($i)=0;$i<$nDims_;$i++) {
206 push(@Dim,$dimList_[$i*3]);
207 push(@dim,$dimList_[$i*3+2]-$dimList_[$i*3+1]+1);
208 push(@Index0,$dimList_[$i*3+1]-1);
209 }
210 local ($Dim_) = join(",",@Dim);
211 local ($dim_) = join(",",@dim);
212
213 (defined $Dim) || ($Dim = $Dim_);
214 ($Dim eq $Dim_) ||
215 die "$fmeta: dimList Global inconsistent with other dataset\n";
216
217 (defined $dim) || ($dim = $dim_);
218 ($dim eq $dim_) ||
219 die "$fmeta: dimList Local inconsistent with other dataset\n";
220
221 $ds_Index0{$ds} = join(",", @Index0);
222
223 # print STDOUT "Okay $fmeta\n";
224 }
225
226 #-------------------------------
227 # check completeness of datasets
228 # need to be more sophisticated
229 #-------------------------------
230 sub check_entirety {
231
232 local (*Dim,*dim,*ds_Index0) = @_;
233
234 local ($N) = &listprod(@Dim);
235 local ($n) = &listprod(@dim);
236 ($N) || return 0; # against null dimension
237 ($n) || return 0; # against null dimension
238 ($N%$n) && return 0; # $N/$n must be a whole number
239
240 local (@ds) = keys %ds_Index0;
241 ($#ds+1 == $N/$n) || return 0; # Num of datasets must match subdomain
242
243 1;
244 }
245
246 #------------------
247 # merge one dataset
248 # assume @Dim, @dim and $bytes existing
249 # assume $Byte_Reorder existing
250 #------------------
251 sub merge_data {
252
253 local ($ds,$dir,*Index0) = @_;
254 local ($fdata) = "$dir/$ds.data";
255
256 # data size of one subset in bytes as told by meta info
257 local ($size) = &listprod(@dim) * $bytes;
258
259 open(DFILE, "<$fdata") || die "$fdata: $!\n";
260
261 local ($raw) = "";
262 sysread(DFILE,$raw,4);
263 # Swap header if bytesex is diff from machine's
264 local ($hdr);
265 if ($Byte_Reorder) {
266 $hdr = unpack("I",join("",reverse(split(//,$raw))));
267 } else {
268 $hdr = unpack("I",$raw);
269 }
270
271 ($size == $hdr) ||
272 die "$fdata: $hdr bytes inconsistent with meta info\n";
273
274 print STDOUT "$ds.data: $size bytes, okay, ";
275
276 # seek(DFILE,4,0); # rewind back to the beginning of data
277
278 local ($data) = ""; # old perl (< 4.0) needs this to
279 sysread(DFILE,$data,$size); # avoid warning by sysread()
280 local ($len_chunk) = $dim[0] * $bytes;
281 local ($num_chunk) = $size/$len_chunk;
282
283 local ($pos,@index,$Pos,@Index);
284 for (local($i)=0;$i<$num_chunk;$i++) {
285 $pos = $i * $dim[0];
286 @index = &pos2index($pos,@dim);
287 @Index = &lists_add(*index,*Index0);
288 $Pos = &index2pos(*Index,*Dim);
289 seek(FILE,$Pos*$bytes+4,0);
290 syswrite(FILE,$data,$len_chunk,$pos*$bytes);
291 }
292
293 close(DFILE);
294
295 print STDOUT "merged from $dir\n";
296 }
297
298 #============
299 # main script
300 #============
301
302 #------------
303 # parse @ARGV
304 #............
305
306 ($#ARGV >= 1) || &usage();
307
308 undef @dirs;
309 while (1) {
310 $x = shift(@ARGV);
311 unless ($x =~ /^-D(.+)$/) {
312 unshift(@ARGV,$x);
313 last;
314 }
315 push(@dirs,$1);
316 }
317 (@dirs) || push(@dirs,".");
318 # @dirs is not empty after this line.
319 #print STDOUT join(" ",@dirs), "\n";
320
321 ($#ARGV >= 1) || &usage();
322
323 # data set prefix and suffix
324 $pref = shift(@ARGV);
325 $suff = shift(@ARGV);
326
327 ($#ARGV >= 1) && &usage();
328 undef $forced_bytesex;
329 if (@ARGV) {
330 $forced_bytesex = shift(@ARGV);
331 $forced_bytesex =~ /^(little|big)-endian$/ || &usage();
332 }
333 #print STDOUT $forced_bytesex, "\n";
334
335 #--------------------------
336 # obtain a list of datasets
337 #..........................
338
339 # %ds_dir is a hash to store the directory that a dataset is in.
340 # After this step, it is assured that, for a dataset $ds,
341 # both $ds.meta and $ds.data exist in a unique dir $ds_dir{$ds}.
342
343 %ds_dir = ();
344 foreach $dir (@dirs) {
345 opendir(DIR, $dir) || die "$dir: $!\n";
346 @fmeta = grep(/^$pref\.$suff\.p\d+\.t\d+\.meta$/, readdir(DIR));
347 closedir(DIR);
348 foreach $fmeta (@fmeta) {
349 $ds = $fmeta; $ds =~ s/\.meta$//g;
350 (defined $ds_dir{$ds}) &&
351 die "$fmeta appears in two dirs: $ds_dir{$ds} & $dir\n";
352 (-f "$dir/$ds.data") || die "In $dir, $ds.data missing\n";
353 $ds_dir{$ds} = $dir;
354 }
355 }
356
357 @ds = sort(keys %ds_dir); # list of datasets
358 (@ds) || die "No dataset found.\n";
359 print STDOUT "There are ", $#ds+1, " datasets.\n";
360
361 #---------------------------------
362 # check meta info for all datasets
363 #.................................
364
365 undef $id;
366 undef $nDims;
367 undef $format;
368
369 undef $Dim;
370 undef $dim;
371 undef %ds_Index0;
372
373 #..............................................
374 # check each meta file and set some global vars
375
376 foreach $ds (@ds) {
377 &check_meta($ds,$ds_dir{$ds});
378 }
379 print STDOUT "All existing meta files are self- and mutually consistent.\n";
380
381 #print join(" ",$id,$nDims,$format,$Dim,$dim), "\n";
382 #foreach $ds (@ds) {
383 # $dir = $ds_dir{$ds};
384 # $Index0 = $ds_Index0{$ds};
385 # print "$ds\n";
386 # print "$Index0\n";
387 #}
388
389 @Dim = split(/,/,$Dim);
390 @dim = split(/,/,$dim);
391
392 #................................
393 # check meta info in its entirety
394
395 &check_entirety(*Dim,*dim,*ds_Index0) ||
396 die "Datasets are not complete!\n";
397
398 print STDOUT "Datasets are complete.\n";
399
400 #...........
401 # set $bytes
402
403 if ($format eq "float32") {
404 $bytes = 4;
405 } elsif ($format eq "float64") {
406 $bytes = 8
407 } else {
408 die "format '$format' unknown\n";
409 }
410
411 #---------------------------
412 # check and merge data files
413 #...........................
414
415 #........................
416 # check machine's bytesex
417 # it dies if neither little- nor big-endian.
418
419 $Mach_Bytesex = &mach_bytesex();
420 print STDOUT "Current machine's endianness: $Mach_Bytesex\n";
421
422 #...................
423 # check file bytesex and resolve realted issues
424 undef $File_Bytesex;
425 foreach $ds (@ds) {
426 $fdata = "$ds.data";
427 $file_bytesex = &file_bytesex($ds_dir{$ds}."/$fdata");
428 ($file_bytesex eq "unknown") &&
429 die "$fdata: endianness is neither little- nor big-endian.\n";
430 print STDOUT "$fdata: $file_bytesex\n";
431 unless ($File_Bytesex) {
432 $File_Bytesex = $file_bytesex;
433 } else {
434 ($File_Bytesex eq $file_bytesex) ||
435 die "Data files are mutually inconsistent in endianness\n";
436 }
437 }
438
439 #------------------
440 # set $Byte_Reorder, which controls swapping of bytes in
441 # header and terminator of Fortran unformatted data files.
442 $Byte_Reorder = 1;
443
444 # if machine and data file have the same bytesex, no need for swapping
445 ($File_Bytesex eq $Mach_Bytesex) && ($Byte_Reorder = 0);
446
447 # if we can't determine bytesex of data file, need forced one from @ARGV.
448 if ($File_Bytesex eq "undecidable") {
449 # if no forced bytesex available, dies.
450 ($forced_bytesex) ||
451 die "Endianness of data files is undecidable, " .
452 "you have to give one at command line.\n";
453 ($forced_bytesex eq $Mach_Bytesex) && ($Byte_Reorder = 0);
454 print STDOUT "Endianness of data files is undecidable.\n";
455 print STDOUT "Data file header/tail will be treated as ";
456 print STDOUT "$forced_bytesex as you have instructed.\n";
457 # otherwise
458 } else {
459 # give a warining, if swapping is needed.
460 ($Byte_Reorder) &&
461 print STDOUT
462 "Please note: data files have different bytesex than machine!\n";
463 }
464
465 #................
466 # merge data sets
467
468 $Size = &listprod(@Dim) * $bytes;
469
470 $fout = "$pref.$suff.data";
471
472 open(FILE, ">$fout") || die "$fout: $!\n";
473
474 # prepare header and teminator. Do byte reordering if necessary
475 $HdrTmr = pack("I",$Size);
476 ($Byte_Reorder) && ($HdrTmr = join("",reverse(split(//,$HdrTmr))));
477
478 # write 4 byte header
479 syswrite(FILE,$HdrTmr,4);
480
481 # merge each dataset
482 foreach $ds (@ds) {
483 $dir = $ds_dir{$ds};
484 @Index0 = split(/,/,$ds_Index0{$ds});
485 &merge_data($ds,$dir,*Index0);
486 }
487
488 # write 4 byte terminator
489 seek(FILE,$Size+4,0);
490 syswrite(FILE,$HdrTmr,4);
491
492 close(FILE);
493
494 print STDOUT "Global data (" .
495 join("x",@Dim) .
496 ") is in ./$fout (endianness is $File_Bytesex).\n";
497
498 exit 0;

  ViewVC Help
Powered by ViewVC 1.1.22