爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 11646|回复: 9

wrf write_geogrid.c编译问题

[复制链接]
发表于 2015-6-8 21:51:55 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
大型机 linux编译 write_geogrid.c 总是提示

[huser037@login src]$ gcc write_geogrid.c

write_geogrid.c:27:1: warning: "BIG_ENDIAN" redefined
In file included from /usr/include/bits/waitstatus.h:65,
                 from /usr/include/stdlib.h:43,
                 from write_geogrid.c:16:
/usr/include/endian.h:47:1: warning: this is the location of the previous definition
write_geogrid.c:28:1: warning: "LITTLE_ENDIAN" redefined
/usr/include/endian.h:46:1: warning: this is the location of the previous definition
write_geogrid.c: In function ?.rite_geogrid?.
write_geogrid.c:102: warning: left shift count >= width of type
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

这个代码是:/* File: write_geogrid.c
   Sample subroutine to write an array into the geogrid binary format.
   Side effects: Upon completion, a file named 00001-<NX>.00001-<NY> is
   created, where <NX> is the argument nx and <NY> is the argument ny,
   both in i5.5 format.
  
   Notes: Depending on the compiler and compiler flags, the name of
   the write_geogrid() routine may need to be adjusted with respect
   to the number of trailing underscores when calling from Fortran.
   Michael G. Duda, NCAR/MMM
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef _UNDERSCORE
#define write_geogrid write_geogrid_
#endif
#ifdef _DOUBLEUNDERSCORE
#define write_geogrid write_geogrid__
#endif
#define BIG_ENDIAN    0
#define LITTLE_ENDIAN 1
int write_geogrid(
      float * rarray,          /* The array to be written */
      int * nx,                /* x-dimension of the array */
      int * ny,                /* y-dimension of the array */
      int * nz,                /* z-dimension of the array */
      int * isigned,           /* 0=unsigned data, 1=signed data */
      int * endian,            /* 0=big endian, 1=little endian */
      float * scalefactor,     /* value to divide array elements by before truncation to integers */
      int * wordsize )         /* number of bytes to use for each array element */
{
   int i, narray;
   int A2, B2;
   int A3, B3, C3;
   int A4, B4, C4, D4;
   unsigned int * iarray;
   unsigned char * barray;
   char fname[24];
   FILE * bfile;
   narray = (*nx) * (*ny) * (*nz);
   iarray = (unsigned int *)malloc(sizeof(int) * narray);
   barray = (unsigned char *)malloc(sizeof(unsigned char) * narray * (*wordsize));
   /* Scale real-valued array by scalefactor and convert to integers */
   for (i=0; i<narray; i++)
      iarray[i] = (unsigned int)(rarray[i] / (*scalefactor));
   /*
      Set up byte offsets for each wordsize depending on byte order.
      A, B, C, D give the offsets of the LSB through MSB (i.e., for
      word ABCD, A=MSB, D=LSB) in the array from the beginning of a word
   */
   if (*endian == BIG_ENDIAN) {
      A2 = 0; B2 = 1;
      A3 = 0; B3 = 1; C3 = 2;
      A4 = 0; B4 = 1; C4 = 2; D4 = 3;
   }
   else {
      B2 = 0; A2 = 1;
      C3 = 0; B3 = 1; A3 = 2;
      D4 = 0; C4 = 1; B4 = 2; A4 = 3;
   }
   /* Place words into storage byte order */
   switch(*wordsize) {
      case 1:
         for(i=0; i<narray; i++) {
            if (iarray[i] < 0 && *isigned) iarray[i] += (1 << 8);
            barray[(*wordsize)*i] = (unsigned char)(iarray[i] & 0xff);
         }
         break;
      case 2:
         for(i=0; i<narray; i++) {
            if (iarray[i] < 0 && *isigned) iarray[i] += (1 << 16);
            barray[(*wordsize)*i+A2] = (unsigned char)((iarray[i] >> 8) & 0xff);
            barray[(*wordsize)*i+B2] = (unsigned char)( iarray[i]       & 0xff);
         }
         break;
      case 3:
         for(i=0; i<narray; i++) {
            if (iarray[i] < 0 && *isigned) iarray[i] += (1 << 24);
            barray[(*wordsize)*i+A3] = (unsigned char)((iarray[i] >> 16) & 0xff);
            barray[(*wordsize)*i+B3] = (unsigned char)((iarray[i] >> 8)  & 0xff);
            barray[(*wordsize)*i+C3] = (unsigned char)( iarray[i]        & 0xff);
         }
         break;
      case 4:
         for(i=0; i<narray; i++) {
            if (iarray[i] < 0 && *isigned) iarray[i] += (1 << 32);
            barray[(*wordsize)*i+A4] = (unsigned char)((iarray[i] >> 24) & 0xff);
            barray[(*wordsize)*i+B4] = (unsigned char)((iarray[i] >> 16) & 0xff);
            barray[(*wordsize)*i+C4] = (unsigned char)((iarray[i] >> 8)  & 0xff);
            barray[(*wordsize)*i+D4] = (unsigned char)( iarray[i]        & 0xff);
         }
         break;
   }
   sprintf(fname,"%5.5i-%5.5i.%5.5i-%5.5i",1,*nx,1,*ny);
   /* Write array to file */
   bfile = fopen(fname,"wb");
   fwrite(barray,sizeof(unsigned char),narray*(*wordsize),bfile);
   fclose(bfile);
   free(iarray);
   free(barray);
   return 0;
}


不知问题出在了什么地方 请各位大侠赐教
密码修改失败请联系微信:mofangbao
发表于 2015-10-23 17:36:03 | 显示全部楼层
楼主这个问题解决了吗?
密码修改失败请联系微信:mofangbao
发表于 2016-3-31 18:09:10 | 显示全部楼层
想问楼主问题解决了吗?遇到了同样的问题
密码修改失败请联系微信:mofangbao
发表于 2016-3-31 18:15:59 | 显示全部楼层
楼主问题解决了吗?我的编译也出现这个错误
密码修改失败请联系微信:mofangbao
发表于 2017-2-17 13:13:20 | 显示全部楼层
快乐的小太阳 发表于 2016-3-31 18:15
楼主问题解决了吗?我的编译也出现这个错误

能问一下qq吗?想请教一些WRF 的问题
密码修改失败请联系微信:mofangbao
发表于 2017-7-18 15:54:16 | 显示全部楼层
我也是这个问题,有人知道为什么嘛
密码修改失败请联系微信:mofangbao
发表于 2017-8-15 14:51:25 | 显示全部楼层
放逐流年 发表于 2017-2-17 13:13
能问一下qq吗?想请教一些WRF 的问题

请问您解决这个问题了吗
密码修改失败请联系微信:mofangbao
发表于 2019-9-18 17:07:20 | 显示全部楼层
同样遇到这个问题
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

发表于 2021-1-8 18:01:03 | 显示全部楼层
虽然这个问题好久了,提供一个解决思路:read_geogrid.c 被WPS的geogrid.exe调用,它和write_geogrid.c功能相反,一个是读一个是写。因此可以在编译WPS的时候把编译信息写入log文件,在log文件中看一下read_geogrid.c 是怎么编译的,然后仿照着编译write_geogrid.c和自己写的fortran文件。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

发表于 2021-12-30 15:29:24 | 显示全部楼层
lion125 发表于 2021-1-8 18:01
虽然这个问题好久了,提供一个解决思路:read_geogrid.c 被WPS的geogrid.exe调用,它和write_geogrid.c功能 ...

这个思路非常有用,似乎已经编译成功了
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表