²é¿´: 1467  |  »Ø¸´: 5

nenyan

Í­³æ (³õÈëÎÄ̳)


[½»Á÷] ¡¾ÇóÖú¡¿²ËÄñÇóÖúcÓïÑÔ¶ÁÎļþСÎÊÌâ

2 UGC12889 0.00047 47.27450 3.1 13.31 1.546 0.498 1.314 ~ 0.85 0.100 ~ -21.05 72.458 10.869 0.61 0.61  
4 PGC000004 0.00096 23.08764 5.0 15.39 0.851 0.078 0.186 ~ 0.219 0.015 ~ -18.68 63.264 13.918 0.39 0.40  
6 PGC000006 0.00058 15.88165 -1.0 15.23 0.457 0.169 0.324 ~ 0.708 0.082 ~ -19.46 84.181 18.520 0.34 0.35  
7 PGC000007 0.00122 -0.08326 -3.2 15.54 0.575 0.093 0.467 ~ 0.813 0.056 ~ -19.46 97.347 21.416 0.33 0.34  
10 PGC000010 0.00217 -0.04057 -3.2 15.56 0.562 0.078 0.446 ~ 0.794 0.037 ~ -19.46 98.250 21.615 0.29 0.31  
12 PGC000012 0.00240 -6.37390 1.1 14.05 1.045 0.336 0.199 ~ 0.19 0.022 ~ -20.79 92.153 13.823 0.36 0.37  

txtÎļþ£¬¸ñʽÈçÉÏ£¬¿Õ¸ñÊÇ·Ö¸ô·û¡£¶Á³öÆÚÖÐÁùÁÐ·Ö±æ´æÎªÊý×é¡£
ÎÒдµÄ³ÌÐòÈçÏ£º
Ìáʾ memory error22 £¨¾ÍÊÇÀ©Õ¹µÄʱºò³ö´íÁË¡££©¡£ÇëºÃÐÄÈ˰ï°ïæ¡£


#include
#include
#include
#define BUF 1024
#define pi 3.14159

/* The function reads stings from a txt file. Here, we read GWGCCatalog.txt.(see main function) */

