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
|
/**
* Copyright 1981-2007 ECMWF
*
* Licensed under the GNU Lesser General Public License which
* incorporates the terms and conditions of version 3 of the GNU
* General Public License.
* See LICENSE and gpl-3.0.txt for details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fortint.h"
#define LINESIZE 80
#define format 0x666F726D
#define table 0x7461626C
#define parameter 0x70617261
#define truncation 0x7472756E
#define accuracy 0x61636375
#define grid 0x67726964
#define gaussian 0x67617573
#define area 0x61726561
#define scan 0x7363616E
#define reduced 0x72656475
#define uselsm 0x7573656C
#define usewind 0x75736577
#define useprecip 0x75736570
#define lsm_param 0x6C736D5F
/*
// defines for FORTRAN subroutine
*/
#ifndef CRAY
#ifdef FORTRAN_NO_UNDERSCORE
#define CLEAR_C clear_c
#define IAINIT iainit
#define INIT_CM init_cm
#define RDDEFS rddefs
#else
#define CLEAR_C clear_c_
#define IAINIT iainit_
#define INIT_CM init_cm_
#define RDDEFS rddefs_
#endif
#endif
#define NIFORM 1
#define NOFORM 2
#define NITABLE 3
#define NIPARAM 4
#define NIRESO 5
#define NORESO 6
#define NOACC 7
#define NIGRID1 8
#define NIGRID2 9
#define NOGRID1 10
#define NOGRID2 11
#define NIGAUSS 12
#define NOGAUSS 13
#define NIAREA1 14
#define NIAREA2 15
#define NIAREA3 16
#define NIAREA4 17
#define NOAREA1 18
#define NOAREA2 19
#define NOAREA3 20
#define NOAREA4 21
#define NISCNM 22
#define NOSCNM 23
#define LSM 24
#define LWIND 25
#define LPREC 26
#define NIREDU 27
#define NOREDU 28
#define LSMPAR 29
/*
// Prototypes
*/
void set_format(char * inputval, char * outputval);
void set_table(char * inputval, char * outputval);
void set_parameter(char * inputval, char * outputval);
void set_truncation(char * inputval, char * outputval);
void set_accuracy(char * inputval, char * outputval);
void set_grid(char * inputval, char * outputval);
void set_gaussian(char * inputval, char * outputval);
void set_area(char * inputval, char * outputval);
void set_scan(char * inputval, char * outputval);
void set_reduced(char * inputval, char * outputval);
void set_uselsm(char * inputval, char * outputval);
void set_usewind(char * inputval, char * outputval);
void set_useprecip(char * inputval, char * outputval);
void set_lsm_param(char * inputval, char * outputval);
void INIT_CM( fortint *, fortint *);
fortint RDDEFS()
{
/*
// The file handling is currently not used!
//
// char * fallback_defaults_file = "/home/ma/mac/public/gp2gp/request_defaults";
// char * fallback_defaults_file = "/home/ma/mac/public/gp2gp/no_chance";
// char * defaults_file;
*/
FILE * file;
int i_status;
char line[LINESIZE+1];
char keyword[LINESIZE];
char inputval[LINESIZE];
char outputval[LINESIZE];
int count = 0, i;
unsigned long code=0;
int kpr = 0;
int kerr = 1;
/*
// Clear the common block
*/
CLEAR_C();
IAINIT( &kpr, kerr);
/*
// The file handling is currently not used!
//
// Open the file defining the defaults
//
// defaults_file = getenv("REQUEST_DEFAULTS");
// if( defaults_file == NULL )
// defaults_file = fallback_defaults_file;
//
// file = fopen( defaults_file, "r");
//
//
// If no file, set the defaults here
*/
file = NULL; /* file handling currently not used! */
if( file == NULL ) {
set_format("grib","grib");
set_table("128","");
set_parameter("0","");
set_area("0/0/0/0","0/0/0/0");
set_scan("0","0");
return 0;
}
/*
// Ignore the 2 title lines, then a line at a time from the file
*/
while( fgets( line, LINESIZE, file) != NULL ) {
count++;
if ( count > 2 ) {
/*
// Split the line up
*/
i_status = sscanf( line, "%s%s%s", keyword, inputval, outputval);
if ( (i_status != 3) && (i_status != EOF ) ) {
perror("sscanf failed");
exit(1);
}
/*
// Move first 4 characters of the keyword into the switch variable
*/
for( i = 0; i < 4; i++ )
code = ( (code << 8) + *(keyword+i) ) & 0xFFFFFFFF;
/*
// Handle the keywords individually
*/
switch( code ) {
case format: set_format(inputval, outputval);
break;
case table: set_table(inputval, outputval);
break;
case parameter: set_parameter(inputval, outputval);
break;
case truncation: set_truncation(inputval, outputval);
break;
case accuracy: set_accuracy(inputval, outputval);
break;
case grid: set_grid(inputval, outputval);
break;
case gaussian: set_gaussian(inputval, outputval);
break;
case area: set_area(inputval, outputval);
break;
case scan: set_scan(inputval, outputval);
break;
case reduced: set_reduced(inputval, outputval);
break;
case uselsm: set_uselsm(inputval, outputval);
break;
case usewind: set_usewind(inputval, outputval);
break;
case useprecip: set_useprecip(inputval, outputval);
break;
case lsm_param: set_lsm_param(inputval, outputval);
break;
default: printf("Invalid code: %x\n", code);
break;
}
}
}
return 0;
}
void set_format(char * inputval, char * outputval)
{
fortint p1, p_1 = 1, p_0 = 0;
p1 = NIFORM;
if ( strcmp( inputval, "grib") == 0 )
INIT_CM( &p1, &p_1);
else
INIT_CM( &p1, &p_0);
p1 = NOFORM;
if ( strcmp( outputval, "grib") == 0 )
INIT_CM( &p1, &p_1);
else
INIT_CM( &p1, &p_0);
return;
}
void set_table(char * inputval, char * outputval)
{
fortint p1, p2;
int q2;
p1 = NITABLE;
q2 = atoi( inputval );
p2 = (fortint) q2;
INIT_CM( &p1, &p2);
return;
}
void set_parameter(char * inputval, char * outputval)
{
fortint p1, p2;
int q2;
p1 = NIPARAM;
q2 = atoi( inputval );
p2 = (fortint) q2;
INIT_CM( &p1, &p2);
return;
}
void set_truncation(char * inputval, char * outputval)
{
fortint p1, p2;
int q2;
p1 = NIRESO;
q2 = atoi( inputval );
p2 = (fortint) q2;
INIT_CM( &p1, &p2);
p1 = NORESO;
q2 = atoi( outputval );
p2 = (fortint) q2;
INIT_CM( &p1, &p2);
return;
}
void set_accuracy(char * inputval, char * outputval)
{
fortint p1, p2;
int q2;
p1 = NOACC;
q2 = atoi( outputval );
p2 = (fortint) q2;
INIT_CM( &p1, &p2);
return;
}
void set_grid(char * inputval, char * outputval)
{
fortint p1,p2,p3;
int q2,q3;
p1 = NIGRID1;
sscanf( inputval, "%d/%d", &q2, &q3);
p2 = (fortint) q2;
p3 = (fortint) q3;
INIT_CM( &p1, &p2);
p1 = NIGRID2;
INIT_CM( &p1, &p3);
p1 = NOGRID1;
sscanf( outputval, "%d/%d", &q2, &q3);
p2 = (fortint) q2;
p3 = (fortint) q3;
INIT_CM( &p1, &p2);
p1 = NOGRID2;
INIT_CM( &p1, &p3);
return;
}
void set_gaussian(char * inputval, char * outputval)
{
fortint p1, p2;
int q2;
p1 = NIGAUSS;
q2 = atoi( inputval );
p2 = (fortint) q2;
INIT_CM( &p1, &p2);
p1 = NOGAUSS;
q2 = atoi( outputval );
p2 = (fortint) q2;
INIT_CM( &p1, &p2);
return;
}
void set_area(char * inputval, char * outputval)
{
fortint p1,p2,p3,p4,p5;
int q2, q3, q4, q5;
p1 = NIAREA1;
sscanf( inputval, "%d/%d/%d/%d", &q2, &q3,&q4,&q5);
p2 = (fortint) q2;
p3 = (fortint) q3;
p4 = (fortint) q4;
p5 = (fortint) q5;
INIT_CM( &p1, &p2);
p1 = NIAREA2;
INIT_CM( &p1, &p3);
p1 = NIAREA3;
INIT_CM( &p1, &p4);
p1 = NIAREA4;
INIT_CM( &p1, &p5);
p1 = NOAREA1;
sscanf( outputval, "%d/%d/%d/%d", &q2, &q3,&q4,&q5);
p2 = (fortint) q2;
p3 = (fortint) q3;
p4 = (fortint) q4;
p5 = (fortint) q5;
INIT_CM( &p1, &p2);
p1 = NOAREA2;
INIT_CM( &p1, &p3);
p1 = NOAREA3;
INIT_CM( &p1, &p4);
p1 = NOAREA4;
INIT_CM( &p1, &p5);
return;
}
void set_scan(char * inputval, char * outputval)
{
fortint p1, p2;
int q2;
p1 = NISCNM;
q2 = atoi( inputval );
p2 = (fortint) q2;
INIT_CM( &p1, &p2);
p1 = NOSCNM;
q2 = atoi( outputval );
p2 = (fortint) q2;
INIT_CM( &p1, &p2);
return;
}
void set_reduced(char * inputval, char * outputval)
{
fortint p1, p2;
p1 = NIREDU;
if ( strcmp( inputval, "standard" ) == 0 )
p2 = 1;
else
p2 = 0;
INIT_CM( &p1, &p2);
p1 = NOREDU;
if ( strcmp( outputval, "standard" ) == 0 )
p2 = 1;
else
p2 = 0;
INIT_CM( &p1, &p2);
return;
}
void set_uselsm(char * inputval, char * outputval)
{
fortint p1, p2;
p1 = LSM;
if ( strcmp( inputval, "yes" ) == 0 )
p2 = 1;
else
p2 = 0;
INIT_CM( &p1, &p2);
return;
}
void set_usewind(char * inputval, char * outputval)
{
fortint p1, p2;
p1 = LWIND;
if ( strcmp( inputval, "yes" ) == 0 )
p2 = 1;
else
p2 = 0;
INIT_CM( &p1, &p2);
return;
}
void set_useprecip(char * inputval, char * outputval)
{
fortint p1, p2;
p1 = LPREC;
if ( strcmp( inputval, "yes" ) == 0 )
p2 = 1;
else
p2 = 0;
INIT_CM( &p1, &p2);
return;
}
void set_lsm_param(char * inputval, char * outputval)
{
fortint p1, p2;
p1 = LSMPAR;
if ( strcmp( inputval, "yes" ) == 0 )
p2 = 1;
else
p2 = 0;
INIT_CM( &p1, &p2);
return;
}
|