-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathliblats.c
1618 lines (1196 loc) · 46.3 KB
/
liblats.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This GrADS extension has been placed in the public domain. See individual
C source files for PCMDI licensing terms.
---
About POD Documentation
The following documentation uses the "Perl On-line Documentation"
(POD) mark up syntax. It is a simple and yet adequate mark up language
for creating basic man pages, and there are converters to html,
MediaWiki, etc. In adittion, the perldoc utility can be used to
display this documentation on the screen by entering:
% perldoc lats
Or else, run this file through cpp to extract the POD fragments:
% cpp -DPOD -P < lats.c > lats.pod
and place lats.pod in a place perldoc can find it, like somewhere in your path.
To generate HTML documentation:
% pod2html --header < lats.pod > lats.html
To generate MediaWiki documentation:
% pod2wiki --style mediawiki < lats.pod > lats.wiki
If you have "pod2html" and "pod2wini" installed (if not, get them from
CPAN), there are targets in the gex.mk fragment for these:
% make lats.html
% make lats.wiki
*/
#ifndef POD
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "grads.h"
#include "gex.h"
#include "galats.h"
#include "lats.h"
#ifdef GOT_NETCDF
# include "netcdf.h"
#endif
static char pout[256]; /* Build error msgs here */
static int Initialized = 0;
struct galats glats ; /* LATS option struct */
int galats (struct gacmn *, int, int); /*mf --- GrADS-lats interface mf*/
/* ..................................................................... */
static void init_() {
strcpy(glats.ptname,"");
/*
initialize to bad values for force failure on create
that is, require specification of frequency
*/
glats.convention=LATS_GRADS_GRIB;
glats.calendar=LATS_STANDARD;
glats.frequency=-1;
glats.deltat=0;
glats.gzip = -1;
glats.shave = -1;
strcpy(glats.model,"Unknown1 LATS model");
strcpy(glats.center,"PCMDI");
strcpy(glats.comment,"Written using the GrADS-LATS interface");
strcpy(glats.oname,"grads.lats");
glats.gridtype=LATS_LINEAR;
strcpy(glats.gridname,"grid1");
strcpy(glats.vertdimname,"plev");
strcpy(glats.var,"unknown1");
glats.timestat=LATS_INSTANT;
strcpy(glats.var_comment,"Unknown1 variable comment");
glats.varlev=-1e20;
glats.lyr=-1;
glats.lmo=-1;
glats.lda=-1;
glats.lhr=-1;
glats.lmn=-1;
glats.fhour=-1;
glats.fmin=-1;
glats.time_opt=1;
glats.id_file=-1;
glats.id_lev=0;
glats.nlev=-1;
glats.id_grid=-1;
glats.id_var=-1;
Initialized = 1;
}
static int do_lats ( int argc, char **argv, struct gacmn *pcm, int opt) {
char *name = argv[0];
int i, rc;
struct gastat *pst;
struct gagrid *pgr;
rc = 0;
if (argc<2) {
sprintf(pout,"\nError from %s: missing expression\n", name);
gaprnt(0,pout);
return(1);
}
/* Evaluate expression */
pst = getpst(pcm);
if (pst==NULL) return(1);
/* Note: gapars() no longer work from extensions since 2.0.a9 */
rc = gaexpr(argv[1],pst);
if (rc) goto retrn;
pcm->type[0] = pst->type;
pcm->result[0] = pst->result;
pcm->numgrd = 1;
pcm->relnum = 1;
/* Make sure UNDEFs are set as in v1 */
pgr = pcm->result[0].pgr;
for (i=0; i<(pgr->isiz*pgr->jsiz); i++ )
if ( ! pgr->umask[i] ) pgr->grid[i] = pgr->undef;
/* Do the LATS thing */
rc=galats(pcm,opt,0);
retrn:
gafree(pst);
return(rc);
}
/* ..................................................................... */
int c_lats_reinit ( int argc, char **argv, struct gacmn *pcm) {
init_();
return 0;
}
int c_lats_grid ( int argc, char **argv, struct gacmn *pcm) {
if ( ! Initialized ) init_();
return do_lats(argc,argv,pcm,3);
}
int c_lats_data ( int argc, char **argv, struct gacmn *pcm) {
if ( ! Initialized ) init_();
return do_lats(argc,argv,pcm,5);
}
int c_lats_set ( int argc, char **argv, struct gacmn *pcm) {
int i, rc, kwrd = 98;
gadouble v1, v2;
rc = 0;
if ( ! Initialized ) init_();
if ( argc<2 ) {
gaprnt (0,"SET_LATS error: No arguments....\n");
gaprnt (0," valid arguments are: \n");
gaprnt (0," parmtab [FILENAME] (e.g., set_lats parmtab lats.ncep.MRFtable)\n");
gaprnt (0," convention [grads_grib|grib_only|coards] (e.g., set_lats convention grib)\n");
gaprnt (0," gzip level (e.g., set_lats gzip 2)\n");
gaprnt (0," shave nbits (e.g., set_lats shave 12)\n");
gaprnt (0," calendar [standard|noleap|clim|climleap] (e.g., set_lats calendar standard)\n");
gaprnt (0," frequency [yearly|monthly|monthly_table_comp|weekly|daily|hourly|minutes|forecast_hourly|forecast_minutes|fixed] (e.g., set_lats frequency hourly)\n");
gaprnt (0," deltat [N] (integer number of freq units per time output, e.g., set_lats deltat 6)\n");
gaprnt (0," fhour [N] (integer forecast hour, e.g., set_lats fhour 120)\n");
gaprnt (0," model [MODEL_NAME] (e.g., set_lats model MRF)\n");
gaprnt (0," center [CENTER_NAME] (e.g., set_lats center NCEP)\n");
gaprnt (0," create [FILENAME] (e.g., set_lats create MRF.EXP1)\n");
gaprnt (0," comment [COMMENT (e.g., set_lats comment \"R1.6.1 of MRF with convection update\")\n");
gaprnt (0," gridtype [linear|gaussian|generic] (e.g., set_lats gridtype gaussian\n");
gaprnt (0," vertdim [DIMNAME LEV_TYPE lev_1 ... lev_N] (e.g., set_lats vertdim plev 1000 850 500 200)\n");
gaprnt (0," var [VARNAME average|accum|instant LEVEL_ID)] (e.g., set_lats var u instant 1)\n");
gaprnt (0," timeoption [grid|dim_env|settime (e.g., set_lats v timeoption dim_env (use the GrADS dimension environment)\n");
gaprnt (0," write [VAR_ID LEVEL] (e.g., set_lats write 1 500 (return from t lats var)\n");
gaprnt (0," close (e.g., set_lats close)\n\n");
return(1);
}
/*-------------------
lats_parmtab interface
-------------------*/
if(cmpwrd("parmtab",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS PARMTAB error: No arguments....\n");
return(1);
} else strcpy(glats.ptname,argv[2]);
rc=galats(pcm,0,0);
sprintf(pout,"LATS PARMTAB ID = %d\n",rc);
gaprnt(2,pout);
}
/*----------
lats_create interface
---------*/
else if (cmpwrd("convention",argv[1])||cmpwrd("format",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS CONVENTION error: No arguments....\n");
return(1);
} else if( cmpwrd("grads_grib",argv[2]) ) glats.convention=LATS_GRADS_GRIB;
else if( cmpwrd("coards",argv[2]) ) glats.convention=LATS_NC3;
else if( cmpwrd("netcdf",argv[2]) ) glats.convention=LATS_NC3;
else if( cmpwrd("nc3",argv[2]) ) glats.convention=LATS_NC3;
else if( cmpwrd("nc4",argv[2]) ) glats.convention=LATS_NC4;
else if( cmpwrd("netcdf4",argv[2]) ) glats.convention=LATS_NC4;
else if( cmpwrd("hdf",argv[2]) ) glats.convention=LATS_HDF4;
else if( cmpwrd("hdf4",argv[2]) ) glats.convention=LATS_HDF4;
else if( cmpwrd("grib_only",argv[2]) ) glats.convention=LATS_GRIB_ONLY;
else {
gaprnt (0,"SET_LATS CONVENTION error: invalid argument using the default...\n");
return(1);
}
}
else if (cmpwrd("gzip",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS GZIP error: No arguments....\n");
return(1);
}
#ifndef NC_NETCDF4
gaprnt (0,"SET_LATS GZIP warning: ignored since NetCDF-4 is not present\n");
return(0);
#else
if ( intprs(argv[2],&(i)) == NULL ) {
gaprnt (0,"SET_LATS GZIP error: invalid or missing gzip level\n");
return(1);
} else if (i<1||i>9) {
gaprnt (0,"SET_LATS GZIP error: level must be between 1 and 9.\n");
return(1);
} else {
glats.gzip=i;
}
#endif
}
else if (cmpwrd("shave",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS SHAVE error: No arguments....\n");
return(1);
}
#ifndef NC_NETCDF4
gaprnt (0,"SET_LATS SHAVE warning: ignored since NetCDF-4 is not present\n");
return(0);
#else
if ( intprs(argv[2],&(i)) == NULL ) {
gaprnt (0,"SET_LATS SHAVE error: invalid or missing number of bits to shave level\n");
return(1);
} else if (i>23) {
gaprnt (0,"SET_LATS SHAVE error: nbits must be at most 23.\n");
return(1);
} else {
glats.shave=i;
if ( glats.gzip < 0 ) glats.gzip = 2; /* no point in shaving without compression */
}
#endif
}
else if (cmpwrd("calendar",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS CALENDAR error: No arguments....\n");
return(1);
}
else if( cmpwrd("standard",argv[2]) ) glats.calendar=LATS_STANDARD;
else if( cmpwrd("noleap",argv[2]) ) glats.calendar=LATS_NOLEAP;
else if( cmpwrd("clim",argv[2]) ) glats.calendar=LATS_CLIM;
else if( cmpwrd("climleap",argv[2]) ) glats.calendar=LATS_CLIMLEAP;
else {
gaprnt (0,"SET_LATS CALENDAR error: Invalid argument using the default...\n");
return(1);
}
}
else if(cmpwrd("frequency",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS FREQUENCY error: No arguments....\n");
return(1);
} else if( cmpwrd("yearly",argv[2]) ) glats.frequency=LATS_YEARLY;
else if( cmpwrd("monthly",argv[2]) ) glats.frequency=LATS_MONTHLY;
else if( cmpwrd("monthly_table_comp",argv[2]) ) glats.frequency=LATS_MONTHLY_TABLE_COMP;
else if( cmpwrd("weekly",argv[2]) ) glats.frequency=LATS_WEEKLY;
else if( cmpwrd("daily",argv[2]) ) glats.frequency=LATS_DAILY;
else if( cmpwrd("hourly",argv[2]) ) glats.frequency=LATS_HOURLY;
else if( cmpwrd("minutes",argv[2]) ) glats.frequency=LATS_MINUTES;
else if( cmpwrd("forecast_hourly",argv[2]) ) {
glats.frequency=LATS_FORECAST_HOURLY;
glats.time_opt=3;
}
else if( cmpwrd("forecast_minutes",argv[2]) ) {
glats.frequency=LATS_FORECAST_MINUTES; /*ams Mike: check this! ams*/
glats.time_opt=3;
}
else if( cmpwrd("fixed",argv[2]) ) glats.frequency=LATS_FIXED;
else {
gaprnt (0,"SET_LATS FREQUENCY error: Invalid arguments LATS_CREATE WILL FAIL....\n");
return(1);
}
}
else if(cmpwrd("deltat",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS DELTAT error: No arguments....\n");
return(1);
}
if ( intprs(argv[2],&(i)) == NULL ) {
gaprnt (0,"SET_LATS DELTAT error: invalid or missing increment\n");
return(1);
} else if (i<0) {
gaprnt (0,"SET_LATS DELTAT error: < 0 LATS_CREATE WILL FAIL...\n");
return(1);
} else {
glats.deltat=i;
}
}
else if(cmpwrd("fhour",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS FHOUR error: No arguments....\n");
return(1);
}
if ( intprs(argv[2],&(i)) == NULL ) {
gaprnt (0,"SET_LATS FHOUR error: invalid or missing increment\n");
return(1);
} else if (i<0) {
gaprnt (0,"SET_LATS FHOUR error: < 0 LATS WILL FAIL...\n");
return(1);
} else {
glats.fmin=0; /* mf set default fmin to 0 if hourly */
glats.fhour=i;
}
}
else if(cmpwrd("fminute",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS FMINUTE error: No arguments....\n");
return(1);
}
if ( intprs(argv[2],&(i)) == NULL ) {
gaprnt (0,"SET_LATS FMINUTE error: invalid or missing increment\n");
return(1);
} else if (i<0) {
gaprnt (0,"SET_LATS FMINUTE error: < 0 LATS WILL FAIL...\n");
return(1);
} else {
glats.fmin=i;
glats.fhour=0; /* mf set default fhour to 0 if minutes */
}
}
else if(cmpwrd("basetime",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS BASETIME error: No arguments....\n");
return(1);
}
if ( intprs(argv[2],&(i)) == NULL ) {
gaprnt (0,"SET_LATS BASETIME ID_FILE error: missing\n");
return(1);
} else if (i<0) {
gaprnt (0,"SET_LATS BASETIME ID_FILE error: id_file < 0\n");
return(1);
} else {
if(i >= 0 && i <= glats.id_file) {
glats.id_user_file=i;
} else {
sprintf(pout,"SET_LATS BASETIME error: FILE ID is %d but the max FILE ID is %d\n",
i,glats.id_file);
gaprnt(0,pout);
return(1);
}
}
if ( argc < 4 ) {
gaprnt (0,"SET_LATS BASETIME YEAR error: missing\n");
return(1);
}
if ( intprs(argv[3],&(i)) == NULL ) {
gaprnt (0,"SET_LATS BASETIME YEAR error: invalid or missing\n");
return(1);
} else if (i<0) {
gaprnt (0,"SET_LATS BASETIME YEAR error: year < 0\n");
return(1);
} else {
glats.lyr=i;
}
if ( argc < 5 ) {
gaprnt (0,"SET_LATS BASETIME MONTH error: missing\n");
return(1);
}
if ( intprs(argv[4],&(i)) == NULL ) {
gaprnt (0,"SET_LATS BASETIME MONTH error: invalid or missing\n");
return(1);
} else if (i<0) {
gaprnt (0,"SET_LATS BASETIME MONTH error: year < 0\n");
return(1);
} else {
glats.lmo=i;
}
if ( argc < 6 ) {
gaprnt (0,"SET_LATS BASETIME DAY error: missing\n");
return(1);
}
if ( intprs(argv[5],&(i)) == NULL ) {
gaprnt (0,"SET_LATS BASETIME DAY error: invalid or missing\n");
return(1);
} else if (i<0) {
gaprnt (0,"SET_LATS BASETIME DAY error: year < 0\n");
return(1);
} else {
glats.lda=i;
}
if ( argc < 7 ) {
gaprnt (0,"SET_LATS BASETIME HOUR error: missing\n");
return(1);
}
if ( intprs(argv[6],&(i)) == NULL ) {
gaprnt (0,"SET_LATS BASETIME HOUR error: invalid or missing\n");
return(1);
} else if (i<0) {
gaprnt (0,"SET_LATS BASETIME HOUR error: year < 0\n");
return(1);
} else {
glats.lhr=i;
}
if ( argc < 9 ) {
gaprnt (0,"SET_LATS BASETIME MIN error: missing\n");
return(1);
}
if ( intprs(argv[7],&(i)) == NULL ) {
gaprnt (0,"SET_LATS BASETIME MIN error: invalid or missing\n");
return(1);
} else if (i<0) {
gaprnt (0,"SET_LATS BASETIME MIN error: year < 0\n");
return(1);
} else {
glats.lmn=i;
}
rc=galats(pcm,10,0); /* set the basetime */
}
else if(cmpwrd("model",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS MODEL error: No arguments....\n");
return(1);
} else strcpy(glats.model,argv[2]);
}
else if(cmpwrd("center",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS CENTER error: No arguments....\n");
return(1);
} else strcpy(glats.center,argv[2]);
}
else if(cmpwrd("comment",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS COMMENT error: No arguments....\n");
return(1);
} else strcpy(glats.comment,argv[2]);
}
else if(cmpwrd("varcomment",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS VARCOMMENT error: No arguments....\n");
return(1);
} else strcpy(glats.var_comment,argv[2]);
}
else if(cmpwrd("create",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS CREATE error: Missing or invalid arguments");
return (1);
} else strcpy(glats.oname,argv[2]);
rc=galats(pcm,1,0); /* open the lats file */
sprintf(pout,"LATS FILE ID = %d\n",rc);
gaprnt(2,pout);
}
/*-----------------
lats_grid interface
-----------------*/
else if (cmpwrd("gridtype",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS GRIDTYPE error: No arguments....\n");
return(1);
} else if( cmpwrd("linear",argv[2]) ) glats.gridtype=LATS_LINEAR;
else if( cmpwrd("gaussian",argv[2]) ) glats.gridtype=LATS_GAUSSIAN;
else if( cmpwrd("generic",argv[2]) ) glats.gridtype=LATS_GENERIC;
else {
gaprnt (0,"SET error: Missing or invalid arguments for GRIDTYPE ");
return (1);
}
}
else if(cmpwrd("gridname",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS GRIDNAME error: No arguments....\n");
return(1);
} else strcpy(glats.gridname,argv[2]);
}
/*------------
lats_vertdim interface
-------------*/
else if(cmpwrd("vertdim",argv[1])) {
glats.nlev=0;
if ( argc < 3 ) {
gaprnt (0,"SET_LATS VERTDIM error: No arguments....\n");
return(1);
} else {
strcpy(glats.vertdimname,argv[2]);
}
if ( argc < 4 ) {
gaprnt (0,"SET_LATS VERTDIM error: no levels given....\n");
return(1);
}
for ( i=3; i<argc; i++ ) {
getdbl(argv[i],&(v1));
glats.levels[glats.nlev]=(double)v1;
glats.nlev++;
}
rc=galats(pcm,2,0); /* set the vertical dimension */
sprintf(pout,"LATS VERTDIM ID = %d\n",rc);
if(rc==0) gaprnt(0,pout);
else gaprnt(2,pout);
}
/*------
lats_var interface
------*/
else if(cmpwrd("var",argv[1])) {
if ( argc < 3 ) {
sprintf(pout,"LATS VAR ID = -1\n");
gaprnt(2,pout);
gaprnt (0,"SET_LATS VAR error: No arguments! args: fileid varname datatype gridid levid\n");
return(1);
}
/* --- file id */
if ( intprs(argv[2],&(i))==NULL) {
sprintf(pout,"LATS VAR ID = -1\n");
gaprnt(2,pout);
gaprnt (0,"SET_LATS VAR FILE ID: invalid FILE ID value given\n");
return(1);
}
if(i >= 0 && i <= glats.id_file) {
glats.id_user_file=i;
} else {
sprintf(pout,"LATS VAR ID = -1\n");
gaprnt(2,pout);
sprintf(pout,
"SET_LATS VAR error: FILE ID is %d but the max FILE ID is %d\n",
i,glats.id_file);
gaprnt(0,pout);
return(1);
}
/* --- var name */
if ( argc < 4 ) {
gaprnt (0,"SET_LATS VAR error: variable name not given...\n");
return(1);
} else { strcpy(glats.var,argv[3]); }
/* --- stat type */
if ( argc < 5 ) {
if( cmpwrd("average",argv[4]) ) glats.timestat=LATS_AVERAGE;
else if( cmpwrd("accum",argv[4]) ) glats.timestat=LATS_ACCUM;
else if( cmpwrd("instant",argv[4]) ) glats.timestat=LATS_INSTANT;
else {
gaprnt (0,"SET_LATS VAR error: invalid variable statistic type given...\n");
return(1);
}
}
/* --- level grid id */
if ( argc < 6 ) {
sprintf(pout,"LATS VAR ID = -1\n");
gaprnt(2,pout);
gaprnt (0,"SET_LATS VAR error: missing GRID ID\n");
return(1);
}
if ( intprs(argv[5],&(i)) == NULL ) {
sprintf(pout,"LATS VAR ID = -1\n");
gaprnt(2,pout);
gaprnt (0,"SET_LATS VAR error: invalid GRID ID value given\n");
return(1);
} else if(i >= 0 && i <= glats.id_grid) {
glats.id_user_grid=i;
} else {
sprintf(pout,"LATS VAR ID = -1\n");
gaprnt(2,pout);
sprintf(pout,
"SET_LATS VAR error: GRID ID is %d but the max GRID ID is %d\n",
i,glats.id_user_grid);
gaprnt(0,pout);
return(1);
}
/* --- level id */
if ( argc < 7 ) {
sprintf(pout,"LATS VAR ID = -1\n");
gaprnt(2,pout);
gaprnt (0,"SET_LATS VAR error: missing LEVEL ID\n");
gaprnt (0," use a value of 0 for surface variables\n");
return(1);
}
if ( intprs(argv[6],&(i)) == NULL ) {
sprintf(pout,"LATS VAR ID = -1\n");
gaprnt(2,pout);
gaprnt (0,"SET_LATS VAR error: invalid LEVEL ID value given\n");
gaprnt (0," use a value of 0 for surface variable\n");
return(1);
} else if(i >= 0 && i <= glats.id_lev) {
glats.id_user_lev=i;
} else {
sprintf(pout,"LATS VAR ID = -1\n");
gaprnt(2,pout);
sprintf(pout,
"SET_LATS VAR error: LEVEL ID is %d but the max LEVEL ID is %d\n",
i,glats.id_user_lev);
gaprnt(0,pout);
gaprnt(0," use a value of 0 for surface variables...\n");
return(1);
}
/* --- call lats_var */
rc=galats(pcm,4,0);
sprintf(pout,"LATS VAR ID = %d\n",rc);
gaprnt(2,pout);
}
/*-------------------
lats_write interface
-------------------*/
else if(cmpwrd("write",argv[1])) {
glats.id_user_write=0;
/* --- file id */
if ( argc < 3 ) {
gaprnt (0,"SET_LATS WRITE error: No arguments (fileid varid)\n");
return(1);
}
if ( intprs(argv[2],&(i)) == NULL ) {
gaprnt (0,"SET_LATS WRITE error: missing or invalid FILE ID given...\n");
return(1);
} else {
glats.id_user_file=i;
if(glats.id_user_file<0 || (glats.id_user_file > glats.id_file) ) {
sprintf(pout,
"SET_LATS WRITE error: FILE ID is outside the valid range of 1 - %d\n",
glats.id_file);
gaprnt (0,pout);
return(1);
}
}
/* --- var id */
if ( argc < 4 ) {
gaprnt (0,"SET_LATS WRITE error: No arguments...\n");
return(1);
}
if ( intprs(argv[3],&(i)) == NULL ) {
gaprnt (0,"SET_LATS WRITE error: missing or invalid VAR ID given...\n");
return(1);
} else {
glats.id_user_var=i;
if(glats.id_user_var<0 || (glats.id_user_var > glats.id_var) ) {
sprintf(pout,
"SET_LATS WRITE error: VAR ID is outside the valid range of 1 - %d\n",
glats.id_var);
gaprnt (0,pout);
return(1);
}
}
if ( argc >= 5 ) {
getdbl(argv[4],&(v1)) ;
glats.varlev=(double)v1;
} else {
glats.varlev=0.0;
}
glats.id_user_write=1;
sprintf(pout,"LATS WRITE ID = %d\n",glats.id_user_write);
gaprnt(2,pout);
}
else if (cmpwrd("timeoption",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS TIMEOPTION error: No arguments....\n");
return(1);
} else if ( cmpwrd("grid",argv[2]) ) glats.time_opt=0;
else if( cmpwrd("dim_env",argv[2]) ) glats.time_opt=1;
else if( cmpwrd("settime",argv[2]) ) glats.time_opt=2;
else {
gaprnt (0,"SET_LATS TIMEOPTION error: invalid option ....\n");
return(1);
}
}
/*-------------------
lats_close interface
-------------------*/
else if(cmpwrd("close",argv[1])) {
if ( argc < 3 ) {
gaprnt (0,"SET_LATS CLOSE error: No arguments, specify a file id...\n");
return(1);
}
if ( intprs(argv[2],&(i)) == NULL ) {
gaprnt (0,"SET_LATS CLOSE error: missing or invalid FILE ID given...\n");
return(1);
} else {
if(i<0 || i>glats.id_file){
sprintf(pout,
"SET_LATS CLOSE error: FILE ID is outside the valid range of 1 - %d\n",
glats.id_file);
gaprnt (0,pout);
return(1);
}
}
rc=galats(pcm,6,i); /* close the lats file */
}
else if(cmpwrd("reset",argv[1])) {
rc=galats(pcm,7,0); /* reset the lats state */
}
else {
gaprnt (0,"SET_LATS error: Missing or invalid arguments:\n ");
sprintf (pout,"for %s option\n",argv[1]);
gaprnt (0,pout);
return (1);
}
/* Consistency checks */
if ( glats.gzip >= 0 && glats.convention==LATS_NC3 ) {
glats.convention = LATS_NC4;
gaprnt(0,"SET_LATS Warning: GZIP compression requires NetCDF-4 --- resetting NetCDF to version 4\n");
}
return(abs(rc));
}
/* .................................................................. */
int c_lats_query ( int argc, char **argv, struct gacmn *pcm) {
int i;
gadouble v1, v2;
if ( ! Initialized ) init_();
/* LATS state */
sprintf(pout,"GrADS-LATS Interface State:\n");
gaprnt (2,pout);
/*=== lats_parmtab ===*/
sprintf(pout,"%s \t:parameter table file (by \"set_lats parmtab \")\n",glats.ptname);
gaprnt (2,pout);
/*=== lats_create ===*/
sprintf(pout,"%d \t: data CONVENTION parameter (by \"set_lats convention\")\n",glats.convention);
gaprnt (2,pout);
sprintf(pout,"%d \t: data CALENDAR parameter (by \"set_lats calendar\")\n",glats.calendar);
gaprnt (2,pout);
sprintf(pout,"%d \t: data time FREQEUENCY parameter (by \"set_lats frequency\")\n",glats.frequency);
gaprnt (2,pout);
sprintf(pout,"%d \t: TIMEOPTION parameter (by \"set_lats timeoption\")\n",glats.time_opt);
gaprnt (2,pout);
sprintf(pout,"%d \t: DELTAT time (# of intervals) (by \"set_lats deltat\")\n",glats.deltat);
gaprnt (2,pout);
sprintf(pout,"%d \t: BASETIME year (# of intervals) (by \"set_lats basetime id_file yr mo da hr\")\n",glats.lyr);
gaprnt (2,pout);
sprintf(pout,"%d \t: BASETIME month (# of intervals) (e.g., \"set_lats basetime 1 1997 5 31 00\")\n",glats.lmo);
gaprnt (2,pout);
sprintf(pout,"%d \t: BASETIME day (# of intervals) (e.g., \"set_lats basetime 1 1997 5 31 00\")\n",glats.lda);
gaprnt (2,pout);
sprintf(pout,"%d \t: BASETIME hour (# of intervals) (e.g., \"set_lats basetime 1 1997 5 31 00\")\n",glats.lhr);
gaprnt (2,pout);
sprintf(pout,"%d \t: BASETIME minute (# of intervals) (e.g., \"set_lats basetime 1 1997 5 31 00 0\")\n",glats.lmn);
gaprnt (2,pout);
sprintf(pout,"%d \t: FHOUR hour (# of intervals) (e.g., \"set_lats fhour 12\")\n",glats.fhour);
gaprnt (2,pout);
sprintf(pout,"%d \t: FMIN hour (# of intervals) (e.g., \"set_lats fmin 12\")\n",glats.fmin);
gaprnt (2,pout);
sprintf(pout,"%s \t: MODEL (by \"set_lats model\")\n",glats.model);
gaprnt (2,pout);
sprintf(pout,"%s \t: data CENTER (by \"set_lats center\")\n",glats.center);
gaprnt (2,pout);
sprintf(pout,"%s \t: COMMENT (by \"set_lats comment\")\n",glats.comment);
gaprnt (2,pout);
sprintf(pout,"%s \t: output file (by \"set_lats open \")\n",glats.oname);
gaprnt (2,pout);
/*=== lats compression ===*/
sprintf(pout,"%d \t: GZIP level (by \"set_lats gzip\")\n",glats.gzip);
gaprnt (2,pout);
sprintf(pout,"%d \t: SHAVE nbits (by \"set_lats shave\")\n",glats.shave);
gaprnt (2,pout);
/*=== lats_grid ===*/
sprintf(pout,"%d \t: GRIDTYPE grid type parameter(by \"set_lats gridtype\")\n",glats.gridtype);
gaprnt (2,pout);
sprintf(pout,"%s \t: GRIDNAME grid type parameter(by \"set_lats gridname\")\n",glats.gridname);
gaprnt (2,pout);
sprintf(pout,"%4d \t: linear in longitude (0=no,1=yes)\n",glats.ilinear);
gaprnt (2,pout);
sprintf(pout,"%4d \t: linear in latitude (0=no,1=yes)\n",glats.jlinear);
gaprnt (2,pout);
sprintf(pout,"%4d \t: # longitude points (nlon) \n",glats.nlon);
gaprnt (2,pout);
sprintf(pout,"%4d \t: # latitude points (nlat) \n",glats.nlat);
gaprnt (2,pout);
sprintf(pout," ( %10.4f , %10.4f ) \t: ( 1, 1) lon lat\n",glats.lon_1,glats.lat_1);
gaprnt (2,pout);
sprintf(pout," ( %10.4f , %10.4f ) \t: (nlat,nlon) lon lat\n",glats.lon_nlon,glats.lat_nlat);
gaprnt (2,pout);
/*=== lats_vertdim ===*/
sprintf(pout,"%s \t: vertical dimension by \"set_lats levels (lev1 ... levN) vertdimname\")\n",glats.vertdimname);
gaprnt (2,pout);
sprintf(pout,"%d \t: # of vertical levels (by \"set_lats levels (lev1 ... levN) vertdimname\")\n",glats.nlev);
gaprnt (2,pout);
for(i=0; i<(glats.nlev) ; i++) {
sprintf(pout," %g",glats.levels[i]);
gaprnt (2,pout);
}
sprintf(pout,"vertical levels\n");
gaprnt (2,pout);
/*=== lats_var ===*/
sprintf(pout,"%s \t: VAR output parameter (by \"set_lats var (name timestat [level])\")\n",glats.var);
gaprnt (2,pout);
sprintf(pout,"%d \t: VAR TIMESTAT time statistic parameter\n",glats.timestat);
gaprnt (2,pout);
/*==== LATS internal id's ===*/
sprintf(pout,"%d \t: id_file LATS internal ID\n",glats.id_file);
gaprnt (2,pout);
sprintf(pout,"%d \t: id_grid LATS internal ID\n",glats.id_grid);
gaprnt (2,pout);
sprintf(pout,"%d \t: id_lev LATS internal ID\n",glats.id_lev);
gaprnt (2,pout);
sprintf(pout,"%d \t: id_var LATS internal ID\n",glats.id_var);
gaprnt (2,pout);
sprintf(pout,"%d \t: id_user_file LATS internal ID\n",glats.id_user_file);
gaprnt (2,pout);
sprintf(pout,"%d \t: id_user_grid LATS internal ID\n",glats.id_user_grid);
gaprnt (2,pout);
sprintf(pout,"%d \t: id_user_var LATS internal ID\n",glats.id_user_var);
gaprnt (2,pout);
sprintf(pout,"%d \t: id_user_lev LATS internal ID\n",glats.id_user_lev);
gaprnt (2,pout);
sprintf(pout,"%d \t: id_user_write LATS internal ID\n",glats.id_user_write);
gaprnt (2,pout);
return(0);
}
/* .................................................................... */
/*
-----------------
POD Documentation
-----------------
*/
#else
=pod
=head1 NAME
liblats.gex - GrADS Extension Library for File Subsetting and Reformatting
=head1 SYNOPSIS
=head3 GrADS Commands:
=over 4
=item
run B<set_lats> I<PARAMETER> I<VALUE> - Set internal parameters
=item