int
readevent( FILE *pFile, int **pgc, char **name, double **rag, double **decg, double **absmag, double **dist)
{
void *pgc1, *name1, *rag1, *decg1, *absmag1, *dist1;
char *temp, *temp1; /* these two variables can be overwritten. */   
int i=0, n=1024; /* n is the buffer. */

if ( !(*pgc=(int *)malloc(n*sizeof(int)))||
  !(*name=(char *)malloc(n*100))||
  !(*rag=(double *)malloc(n*sizeof(double)))||
  !(*decg=(double *)malloc(n*sizeof(double)))||
  !(*absmag=(double *)malloc(n*sizeof(double)))||
  !(*dist=(double *)malloc(n*sizeof(double)))||
  !(temp=(char *)malloc(n*100)) ) /* assume the longth of all strings less than 300 */
printf("memory error11\n";

while (!feof(pFile))
{ fscanf(pFile, "%d %s %e %e %s %s %s %s %s %s %s %s %s %e %e %s %s %s", *pgc+i, *name+i*100, *rag+i, *decg+i, temp, temp, temp, temp, temp, temp, temp, temp, temp, *absmag+i, *dist+i, temp, temp, temp);
i++;
if (i==(n-1)) /*the number of lines is going to be longer than buffer. */
{
  if(!(pgc1=realloc(*pgc, 2*n*sizeof(int)))||
  !(name1=realloc(*name, 2*n*100))||
  !(rag1=realloc(*rag, 2*n*sizeof(double)))||
  !(decg1=realloc(*decg, 2*n*sizeof(double)))||
  !(absmag1=realloc(*absmag, 2*n*sizeof(double)))||
  !(dist1=realloc(*dist, 2*n*sizeof(double)))||
  !(temp1=realloc(temp, 2*n*100))) {
  printf("memory error22\n"; }
*pgc=pgc1;
*name=name1;
*rag=rag1;
*decg=decg1;
*absmag=absmag1;
*dist=dist1;
temp=temp1;
n*=2; } /*double the buffer*/
}   
free(temp);
return i; /* Returning i tell us the accurate number.*/
}


int
main()
{
int i, n; /* n is the number of lines in GWGCCatalog.txt. n1 is that in skymap.txt */
int *pgc;
char *name=NULL;
double *rag, *decg, *absmag, *dist;
FILE *pFile, *out;



if ( !( pFile=fopen("GWGCCatalog.txt", "r")) {
printf ("cannot open the GWGCCatalog.txt file\n";
return 1;}

if ( !( out=fopen("goutput.txt", "w")) {
printf ("cannot open the goutput.txt file\n";
return 1;}

n=readevent(pFile, &pgc, &name, &rag, &decg, &absmag, &dist);

for (i=0; i fprintf(out, "%d, %s, %e, %e, %e, %e \n", pgc, name+i*100, rag, decg, absmag, dist);


free(pgc);
free(name);
free(rag);
free(decg);
free(absmag);
free(dist);

fclose(pFile);
fclose(out);
}
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

» ±¾Ö÷ÌâÏà¹Ø¼ÛÖµÌùÍÆ¼ö£¬¶ÔÄúͬÑùÓаïÖú:

» ÇÀ½ð±ÒÀ²£¡»ØÌû¾Í¿ÉÒԵõ½:

²é¿´È«²¿É¢½ðÌù

ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
¡ï ¡ï ¡ï ¡ï ¡ï
ÓàÔó³É(½ð±Ò+5): лл²ÎÓëÓ¦Öú£¡ 2011-02-27 15:05:48
£¨1£©½¨ÒéÄúÈÏÕæ¿´¿´scanfº¯ÊýµÄ¶ÁÈ¡¸ñʽ£¨%ºóÃæÄǼ¸¸ö×Öĸ£©µÄº¬Òå¡£
Èç%*s£¬%*dµÈ¡£Ó¦¸ÃºÜ¼ò½à£¬ÄúдµÃÌ«......·±ËöÁË
£¨2£©Ö¸ÕëµÄ·ÖÅä¡¢ÊÍ·Å£¬Ó¦¸ÃÔÚͬһ¸öº¯ÊýÀï¡£
£¨3£©ÓÀÔ¶²»Òª¼ÙÉèÒª¶ÁÈ¡µÄÎļþÂú×ãÄúÏëÏóµÄ¸ñʽ
£¨4£©feof()²»ÄÜÕâôÓá£ÄúÄÜÕÒµ½µÄËùÓÐfeofÀý×Ó(°üÀ¨½Ì¿ÆÊé¡¢½Ì³Ì)£¬¼¸ºõ¶¼ÊÇ´íÎóµÄ¡£
2Â¥2011-02-24 11:47:13
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

bitgreen

½ð³æ (СÓÐÃûÆø)


¡ï ¡ï
ÓàÔó³É(½ð±Ò+2): лл²ÎÓëÓ¦Öú£¡ 2011-02-27 15:05:56
Èç¹û´¿´âÊý¾Ý´¦Àí£¬ÎÒͨ³£Ñ¡ÔñshellºÍmathematicaºÏÓ㬸ßЧʡÊÂ
3Â¥2011-02-24 12:09:25
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

nenyan

Í­³æ (³õÈëÎÄ̳)


ÒýÓûØÌû:
Originally posted by yalefield at 2011-02-24 11:47:13:
£¨1£©½¨ÒéÄúÈÏÕæ¿´¿´scanfº¯ÊýµÄ¶ÁÈ¡¸ñʽ£¨%ºóÃæÄǼ¸¸ö×Öĸ£©µÄº¬Òå¡£
Èç%*s£¬%*dµÈ¡£Ó¦¸ÃºÜ¼ò½à£¬ÄúдµÃÌ«......·±ËöÁË
£¨2£©Ö¸ÕëµÄ·ÖÅä¡¢ÊÍ·Å£¬Ó¦¸ÃÔÚͬһ¸öº¯ÊýÀï¡£
£¨3£©ÓÀÔ¶²»Òª¼ÙÉèÒª¶ÁÈ¡µÄÎļþÂú×ãÄúÏë ...

ÊÇ%*sÂð£¬ÄÄÀï¿ÉÒÔ²éµ½ÄØ¡£¸øÒ»¸ö½¨Òé°É¡£

Ö¸ÕëÔÚ×Óº¯ÊýÖоÍÊÍ·ÅÂ𣿺óÃæÖ÷º¯ÊýÖÐÖ±½Óµ±³ÉÊý×éÓþͿÉÒÔÁËÂð£¿

ÎļþÊDZ»ÎÒ´¦Àí³ÉÄǸö¸ñʽµÄ¡£¡£¡£
4Â¥2011-02-24 14:27:42
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

nenyan

Í­³æ (³õÈëÎÄ̳)


ÒýÓûØÌû:
Originally posted by bitgreen at 2011-02-24 12:09:25:
Èç¹û´¿´âÊý¾Ý´¦Àí£¬ÎÒͨ³£Ñ¡ÔñshellºÍmathematicaºÏÓ㬸ßЧʡÊÂ

ßÀ£¬mathematicaËÆºõ¶ÁÈëÊý¾ÝÒ²ºÜÂé·³¡£
5Â¥2011-02-24 14:28:31
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

bitgreen

½ð³æ (СÓÐÃûÆø)


¡ï ¡ï ¡ï ¡ï ¡ï
ÓàÔó³É(½ð±Ò+5): лл²ÎÓëÓ¦Öú£¡ 2011-02-27 15:06:14
nenyan(½ð±Ò+5): ²»´í²»´í 2011-02-28 07:35:09
ÒýÓûØÌû:
Originally posted by nenyan at 2011-02-24 14:28:31:
ßÀ£¬mathematicaËÆºõ¶ÁÈëÊý¾ÝÒ²ºÜÂé·³¡£

ºÇºÇ£¬²»Âé·³¡£±ÈÈçÄãÉÏÃæµÄÊý¾Ý¿ÉÒÔÓÃbash shell ºÜÈÝÒ×д³ÉmathematicaµÄÊäÈëÐÎʽ
{
{1,2,3,4,5,6,7,¡­¡­},
{1,2,3,4,5,6,7,¡­¡­},
.
.
.
.
{1,2,3,4,5,6,7,¡­¡­},
{1,2,3,4,5,6,7,¡­¡­}
}
È»ºóÓÃmathematicaµÄGetÀ´¶ÁÈ룬mathematicaÓÐÒ»´ó¶Ñ¹¦ÄÜÇ¿´óµÄº¯ÊýÀ´´¦ÀíÊý¾Ý£¬·Ç³£¸ßЧ£¬ºÇºÇ¡£
±ÈÈçÄãµÄÊý¾ÝÎļþÃûΪurfile
1)##ÒÔÏÂÃüÁîÐÐÈÃÊý¾ÝÒÔ¶ººÅΪ¼ä¸ô£¬´æ³Éurfile_for_Ma
cat urfile |awk '{$1=$1;print}'|sed 's/ /,/g' >urfile_for_Ma

2£©##ÒÔÏÂÃüÁî¸øÊý¾ÝÐÐÌí¼Ó{}
sed -i 's/^/{/'  urfile_for_Ma  #¸øËùÓÐÊý¾ÝÐÐÊ×Ìí¼Ó{
sed -i 's/$/},/'  urfile_for_Ma  #Êý¾ÝÐÐĩβÌí¼Ó},
sed -i '1s/^/{/' urfile_for_Ma  #µÚÒ»ÐÐÊ×ÔÙ¼Ó¸ö{
sed -i '$s/,$/}/' urfile_for_Ma  #×îºóÒ»ÐÐÐÐβµÄ¡°,¡±»»³É¡°}¡±


¸ã¶¨¡£¿ÉÒÔÓÃmathematicaÀ´´¦ÀíÁË¡£

p.s.:
µ±È»¿ÉÒÔ°ÑÕâЩÃüÁî·ÅÒ»¸ö½Å±¾ÎļþÀï±ÈÈç½Ðform_change£¬Ö´ÐÐһϾÍokÁË.
Ä㻹¿ÉÒÔÔڽű¾ÀﶨÒå±äÁ¿
urfile=$1
È»ºóÔÙµ÷ÓÃ$urfileÕâ¸ö±äÁ¿£¬ÕâÑùÄã¾Í¿ÉÒÔÓÃform_change urfileÀ´Ö´ÐУ¬²»ÓÃÿ´Î´¦Àí²»Í¬µÄÎļþ¶¼Òª¸Ä½Å±¾ÎļþÀïµÄÎļþÃû£¬Ê¡Êºܶà

[ Last edited by bitgreen on 2011-2-25 at 05:17 ]
6Â¥2011-02-25 05:16:26
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ nenyan µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[»ù½ðÉêÇë] Ϊʲô×ÊÖúÊý¸÷´ó¸ßУ¶¼´´Ð¸ߣ¬×Ô¼ºÉêÇëÔõô¾ÍÕâôÄÑ +8 Kittylucky 2026-08-27 8/400 2026-08-27 18:33 by raiy123
[½Ìʦ֮¼Ò] µ¼Ê¦Í²ۣºÎÒÔõô̯ÉÏÁËÕâô¸ö¼«Æ·Ñо¿Éú£¡ +7 ËÕ¶«ÆÂ¶þÊÀ 2026-08-23 7/350 2026-08-27 18:14 by ˲ϢÓîÖæ
[»ù½ðÉêÇë] Çà»ùÈçºÎÆÆ¾Ö +6 lyz123lyz 2026-08-27 7/350 2026-08-27 17:31 by Äþ¾²ÖÂÔ¶sy
[»ù½ðÉêÇë] ¹ú×ÔÈ»ÃæÉϸ´ÅÌ~»¶Ó­ÌÖÂÛ (½ð±Ò+5) +10 ÇçÌì¼ÓÓÍ 2026-08-26 11/550 2026-08-27 16:35 by msuhlx
[»ù½ðÉêÇë] »ù½ðδÖУ¬ÕâÖÖ´ð¸´ÊÇÄ£°åÂ𣿠+5 zhaosm1982 2026-08-27 6/300 2026-08-27 16:00 by lfy8008
[½Ìʦ֮¼Ò] ÊÛSCIÒ»ÇøÎÄÕ£¬ÎÒ:8.O.551.O.5.4,¿ÆÄ¿È«,¿ÉÙ¤¼± +3 LIbGuocjEEYw 2026-08-26 4/200 2026-08-27 04:33 by Ie9AyIAvGbvs
[»ù½ðÉêÇë] 2026Äê8ÔÂ25ÈÕ¹ú×ÔÈ»·Å°ñǰͻȻÊÕµ½ÁÐÈëÆÀÉóר¼ÒÓʼþ£¬ÓйØÏµÂ𣿠+25 ľˮ˼¶¹ 2026-08-25 28/1400 2026-08-26 14:53 by draco1987
[»ù½ðÉêÇë] Ϊʲô¹ú×ÔÈ»²»ÄÜÖ±½Ó¹«²¼ +4 bjdxyxy 2026-08-26 4/200 2026-08-26 13:12 by qingmu1201
[»ù½ðÉêÇë] ¹úºÏÀïÃæÄÜ¿´µ½ÁË +7 Ò»»³Ü°Çï 2026-08-26 7/350 2026-08-26 11:23 by zhaosm1982
[»ù½ðÉêÇë] ÏîÄ¿ÐÅÏ¢ºÍ¾­·ÑÐÅÏ¢ÔÚϵͳÀï¶¼¿ÉÒÔ¿´µ½ÁË +6 wittyboy 2026-08-26 14/700 2026-08-26 10:55 by wittyboy
[»ù½ðÉêÇë] ¹úºÏ¿É²éÁË +3 paperzjh 2026-08-26 3/150 2026-08-26 10:41 by LemmonTr
[Ö°³¡ÈËÉú] ѧÉúײ¼û¸¨µ¼Ô±ËÍÍâÂô£¬µÚ¶þÌìÈ«°à¶¼³ÁĬÁË +3 ¾¨ÓãÈÚ½ð_Õã½­_É 2026-08-22 3/150 2026-08-26 09:01 by zzuzxg
[»ù½ðÉêÇë] ¹úºÏÏÖÔڲ鲻µ½ÁËÂ𣿠+10 chengyan1220 2026-08-24 20/1000 2026-08-26 08:57 by peasantsprig
[»ù½ðÉêÇë] Å£À´£¡Ã×À´£¡ÃæÀ´£¡ +8 beefly 2026-08-26 8/400 2026-08-26 08:37 by xuzhipiao
[»ù½ðÉêÇë] ÔÚ¼á±ù»¹¸Ç×ű±º£µÄʱºò£¬ÎÒ¿´µ½ÁËÅ­·ÅµÄ÷»¨¡£ (½ð±Ò+10) +6 ziyangfang 2026-08-25 9/450 2026-08-25 20:26 by huagongfeihu
[»ù½ðÉêÇë] Ã÷ÌìÓ¦¸Ã¿É²éÁË£¡£¿ +6 chengyan1220 2026-08-23 6/300 2026-08-25 19:45 by zfd97
[»ù½ðÉêÇë] ijЩ»ú¹¹£¬ÒÔЧÂʵÍΪÈÙ£¬ÒÔЧÂʵÍ×÷Ϊ´æÔڸР+9 yuleib84 2026-08-25 10/500 2026-08-25 17:14 by alexon
[½Ìʦ֮¼Ò] Ìø²ÛºóÔÚÑÐÏîÄ¿Ôõô°ì£¿ +5 ¼òµ¥»¯xn 2026-08-22 10/500 2026-08-23 12:38 by ¼òµ¥»¯xn
[»ù½ðÉêÇë] ʱ¼ä´Á½ñÌ죬20ºÅ±äÁË +5 archvillain 2026-08-20 5/250 2026-08-22 06:12 by hui_daxiao
[»ù½ðÉêÇë] Ó¦¸ÃÊÇÏÂÖÜÈý26ÈÕ¹«²¼Á˰ɣ¿ +4 ¹þ¹þ¸ò£¿ 2026-08-21 4/200 2026-08-21 10:58 by Vivilian
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û